Compare commits
9 Commits
pr@dev@ngi
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce3d4b16d7 | ||
|
|
4399ffa9a4 | ||
|
|
44a1d9d16c | ||
|
|
565fd1c605 | ||
|
|
09ac40846f | ||
|
|
a0b820649e | ||
|
|
6cee4bfe7c | ||
|
|
39335d848f | ||
|
|
86ab3eaa05 |
@@ -368,7 +368,11 @@ func (u *FirewallService) pingStatus() string {
|
|||||||
if _, err := os.Stat("/etc/sysctl.conf"); err != nil {
|
if _, err := os.Stat("/etc/sysctl.conf"); err != nil {
|
||||||
return constant.StatusNone
|
return constant.StatusNone
|
||||||
}
|
}
|
||||||
stdout, _ := cmd.Exec("sudo cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= ")
|
commond := "cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= "
|
||||||
|
if cmd.HasNoPasswordSudo() {
|
||||||
|
commond = "sudo cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= "
|
||||||
|
}
|
||||||
|
stdout, _ := cmd.Exec(commond)
|
||||||
if stdout == "net/ipv4/icmp_echo_ignore_all=1\n" {
|
if stdout == "net/ipv4/icmp_echo_ignore_all=1\n" {
|
||||||
return constant.StatusEnable
|
return constant.StatusEnable
|
||||||
}
|
}
|
||||||
@@ -404,7 +408,11 @@ func (u *FirewallService) updatePingStatus(enabel string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout, err := cmd.Exec("sudo sysctl -p")
|
commond := "sysctl -p"
|
||||||
|
if cmd.HasNoPasswordSudo() {
|
||||||
|
commond = "sudo sysctl -p"
|
||||||
|
}
|
||||||
|
stdout, err := cmd.Exec(commond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update ping status failed, err: %v", stdout)
|
return fmt.Errorf("update ping status failed, err: %v", stdout)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -999,7 +999,7 @@ func (w WebsiteService) UpdateRewriteConfig(req request.NginxRewriteUpdate) erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
includePath := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.PrimaryDomain, website.PrimaryDomain)
|
includePath := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.Alias, website.PrimaryDomain)
|
||||||
absolutePath := path.Join(nginxFull.Install.GetPath(), includePath)
|
absolutePath := path.Join(nginxFull.Install.GetPath(), includePath)
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
var oldRewriteContent []byte
|
var oldRewriteContent []byte
|
||||||
@@ -1041,7 +1041,7 @@ func (w WebsiteService) GetRewriteConfig(req request.NginxRewriteReq) (*response
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rewriteConfPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.PrimaryDomain, "rewrite", fmt.Sprintf("%s.conf", website.PrimaryDomain))
|
rewriteConfPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "rewrite", fmt.Sprintf("%s.conf", website.PrimaryDomain))
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
if fileOp.Stat(rewriteConfPath) {
|
if fileOp.Stat(rewriteConfPath) {
|
||||||
contentByte, err = fileOp.GetContent(rewriteConfPath)
|
contentByte, err = fileOp.GetContent(rewriteConfPath)
|
||||||
@@ -1087,12 +1087,18 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
absoluteIndexPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.PrimaryDomain, "index")
|
absoluteIndexPath := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index")
|
||||||
if website.SiteDir != "/" {
|
if website.SiteDir != "/" {
|
||||||
absoluteIndexPath = path.Join(absoluteIndexPath, website.SiteDir)
|
absoluteIndexPath = path.Join(absoluteIndexPath, website.SiteDir)
|
||||||
}
|
}
|
||||||
chownCmd := fmt.Sprintf("chown -R %s:%s %s", req.User, req.Group, absoluteIndexPath)
|
chownCmd := fmt.Sprintf("chown -R %s:%s %s", req.User, req.Group, absoluteIndexPath)
|
||||||
if _, err := cmd.ExecWithTimeOut(chownCmd, 1*time.Second); err != nil {
|
if cmd.HasNoPasswordSudo() {
|
||||||
|
chownCmd = fmt.Sprintf("sudo %s", chownCmd)
|
||||||
|
}
|
||||||
|
if out, err := cmd.ExecWithTimeOut(chownCmd, 1*time.Second); err != nil {
|
||||||
|
if out != "" {
|
||||||
|
return errors.New(out)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
website.User = req.User
|
website.User = req.User
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Exec(cmdStr string) (string, error) {
|
func Exec(cmdStr string) (string, error) {
|
||||||
@@ -88,3 +89,14 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
return stdout.String(), nil
|
return stdout.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasNoPasswordSudo() bool {
|
||||||
|
cmd := exec.Command("sudo", "-v")
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
cmd2 := exec.Command("sudo", "-n", "ls")
|
||||||
|
err2 := cmd2.Run()
|
||||||
|
return err2 == nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,18 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ufw struct{}
|
type Ufw struct {
|
||||||
|
CmdStr string
|
||||||
|
}
|
||||||
|
|
||||||
func NewUfw() (*Ufw, error) {
|
func NewUfw() (*Ufw, error) {
|
||||||
return &Ufw{}, nil
|
var ufw Ufw
|
||||||
|
if cmd.HasNoPasswordSudo() {
|
||||||
|
ufw.CmdStr = "sudo ufw"
|
||||||
|
} else {
|
||||||
|
ufw.CmdStr = "ufw"
|
||||||
|
}
|
||||||
|
return &ufw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) Name() string {
|
func (f *Ufw) Name() string {
|
||||||
@@ -18,18 +26,19 @@ func (f *Ufw) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) Status() (string, error) {
|
func (f *Ufw) Status() (string, error) {
|
||||||
stdout, err := cmd.Exec("sudo ufw status | grep Status")
|
stdout, _ := cmd.Execf("%s status | grep Status", f.CmdStr)
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("load the firewall status failed, err: %s", stdout)
|
|
||||||
}
|
|
||||||
if stdout == "Status: active\n" {
|
if stdout == "Status: active\n" {
|
||||||
return "running", nil
|
return "running", nil
|
||||||
}
|
}
|
||||||
|
stdout1, _ := cmd.Execf("%s status | grep 状态", f.CmdStr)
|
||||||
|
if stdout1 == "状态: 激活\n" {
|
||||||
|
return "running", nil
|
||||||
|
}
|
||||||
return "not running", nil
|
return "not running", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) Version() (string, error) {
|
func (f *Ufw) Version() (string, error) {
|
||||||
stdout, err := cmd.Exec("sudo ufw version | grep ufw")
|
stdout, err := cmd.Execf("%s version | grep ufwHasNoPasswordSudo", f.CmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("load the firewall status failed, err: %s", stdout)
|
return "", fmt.Errorf("load the firewall status failed, err: %s", stdout)
|
||||||
}
|
}
|
||||||
@@ -38,7 +47,7 @@ func (f *Ufw) Version() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) Start() error {
|
func (f *Ufw) Start() error {
|
||||||
stdout, err := cmd.Exec("echo y | sudo ufw enable")
|
stdout, err := cmd.Execf("echo y | %s enable", f.CmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("enable the firewall failed, err: %s", stdout)
|
return fmt.Errorf("enable the firewall failed, err: %s", stdout)
|
||||||
}
|
}
|
||||||
@@ -46,7 +55,7 @@ func (f *Ufw) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) Stop() error {
|
func (f *Ufw) Stop() error {
|
||||||
stdout, err := cmd.Exec("sudo ufw disable")
|
stdout, err := cmd.Execf("%s disable", f.CmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("stop the firewall failed, err: %s", stdout)
|
return fmt.Errorf("stop the firewall failed, err: %s", stdout)
|
||||||
}
|
}
|
||||||
@@ -58,7 +67,7 @@ func (f *Ufw) Reload() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) ListPort() ([]FireInfo, error) {
|
func (f *Ufw) ListPort() ([]FireInfo, error) {
|
||||||
stdout, err := cmd.Exec("sudo ufw status verbose")
|
stdout, err := cmd.Execf("%s status verbose", f.CmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -83,7 +92,7 @@ func (f *Ufw) ListPort() ([]FireInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Ufw) ListAddress() ([]FireInfo, error) {
|
func (f *Ufw) ListAddress() ([]FireInfo, error) {
|
||||||
stdout, err := cmd.Exec("sudo ufw status verbose")
|
stdout, err := cmd.Execf("%s status verbose", f.CmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -123,9 +132,9 @@ func (f *Ufw) Port(port FireInfo, operation string) error {
|
|||||||
return fmt.Errorf("unsupport strategy %s", port.Strategy)
|
return fmt.Errorf("unsupport strategy %s", port.Strategy)
|
||||||
}
|
}
|
||||||
|
|
||||||
command := fmt.Sprintf("sudo ufw %s %s", port.Strategy, port.Port)
|
command := fmt.Sprintf("%s %s %s", f.CmdStr, port.Strategy, port.Port)
|
||||||
if operation == "remove" {
|
if operation == "remove" {
|
||||||
command = fmt.Sprintf("sudo ufw delete %s %s", port.Strategy, port.Port)
|
command = fmt.Sprintf("%s delete %s %s", f.CmdStr, port.Strategy, port.Port)
|
||||||
}
|
}
|
||||||
if len(port.Protocol) != 0 {
|
if len(port.Protocol) != 0 {
|
||||||
command += fmt.Sprintf("/%s", port.Protocol)
|
command += fmt.Sprintf("/%s", port.Protocol)
|
||||||
@@ -147,9 +156,9 @@ func (f *Ufw) RichRules(rule FireInfo, operation string) error {
|
|||||||
return fmt.Errorf("unsupport strategy %s", rule.Strategy)
|
return fmt.Errorf("unsupport strategy %s", rule.Strategy)
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleStr := fmt.Sprintf("sudo ufw %s ", rule.Strategy)
|
ruleStr := fmt.Sprintf("%s %s ", f.CmdStr, rule.Strategy)
|
||||||
if operation == "remove" {
|
if operation == "remove" {
|
||||||
ruleStr = fmt.Sprintf("sudo ufw delete %s ", rule.Strategy)
|
ruleStr = fmt.Sprintf("%s delete %s ", f.CmdStr, rule.Strategy)
|
||||||
}
|
}
|
||||||
if len(rule.Protocol) != 0 {
|
if len(rule.Protocol) != 0 {
|
||||||
ruleStr += fmt.Sprintf("proto %s ", rule.Protocol)
|
ruleStr += fmt.Sprintf("proto %s ", rule.Protocol)
|
||||||
|
|||||||
@@ -54,16 +54,16 @@ export const loadBaseDir = () => {
|
|||||||
|
|
||||||
// backup
|
// backup
|
||||||
export const handleBackup = (params: Backup.Backup) => {
|
export const handleBackup = (params: Backup.Backup) => {
|
||||||
return http.post(`/settings/backup/backup`, params, 400000);
|
return http.post(`/settings/backup/backup`, params, 600000);
|
||||||
};
|
};
|
||||||
export const handleRecover = (params: Backup.Recover) => {
|
export const handleRecover = (params: Backup.Recover) => {
|
||||||
return http.post(`/settings/backup/recover`, params, 400000);
|
return http.post(`/settings/backup/recover`, params, 600000);
|
||||||
};
|
};
|
||||||
export const handleRecoverByUpload = (params: Backup.Recover) => {
|
export const handleRecoverByUpload = (params: Backup.Recover) => {
|
||||||
return http.post(`/settings/backup/recover/byupload`, params, 400000);
|
return http.post(`/settings/backup/recover/byupload`, params, 600000);
|
||||||
};
|
};
|
||||||
export const downloadBackupRecord = (params: Backup.RecordDownload) => {
|
export const downloadBackupRecord = (params: Backup.RecordDownload) => {
|
||||||
return http.post<string>(`/settings/backup/record/download`, params);
|
return http.post<string>(`/settings/backup/record/download`, params, 600000);
|
||||||
};
|
};
|
||||||
export const deleteBackupRecord = (params: { ids: number[] }) => {
|
export const deleteBackupRecord = (params: { ids: number[] }) => {
|
||||||
return http.post(`/settings/backup/record/del`, params);
|
return http.post(`/settings/backup/record/del`, params);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue';
|
|||||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||||
import { Host } from '@/api/interface/host';
|
import { Host } from '@/api/interface/host';
|
||||||
import { operatePortRule, updatePortRule } from '@/api/modules/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 loading = ref();
|
||||||
const oldRule = ref<Host.RulePort>();
|
const oldRule = ref<Host.RulePort>();
|
||||||
@@ -107,7 +107,7 @@ const handleClose = () => {
|
|||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
protocol: [Rules.requiredSelect],
|
protocol: [Rules.requiredSelect],
|
||||||
port: [Rules.requiredInput],
|
port: [Rules.requiredInput],
|
||||||
address: [Rules.ip],
|
address: [Rules.requiredInput],
|
||||||
});
|
});
|
||||||
|
|
||||||
type FormInstance = InstanceType<typeof ElForm>;
|
type FormInstance = InstanceType<typeof ElForm>;
|
||||||
@@ -121,6 +121,18 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||||||
if (!dialogData.value.rowData) return;
|
if (!dialogData.value.rowData) return;
|
||||||
if (dialogData.value.rowData.source === 'anyWhere') {
|
if (dialogData.value.rowData.source === 'anyWhere') {
|
||||||
dialogData.value.rowData.address = '';
|
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 = [];
|
let ports = [];
|
||||||
if (dialogData.value.rowData.port.indexOf('-') !== -1 && !dialogData.value.rowData.port.startsWith('-')) {
|
if (dialogData.value.rowData.port.indexOf('-') !== -1 && !dialogData.value.rowData.port.startsWith('-')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user