/** Update routine. * This function represents the update routine, which will perform updates in background while the bot runs normally. * * \return Nothing. */ public function updateRoutine() { foreach ($this->_scheduled as $i => &$update) { if (!$update['started']) { Leelabot::message("Downloading update \$0...", array($this->_updates[$update['i']]->rev)); if (!is_dir('tmp')) { mkdir('tmp'); } $update['started'] = TRUE; $update['infp'] = fopen($this->_updates[$update['i']]->url, 'r'); $update['outfp'] = fopen('tmp/update_' . $this->_updates[$update['i']]->rev . '.tar.gz', 'w+'); } //If we haven't downloaded all the file if (!feof($update['infp'])) { fputs($update['outfp'], fread($update['infp'], 1024)); return; } Leelabot::message("Installing update \$0...", array($this->_updates[$update['i']]->rev)); $gz = new gzip_file("tmp/update_" . $this->_updates[$update['i']]->rev . '.tar.gz'); $gz->set_options(array('overwrite' => 1)); $gz->extract_files(); Leelabot::message("Update \$0 done.", array($this->_updates[$update['i']]->rev)); unset($this->_scheduled[$i]); } }
echo $extracter->error; } //$errors.="<li>".$_FILES[$id."file_".$i]["name"]." ".$this->Lang("unpackfail"); //$errors.=implode(",",$extracter->error)."</li>\n"; } else { $message = "newuploadsuccess"; $messagecount++; //$messages.="<li>".$_FILES[$id."file_".$i]["name"]." ".$this->Lang("unpacksuccess")."</li>\n"; } break; case "bzip": case "bz": include_once dirname(__FILE__) . "/untgz.php"; $extracter = new gzip_file($_FILES[$id . "file_" . $i]["tmp_name"]); $extracter->set_options(array("basedir" => $fullpath . "/tmp/testtmp/", "overwrite" => 1)); $extracter->extract_files(); if (count($extracter->error) > 0) { //$errors.="<li>".$_FILES[$id."file_".$i]["name"]." ".$this->Lang("unpackfail"); //$errors.=implode(",",$extracter->error)."</li>\n"; $error = "newuploadfailed"; $errorcount++; if ($config["debug"]) { echo $extracter->error; } } else { $message = "newuploadsuccess"; $messagecount++; //$messages.="<li>".$_FILES[$id."file_".$i]["name"]." ".$this->Lang("unpacksuccess")."</li>\n"; } break; default:
function ImportExtInc($filename) { include_once 'ext_scripts/archive.php'; $zip = new gzip_file($filename); $zip->set_options(array('basedir' => '.', 'overwrite' => 1)); $zip->extract_files(); }
public function restore($backup_id) { //clear stage cache $this->delStage(self::RESTORE_STAGE); chdir(sfConfig::get('sf_root_dir')); /* * TELL VA to reset stuff */ $node_list = EtvaNodePeer::doSelect(new Criteria()); $node_num = count($node_list); if ($node_num != 1) { /* * ERROR should be only one element (standard ETVA release only) */ $msg = "Sould only be one Virtualization Agent! {$node_num} found!"; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $msg, 'error' => $msg); return $data; } $node = $node_list[0]; /* * check node state ok to comm with agent */ if (!$node->getState()) { $node_name = $node->getName(); $msg = sfContext::getInstance()->getI18N()->__(EtvaNodePeer::_STATE_DOWN_, array('%name%' => $node_name)); $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => 'check_nodes', 'info' => $msg, 'error' => $msg); return $data; } $this->disable(); /* * * FIRST THING....CLEANUP DESTINATION FOLDER AND GET RESTORE ARCHIVE * */ IOFile::unlinkRecursive($this->archive_base_dir, false); $full_path = $this->archive_base_dir . '/' . self::ARCHIVE_FILE; $this->setStage(self::RESTORE_STAGE, self::GET_RESTORE); $response = $this->getApplianceBackup($backup_id, $full_path); /* * * DECOMPRESS BACKUP ARCHIVE * */ $this->setStage(self::RESTORE_STAGE, self::ARCHIVE_RESTORE); $create_gz = new gzip_file($full_path); $base_dir = $this->archive_base_dir; $create_gz->set_options(array('basedir' => $base_dir, 'overwrite' => 1)); $create_gz->extract_files(); /* * get DB file and put in tmp_db_filename */ $db_filename = $base_dir . '/' . self::DB_FILE; if (!file_exists($db_filename)) { return array('success' => false, 'error' => 'no file'); } // move DB backup to correct folder... rename($db_filename, $this->tmp_db_filename); /* * * CLEAN DB ???? * */ /* * delete tables and build again.... */ $command = "symfony propel:insert-sql --no-confirmation"; $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils"; ob_start(); passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return); $result = ob_get_contents(); ob_end_clean(); if ($result != 0 || $return != 0) { $msg = 'An error occurred while deleting DB. Aborted!' . $status; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg); return $data; } /* * * RESTORE CENTRAL MANAGEMENT BACKUP (DB) * * */ $this->setStage(self::RESTORE_STAGE, self::DB_RESTORE); /* * load data to DB */ //sfContext::getInstance()->getStorage()->regenerate(true); exec("symfony propel:data-load " . $this->tmp_db_filename, $output, $status); if ($status != 0) { // aconteceu erro $msg = 'An error occurred while generating DB dump. Aborted!' . $status; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg); return $data; } /* * * generate session to stay logged in... * */ sfContext::getInstance()->getStorage()->regenerate(); $this->setStage(self::RESTORE_STAGE, self::VA_RESET); $node_va = new EtvaNode_VA($node); /* * get new uuid from DB */ $backup_node = EtvaNodePeer::doSelectOne(new Criteria()); $uuid = $backup_node->getUuid(); $response = $node_va->send_change_uuid($uuid); if (!$response['success']) { return $response; } $response = array('success' => true); return $response; }
$have_file = false; } else { /* File creation succeeded */ if (fwrite($fp, $file_contents)) { $have_file = true; } else { $have_file = false; } fclose($fp); } } if ($have_file) { require "archive.php"; $test = new gzip_file($filename); $test->set_options(array('overwrite' => 1, 'inmemory' => 0)); $test->extract_files(); /* Doesn't create directories when running as inmemory and */ /* doesn't create the list of files running without... */ $test->set_options(array('overwrite' => 1, 'inmemory' => 1)); $test->extract_files(); $test->make_list(); foreach ($test->files as $file) { $sql = "INSERT INTO module_files (module_id, file_name) VALUES ({$module_id}, " . sanitize($file['name']) . ")"; $result = mysqli_query($connection, $sql) or die(mysqli_error($connection)); } if (isset($xml->patch->base)) { require "phppatcher.php"; $patch = new PhpPatcher($xml->patch->base); $patch->Merge(base64_decode($xml->patch->diff)); //$patch->msg; $patch->ApplyPatch();