mirror of
https://github.com/tnb-labs/panel.git
synced 2026-09-01 14:55:12 +08:00
fix: 优化代码
This commit is contained in:
@@ -372,7 +372,7 @@ func (r *websiteRepo) Create(ctx context.Context, req *request.WebsiteCreate) (*
|
||||
if err = phpVhost.SetIndex([]string{"index.php", "index.html"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = phpVhost.SetConfig("010-rewrite.conf", "site", ""); err != nil {
|
||||
if err = phpVhost.SetConfig("010-rewrite.conf", "site", "", true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cacheConfig string
|
||||
@@ -671,7 +671,7 @@ func (r *websiteRepo) Update(ctx context.Context, req *request.WebsiteUpdate) er
|
||||
return err
|
||||
}
|
||||
// 伪静态
|
||||
if err = phpVhost.SetConfig("010-rewrite.conf", "site", req.Rewrite); err != nil {
|
||||
if err = phpVhost.SetConfig("010-rewrite.conf", "site", req.Rewrite, true); err != nil {
|
||||
return err
|
||||
}
|
||||
// 防跨站
|
||||
|
||||
@@ -1045,7 +1045,7 @@ func (s *CliService) Init(ctx context.Context, cmd *cli.Command) error {
|
||||
{Key: biz.SettingKeyProjectPath, Value: filepath.Join(app.Root, "projects")},
|
||||
{Key: biz.SettingKeyContainerSock, Value: "/var/run/docker.sock"},
|
||||
{Key: biz.SettingKeyWebsiteTLSVersions, Value: `["TLSv1.2","TLSv1.3"]`},
|
||||
{Key: biz.SettingKeyWebsiteCipherSuites, Value: `ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305`},
|
||||
{Key: biz.SettingKeyWebsiteCipherSuites, Value: `ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305`},
|
||||
{Key: biz.SettingKeyOfflineMode, Value: "false"},
|
||||
{Key: biz.SettingKeyAutoUpdate, Value: "true"},
|
||||
{Key: biz.SettingHiddenMenu, Value: "[]"},
|
||||
|
||||
@@ -356,8 +356,11 @@ func (v *baseVhost) Config(name string, typ string) string {
|
||||
return strings.TrimSpace(string(content))
|
||||
}
|
||||
|
||||
func (v *baseVhost) SetConfig(name string, typ string, content string) error {
|
||||
func (v *baseVhost) SetConfig(name string, typ string, content string, skipComment ...bool) error {
|
||||
conf := filepath.Join(v.configDir, typ, name)
|
||||
if len(skipComment) == 0 || !skipComment[0] {
|
||||
content = "# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!\n" + content
|
||||
}
|
||||
if err := os.WriteFile(conf, []byte(content), 0600); err != nil {
|
||||
return fmt.Errorf("failed to write config file: %w", err)
|
||||
}
|
||||
@@ -695,8 +698,7 @@ func (v *PHPVhost) SetPHP(version uint) error {
|
||||
|
||||
// 生成 PHP-FPM 配置
|
||||
// sock 路径格式: unix:/tmp/php-cgi-84.sock
|
||||
content := fmt.Sprintf(`# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!
|
||||
<FilesMatch \.php$>
|
||||
content := fmt.Sprintf(`<FilesMatch \.php$>
|
||||
SetHandler "proxy:unix:/tmp/php-cgi-%d.sock|fcgi://localhost/"
|
||||
</FilesMatch>
|
||||
`, version)
|
||||
|
||||
@@ -389,8 +389,11 @@ func (v *baseVhost) Config(name string, typ string) string {
|
||||
return strings.TrimSpace(string(content))
|
||||
}
|
||||
|
||||
func (v *baseVhost) SetConfig(name string, typ string, content string) error {
|
||||
func (v *baseVhost) SetConfig(name string, typ string, content string, skipComment ...bool) error {
|
||||
conf := filepath.Join(v.configDir, typ, name)
|
||||
if len(skipComment) == 0 || !skipComment[0] {
|
||||
content = "# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!\n" + content
|
||||
}
|
||||
if err := os.WriteFile(conf, []byte(content), 0600); err != nil {
|
||||
return fmt.Errorf("failed to write config file: %w", err)
|
||||
}
|
||||
@@ -476,7 +479,7 @@ func (v *baseVhost) SetSSLConfig(cfg *types.SSLConfig) error {
|
||||
cfg.Protocols = []string{"TLSv1.2", "TLSv1.3"}
|
||||
}
|
||||
if cfg.Ciphers == "" {
|
||||
cfg.Ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305"
|
||||
cfg.Ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305"
|
||||
}
|
||||
|
||||
err := v.parser.Set("server", []*config.Directive{
|
||||
@@ -842,8 +845,7 @@ func (v *PHPVhost) SetPHP(version uint) error {
|
||||
|
||||
// 生成 PHP-FPM 配置
|
||||
// sock 路径格式: unix:/tmp/php-cgi-84.sock
|
||||
content := fmt.Sprintf(`# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!
|
||||
location ~ \.php$ {
|
||||
content := fmt.Sprintf(`location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:/tmp/php-cgi-%d.sock;
|
||||
fastcgi_index index.php;
|
||||
|
||||
@@ -88,7 +88,7 @@ type Vhost interface {
|
||||
Config(name string, typ string) string
|
||||
// SetConfig 设置指定名称的配置内容
|
||||
// type 可选值: "site", "shared"
|
||||
SetConfig(name string, typ string, content string) error
|
||||
SetConfig(name string, typ string, content string, skipComment ...bool) error
|
||||
// RemoveConfig 清除指定名称的配置内容
|
||||
// type 可选值: "site", "shared"
|
||||
RemoveConfig(name string, typ string) error
|
||||
|
||||
@@ -45,11 +45,11 @@ watch(
|
||||
if (!newVal.includes('TLSv1.1') && !newVal.includes('TLSv1.0')) {
|
||||
// 不包含 TLSv1.0 和 TLSv1.1
|
||||
model.value.cipher_suites =
|
||||
'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305'
|
||||
'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305'
|
||||
} else {
|
||||
// 包含 TLSv1.0 或 TLSv1.1
|
||||
model.value.cipher_suites =
|
||||
'@SECLEVEL=0:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA'
|
||||
'@SECLEVEL=0:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user