cmd

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiKey = &cobra.Command{
	Use:   "key",
	Short: "Returns the host API key",
	Run: func(cmd *cobra.Command, args []string) {
		var password string
		fmt.Print("Enter password: ")
		fmt.Println("\033[8m")
		fmt.Scan(&password)
		fmt.Println("\033[28m")
		user := database.GetUserByID("1")

		if utils.PasswordHash(password) == user.Password {
			fmt.Println("Your api key is:", user.Apikey)
		} else {
			fmt.Println("Wrong password.")
		}
	},
}
View Source
var Passwd = &cobra.Command{
	Use:   "passwd",
	Short: "Changes current password.",
	Run: func(cmd *cobra.Command, args []string) {
		var currentPassword string
		var newPassword string
		var newPasswordRepeat string
		fmt.Print("Enter current password: ")
		fmt.Println("\033[8m")
		fmt.Scan(&currentPassword)
		fmt.Println("\033[28m")
		user := database.GetUserByID("1")

		if utils.PasswordHash(currentPassword) == user.Password {
			fmt.Print("Enter a new password: ")
			fmt.Println("\033[8m")
			fmt.Scan(&newPassword)
			fmt.Println("\033[28m")
			fmt.Print("Repeat your new password: ")
			fmt.Println("\033[8m")
			fmt.Scan(&newPasswordRepeat)
			fmt.Println("\033[28m")
			if newPassword == newPasswordRepeat {
				user := models.User{Password: utils.PasswordHash(newPassword), Apikey: user.Apikey}
				err := database.SetUserData("1", user)
				if err != nil {
					fmt.Println(err)
				}
				fmt.Println("Password changed succesfully!")
			} else {
				fmt.Println("Passwords don't match")

			}

		} else {
			fmt.Println("Wrong password.")
		}
	},
}
View Source
var QrCode = &cobra.Command{
	Use:   "qr",
	Short: "Prints host QR Code.",
	Run: func(cmd *cobra.Command, args []string) {
		var password string
		fmt.Print("Enter password: ")
		fmt.Println("\033[8m")
		fmt.Scan(&password)
		fmt.Println("\033[28m")
		user := database.GetUserByID("1")

		if utils.PasswordHash(password) == user.Password {
			hostInfo := models.HostInfo{
				Name:        host.Info().Name,
				Description: host.Info().Platform + "/" + host.Info().Arch,
				IP:          utils.GetLocalIP(),
				Port:        utils.GetLocalPort(),
				Key:         database.GetApiKey(),
			}

			hostInfoJSON, err := json.Marshal(hostInfo)
			if err != nil {
				fmt.Println(err)
			}

			config := qrterminal.Config{
				Level:     qrterminal.M,
				Writer:    os.Stdout,
				BlackChar: qrterminal.WHITE,
				WhiteChar: qrterminal.BLACK,
				QuietZone: 2,
			}
			qrterminal.GenerateWithConfig(string(hostInfoJSON), config)

		} else {
			fmt.Println("Wrong password.")
		}
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number of nitr",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("Nitr v%v", version.Version)
	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL