Documentation ¶
Overview ¶
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Package cmd Copyright © 2022 Noah Hsu<i@nn.ci>
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AdminCmd = &cobra.Command{ Use: "admin", Aliases: []string{"password"}, Short: "Show admin user's info and some operations about admin user's password", Run: func(cmd *cobra.Command, args []string) { Init() defer Release() admin, err := op.GetAdmin() if err != nil { utils.Log.Errorf("failed get admin user: %+v", err) } else { utils.Log.Infof("Admin user's username: %s", admin.Username) utils.Log.Infof("The password can only be output at the first startup, and then stored as a hash value, which cannot be reversed") utils.Log.Infof("You can reset the password with a random string by running [alist admin random]") utils.Log.Infof("You can also set a new password by running [alist admin set NEW_PASSWORD]") } }, }
AdminCmd represents the password command
View Source
var Cancel2FACmd = &cobra.Command{ Use: "cancel2fa", Short: "Delete 2FA of admin user", Run: func(cmd *cobra.Command, args []string) { Init() defer Release() admin, err := op.GetAdmin() if err != nil { utils.Log.Errorf("failed to get admin user: %+v", err) } else { err := op.Cancel2FAByUser(admin) if err != nil { utils.Log.Errorf("failed to cancel 2FA: %+v", err) } else { utils.Log.Info("2FA canceled") DelAdminCacheOnline() } } }, }
Cancel2FACmd represents the delete2fa command
View Source
var LangCmd = &cobra.Command{ Use: "lang", Short: "Generate language json file", Run: func(cmd *cobra.Command, args []string) { err := os.MkdirAll("lang", 0777) if err != nil { utils.Log.Fatal("failed create folder: %s", err.Error()) } generateDriversJson() generateSettingsJson() }, }
LangCmd represents the lang command
View Source
var RandomPasswordCmd = &cobra.Command{ Use: "random", Short: "Reset admin user's password to a random string", Run: func(cmd *cobra.Command, args []string) { newPwd := random.String(8) setAdminPassword(newPwd) }, }
View Source
var RestartCmd = &cobra.Command{ Use: "restart", Short: "Restart alist server by daemon/pid file", Run: func(cmd *cobra.Command, args []string) { stop() start() }, }
RestartCmd represents the restart command
View Source
var RootCmd = &cobra.Command{
Use: "alist",
Short: "A file list program that supports multiple storage.",
Long: `A file list program that supports multiple storage,
built with love by Xhofe and friends in Go/Solid.js.
Complete documentation is available at https://alist.nn.ci/`,
}
View Source
var ServerCmd = &cobra.Command{ Use: "server", Short: "Start the server at the specified address", Long: `Start the server at the specified address the address is defined in config file`, Run: func(cmd *cobra.Command, args []string) { Init() if conf.Conf.DelayedStart != 0 { utils.Log.Infof("delayed start for %d seconds", conf.Conf.DelayedStart) time.Sleep(time.Duration(conf.Conf.DelayedStart) * time.Second) } bootstrap.InitOfflineDownloadTools() bootstrap.LoadStorages() bootstrap.InitTaskManager() if !flags.Debug && !flags.Dev { gin.SetMode(gin.ReleaseMode) } r := gin.New() r.Use(gin.LoggerWithWriter(log.StandardLogger().Out), gin.RecoveryWithWriter(log.StandardLogger().Out)) server.Init(r) var httpSrv, httpsSrv, unixSrv *http.Server if conf.Conf.Scheme.HttpPort != -1 { httpBase := fmt.Sprintf("%s:%d", conf.Conf.Scheme.Address, conf.Conf.Scheme.HttpPort) utils.Log.Infof("start HTTP server @ %s", httpBase) httpSrv = &http.Server{Addr: httpBase, Handler: r} go func() { err := httpSrv.ListenAndServe() if err != nil && !errors.Is(err, http.ErrServerClosed) { utils.Log.Fatalf("failed to start http: %s", err.Error()) } }() } if conf.Conf.Scheme.HttpsPort != -1 { httpsBase := fmt.Sprintf("%s:%d", conf.Conf.Scheme.Address, conf.Conf.Scheme.HttpsPort) utils.Log.Infof("start HTTPS server @ %s", httpsBase) httpsSrv = &http.Server{Addr: httpsBase, Handler: r} go func() { err := httpsSrv.ListenAndServeTLS(conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile) if err != nil && !errors.Is(err, http.ErrServerClosed) { utils.Log.Fatalf("failed to start https: %s", err.Error()) } }() } if conf.Conf.Scheme.UnixFile != "" { utils.Log.Infof("start unix server @ %s", conf.Conf.Scheme.UnixFile) unixSrv = &http.Server{Handler: r} go func() { listener, err := net.Listen("unix", conf.Conf.Scheme.UnixFile) if err != nil { utils.Log.Fatalf("failed to listen unix: %+v", err) } mode, err := strconv.ParseUint(conf.Conf.Scheme.UnixFilePerm, 8, 32) if err != nil { utils.Log.Errorf("failed to parse socket file permission: %+v", err) } else { err = os.Chmod(conf.Conf.Scheme.UnixFile, os.FileMode(mode)) if err != nil { utils.Log.Errorf("failed to chmod socket file: %+v", err) } } err = unixSrv.Serve(listener) if err != nil && !errors.Is(err, http.ErrServerClosed) { utils.Log.Fatalf("failed to start unix: %s", err.Error()) } }() } if conf.Conf.S3.Port != -1 && conf.Conf.S3.Enable { s3r := gin.New() s3r.Use(gin.LoggerWithWriter(log.StandardLogger().Out), gin.RecoveryWithWriter(log.StandardLogger().Out)) server.InitS3(s3r) s3Base := fmt.Sprintf("%s:%d", conf.Conf.Scheme.Address, conf.Conf.S3.Port) utils.Log.Infof("start S3 server @ %s", s3Base) go func() { var err error if conf.Conf.S3.SSL { httpsSrv = &http.Server{Addr: s3Base, Handler: s3r} err = httpsSrv.ListenAndServeTLS(conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile) } if !conf.Conf.S3.SSL { httpSrv = &http.Server{Addr: s3Base, Handler: s3r} err = httpSrv.ListenAndServe() } if err != nil && !errors.Is(err, http.ErrServerClosed) { utils.Log.Fatalf("failed to start s3 server: %s", err.Error()) } }() } quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit utils.Log.Println("Shutdown server...") Release() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() var wg sync.WaitGroup if conf.Conf.Scheme.HttpPort != -1 { wg.Add(1) go func() { defer wg.Done() if err := httpSrv.Shutdown(ctx); err != nil { utils.Log.Fatal("HTTP server shutdown err: ", err) } }() } if conf.Conf.Scheme.HttpsPort != -1 { wg.Add(1) go func() { defer wg.Done() if err := httpsSrv.Shutdown(ctx); err != nil { utils.Log.Fatal("HTTPS server shutdown err: ", err) } }() } if conf.Conf.Scheme.UnixFile != "" { wg.Add(1) go func() { defer wg.Done() if err := unixSrv.Shutdown(ctx); err != nil { utils.Log.Fatal("Unix server shutdown err: ", err) } }() } wg.Wait() utils.Log.Println("Server exit") }, }
ServerCmd represents the server command
View Source
var SetPasswordCmd = &cobra.Command{ Use: "set", Short: "Set admin user's password", Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { utils.Log.Errorf("Please enter the new password") return } setAdminPassword(args[0]) }, }
View Source
var ShowTokenCmd = &cobra.Command{ Use: "token", Short: "Show admin token", Run: func(cmd *cobra.Command, args []string) { Init() defer Release() token := setting.GetStr(conf.Token) utils.Log.Infof("Admin token: %s", token) }, }
View Source
var StartCmd = &cobra.Command{ Use: "start", Short: "Silent start alist server with `--force-bin-dir`", Run: func(cmd *cobra.Command, args []string) { start() }, }
StartCmd represents the start command
View Source
var StopCmd = &cobra.Command{ Use: "stop", Short: "Stop alist server by daemon/pid file", Run: func(cmd *cobra.Command, args []string) { stop() }, }
StopCmd represents the stop command
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Show current version of AList", Run: func(cmd *cobra.Command, args []string) { fmt.Printf(`Built At: %s Go Version: %s Author: %s Commit ID: %s Version: %s WebVersion: %s `, conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.Version, conf.WebVersion) os.Exit(0) }, }
VersionCmd represents the version command
Functions ¶
func DelAdminCacheOnline ¶
func DelAdminCacheOnline()
func DelUserCacheOnline ¶
func DelUserCacheOnline(username string)
Types ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.