diff --git a/docs/faq.md b/docs/faq.md index 49f14f0..fda1bc1 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -58,4 +58,33 @@ docker rm -f 2. 原生:使用golang+xterm.js方式实现的webssh,传输协议是文本,操作响应更快。但目前尚未实现实时监控。 3. guacd:Apache Guacamole包装了一层的ssh协议,支持实时监控,录屏播放更加统一。但某些密钥不支持。 - \ No newline at end of file + + +
+ 系统密码忘记了怎么办? +首先需要进入程序所在目录,使用docker安装的程序目录为:/usr/local/next-terminal + +执行命令 + +```shell +./next-terminal --reset-password admin +``` + +其中 admin 为用户登录账号,成功之后会输出 + +``` shell + + _______ __ ___________ .__ .__ + \ \ ____ ___ ____/ |_ \__ ___/__________ _____ |__| ____ _____ | | + / | \_/ __ \\ \/ /\ __\ | |_/ __ \_ __ \/ \| |/ \\__ \ | | +/ | \ ___/ > < | | | |\ ___/| | \/ Y Y \ | | \/ __ \| |__ +\____|__ /\___ >__/\_ \ |__| |____| \___ >__| |__|_| /__|___| (____ /____/ + \/ \/ \/ \/ \/ \/ \/ v0.3.0 + +当前数据库模式为:mysql +Mar 5 20:00:16.923 [DEBU] 用户「admin」密码初始化为: next-terminal + +``` + +
+ diff --git a/main.go b/main.go index 0d4cbf5..073802c 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,10 @@ import ( const Version = "v0.3.0" func main() { - log.Fatal(Run()) + err := Run() + if err != nil { + log.Fatal(err) + } } func Run() error { @@ -85,6 +88,24 @@ func Run() error { return err } + if global.Config.ResetPassword != "" { + user, err := model.FindUserByUsername(global.Config.ResetPassword) + if err != nil { + return err + } + password := "next-terminal" + passwd, err := utils.Encoder.Encode([]byte(password)) + if err != nil { + return err + } + u := &model.User{ + Password: string(passwd), + } + model.UpdateUserById(u, user.ID) + logrus.Debugf("用户「%v」密码初始化为: %v", user.Username, password) + return nil + } + if err := global.DB.AutoMigrate(&model.User{}); err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index 23d21a8..fe9cceb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,10 +8,11 @@ import ( ) type Config struct { - DB string - Server *Server - Mysql *Mysql - Sqlite *Sqlite + DB string + Server *Server + Mysql *Mysql + Sqlite *Sqlite + ResetPassword string } type Mysql struct { @@ -53,6 +54,7 @@ func SetupConfig() (*Config, error) { pflag.String("server.addr", "", "server listen addr") pflag.String("server.cert", "", "tls cert file") pflag.String("server.key", "", "tls key file") + pflag.String("reset-password", "", "") pflag.Parse() _ = viper.BindPFlags(pflag.CommandLine) @@ -75,6 +77,7 @@ func SetupConfig() (*Config, error) { Cert: viper.GetString("server.cert"), Key: viper.GetString("server.key"), }, + ResetPassword: viper.GetString("reset-password"), } return config, nil