@@ -2555,7 +2555,7 @@ public function create_jailkit_chroot($home_dir, $app_sections = array(), $optio
25552555 } elseif (is_string ($ app_sections )) {
25562556 $ app_sections = preg_split ('/[\s,]+/ ' , $ app_sections );
25572557 }
2558- if (! is_array ($ options )) {
2558+ if (!is_array ($ options )) {
25592559 $ options = (is_string ($ options ) ? preg_split ('/[\s,]+/ ' , $ options ) : array ());
25602560 }
25612561
@@ -2588,8 +2588,15 @@ public function create_jailkit_chroot($home_dir, $app_sections = array(), $optio
25882588
25892589 // Initialize the chroot into the specified directory with the specified applications
25902590 $ cmd = 'jk_init ' . $ program_args ;
2591+ $ app ->log ("Executing command: $ cmd " , LOGLEVEL_DEBUG );
25912592 $ this ->exec_safe ($ cmd , $ home_dir );
25922593
2594+ // Check for errors in the command execution
2595+ if ($ this ->last_exec_retcode () != 0 ) {
2596+ $ app ->log ("Error executing jk_init command: " . implode ("\n" , $ this ->last_exec_out ()), LOGLEVEL_ERROR );
2597+ return false ;
2598+ }
2599+
25932600 // Create the tmp and /var/run directories
25942601 if (!is_dir ($ home_dir . '/tmp ' )) {
25952602 $ this ->mkdirpath ($ home_dir . '/tmp ' , 0770 );
@@ -2694,6 +2701,8 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
26942701 global $ app ;
26952702
26962703 $ app ->log ("update_jailkit_chroot called for $ home_dir with options " .print_r ($ options , true ), LOGLEVEL_DEBUG );
2704+ $ app ->log ("update_jailkit_chroot called for $ home_dir with sections " .print_r ($ sections , true ), LOGLEVEL_DEBUG );
2705+
26972706 $ app ->uses ('ini_parser ' );
26982707
26992708 // Disallow operating on root directory
@@ -2738,7 +2747,7 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
27382747 $ jk_cp_args .= ' -f ' ;
27392748 break ;
27402749 default :
2741- if (preg_match ('@^skip[ =]/?(.+)$@ ' , $ opt , $ matches ) ) {
2750+ if (is_string ( $ opt ) && preg_match ('@^skip[ =]/?(.+)$@ ' , $ opt , $ matches ) ) {
27422751 if (in_array ($ matches [1 ], $ jailkit_directories )) {
27432752 $ app ->log ("update_jailkit_chroot: skipping update of jailkit directory $ home_dir/ " .$ matches [1 ]
27442753 . "; if this is in use as a web folder, it is insecure and should be fixed. " , LOGLEVEL_WARN );
@@ -2877,37 +2886,48 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
28772886 $ this ->chmod ($ home_dir . '/var/tmp ' , 0770 , true );
28782887 }
28792888
2880- $ os_type = $ app ->system ->get_os_type ();
2881- if (isset ($ os_type ['type ' ])) {
2882- $ used_os_type = $ os_type ['type ' ];
2883- } else {
2884- $ used_os_type = 'unknown ' ;
2885- }
2889+ // If update_jailkit_chroot was called from cronjob 600-jailkit.inc.php, we need to check if the PHP cli binary is available in the jail
2890+ if (isset ($ options ['jk_php_maintenance_check ' ]) && $ options ['jk_php_maintenance_check ' ] == 'yes ' ) {
2891+ $ os_type = $ app ->system ->get_os_type ();
2892+ $ used_os_type = isset ($ os_type ['type ' ]) ? $ os_type ['type ' ] : 'unknown ' ;
2893+
2894+ if (is_array ($ options ['homedir_usernames ' ]) && !empty ($ options ['homedir_usernames ' ])) {
2895+ foreach ($ options ['homedir_usernames ' ] as $ homedir_username ) {
28862896
2887- if ($ options ['jk_php_maintenance_check ' ] == 'yes ' ) {
2888- $ alternatives_php = $ home_dir . '/etc/alternatives/php ' ;
2897+ if ($ used_os_type == "debian " || $ used_os_type == "ubuntu " ) {
2898+ $ php_binary = $ home_dir . '/etc/alternatives/php ' ;
2899+ } elseif ($ used_os_type == "redhat " ) {
2900+ $ php_binary = $ home_dir . '/home/ ' . $ homedir_username . '/.local/bin/php ' ;
2901+ } else {
2902+ $ php_binary = $ home_dir . '/home/ ' . $ homedir_username . '/.local/bin/php ' ;
2903+ }
28892904
2890- if (!empty ($ options ['php_cli_binary ' ])) {
2891- $ php_bin_dir = dirname ($ options ['php_cli_binary ' ]);
2892- if (!file_exists ($ home_dir . '/ ' . $ options ['php_cli_binary ' ])) {
2893- $ app ->log ("update_jailkit_chroot: The PHP cli binary " . $ options ['php_cli_binary ' ] . " is not available in the jail of the web " . $ options ['domain ' ], LOGLEVEL_DEBUG );
2905+ if (!empty ($ options ['php_cli_binary ' ])) {
2906+ $ php_bin_dir = dirname ($ options ['php_cli_binary ' ]);
2907+ if (!file_exists ($ home_dir . '/ ' . $ options ['php_cli_binary ' ])) {
2908+ $ app ->log ("update_jailkit_chroot: The PHP cli binary " . $ options ['php_cli_binary ' ] . " is not available in the jail of the web " . $ options ['domain ' ], LOGLEVEL_DEBUG );
28942909
2895- $ fallback_php = $ app ->system ->get_newest_php_bin ($ home_dir . $ php_bin_dir );
2896- $ fallback_php_bin = str_replace ($ home_dir , '' , $ fallback_php );
2910+ $ fallback_php = $ app ->system ->get_newest_php_bin ($ home_dir . $ php_bin_dir );
2911+ $ fallback_php_bin = str_replace ($ home_dir , '' , $ fallback_php );
28972912
2898- if (!empty ($ fallback_php ) && file_exists ($ fallback_php_bin )) {
2899- if (is_link ($ alternatives_php ) || is_file ($ alternatives_php ) || !file_exists ($ alternatives_php )) {
2900- unlink ($ alternatives_php );
2901- symlink ($ fallback_php_bin , $ alternatives_php );
2902- $ app ->log ("update_jailkit_chroot: Found " . $ fallback_php_bin . " as a fallback for alternatives/php in the jail of " . $ options ['domain ' ], LOGLEVEL_DEBUG );
2903- }
2904- }
2905- } else {
2906- if ($ used_os_type == "debian " || $ $ used_os_type == "ubuntu " ) {
2907- $ app ->log ("update_jailkit_chroot: setting alternatives/php to " . $ options ['php_cli_binary ' ], LOGLEVEL_DEBUG );
2908- if (is_link ($ alternatives_php ) || is_file ($ alternatives_php ) || !file_exists ($ alternatives_php )) {
2909- unlink ($ alternatives_php );
2910- symlink ($ options ['php_cli_binary ' ], $ alternatives_php );
2913+ if (!empty ($ fallback_php ) && file_exists ($ fallback_php_bin )) {
2914+ if (is_link ($ php_binary ) || is_file ($ php_binary ) || !file_exists ($ php_binary )) {
2915+ unlink ($ php_binary );
2916+ symlink ($ fallback_php_bin , $ php_binary );
2917+ $ app ->log ("update_jailkit_chroot: Found " . $ fallback_php_bin . " as a fallback for PHP in the jail of " . $ options ['domain ' ], LOGLEVEL_DEBUG );
2918+ }
2919+ }
2920+ } else {
2921+ $ app ->log ("update_jailkit_chroot: setting PHP to " . $ options ['php_cli_binary ' ], LOGLEVEL_DEBUG );
2922+ if (is_link ($ php_binary ) || is_file ($ php_binary ) || !file_exists ($ php_binary )) {
2923+ unlink ($ php_binary );
2924+ symlink ($ options ['php_cli_binary ' ], $ php_binary );
2925+ if ($ used_os_type == "debian " || $ $ used_os_type == "ubuntu " ) {
2926+ if (file_exists ($ home_dir . '/home/ ' . $ homedir_username . '/.local/bin/php ' )) {
2927+ unlink ($ home_dir . '/home/ ' . $ homedir_username . '/.local/bin/php ' );
2928+ }
2929+ }
2930+ }
29112931 }
29122932 }
29132933 }
@@ -3096,8 +3116,7 @@ public function get_newest_php_bin($bin_directory) {
30963116 while (false !== ($ entry = readdir ($ handle ))) {
30973117 $ full_path = $ bin_directory . '/ ' . $ entry ;
30983118 // Check if the filename matches a pattern for commonly available PHP CLI binaries
3099- // and ensure they are not symbolic links
3100- if (preg_match ('/^php(\d{1,2}\.?\d{1,2})?$/ ' , $ entry ) && !is_link ($ full_path ) && is_file ($ full_path )) {
3119+ if (preg_match ('/^php(\d{1,2}\.?\d{1,2})?$/ ' , $ entry ) && file_exists ($ full_path )) {
31013120 $ php_binaries [] = $ entry ;
31023121 }
31033122 }
0 commit comments