diff options
| author | Maisam <maisam.vahidsafa@gmail.com> | 2024-05-25 12:35:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-25 12:35:27 +0300 |
| commit | adcfccbe4550ebca477e8fd9a6ef00dd10002809 (patch) | |
| tree | ac4e54b87b1660f17593f97cd7b00e9785da2a0a | |
| parent | c422214ae8e1da9d9ed210f85f63356f8943a2cf (diff) | |
Add CLI to set panel cert (#2305)
* Add webBasePath update feature to CLI
* Add certificate setting update to CLI
* Revert "Add certificate setting update to CLI"
This reverts commit 2a937d59d7c1f3edeb66782a4b235bafc89dfff6.
* Add certificate setting update to CLI
(cherry picked from commit 2a937d59d7c1f3edeb66782a4b235bafc89dfff6)
| -rw-r--r-- | main.go | 43 | ||||
| -rw-r--r-- | web/service/setting.go | 8 |
2 files changed, 51 insertions, 0 deletions
@@ -254,6 +254,33 @@ func updateSetting(port int, username string, password string, webBasePath strin } } +func updateCert(publicKey string, privateKey string) { + err := database.InitDB(config.GetDBPath()) + if err != nil { + fmt.Println(err) + return + } + + if (privateKey != "" && publicKey != "") || (privateKey == "" && publicKey == "") { + settingService := service.SettingService{} + err = settingService.SetCertFile(publicKey) + if err != nil { + fmt.Println("set certificate public key failed:", err) + } else { + fmt.Println("set certificate public key success") + } + + err = settingService.SetKeyFile(privateKey) + if err != nil { + fmt.Println("set certificate private key failed:", err) + } else { + fmt.Println("set certificate private key success") + } + } else { + fmt.Println("both public and private key should be entered.") + } +} + func migrateDb() { inboundService := service.InboundService{} @@ -312,6 +339,8 @@ func main() { var username string var password string var webBasePath string + var webCertFile string + var webKeyFile string var tgbottoken string var tgbotchatid string var enabletgbot bool @@ -326,6 +355,8 @@ func main() { settingCmd.StringVar(&username, "username", "", "set login username") settingCmd.StringVar(&password, "password", "", "set login password") settingCmd.StringVar(&webBasePath, "webBasePath", "", "set web base path") + settingCmd.StringVar(&webCertFile, "webCert", "", "set web public key path") + settingCmd.StringVar(&webKeyFile, "webCertKey", "", "set web private key path") settingCmd.StringVar(&tgbottoken, "tgbottoken", "", "set telegram bot token") settingCmd.StringVar(&tgbotRuntime, "tgbotRuntime", "", "set telegram bot cron time") settingCmd.StringVar(&tgbotchatid, "tgbotchatid", "", "set telegram bot chat id") @@ -380,6 +411,18 @@ func main() { if enabletgbot { updateTgbotEnableSts(enabletgbot) } + case "cert": + err := settingCmd.Parse(os.Args[2:]) + if err != nil { + fmt.Println(err) + return + } + if reset { + updateCert("", "") + } else { + updateCert(webCertFile, webKeyFile) + } + default: fmt.Println("Invalid subcommands") fmt.Println() diff --git a/web/service/setting.go b/web/service/setting.go index 69b1fece..bc5aeaa4 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -309,10 +309,18 @@ func (s *SettingService) SetPort(port int) error { return s.setInt("webPort", port) } +func (s *SettingService) SetCertFile(webCertFile string) error { + return s.setString("webCertFile", webCertFile) +} + func (s *SettingService) GetCertFile() (string, error) { return s.getString("webCertFile") } +func (s *SettingService) SetKeyFile(webKeyFile string) error { + return s.setString("webKeyFile", webKeyFile) +} + func (s *SettingService) GetKeyFile() (string, error) { return s.getString("webKeyFile") } |
