@@ -2064,15 +2064,15 @@ function umount_backup_dir($backup_dir, $mount_cmd = '/usr/local/ispconfig/serve
20642064
20652065 function _getinitcommand ($ servicename , $ action , $ init_script_directory = '' , $ check_service ) {
20662066 global $ conf , $ app ;
2067-
2067+
20682068 // upstart
20692069 /* removed upstart support - deprecated
20702070 if(is_executable('/sbin/initctl')){
20712071 exec('/sbin/initctl version 2>/dev/null | /bin/grep -q upstart', $retval['output'], $retval['retval']);
20722072 if(intval($retval['retval']) == 0) return 'service '.$servicename.' '.$action;
20732073 }
20742074 */
2075-
2075+
20762076 if (!in_array ($ action ,array ('start ' ,'stop ' ,'restart ' ,'reload ' ,'force-reload ' ))) {
20772077 $ app ->log ('Invalid init command action ' .$ action ,LOGLEVEL_WARN );
20782078 return false ;
@@ -2081,18 +2081,18 @@ function _getinitcommand($servicename, $action, $init_script_directory = '', $ch
20812081 //* systemd (now default in all supported OS)
20822082 if (is_executable ('/bin/systemd ' ) || is_executable ('/usr/bin/systemctl ' )){
20832083 $ app ->log ('Trying to use Systemd to restart service ' ,LOGLEVEL_DEBUG );
2084-
2084+
20852085 //* Test service name via regex
20862086 if (preg_match ('/[a-zA-Z0-9\.\-\_]/ ' ,$ servicename )) {
2087-
2087+
20882088 //* Test if systemd service is enabled
20892089 if ($ check_service ) {
20902090 $ this ->exec_safe ("systemctl is-enabled ? 2>&1 " , $ servicename );
20912091 $ ret_val = $ this ->last_exec_retcode ();
20922092 } else {
20932093 $ app ->log ('Systemd service ' .$ servicename .' not found or not enabled. ' ,LOGLEVEL_DEBUG );
20942094 }
2095-
2095+
20962096 //* Return service command
20972097 if ($ ret_val == 0 || !$ check_service ) {
20982098 return 'systemctl ' .$ action .' ' .$ servicename .'.service ' ;
@@ -2108,69 +2108,69 @@ function _getinitcommand($servicename, $action, $init_script_directory = '', $ch
21082108
21092109 //* sysvinit fallback
21102110 $ app ->log ('Using init script to restart service ' ,LOGLEVEL_DEBUG );
2111-
2111+
21122112 //* Get init script directory
21132113 if ($ init_script_directory == '' ) $ init_script_directory = $ conf ['init_scripts ' ];
21142114 if (substr ($ init_script_directory , -1 ) === '/ ' ) $ init_script_directory = substr ($ init_script_directory , 0 , -1 );
21152115 $ init_script_directory = realpath ($ init_script_directory );
2116-
2116+
21172117 //* Check init script dir
21182118 if (!is_dir ($ init_script_directory )) {
21192119 $ app ->log ('Init script directory ' .$ init_script_directory .' not found ' ,LOGLEVEL_WARN );
21202120 return false ;
21212121 }
2122-
2122+
21232123 //* Forbidden init script paths
21242124 if (substr ($ init_script_directory ,0 ,4 ) == '/var ' || substr ($ init_script_directory ,0 ,4 ) == '/tmp ' ) {
21252125 $ app ->log ('Do not put init scripts in /var or /tmp folder. ' ,LOGLEVEL_WARN );
21262126 return false ;
21272127 }
2128-
2128+
21292129 //* Check init script dir owner
21302130 if (fileowner ($ init_script_directory ) !== 0 ) {
21312131 $ app ->log ('Init script directory ' .$ init_script_directory .' not owned by root user ' ,LOGLEVEL_WARN );
21322132 return false ;
21332133 }
2134-
2134+
21352135 $ full_init_script_path = realpath ($ init_script_directory .'/ ' .$ servicename );
2136-
2136+
21372137 //** Gentoo, keep symlink as init script, but do some checks
2138- if (file_exists ('/etc/gentoo-release ' )) {
2138+ if (file_exists ('/etc/gentoo-release ' )) {
21392139 //* check if init script is symlink
2140- if (is_link ($ init_script_directory .'/ ' .$ servicename )) {
2140+ if (is_link ($ init_script_directory .'/ ' .$ servicename )) {
21412141 //* Check init script owner (realpath, symlink is checked later)
21422142 if (fileowner ($ full_init_script_path ) !== 0 ) {
21432143 $ app ->log ('Init script ' .$ full_init_script_path .' not owned by root user ' ,LOGLEVEL_WARN );
21442144 return false ;
21452145 }
2146-
2146+
21472147 //* full path is symlink
21482148 $ full_init_script_path_symlink = $ init_script_directory .'/ ' .$ servicename ;
2149-
2149+
21502150 //* check if realpath matches symlink
21512151 if (strpos ($ full_init_script_path_symlink ,$ full_init_script_path ) == 0 ) {
21522152 $ full_init_script_path = $ full_init_script_path_symlink ;
21532153 }
21542154 }
21552155 }
2156-
2156+
21572157 if ($ full_init_script_path == '' ) {
21582158 $ app ->log ('No init script, we quit here. ' ,LOGLEVEL_WARN );
21592159 return false ;
21602160 }
2161-
2161+
21622162 //* Check init script
21632163 if (!is_file ($ full_init_script_path )) {
21642164 $ app ->log ('Init script ' .$ full_init_script_path .' not found ' ,LOGLEVEL_WARN );
21652165 return false ;
21662166 }
2167-
2167+
21682168 //* Check init script owner
21692169 if (fileowner ($ full_init_script_path ) !== 0 ) {
21702170 $ app ->log ('Init script ' .$ full_init_script_path .' not owned by root user ' ,LOGLEVEL_WARN );
21712171 return false ;
21722172 }
2173-
2173+
21742174 if ($ check_service && is_executable ($ full_init_script_path )) {
21752175 return $ full_init_script_path .' ' .$ action ;
21762176 }
0 commit comments