plugins->registerEvent('software_update_inst_insert',$this->plugin_name,'process'); //$app->plugins->registerEvent('software_update_inst_update',$this->plugin_name,'process'); //$app->plugins->registerEvent('software_update_inst_delete',$this->plugin_name,'process'); } function process($event_name,$data) { global $app, $conf; if(!$conf['software_updates_enabled'] == true) { $app->log('Software Updates not enabled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_ERROR); return false; } //* Get the info of the package: $software_update_id = intval($data["new"]["software_update_id"]); $software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'"); $temp_dir = '/tmp/'.md5 (uniqid (rand())); $app->log("The temp dir is $temp_dir",LOGLEVEL_DEBUG); mkdir($temp_dir); if(!is_dir($temp_dir)) { $app->log("Unable to create temp directory.",LOGLEVEL_ERROR); return false; } exec("cd $temp_dir && wget ".$software_update["update_url"]); $app->log("Downloading the update file from: ".$software_update["update_url"],LOGLEVEL_DEBUG); $url_parts = parse_url($software_update["update_url"]); $update_filename = basename($url_parts["path"]); $app->log("The update filename is $update_filename",LOGLEVEL_DEBUG); if(is_file($temp_dir.'/'.$update_filename)) { //* Checking the md5sum if(md5_file($temp_dir.'/'.$update_filename) != $software_update["update_md5"]) { $app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_ERROR); exec("rm -rf $temp_dir"); $app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG); return false; } else { $app->log("md5sum of the downloaded file is verified.",LOGLEVEL_DEBUG); } //* unpacking the update exec("cd $temp_dir && unzip $update_filename"); if(is_file($temp_dir.'/setup.sh')) { // Execute the setup script exec('chmod +x '.$temp_dir.'/setup.sh'); $app->log("Executing setup.sh file in directory $temp_dir",LOGLEVEL_DEBUG); exec('cd '.$temp_dir.' && ./setup.sh'); $app->db->query("UPDATE software_update_inst SET status = 'installed' WHERE software_update_inst_id = ".$data["new"]["software_update_inst_id"]); } else { $app->log("setup.sh file not found",LOGLEVEL_ERROR); } } else { $app->log("Download of the update file failed",LOGLEVEL_ERROR); } exec("rm -rf $temp_dir"); $app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG); } } // end class ?>