mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 12:39:01 +08:00
fix: 防火墙端口添加支持输入网段 (#738)
This commit is contained in:
parent
565fd1c605
commit
44a1d9d16c
@ -369,7 +369,7 @@ func (u *FirewallService) pingStatus() string {
|
||||
return constant.StatusNone
|
||||
}
|
||||
commond := "cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= "
|
||||
if cmd.HasSudo() {
|
||||
if cmd.HasNoPasswordSudo() {
|
||||
commond = "sudo cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= "
|
||||
}
|
||||
stdout, _ := cmd.Exec(commond)
|
||||
@ -409,7 +409,7 @@ func (u *FirewallService) updatePingStatus(enabel string) error {
|
||||
}
|
||||
|
||||
commond := "sysctl -p"
|
||||
if cmd.HasSudo() {
|
||||
if cmd.HasNoPasswordSudo() {
|
||||
commond = "sudo sysctl -p"
|
||||
}
|
||||
stdout, err := cmd.Exec(commond)
|
||||
|
@ -100,11 +100,3 @@ func HasNoPasswordSudo() bool {
|
||||
err2 := cmd2.Run()
|
||||
return err2 == nil
|
||||
}
|
||||
|
||||
func HasSudo() bool {
|
||||
cmd := exec.Command("sudo", "-nv")
|
||||
if err := cmd.Run(); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ type Ufw struct {
|
||||
|
||||
func NewUfw() (*Ufw, error) {
|
||||
var ufw Ufw
|
||||
if cmd.HasSudo() {
|
||||
if cmd.HasNoPasswordSudo() {
|
||||
ufw.CmdStr = "sudo ufw"
|
||||
} else {
|
||||
ufw.CmdStr = "ufw"
|
||||
|
@ -70,7 +70,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue';
|
||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||
import { Host } from '@/api/interface/host';
|
||||
import { operatePortRule, updatePortRule } from '@/api/modules/host';
|
||||
import { checkPort, deepCopy } from '@/utils/util';
|
||||
import { checkIp, checkPort, deepCopy } from '@/utils/util';
|
||||
|
||||
const loading = ref();
|
||||
const oldRule = ref<Host.RulePort>();
|
||||
@ -107,7 +107,7 @@ const handleClose = () => {
|
||||
const rules = reactive({
|
||||
protocol: [Rules.requiredSelect],
|
||||
port: [Rules.requiredInput],
|
||||
address: [Rules.ip],
|
||||
address: [Rules.requiredInput],
|
||||
});
|
||||
|
||||
type FormInstance = InstanceType<typeof ElForm>;
|
||||
@ -121,6 +121,18 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
||||
if (!dialogData.value.rowData) return;
|
||||
if (dialogData.value.rowData.source === 'anyWhere') {
|
||||
dialogData.value.rowData.address = '';
|
||||
} else {
|
||||
if (dialogData.value.rowData.address.indexOf('/') !== -1) {
|
||||
if (checkIp(dialogData.value.rowData.address.split('/')[0])) {
|
||||
MsgError(i18n.global.t('firewall.addressFormatError'));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (checkIp(dialogData.value.rowData.address)) {
|
||||
MsgError(i18n.global.t('firewall.addressFormatError'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let ports = [];
|
||||
if (dialogData.value.rowData.port.indexOf('-') !== -1 && !dialogData.value.rowData.port.startsWith('-')) {
|
||||
|
Loading…
Reference in New Issue
Block a user