Skip to content

Commit

Permalink
feat: logrotate cron task for docker users #255
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Feb 25, 2024
1 parent b7f50f0 commit 0fa9870
Show file tree
Hide file tree
Showing 26 changed files with 663 additions and 119 deletions.
21 changes: 15 additions & 6 deletions api/system/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system

import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/cron"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/gin-gonic/gin"
"net/http"
Expand All @@ -10,26 +11,34 @@ import (

func GetSettings(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"server": settings.ServerSettings,
"nginx": settings.NginxSettings,
"openai": settings.OpenAISettings,
"server": settings.ServerSettings,
"nginx": settings.NginxSettings,
"openai": settings.OpenAISettings,
"logrotate": settings.LogrotateSettings,
})
}

func SaveSettings(c *gin.Context) {
var json struct {
Server settings.Server `json:"server"`
Nginx settings.Nginx `json:"nginx"`
Openai settings.OpenAI `json:"openai"`
Server settings.Server `json:"server"`
Nginx settings.Nginx `json:"nginx"`
Openai settings.OpenAI `json:"openai"`
Logrotate settings.Logrotate `json:"logrotate"`
}

if !api.BindAndValid(c, &json) {
return
}

if settings.LogrotateSettings.Enabled != json.Logrotate.Enabled ||
settings.LogrotateSettings.Interval != json.Logrotate.Interval {
go cron.RestartLogrotate()
}

fillSettings(&settings.ServerSettings, &json.Server)
fillSettings(&settings.NginxSettings, &json.Nginx)
fillSettings(&settings.OpenAISettings, &json.Openai)
fillSettings(&settings.LogrotateSettings, &json.Logrotate)

settings.ReflectFrom()

Expand Down
55 changes: 44 additions & 11 deletions app/src/language/en/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ msgstr "Base information"

#: src/views/config/ConfigEdit.vue:117
#: src/views/domain/components/RightSettings.vue:76
#: src/views/preference/Preference.vue:96
#: src/views/preference/Preference.vue:95
#: src/views/stream/components/RightSettings.vue:76
#, fuzzy
msgid "Basic"
Expand Down Expand Up @@ -255,6 +255,11 @@ msgstr ""
msgid "Cleared successfully"
msgstr "Disabled successfully"

#: src/views/preference/LogrotateSettings.vue:27
#, fuzzy
msgid "Command"
msgstr "Comments"

#: src/views/domain/ngx_conf/directive/DirectiveEditorItem.vue:107
#: src/views/domain/ngx_conf/LocationEditor.vue:119
#: src/views/domain/ngx_conf/LocationEditor.vue:88
Expand Down Expand Up @@ -503,7 +508,7 @@ msgstr "Are you sure you want to remove this directive?"
msgid "Do you want to remove this upstream?"
msgstr "Are you sure you want to remove this directive?"

#: src/views/certificate/WildcardCertificate.vue:72
#: src/views/certificate/WildcardCertificate.vue:100
msgid "Domain"
msgstr ""

Expand Down Expand Up @@ -618,6 +623,7 @@ msgstr "Enable TLS"
#: src/views/domain/cert/ChangeCert.vue:44
#: src/views/domain/components/RightSettings.vue:78
#: src/views/domain/DomainEdit.vue:179 src/views/domain/DomainList.vue:32
#: src/views/preference/LogrotateSettings.vue:24
#: src/views/stream/components/RightSettings.vue:78
#: src/views/stream/StreamEdit.vue:170 src/views/stream/StreamList.vue:32
msgid "Enabled"
Expand Down Expand Up @@ -838,12 +844,16 @@ msgstr "Enabled successfully"
msgid "Intermediate Certification Authorities: %{issuer}"
msgstr "Intermediate Certification Authorities: %{issuer}"

#: src/views/preference/LogrotateSettings.vue:30
msgid "Interval"
msgstr ""

#: src/views/certificate/Certificate.vue:137
#, fuzzy
msgid "Issue wildcard certificate"
msgstr "Certificate is valid"

#: src/views/certificate/WildcardCertificate.vue:61
#: src/views/certificate/WildcardCertificate.vue:89
#, fuzzy
msgid "Issue Wildcard Certificate"
msgstr "Certificate Status"
Expand All @@ -857,6 +867,7 @@ msgstr "Enabled successfully"
msgid "Jwt Secret"
msgstr ""

#: src/views/certificate/WildcardCertificate.vue:107
#: src/views/domain/cert/components/AutoCertStepOne.vue:108
msgid "Key Type"
msgstr ""
Expand Down Expand Up @@ -924,6 +935,20 @@ msgstr "Login successful"
msgid "Logout successful"
msgstr "Logout successful"

#: src/views/preference/Preference.vue:113
msgid "Logrotate"
msgstr ""

#: src/views/preference/LogrotateSettings.vue:17
msgid ""
"Logrotate, by default, is enabled in most mainstream Linux distributions for "
"users who install Nginx UI on the host machine, so you don't need to modify "
"the parameters on this page. For users who install Nginx UI using Docker "
"containers, you can manually enable this option. The crontab task scheduler "
"of Nginx UI will execute the logrotate command at the interval you set in "
"minutes."
msgstr ""

#: src/views/domain/cert/components/AutoCertStepOne.vue:87
#, fuzzy
msgid ""
Expand Down Expand Up @@ -963,6 +988,10 @@ msgstr "Memory"
msgid "Memory and Storage"
msgstr "Memory and Storage"

#: src/views/preference/LogrotateSettings.vue:34
msgid "Minutes"
msgstr ""

#: src/components/ChatGPT/ChatGPT.vue:256
#: src/components/StdDesign/StdDataDisplay/StdCurd.vue:141
#: src/components/StdDesign/StdDataDisplay/StdTable.vue:336
Expand Down Expand Up @@ -1019,13 +1048,13 @@ msgstr "Network Total Send"
msgid "New version released"
msgstr ""

#: src/views/certificate/WildcardCertificate.vue:87
#: src/views/certificate/WildcardCertificate.vue:127
#: src/views/domain/cert/components/ObtainCert.vue:204
#: src/views/domain/DomainAdd.vue:145
msgid "Next"
msgstr "Next"

#: src/views/preference/Preference.vue:102
#: src/views/preference/Preference.vue:101
msgid "Nginx"
msgstr ""

Expand Down Expand Up @@ -1148,7 +1177,7 @@ msgstr ""
msgid "Online"
msgstr ""

#: src/views/preference/Preference.vue:108
#: src/views/preference/Preference.vue:107
msgid "OpenAI"
msgstr ""

Expand Down Expand Up @@ -1242,7 +1271,7 @@ msgstr ""
msgid "Pre-release"
msgstr ""

#: src/routes/index.ts:210 src/views/preference/Preference.vue:91
#: src/routes/index.ts:210 src/views/preference/Preference.vue:90
msgid "Preference"
msgstr ""

Expand Down Expand Up @@ -1334,7 +1363,7 @@ msgid "Renew Certificate Success"
msgstr "Certificate is valid"

#: src/views/certificate/RenewCert.vue:25
#: src/views/certificate/WildcardCertificate.vue:50
#: src/views/certificate/WildcardCertificate.vue:51
#, fuzzy
msgid "Renew successfully"
msgstr "Enabled successfully"
Expand Down Expand Up @@ -1368,7 +1397,7 @@ msgstr ""
#: src/views/certificate/CertificateEditor.vue:245
#: src/views/config/ConfigEdit.vue:98 src/views/domain/DomainEdit.vue:263
#: src/views/domain/ngx_conf/directive/DirectiveEditorItem.vue:121
#: src/views/preference/Preference.vue:119 src/views/stream/StreamEdit.vue:253
#: src/views/preference/Preference.vue:124 src/views/stream/StreamEdit.vue:253
msgid "Save"
msgstr "Save"

Expand All @@ -1383,7 +1412,7 @@ msgstr "Save error %{msg}"

#: src/components/StdDesign/StdDataDisplay/StdBatchEdit.vue:42
#: src/views/certificate/CertificateEditor.vue:48
#: src/views/preference/Preference.vue:61
#: src/views/preference/Preference.vue:60
#, fuzzy
msgid "Save successfully"
msgstr "Saved successfully"
Expand Down Expand Up @@ -1416,7 +1445,7 @@ msgstr "Send"
#: src/components/StdDesign/StdDataDisplay/StdBatchEdit.vue:45
#: src/components/StdDesign/StdDataDisplay/StdTable.vue:157
#: src/views/config/ConfigEdit.vue:42 src/views/domain/DomainList.vue:84
#: src/views/other/Install.vue:72 src/views/preference/Preference.vue:65
#: src/views/other/Install.vue:72 src/views/preference/Preference.vue:64
#: src/views/stream/StreamList.vue:116 src/views/stream/StreamList.vue:84
#: src/views/system/Upgrade.vue:45
msgid "Server error"
Expand Down Expand Up @@ -1617,6 +1646,10 @@ msgstr ""
msgid "This field should not be empty"
msgstr ""

#: src/views/preference/LogrotateSettings.vue:16
msgid "Tips"
msgstr ""

#: src/views/notification/Notification.vue:21
msgid "Title"
msgstr ""
Expand Down
Loading

0 comments on commit 0fa9870

Please sign in to comment.