mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-05 05:19:08 +08:00
feat: 优化文本域换行符校验 (#3399)
This commit is contained in:
parent
f50972a0e3
commit
733889407e
@ -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":
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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')));
|
||||
}
|
||||
|
@ -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')));
|
||||
}
|
||||
|
@ -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'));
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user