cmd

package
v1.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChpasswdCmd = &cobra.Command{
	Use:     "chpasswd",
	Short:   "Force change password",
	Long:    `Force change password`,
	Example: `sonar chpasswd -p <password>`,
	Run: func(cmd *cobra.Command, args []string) {
		if NewPassword == "" {
			cmd.Help()
			return
		}
		if _, err := os.Stat(dbcore.DatabaseFile); errors.Is(err, fs.ErrNotExist) {
			cmd.Println("Database file does not exist.")
			return
		}
		user, err := auth.GetFirstUser()
		if err != nil {
			cmd.Println("Error:", err)
			return
		}
		cmd.Println("Changing password for user:", user.Username)
		if err := auth.ForceResetPassword(user.Username, NewPassword); err != nil {
			cmd.Println("Error:", err)
			return
		}
		cmd.Println("Password changed successfully, new password:", NewPassword)

		if err := auth.DeleteAllSessions(); err != nil {
			cmd.Println("Unable to force logout of other devices:", err)
			return
		}

		cmd.Println("Please restart the server to apply the changes.")
	},
}
View Source
var Disable2FA = &cobra.Command{
	Use:   "disable-2fa",
	Short: "Force disable 2FA",
	Long:  `Force disable 2FA`,
	Run: func(cmd *cobra.Command, args []string) {
		if err := auth.ForceDisableAllTwoFactor(); err != nil {
			cmd.Println("Error:", err)
			os.Exit(1)
		}
		cmd.Println("2FA has been disabled.")
		cmd.Println("Please restart the server to apply the changes.")
	},
}
View Source
var (
	//Username    string
	NewPassword string
)
View Source
var PermitPasswordLoginCmd = &cobra.Command{
	Use:   "permit-login",
	Short: "Force permit password login",
	Long:  `Force permit password login`,
	Run: func(cmd *cobra.Command, args []string) {
		dbcore.GetDBInstance()
		if err := kv.Set(settings.DisablePasswordLoginKey, false); err != nil {
			cmd.Println("Error:", err)
			os.Exit(1)
		}
		cmd.Println("Password login has been permitted.")
		cmd.Println("Please restart the server to apply the changes.")
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "sonar",
	Short: "Sonar is a simple, lightweight server monitoring tool",
	Long:  `Sonar is a simple, lightweight server monitoring tool.`,
	Run: func(cmd *cobra.Command, args []string) {
		cmd.SetArgs([]string{"server"})
		cmd.Execute()
	},
}
View Source
var ServerCmd = &cobra.Command{
	Use:   "server",
	Short: "Start the server",
	Long:  `Start the server`,
	Run: func(cmd *cobra.Command, args []string) {
		app.Start(listen)
	},
}

Functions

func Execute

func Execute()

func GetEnv

func GetEnv(key, defaultValue string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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