diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 1f9f45c5..92f27eae 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -115,7 +115,6 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Redln("生成密码失败") return nil } - user.Username = tools.RandomString(8) user.Password = hash @@ -130,11 +129,20 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Redln("获取面板端口失败") return nil } + ip, err := tools.GetPublicIP() + if err != nil { + ip = "127.0.0.1" + } + protocol := "http" + if facades.Config().GetBool("panel.ssl") { + protocol = "https" + } color.Greenln("用户名: " + user.Username) color.Greenln("密码: " + password) color.Greenln("面板端口: " + port) color.Greenln("面板入口: " + facades.Config().GetString("http.entrance")) + color.Greenln("面板地址: " + protocol + "://" + ip + ":" + port + facades.Config().GetString("http.entrance")) case "getPort": port, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`) diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go index 6d214e50..e25b710d 100644 --- a/pkg/tools/tools.go +++ b/pkg/tools/tools.go @@ -528,3 +528,18 @@ func IsChina() bool { return false } + +// GetPublicIP 获取公网IP +func GetPublicIP() (string, error) { + client := req.C() + client.SetTimeout(5 * time.Second) + client.SetCommonRetryCount(2) + client.ImpersonateSafari() + + resp, err := client.R().Get("https://www.cloudflare-cn.com/cdn-cgi/trace") + if err != nil || !resp.IsSuccessState() { + return "", errors.New("获取公网IP失败") + } + + return strings.TrimPrefix(strings.Split(resp.String(), "\n")[2], "ip="), nil +} diff --git a/pkg/tools/tools_test.go b/pkg/tools/tools_test.go index 633d0f82..fe2fbc03 100644 --- a/pkg/tools/tools_test.go +++ b/pkg/tools/tools_test.go @@ -97,7 +97,13 @@ func (s *HelperTestSuite) TestGetPanelVersion() { if env.IsWindows() { return } - version, err := GetPanelVersion("v2.0.58") + version, err := GetPanelVersion("v2.1.29") s.NotEmpty(version) s.Nil(err) } + +func (s *HelperTestSuite) TestGetPublicIP() { + ip, err := GetPublicIP() + s.Nil(err) + s.NotEmpty(ip) +} diff --git a/scripts/install_panel.sh b/scripts/install_panel.sh index dbc6650d..3719a53d 100644 --- a/scripts/install_panel.sh +++ b/scripts/install_panel.sh @@ -240,6 +240,10 @@ Init_Panel() { rm -rf ${panelZipName} rm -rf ${checksumsFileName} cp panel-example.conf panel.conf + + # 设置面板 + entrance=$(cat /dev/urandom | head -n 16 | md5sum | head -c 6) + sed -i "s!APP_ENTRANCE=.*!APP_ENTRANCE=${entrance}!g" panel.conf ${setup_Path}/panel/panel --env="panel.conf" artisan key:generate ${setup_Path}/panel/panel --env="panel.conf" artisan jwt:secret ${setup_Path}/panel/panel --env="panel.conf" artisan migrate