mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 11:27:17 +08:00
feat: 自动设置面板入口与显示地址信息
This commit is contained in:
@@ -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'`)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user