/** * Creates a new instance of DynamicHostManager */ protected function initHostManager() { require_once WCF_DIR . 'lib/page/util/DynamicHostManager.class.php'; self::$hostManagerObj = new DynamicHostManager(); self::$activeHost = self::$hostManagerObj->getHost(); self::$activeHostID = self::$activeHost->hostID; }
public function __construct() { $this->welcomInformations(); $backupTypeU = unserialize(BACKUP_TYPE); // init task manager. $this->backupLogger = GlobalLogger::getLoggerInstance(); $this->backupDate = Utils::getDateInstance(); $tmp_tasks = array(); $taskManager = new TaskManager(); $this->taskList = $taskManager->getTasks(); $array_length = count($this->taskList); $num = 1; foreach ($this->taskList as $key => $task) { $credentialInitInfo = "\n----------------task credential init begin--------------" . "\n"; $this->backupLogger->addLog('credential init', 100, $credentialInitInfo, $task->target_host_spec->getIp()); //echo $credentialInitInfo; $task = $this->initialize_credential($task); $this->backupLogger->addLog('credential init', 100, "init....", $task->target_host_spec->getIp()); $tmp_tasks[$key] = $task; $credentialInitEndInfo = "\n----------------task credential init end----------------" . "\n\n\n\n"; $this->backupLogger->addLog('credential init', 100, $credentialInitEndInfo, $task->target_host_spec->getIp()); //echo $credentialInitEndInfo; $num++; //print_r($tmp_tasks); } //print_r($tmp_tasks); if ($num < $array_length + 1 or $num == 1) { exit("your credential is not complete, please try again!\n"); } $task_num = 1; print_r($tmp_tasks); while (1) { $total_timer = Utils::getTimer(); $total_timer->start(); foreach ($tmp_tasks as $task) { $timer = Utils::getTimer(); $host_type = $task->target_host_spec->getHost_type(); //echo $host_type . "\n"; $hostManager = new HostManager(); // srcHost $srcHost = $hostManager->get_host($host_type); //print_r($task->target_host_spec); $srcHost->hostSpec = $task->target_host_spec; $srcHost->hostCredential = $task->target_host_credential; // destHost $target_dest_ip = $task->target_host_spec->getBackup_dest_ip(); $hostSpecManager = new HostSpecManager(); $storageHostSpec = $hostSpecManager->querryHostSpecByHostIp($target_dest_ip); $storageHost = new DestHost(); $storageHost->hostSpec = $storageHostSpec; $storageHost->storageCredential = $task->storage_credential; $backupTaskInfo = "\n\n-----------------backup task {$task_num} begin-----------------\n\n"; echo "time: " . $timer->startTime; $this->backupLogger->addLog('backup task', 100, $backupTaskInfo, $srcHost->hostSpec->getIp()); echo $backupTaskInfo; $backupHandlerManager = new BackupHandlerManager(); $backupType = $this->getBackupType($srcHost); $db_inputs = array(); if ($backupType == $backupTypeU[1]) { echo "This is a MySQLdb backup ....\n"; $db_inputs = $this->getDBInput(); $srcHost->hostCredential->user_db = $db_inputs['username']; $srcHost->hostCredential->password_db = $db_inputs['password']; } //"linux_mysqldb"; $this->backupHandler = $backupHandlerManager->getBackupHandler($backupType); $createBackupInfo = "\n...backup handler create ok!...\n"; $this->backupLogger->addLog("backup task", 100, $createBackupInfo, $srcHost->hostSpec->getIp()); $beginBackupInfo = "\n...begin execute backup task!...\n"; $this->backupLogger->addLog("backup task", 100, $beginBackupInfo, $srcHost->hostSpec->getIp()); $begin_time = microtime(true); $timer->start(); $this->backupHandler->execute($srcHost, $storageHost, $this->backupLogger); $timer->stop(); echo "time: " . $timer->stopTime; $total_time = $timer->spent(); echo "\nUsed time: " . $total_time . "\n\n"; $endInfo = "\n-----------------backup task {$task_num} end-------------------\n\n\n\n\n"; $this->backupLogger->addLog("backup task", 100, $endInfo, $srcHost->hostSpec->getIp()); echo $endInfo; $task_num++; } $total_timer->stop(); $spent_time = $total_timer->total_time_H(); echo "\n\n ############# all time spent {$spent_time} H #############\n\n"; if ($spent_time > 24) { echo "\nBigger than 24 hours.\n"; $sleep_time = (48 - $spent_time) * 3600; echo "sleep {$spent_time} s"; sleep($sleep_time); } elseif ($spent_time <= 24) { $sleep_time = (24 - $spent_time) * 3600; echo "sleep {$sleep_time} s"; sleep($sleep_time); } } }
<?php require_once '../commons/base.inc.php'; try { // Just for checking if the host exists // Sends back if it does or doesn't. $HostMan = new HostManager(); $hostname = trim(base64_decode(trim($_REQUEST['host']))); if ($HostMan->exists($hostname)) { $Host = current($HostMan->find(array('name' => $hostname))); throw new Exception("\tA hostname with that name already exists.\nThe MAC address associated with this host is:" . $Host->get('mac')); } throw new Exception('#!ok'); } catch (Exception $e) { print $e->getMessage(); }
public function isValid() { return $this->get('id') && HostManager::isHostnameSafe($this->get('name')) && $this->getMACAddress(); }
protected function loadSiteUrl() { $this->register(HostManager::getSiteUrl()); }
require_once '../commons/base.inc.php'; try { $HostManager = new HostManager(); if (!$_REQUEST['newService'] && $_REQUEST['version'] != 2) { throw new Exception('#!er:Invalid Version Number, please update this module.'); } // The total number of pending macs that can be used. $maxPending = $FOGCore->getSetting('FOG_QUICKREG_MAX_PENDING_MACS'); // Get the actual host (if it is registered) $MACs = $FOGCore->getHostItem(true, false, false, true); $Host = $FOGCore->getHostItem(true, false, true, false, true); if (!($Host instanceof Host && $Host->isValid()) && $_REQUEST['newService'] && $_REQUEST['hostname']) { $Host = current($FOGCore->getClass('HostManager')->find(array('name' => $_REQUEST['hostname']))); } if ($_REQUEST['newService'] && !($Host instanceof Host && $Host->isValid())) { if (!$_REQUEST['hostname'] || !HostManager::isHostnameSafe($_REQUEST['hostname'])) { throw new Exception('#!ih'); } foreach ($FOGCore->getClass('ModuleManager')->find() as $Module) { $ModuleIDs[] = $Module->get('id'); } $MACs = explode('|', $_REQUEST['mac']); $PriMAC = array_shift($MACs); $Host = $FOGCore->getClass('Host')->set('name', $_REQUEST['hostname'])->set('description', 'Pending Registration created by FOG_CLIENT')->set('pending', 1)->addModule($ModuleIDs)->addPriMAC($PriMAC)->save(); } // Check if count is okay. if (count($MACs) > $maxPending + 1) { throw new Exception('#!er:Too many MACs'); } // Cycle the MACs foreach ($MACs as $MAC) {
/** getPing() Performs the ping stuff. * @return void */ public function getPing() { try { $ping = $_REQUEST['ping']; if (!$_SESSION['AllowAJAXTasks']) { throw new Exception(_('FOG Session Invalid')); } if (!$ping || $ping == 'undefined') { throw new Exception(_('Undefined host to ping')); } if (!HostManager::isHostnameSafe($ping)) { throw new Exception(_('Invalid Hostname')); } if (is_numeric($ping)) { $Host = Host($ping); $ping = $Host->get('name'); } // Resolve Hostname $ip = gethostbyname($ping); if ($ip == $ping) { throw new Exception(_('Unable to resolve hostname')); } $result = $this->getClass('Ping', $ip)->execute(); if ($result !== true) { throw new Exception($result); } $SendMe = true; } catch (Exception $e) { $SendMe = $e->getMessage(); } if ($this->isAJAXRequest()) { print $SendMe; } }