Added config of php path
This commit is contained in:
@@ -25,6 +25,8 @@ const (
|
||||
PATH_TO_LOCAL_PHP_ROOT = "php_sel"
|
||||
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"
|
||||
)
|
||||
|
||||
func escapeUserName(username string) string {
|
||||
@@ -41,6 +43,21 @@ func isExecOther(mode os.FileMode) bool {
|
||||
return mode&0001 != 0
|
||||
}
|
||||
|
||||
func getPathtpPHP(phpVer string) string {
|
||||
cont, err := os.ReadFile(PHP_SEL_CONF)
|
||||
if err == nil {
|
||||
result := strings.Split(strings.TrimSpace(string(cont)), "\n")
|
||||
if len(result) > 0 {
|
||||
php_check := strings.TrimSpace(result[0])
|
||||
if (len(php_check) > 0) && (strings.Contains(php_check, "%s")) {
|
||||
return fmt.Sprintf(php_check, phpVer)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(PHP_TEMPLATE, phpVer)
|
||||
|
||||
}
|
||||
|
||||
func getPHPVerFromConf(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
@@ -77,7 +94,7 @@ func getUserPHPVerHestia(username string) (string, string, error) {
|
||||
if phpVer == "" {
|
||||
return "", "", nil
|
||||
}
|
||||
phpPath := "/usr/bin/php" + phpVer
|
||||
phpPath := getPathtpPHP(phpVer)
|
||||
if finfo, err := os.Stat(phpPath); err != nil {
|
||||
return "", "", err
|
||||
} else {
|
||||
@@ -97,7 +114,7 @@ func setUserPHPVer(username string, php_ver string) error {
|
||||
matches := reIsVer.FindStringSubmatch(php_ver)
|
||||
if len(matches) > 1 {
|
||||
phpver := strings.TrimSpace(matches[1])
|
||||
phpPath := "/usr/bin/php" + phpver
|
||||
phpPath := getPathtpPHP(phpver)
|
||||
if finfo, err := os.Stat(phpPath); err != nil {
|
||||
return err
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user