mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-09 16:00:29 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0b820649e | ||
|
|
6cee4bfe7c |
@@ -999,7 +999,7 @@ func (w WebsiteService) UpdateRewriteConfig(req request.NginxRewriteUpdate) erro
|
||||
if err != nil {
|
||||
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)
|
||||
fileOp := files.NewFileOp()
|
||||
var oldRewriteContent []byte
|
||||
@@ -1041,7 +1041,7 @@ func (w WebsiteService) GetRewriteConfig(req request.NginxRewriteReq) (*response
|
||||
if err != nil {
|
||||
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()
|
||||
if fileOp.Stat(rewriteConfPath) {
|
||||
contentByte, err = fileOp.GetContent(rewriteConfPath)
|
||||
@@ -1087,12 +1087,18 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss
|
||||
if err != nil {
|
||||
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 != "/" {
|
||||
absoluteIndexPath = path.Join(absoluteIndexPath, website.SiteDir)
|
||||
}
|
||||
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
|
||||
}
|
||||
website.User = req.User
|
||||
|
||||
@@ -88,3 +88,14 @@ func Execf(cmdStr string, a ...interface{}) (string, error) {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user