log($level,$message,$data,true); } public static function shellExec($cmdName,$cmdParams="",$sudo=false){ $myCmd=($sudo?"sudo ":"").$cmdName.($cmdParams!=""?" ".$cmdParams:""); self::logMessage(LoggingFacility::$LEVEL_DEBUG,"log.sysctl.tryexecute",$myCmd." 2>&1"); $answers=array(); $execReturn=null; exec($myCmd." 2>&1",$answers,$execReturn); $return=new SystemAnswer($execReturn,$answers); if ($return->status!=0){ if ( is_array($return->messages) && sizeof($return->messages)>0 ){ foreach ($return->messages as $answer){ self::logMessage(LoggingFacility::$LEVEL_DEBUG,$answer); } } self::logMessage(LoggingFacility::$LEVEL_ERROR,"log.sysctl.cantexecute",$myCmd." 2>&1",true); // $catParameters=array($myCmd,$return->messages[sizeof($return->messages)-1],$return); throw new SystemException("Error while executing command '".$myCmd."'. Last message '".$return->messages[sizeof($return->messages)-1]."'"); } self::logMessage(LoggingFacility::$LEVEL_INFO,"log.sysctl.correctlyexecute",$myCmd." 2>&1",true); return $return; } public static function executeCustomCommand($cmdName,$cmdParams="",$sudo=false){ $binpath = GlobalVariables::get("config")->paths->binaries; return self::shellExec($binpath."/".$cmdName,$cmdParams,$sudo); } // public static function executeTask($cmdName,$cmdParams="",$sudo=false){ // $basePath = GlobalVariables::get("config")->paths->task; // return self::shellExec($basePath."/".$cmdName,$cmdParams,$sudo); // } public static function mountRo($path) { return self::executeCustomCommand("mountro",'"'.$path.'"'); } public static function mountRw($path) { return self::executeCustomCommand("mountrw",'"'.$path.'"'); } public static function cp($source,$dest,$useSudo=false){ return self::shellExec("cp",'"'.$source.'" "'.$dest.'"',$useSudo); } public static function cpRec($source,$dest,$useSudo=false){ return self::shellExec("cp",'-r "'.$source.'" "'.$dest.'"',$useSudo); } public static function mv($source,$dest,$useSudo=false){ return self::shellExec("mv",'"'.$source.'" "'.$dest.'"',$useSudo); } public static function touch($path,$useSudo=false){ return self::shellExec("touch",'"'.$path.'"',$useSudo); } public static function mkdir($path,$useSudo=false){ return self::shellExec("mkdir",'"'.$path.'"',$useSudo); } public static function rm($path,$useSudo=false){ return self::shellExec("rm",'"'.$path.'"',$useSudo); } public static function wget($targetPage,$destFile,$useSudo=false){ return self::shellExec("wget",'-O "'.$destFile.'" '.$targetPage,$useSudo); } } class SystemAnswer { public $status; public $messages; public function __construct($status,$messages){ $this->status=$status; $this->messages=$messages; } } ?>