|
|
|
@ -26,9 +26,54 @@ const (
|
|
|
|
|
PATH_TO_LOCAL_PHP = PATH_TO_LOCAL_PHP_ROOT + PATH_TO_CONFIG_NAME
|
|
|
|
|
LOCK_PATH = "lock"
|
|
|
|
|
PHP_SEL_CONF = "/etc/hestia_php_selector/php_sel_path.conf"
|
|
|
|
|
PHP_TEMPLATE = "/usr/bin/php%s"
|
|
|
|
|
PHP_TEMPLATE_REMI = "/usr/bin/php%s"
|
|
|
|
|
PHP_TEMPLATE_BREPO = "/opt/brepo/php%s/bin/php"
|
|
|
|
|
HESTIA_CONF = "/usr/local/hestia/conf/hestia.conf"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func isFileExists(path string) (bool, bool, error) {
|
|
|
|
|
if fi, err := os.Stat(path); err == nil {
|
|
|
|
|
return true, fi.IsDir(), nil
|
|
|
|
|
} else if errors.Is(err, os.ErrNotExist) {
|
|
|
|
|
return false, false, nil
|
|
|
|
|
} else {
|
|
|
|
|
return false, false, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func get_php_type() string {
|
|
|
|
|
res := "remi"
|
|
|
|
|
ext, isd, err := isFileExists(HESTIA_CONF)
|
|
|
|
|
if err == nil && ext && !isd {
|
|
|
|
|
f, err := os.Open(HESTIA_CONF)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
scanner := bufio.NewScanner(f)
|
|
|
|
|
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
line := scanner.Text()
|
|
|
|
|
formatedLine := strings.SplitN(strings.TrimSpace(line), "=", 2)
|
|
|
|
|
if len(formatedLine) < 2 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if strings.TrimSpace(formatedLine[0]) == "LOCAL_PHP" {
|
|
|
|
|
result := strings.Trim(formatedLine[1], "' ")
|
|
|
|
|
if result == "yes" {
|
|
|
|
|
res = "brepo"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func escapeUserName(username string) string {
|
|
|
|
|
username0 := strings.TrimSpace(username)
|
|
|
|
|
uname := strings.Split(username0, "/")
|
|
|
|
@ -54,7 +99,11 @@ func getPathtpPHP(phpVer string) string {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf(PHP_TEMPLATE, phpVer)
|
|
|
|
|
if get_php_type() == "remi" {
|
|
|
|
|
return fmt.Sprintf(PHP_TEMPLATE_REMI, phpVer)
|
|
|
|
|
} else {
|
|
|
|
|
return fmt.Sprintf(PHP_TEMPLATE_BREPO, phpVer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -138,16 +187,6 @@ func setUserPHPVer(username string, php_ver string) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isFileExists(path string) (bool, bool, error) {
|
|
|
|
|
if fi, err := os.Stat(path); err == nil {
|
|
|
|
|
return true, fi.IsDir(), nil
|
|
|
|
|
} else if errors.Is(err, os.ErrNotExist) {
|
|
|
|
|
return false, false, nil
|
|
|
|
|
} else {
|
|
|
|
|
return false, false, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setUserPhpPathVer(username string, php_ver string, php_path string) error {
|
|
|
|
|
un := escapeUserName(username)
|
|
|
|
|
if un == "" {
|
|
|
|
|