feat: 优化文本域换行符校验 (#3399)

This commit is contained in:
ssongliu 2023-12-20 13:46:09 +08:00 committed by GitHub
parent f50972a0e3
commit 733889407e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 55 additions and 7 deletions

View File

@ -196,6 +196,12 @@ func (u *FirewallService) OperateFirewall(operation string) error {
}
_, _ = cmd.Exec("systemctl restart docker")
return nil
case "restart":
if err := client.Restart(); err != nil {
return err
}
_, _ = cmd.Exec("systemctl restart docker")
return nil
case "disablePing":
return u.updatePingStatus("0")
case "enablePing":

View File

@ -12,6 +12,7 @@ type FirewallClient interface {
Name() string // ufw firewalld
Start() error
Stop() error
Restart() error
Reload() error
Status() (string, error) // running not running
Version() (string, error)

View File

@ -52,6 +52,14 @@ func (f *Firewall) Stop() error {
return nil
}
func (f *Firewall) Restart() error {
stdout, err := cmd.Exec("systemctl restart firewalld")
if err != nil {
return fmt.Errorf("restart the firewall failed, err: %s", stdout)
}
return nil
}
func (f *Firewall) Reload() error {
stdout, err := cmd.Exec("firewall-cmd --reload")
if err != nil {

View File

@ -64,6 +64,14 @@ func (f *Ufw) Stop() error {
return nil
}
func (f *Ufw) Restart() error {
stdout, err := cmd.Execf("%s systemctl restart ufw.service", cmd.SudoHandleCmd())
if err != nil {
return fmt.Errorf("restart the firewall failed, err: %s", stdout)
}
return nil
}
func (f *Ufw) Reload() error {
return nil
}

View File

@ -97,7 +97,7 @@ func (f *Fail2ban) ListBanned() ([]string, error) {
if err != nil {
return lists, err
}
itemList := strings.Split(stdout, " ")
itemList := strings.Split(strings.ReplaceAll(stdout, "\n", ""), " ")
for _, item := range itemList {
if len(item) != 0 {
lists = append(lists, item)

View File

@ -21,7 +21,7 @@
:rules="Rules.requiredSelect"
prop="repoID"
>
<el-select style="width: 100%" filterable v-model="form.repoID">
<el-select clearable style="width: 100%" filterable v-model="form.repoID">
<el-option v-for="item in repos" :key="item.id" :value="item.id" :label="item.name" />
</el-select>
</el-form-item>

View File

@ -18,7 +18,7 @@
</el-select>
</el-form-item>
<el-form-item :label="$t('container.repoName')" :rules="Rules.requiredSelect" prop="repoID">
<el-select style="width: 100%" filterable v-model="form.repoID">
<el-select clearable style="width: 100%" filterable v-model="form.repoID">
<el-option
v-for="item in dialogData.repos"
:key="item.id"

View File

@ -15,7 +15,7 @@
:rules="Rules.requiredSelect"
prop="repo"
>
<el-select style="width: 100%" filterable v-model="form.repo" @change="changeRepo">
<el-select style="width: 100%" clearable filterable v-model="form.repo" @change="changeRepo">
<el-option v-for="item in repos" :key="item.id" :value="item.name" :label="item.name" />
</el-select>
</el-form-item>

View File

@ -70,6 +70,9 @@ function checkMirrors(rule: any, value: any, callback: any) {
const reg = /^https?:\/\/[a-zA-Z0-9.-]+$/;
let mirrors = form.mirrors.split('\n');
for (const item of mirrors) {
if (item === '') {
continue;
}
if (!reg.test(item)) {
return callback(new Error(i18n.global.t('commons.rule.mirror')));
}

View File

@ -70,6 +70,9 @@ function checkRegistries(rule: any, value: any, callback: any) {
const reg = /^[a-zA-Z0-9]{1}[a-z:A-Z0-9_/.-]{0,150}$/;
let regis = form.registries.split('\n');
for (const item of regis) {
if (item === '') {
continue;
}
if (!reg.test(item)) {
return callback(new Error(i18n.global.t('commons.rule.imageName')));
}

View File

@ -58,6 +58,9 @@ function checkAddress(rule: any, value: any, callback: any) {
if (form.allowIPs !== '') {
let addrs = form.allowIPs.split('\n');
for (const item of addrs) {
if (item === '') {
continue;
}
if (item === '0.0.0.0') {
return callback(new Error(i18n.global.t('firewall.addressFormatError')));
}
@ -102,8 +105,14 @@ const onSave = async (formEl: FormInstance | undefined) => {
type: 'info',
}).then(async () => {
loading.value = true;
await updateSetting({ key: 'AllowIPs', value: form.allowIPs.replaceAll('\n', ',') })
let ipItems = form.allowIPs.split('\n');
let ips = [];
for (const item of ipItems) {
if (item !== '') {
ips.push(item);
}
}
await updateSetting({ key: 'AllowIPs', value: ips.join(',') })
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));

View File

@ -49,6 +49,9 @@ function checkIPs(rule: any, value: any, callback: any) {
if (form.ips !== '') {
let addr = form.ips.split('\n');
for (const item of addr) {
if (item === '') {
continue;
}
if (item.indexOf('/') !== -1) {
if (checkCidr(item)) {
return callback(new Error(i18n.global.t('firewall.addressFormatError')));
@ -95,9 +98,16 @@ const onSave = async (formEl: FormInstance | undefined) => {
type: 'info',
},
).then(async () => {
let ipItems = form.ips.split('\n');
let ips = [];
for (const item of ipItems) {
if (item !== '') {
ips.push(item);
}
}
let param = {
operate: form.operate,
ips: form.ips.split('\n'),
ips: ips,
};
loading.value = true;
await operatorFail2banSSHD(param)