安全配置

dev
truthhun 1 year ago
parent 3b8c3e5740
commit 279d64df4d

@ -242,12 +242,14 @@ const (
ConfigSecurityDocumentRelatedDuration = "document_related_duration" // 相关文档有效期默认为7天最小值为1
ConfigSecurityDocumentAllowedExt = "document_allowed_ext" // 允许上传的文档类型
ConfigSecurityLoginRequired = "login_required" // 是否需要登录才能查看文档
ConfigSecurityAttachmentRetentionMinute = "attachment_retention_minute" // 被删除的附件,保留时长,单位分钟
)
type ConfigSecurity struct {
MaxDocumentSize int32 `json:"max_document_size"` // 允许上传的最大文档大小
CommentInterval int32 `json:"comment_interval"` // 评论时间间隔, 单位秒
DocumentRelatedDuration int32 `json:"document_related_duration"` // 相关文档有效期默认为7天最小值为1
AttachmentRetentionMinute int32 `json:"attachment_retention_minute"` // 被删除的附件,保留时长,单位分钟
IsClose bool `json:"is_close"` // 是否闭站
CloseStatement string `json:"close_statement"` // 闭站说明
EnableRegister bool `json:"enable_register"` // 是否启用注册
@ -659,7 +661,8 @@ func (m *DBModel) initConfig() (err error) {
{Category: ConfigCategorySecurity, Name: ConfigSecurityMaxDocumentSize, Label: "最大文档大小(MB)", Value: "50", Placeholder: "允许用户上传的最大文档大小默认为50即50MB。配置时仍需配置反向代理服务所允许传输的最大大小如nginx的client_max_body_size值", InputType: InputTypeNumber, Sort: 1, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityCommentInterval, Label: "评论时间间隔", Value: "10", Placeholder: "用户评论时间间隔单位为秒。0表示不限制。", InputType: InputTypeNumber, Sort: 2, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityDocumentRelatedDuration, Label: "文档的【相关文档】有效期", Value: "7", Placeholder: "文档的相关联文档的有效期默认为7即7天0或小于0表示不开启相关文档功能", InputType: InputTypeNumber, Sort: 15, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityDocumentAllowedExt, Label: "允许上传的文档类型", Value: "", Placeholder: "留空表示允许程序所支持的全部文档类型", InputType: InputTypeSelectMulti, Sort: 3, Options: strings.Join(filetil.GetDocumentExts(), "\n")},
{Category: ConfigCategorySecurity, Name: ConfigSecurityAttachmentRetentionMinute, Label: "从回收站清除的文档文件保留时长", Value: "1440", Placeholder: "单位为分钟默认为1440即24小时。文档被从回收站清除之后文档文件并未真正删除用以规避操作失误的情况。设为 0 则表示即时删除文档文件,用以释放存储空间。", InputType: InputTypeNumber, Sort: 16, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityDocumentAllowedExt, Label: "允许上传的文档类型", Value: "", Placeholder: "留空表示允许程序所支持的全部文档类型", InputType: InputTypeSelectMulti, Sort: 30, Options: strings.Join(filetil.GetDocumentExts(), "\n")},
{Category: ConfigCategorySecurity, Name: ConfigSecurityIsClose, Label: "是否关闭网站", Value: "false", Placeholder: "请选择是否关闭网站", InputType: InputTypeSwitch, Sort: 160, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityCloseStatement, Label: "闭站说明", Value: closeStatement, Placeholder: "关闭网站后页面提示内容支持HTML", InputType: InputTypeTextarea, Sort: 170, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityEnableRegister, Label: "是否允许注册", Value: "true", Placeholder: "请选择是否允许用户注册", InputType: InputTypeSwitch, Sort: 18, Options: ""},

@ -196,15 +196,15 @@ func (m *DBModel) cronCleanInvalidAttachment() {
hashes []string
hashMap = make(map[string]struct{})
ids []int64
beforeHour, _ = strconv.Atoi(os.Getenv("MOREDOC_CLEAN_ATTACHMENT")) // 默认为每天凌晨0点更新站点地图
retentionMinute = m.GetConfigOfSecurity(ConfigSecurityAttachmentRetentionMinute).AttachmentRetentionMinute
)
if beforeHour <= 0 {
beforeHour = 24
if retentionMinute < 0 {
retentionMinute = 0
}
// 1. 找出已被标记删除的附件
m.db.Unscoped().Where("deleted_at IS NOT NULL").Where("deleted_at < ?", time.Now().Add(-time.Duration(beforeHour)*time.Hour)).Limit(100).Find(&deletedAttachemnts)
m.db.Unscoped().Where("deleted_at IS NOT NULL").Where("deleted_at < ?", time.Now().Add(-time.Duration(retentionMinute)*time.Minute)).Limit(100).Find(&deletedAttachemnts)
if len(deletedAttachemnts) == 0 {
m.logger.Info("cronCleanInvalidAttachmentend...")
time.Sleep(sleepDuration)

@ -1,7 +1,7 @@
<template>
<div class="page-admin-dashboard">
<el-card shadow="never">
<div slot="header">状态</div>
<div slot="header">服务器状态</div>
<el-row :gutter="20" class="gauges">
<el-col
:span="6"
@ -15,7 +15,7 @@
<v-chart class="chart" autoresize :option="gauge" />
<div class="text-center">
<ul>
<li v-for="item in gauge.labels" :key="item">
<li v-for="(item, index) in gauge.labels" :key="'label-' + index">
<small v-if="item.label">{{ item.label }} : </small
>{{ item.value }}
</li>
@ -415,15 +415,15 @@ export default {
...this.getGaugeOption('内存', '0.00'),
labels: [
{
label: 'Total',
label: 'Used',
value: '-',
},
{
label: 'Used',
label: 'Free',
value: '-',
},
{
label: 'Free',
label: 'Total',
value: '-',
},
],
@ -433,15 +433,15 @@ export default {
...this.getGaugeOption('磁盘', '0.00'),
labels: [
{
label: 'Total',
label: 'Used',
value: '-',
},
{
label: 'Used',
label: 'Free',
value: '-',
},
{
label: 'Free',
label: 'Total',
value: '-',
},
],

@ -110,7 +110,7 @@ export function formatBytes(bytes, decimals = 2) {
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
return `${(bytes / Math.pow(k, i)).toFixed(dm)} ${sizes[i]}`
}
// categoryToTrees 分类转树形结构

Loading…
Cancel
Save