安装时默认设置访问日志保留30天

This commit is contained in:
GoEdgeLab
2021-06-24 21:06:43 +08:00
parent 5bbfab9498
commit b80aabc65d
3 changed files with 67 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/go-yaml/yaml"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/actions"
@@ -200,6 +201,26 @@ func (this *InstallAction) RunPost(params struct {
this.Fail("设置管理员账号出错:" + err.Error())
}
// 设置访问日志保留天数
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
if accessLogKeepDays > 0 {
var config = &systemconfigs.DatabaseConfig{}
config.ServerAccessLog.Clean.Days = accessLogKeepDays
configJSON, err := json.Marshal(config)
if err != nil {
this.Fail("配置设置访问日志保留天数出错:" + err.Error())
return
}
_, err = client.SysSettingRPC().UpdateSysSetting(ctx, &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeDatabaseConfigSetting,
ValueJSON: configJSON,
})
if err != nil {
this.Fail("配置设置访问日志保留天数出错:" + err.Error())
return
}
}
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
if err != nil {
this.Fail("保存配置失败,原因:" + err.Error())
@@ -232,6 +253,26 @@ func (this *InstallAction) RunPost(params struct {
this.Fail("设置管理员账号出错:" + err.Error())
}
// 设置访问日志保留天数
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
if accessLogKeepDays > 0 {
var config = &systemconfigs.DatabaseConfig{}
config.ServerAccessLog.Clean.Days = accessLogKeepDays
configJSON, err := json.Marshal(config)
if err != nil {
this.Fail("配置设置访问日志保留天数出错:" + err.Error())
return
}
_, err = client.SysSettingRPC().UpdateSysSetting(ctx, &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeDatabaseConfigSetting,
ValueJSON: configJSON,
})
if err != nil {
this.Fail("配置设置访问日志保留天数出错:" + err.Error())
return
}
}
// 写入API节点配置完成安装
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
if err != nil {

View File

@@ -15,11 +15,12 @@ type ValidateDbAction struct {
}
func (this *ValidateDbAction) RunPost(params struct {
Host string
Port string
Database string
Username string
Password string
Host string
Port string
Database string
Username string
Password string
AccessLogKeepDays int
Must *actions.Must
}) {
@@ -98,12 +99,13 @@ func (this *ValidateDbAction) RunPost(params struct {
}
this.Data["db"] = maps.Map{
"host": params.Host,
"port": params.Port,
"database": params.Database,
"username": params.Username,
"password": params.Password,
"passwordMask": strings.Repeat("*", len(params.Password)),
"host": params.Host,
"port": params.Port,
"database": params.Database,
"username": params.Username,
"password": params.Password,
"passwordMask": strings.Repeat("*", len(params.Password)),
"accessLogKeepDays": params.AccessLogKeepDays,
}
this.Success()

View File

@@ -188,6 +188,13 @@
<p class="comment">连接数据库所需密码,没有密码的话就不需要填写。</p>
</td>
</tr>
<tr>
<td>访问日志保留天数</td>
<td>
<input type="number" name="accessLogKeepDays" style="width: 5em" maxlength="4" value="30"/>
<p class="comment">网站等服务记录的访问日志保留天数,防止无限制地占用数据库空间。</p>
</td>
</tr>
</table>
<button class="ui button" type="button" @click.prevent="goBackAPI"><i class="icon long arrow left"></i>上一步</button> &nbsp;
@@ -325,6 +332,12 @@
<span v-else class="disabled">未填入密码</span>
</td>
</tr>
<tr>
<td>访问日志保留天数</td>
<td>
{{dbInfo.accessLogKeepDays}}天
</td>
</tr>
</table>
<h3>管理员信息</h3>