Added config of php path

This commit is contained in:
Alexey Berezhok
2024-08-27 16:08:31 +03:00
parent 1554fe41b7
commit 9ba459325f
3 changed files with 44 additions and 7 deletions

View File

@@ -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 {