63 mail(
"alterncpanel@$L_FQDN",
'Script do_actions.php issues',
"\n Errors reporting mail:\n\n$error_raise");
72 $cmd_line =
"$command ";
76 $cmd_line.=
" ".escapeshellarg($pp).
" ";
83 exec($cmd_line, $output, $code);
84 return array(
'executed' => $cmd_line,
'output'=>$output,
'return_var'=>$code);
87 require_once(
"/usr/share/alternc/panel/class/config_nochk.php");
89 $admin->stop_if_jobs_locked();
98 d(
"Lock file already exists. ");
101 d(
"My PID is $MY_PID, PID in the lock file is $PID");
102 if ($PID == exec(
"pidof $SCRIPT | tr ' ' '\n' | grep -v $MY_PID")){
104 d(
"Previous cron is already running, we just exit and let it finish :-)");
108 $error_raise.=
"Lock file already exists. No process with PID $PID found! Previous cron failed...\n";
124 while($cc=$action->get_job()){
126 $params=unserialize(
$c[
"parameters"]);
128 d(
"Previous job was the n°".
$c[
"id"].
" : '".
$c[
"type"].
"'");
129 if($c[
"type"] ==
"CREATE_FILE" && is_dir(dirname($params[
"file"])) || $c[
"type"] ==
"CREATE_DIR" || $c[
"type"] ==
"DELETE" || $c[
"type"] ==
"FIX_DIR" || $c[
"type"] ==
"FIX_FILE"){
130 d(
"Reset of the job! So it will be resumed...");
131 $action->reset_job($c[
"id"]);
134 $error_raise.=
"Can't resume the job n°".$c[
"id"].
" action '".$c[
"type"].
"', finishing it with a fail status.\n";
135 if(!$action->finish($c[
"id"],
"Fail: Previous script crashed while processing this action, cannot resume it.")){
136 $error_raise.=
"Cannot finish the action! Error while inserting the error value in the DB for action n°".$c[
"id"].
" : action '".$c[
"type"].
"'\n";
152 while ($rr=$action->get_action()){
156 if(
$r[
"user"] !=
"root")
157 $SU=
"su ".$r[
"user"].
" 2>&1 ;";
162 d(
"-----------\nBeginning action n°".
$r[
"id"]);
163 $action->begin(
$r[
"id"]);
165 $params=@unserialize(
$r[
"parameters"]);
167 d(
"Executing action '".
$r[
"type"].
"' with user '".
$r[
"user"].
"'");
171 #@exec("$FIXPERM -u ".$params["uid"]." 2>&1", $trash, $code);
172 $returned =
execute_cmd(
"$FIXPERM -u", $params[
"uid"]);
175 if(!file_exists($params[
"file"])) {
176 #@exec("$SU touch ".$params["file"]." 2>&1 ; echo '".$params["content"]."' > '".$params["file"]."' 2>&1", $output);
177 if ( file_put_contents($params[
"file"], $params[
"content"]) ===
false ) {
178 $log_error=array(
"Fail: can't write into file ".$params[
"file"]);
180 if (!chown($params[
"file"],
$r[
"user"])) {
181 $log_error=array(
"Fail: cannot chown ".$params[
"file"]);
185 $log_error=array(
"Fail: file already exists ".$params[
"file"]);
190 #@exec("$SU mkdir -p ".$params["dir"]." 2>&1",$output);
191 $returned =
execute_cmd(
"$SU mkdir", array(
'-p', $params[
"dir"]));
195 #@exec("$SU rm -rf ".$params["dir"]." 2>&1", $output);
196 $returned =
execute_cmd(
"$SU rm", array(
'-rf', $params[
"dir"]));
200 if(!is_dir($params[
"dst"]))
201 if ( @mkdir($params[
"dst"], 0777,
true)) {
202 if ( @chown($params[
"dst"],
$r[
"user"]) ) {
203 $returned =
execute_cmd(
"$SU mv -f", array($params[
"src"], $params[
"dst"]));
206 $log_error=array(
"Fail: cannot create ".$params[
"dst"]);
212 if($returned[
'return_val'] != 0) $log_error=array(
"Fixperms.sh failed, returned error code : ".$returned[
'return_val']);
215 #@exec("$FIXPERM -f ".$params["file"]." 2>&1", $trash, $code);
217 if($returned[
'return_val'] != 0) $log_error=array(
"Fixperms.sh failed, returned error code : ".$returned[
'return_val']);
220 $output=array(
"Fail: Sorry dude, i do not know this type of action");
224 if(
isset($output[0])){
226 $error_raise.=
"\nAction n°".$r[
"id"].
" '".
$r[
"type"].
"' failed! With user: ".
$r[
"user"].
"\nHere is the complete output:\n".print_r($output);
229 d(
"Finishing... return value is : $return\n");
230 if(!$action->finish(
$r[
"id"],addslashes($return))){
231 $error_raise.=
"Cannot finish the action! Error while inserting the error value in the DB for action n°".$c[
"id"].
" : action '".
$c[
"type"].
"'\nReturn value: ".addslashes($return).
"\n";