cmd

package
v1.6.26 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 17 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: `komari chpasswd -p <password>`,
	Run: func(cmd *cobra.Command, args []string) {
		if NewPassword == "" {
			cmd.Help()
			return
		}
		if _, err := os.Stat(flags.DatabaseFile); os.IsNotExist(err) {
			cmd.Println("Database file does not exist.")
			return
		}
		user := &models.User{}
		dbcore.GetDBInstance().Model(&models.User{}).First(user)
		cmd.Println("Changing password for user:", user.Username)
		if err := accounts.ForceResetPassword(user.Username, NewPassword); err != nil {
			cmd.Println("Error:", err)
			return
		}
		cmd.Println("Password changed successfully, new password:", NewPassword)

		if err := accounts.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) {
		db := dbcore.GetDBInstance()
		err := db.Transaction(func(tx *gorm.DB) error {
			return tx.Model(&models.User{}).Where("two_factor != ?", "").
				Update("two_factor", "").Error
		})
		if 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 NetcheckCmd = &cobra.Command{
	Use:   "netcheck <host[:port]>",
	Short: "探测目标的 ICMP/TCP 可达性并给出监测任务类型建议",
	Long: `netcheck 会在当前机器上对一个目标做多协议探测:
  · DNS 解析(A / AAAA)
  · ICMP ping
  · TCP 连接(默认 22/80/443)
然后给出结论:该目标适合用 icmp、还是必须用 tcp(以及端口)。

典型用途:在配置延迟监测任务前,先确认目标答应哪种协议。
注意:结论反映的是【当前这台机器】的可达性。`,
	Args: cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var ports []int
		for _, s := range strings.Split(ncPorts, ",") {
			if v, err := strconv.Atoi(strings.TrimSpace(s)); err == nil && v > 0 && v <= 65535 {
				ports = append(ports, v)
			}
		}
		rep := netcheck.Run(args[0], netcheck.Options{
			Ports:    ports,
			Count:    ncCount,
			Timeout:  ncTimeout,
			SkipICMP: ncNoICMP,
		})
		if ncJSON {
			b, _ := json.MarshalIndent(rep, "", "  ")
			fmt.Println(string(b))
			return
		}
		printReport(rep)
	},
}
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 := config.Set(config.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:   "Nekomari",
	Short: "Nekomari is a simple server monitoring tool",
	Long: `Nekomari is a simple server monitoring tool. 
Made by Akizon77 with love.`,
	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) {
		RunServer()
	},
}

Functions

func Execute

func Execute()

func GetEnv

func GetEnv(key, defaultValue string) string

func RunServer

func RunServer()

RunServer 按显式的生命周期阶段启动服务端。

具体各阶段的职责与顺序见 internal/server.App。这里只负责串联: 任一初始化阶段失败即中止启动,避免在半初始化状态下对外提供服务。

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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