-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"s-ui/config" | ||
"s-ui/database" | ||
"s-ui/service" | ||
) | ||
|
||
func resetAdmin() { | ||
err := database.InitDB(config.GetDBPath()) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
userService := service.UserService{} | ||
err = userService.UpdateFirstUser("admin", "admin") | ||
if err != nil { | ||
fmt.Println("reset admin credentials failed:", err) | ||
} else { | ||
fmt.Println("reset admin credentials success") | ||
} | ||
} | ||
|
||
func updateAdmin(username string, password string) { | ||
err := database.InitDB(config.GetDBPath()) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
if username != "" || password != "" { | ||
userService := service.UserService{} | ||
err := userService.UpdateFirstUser(username, password) | ||
if err != nil { | ||
fmt.Println("reset admin credentials failed:", err) | ||
} else { | ||
fmt.Println("reset admin credentials success") | ||
} | ||
} | ||
} | ||
|
||
func showAdmin() { | ||
userService := service.UserService{} | ||
userModel, err := userService.GetFirstUser() | ||
if err != nil { | ||
fmt.Println("get current user info failed,error info:", err) | ||
} | ||
username := userModel.Username | ||
userpasswd := userModel.Password | ||
if (username == "") || (userpasswd == "") { | ||
fmt.Println("current username or password is empty") | ||
} | ||
fmt.Println("First admin credentials:") | ||
fmt.Println("\tUsername:\t", username) | ||
fmt.Println("\tPassword:\t", userpasswd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"s-ui/config" | ||
) | ||
|
||
func ParseCmd() { | ||
var showVersion bool | ||
flag.BoolVar(&showVersion, "v", false, "show version") | ||
|
||
adminCmd := flag.NewFlagSet("admin", flag.ExitOnError) | ||
settingCmd := flag.NewFlagSet("setting", flag.ExitOnError) | ||
|
||
var username string | ||
var password string | ||
var port int | ||
var path string | ||
var subPort int | ||
var subPath string | ||
var reset bool | ||
var show bool | ||
settingCmd.BoolVar(&reset, "reset", false, "reset all settings") | ||
settingCmd.BoolVar(&show, "show", false, "show current settings") | ||
settingCmd.IntVar(&port, "port", 0, "set panel port") | ||
settingCmd.StringVar(&path, "path", "", "set panel path") | ||
settingCmd.IntVar(&subPort, "subPort", 0, "set sub port") | ||
settingCmd.StringVar(&subPath, "subPath", "", "set sub path") | ||
|
||
adminCmd.BoolVar(&show, "show", false, "show first admin credentials") | ||
adminCmd.BoolVar(&reset, "reset", false, "reset first admin credentials") | ||
adminCmd.StringVar(&username, "username", "", "set login username") | ||
adminCmd.StringVar(&password, "password", "", "set login password") | ||
|
||
oldUsage := flag.Usage | ||
flag.Usage = func() { | ||
oldUsage() | ||
fmt.Println() | ||
fmt.Println("Commands:") | ||
fmt.Println(" admin set/reset/show first admin credentials") | ||
fmt.Println(" setting set/reset/show settings") | ||
fmt.Println() | ||
adminCmd.Usage() | ||
fmt.Println() | ||
settingCmd.Usage() | ||
} | ||
|
||
flag.Parse() | ||
if showVersion { | ||
fmt.Println(config.GetVersion()) | ||
return | ||
} | ||
|
||
switch os.Args[1] { | ||
case "admin": | ||
err := adminCmd.Parse(os.Args[2:]) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
switch { | ||
case show: | ||
showAdmin() | ||
case reset: | ||
resetAdmin() | ||
default: | ||
updateAdmin(username, password) | ||
showAdmin() | ||
} | ||
|
||
case "setting": | ||
err := settingCmd.Parse(os.Args[2:]) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
switch { | ||
case show: | ||
showSetting() | ||
case reset: | ||
resetSetting() | ||
default: | ||
updateSetting(port, path, subPort, subPath) | ||
showSetting() | ||
} | ||
default: | ||
fmt.Println("Invalid subcommands") | ||
flag.Usage() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"s-ui/config" | ||
"s-ui/database" | ||
"s-ui/service" | ||
) | ||
|
||
func resetSetting() { | ||
err := database.InitDB(config.GetDBPath()) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
settingService := service.SettingService{} | ||
err = settingService.ResetSettings() | ||
if err != nil { | ||
fmt.Println("reset setting failed:", err) | ||
} else { | ||
fmt.Println("reset setting success") | ||
} | ||
} | ||
|
||
func updateSetting(port int, path string, subPort int, subPath string) { | ||
err := database.InitDB(config.GetDBPath()) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
settingService := service.SettingService{} | ||
|
||
if port > 0 { | ||
err := settingService.SetPort(port) | ||
if err != nil { | ||
fmt.Println("set port failed:", err) | ||
} else { | ||
fmt.Println("set port success") | ||
} | ||
} | ||
if path != "" { | ||
err := settingService.SetWebPath(path) | ||
if err != nil { | ||
fmt.Println("set path failed:", err) | ||
} else { | ||
fmt.Println("set path success") | ||
} | ||
} | ||
if subPort > 0 { | ||
err := settingService.SetSubPort(subPort) | ||
if err != nil { | ||
fmt.Println("set sub port failed:", err) | ||
} else { | ||
fmt.Println("set sub port success") | ||
} | ||
} | ||
if subPath != "" { | ||
err := settingService.SetSubPath(subPath) | ||
if err != nil { | ||
fmt.Println("set sub path failed:", err) | ||
} else { | ||
fmt.Println("set sub path success") | ||
} | ||
} | ||
} | ||
|
||
func showSetting() { | ||
settingService := service.SettingService{} | ||
allSetting, err := settingService.GetAllSetting() | ||
if err != nil { | ||
fmt.Println("get current port failed,error info:", err) | ||
} | ||
fmt.Println("Current panel settings:") | ||
fmt.Println("\tPanel port:\t", (*allSetting)["webPort"]) | ||
fmt.Println("\tPanel path:\t", (*allSetting)["webPath"]) | ||
if (*allSetting)["webListen"] != "" { | ||
fmt.Println("\tPanel IP:\t", (*allSetting)["webListen"]) | ||
} | ||
if (*allSetting)["webDomain"] != "" { | ||
fmt.Println("\tPanel Domain:\t", (*allSetting)["webDomain"]) | ||
} | ||
if (*allSetting)["webURI"] != "" { | ||
fmt.Println("\tPanel URI:\t", (*allSetting)["webURI"]) | ||
} | ||
fmt.Println() | ||
fmt.Println("Current subscription settings:") | ||
fmt.Println("\tSub port:\t", (*allSetting)["subPort"]) | ||
fmt.Println("\tSub path:\t", (*allSetting)["subPath"]) | ||
if (*allSetting)["subListen"] != "" { | ||
fmt.Println("\tSub IP:\t", (*allSetting)["subListen"]) | ||
} | ||
if (*allSetting)["subDomain"] != "" { | ||
fmt.Println("\tSub Domain:\t", (*allSetting)["subDomain"]) | ||
} | ||
if (*allSetting)["subURI"] != "" { | ||
fmt.Println("\tSub URI:\t", (*allSetting)["subURI"]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters