Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/app/service/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
1 change: 1 addition & 0 deletions backend/utils/firewall/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions backend/utils/firewall/client/firewalld.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions backend/utils/firewall/client/ufw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/toolbox/fail2ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/container/image/pull/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/container/image/push/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/container/image/tag/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/container/setting/mirror/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/container/setting/registry/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/views/setting/safe/allowips/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
Expand Down Expand Up @@ -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'));
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/views/toolbox/fail2ban/ips/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down Expand Up @@ -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)
Expand Down
Loading