public function search_post() { unset($this->headerData[0], $this->headerData[5], $this->attributes[0], $this->attributes[5], $this->templates[0], $this->templates[5]); foreach ((array) $this->getClass('TaskManager')->search() as $Task) { $Host = new Host($Task->get('hostID')); $this->data[] = array('task_id' => $Task->get('id'), 'task_name' => $Task->get('name'), 'host_name' => $Task->get('isForced') ? '* ' . $Host->get('name') : $Host->get('name'), 'task_type' => $Task->getTaskTypeText(), 'task_state' => $Task->getTaskStateText()); } $this->render(); }
public function destroy($field = 'id') { $Host = new Host($this->get('hostID')); $SnapinJobs = $this->getClass('SnapinJobManager')->find(array('hostID' => $Host->get('id'))); if ($SnapinJobs) { foreach ($SnapinJobs as $SnapinJob) { $SnapinTasks[] = $this->getClass('SnapinTaskManager')->find(array('jobID' => $SnapinJob->get('id'), 'stateID' => array(0, 1))); } } // cancel's all the snapin tasks for that host. if ($SnapinTasks) { foreach ($SnapinTasks as $ST) { foreach ($ST as $SnapinTask) { $SnapinTask->set('stateID', -1)->save(); } } } // FOGController destroy return parent::destroy($field); }
/** snapin_log_post() Display's the dates to filter through. */ public function snapin_log_post() { // Set title $this->title = _('FOG Snapin Log'); // This gets the download links for which type of file you want. print "\n\t\t\t\t<h2>" . '<a href="export.php?type=csv&filename=SnapinLog" alt="Export CSV" title="Export CSV" target="_blank">' . $this->csvfile . '</a> <a href="export.php?type=pdf&filename=SnapinLog" alt="Export PDF" title="Export PDF" target="_blank">' . $this->pdffile . '</a></h2>'; // Header Data $this->headerData = array(_('Snapin Name'), _('State'), _('Return Code'), _('Return Desc'), _('Create Date'), _('Create Time')); // Templates $this->templates = array('${snap_name}', '${snap_state}', '${snap_return}', '${snap_detail}', '${snap_create}', '${snap_time}'); // Setup Report Maker for this class. $ReportMaker = new ReportMaker(); // Set dates and check order is proper $date1 = $_REQUEST['date1']; $date2 = $_REQUEST['date2']; if ($date1 > $date2) { $date1 = $_REQUEST['date2']; $date2 = $_REQUEST['date1']; } $date2 = date('Y-m-d', strtotime($date2 . '+1 day')); // This is just for the header in the CSV: $csvHead = array(_('Host ID'), _('Host Name'), _('Host MAC'), _('Snapin ID'), _('Snapin Name'), _('Snapin Description'), _('Snapin File'), _('Snapin Args'), _('Snapin Run With'), _('Snapin Run With Args'), _('Snapin State'), _('Snapin Return Code'), _('Snapin Return Detail'), _('Snapin Creation Date'), _('Snapin Creation Time'), _('Job Create Date'), _('Job Create Time'), _('Task Checkin Date'), _('Task Checkin Time')); foreach ((array) $csvHead as $csvHeader) { $ReportMaker->addCSVCell($csvHeader); } $ReportMaker->endCSVLine(); // Find all snapin tasks $SnapinTasks = $this->getClass('SnapinTaskManager')->find(array('checkin' => '', 'complete' => ''), 'OR', '', '', "BETWEEN '{$date1}' AND '{$date2}'"); foreach ((array) $SnapinTasks as $SnapinTask) { $SnapinCheckin1 = $this->nice_date($SnapinTask->get('checkin')); $SnapinCheckin2 = $this->nice_date($SnapinTask->get('complete')); // Get the Task based on create date thru complete date // Get the snapin $Snapin = new Snapin($SnapinTask->get('snapinID')); // Get the Job $SnapinJob = new SnapinJob($SnapinTask->get('jobID')); // Get the Host $Host = new Host($SnapinJob->get('hostID')); $hostID = $SnapinJob->get('hostID'); $hostName = $Host->isValid() ? $Host->get('name') : ''; $hostMac = $Host->isValid() ? $Host->get('mac') : ''; $snapinID = $SnapinTask->get('snapinID'); $snapinName = $Snapin->isValid() ? $Snapin->get('name') : ''; $snapinDesc = $Snapin->isValid() ? $Snapin->get('description') : ''; $snapinFile = $Snapin->isValid() ? $Snapin->get('file') : ''; $snapinArgs = $Snapin->isValid() ? $Snapin->get('args') : ''; $snapinRw = $Snapin->isValid() ? $Snapin->get('runWith') : ''; $snapinRwa = $Snapin->isValid() ? $Snapin->get('runWithArgs') : ''; $snapinState = $SnapinTask->get('stateID'); $snapinReturn = $SnapinTask->get('return'); $snapinDetail = $SnapinTask->get('detail'); $snapinCreateDate = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'Y-m-d') : ''; $snapinCreateTime = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'H:i:s') : ''; $jobCreateDate = $this->formatTime($SnapinJob->get('createdTime'), 'Y-m-d'); $jobCreateTime = $this->formatTime($SnapinJob->get('createdTime'), 'H:i:s'); $TaskCheckinDate = $SnapinCheckin1->format('Y-m-d'); $TaskCheckinTime = $SnapinCheckin2->format('H:i:s'); $this->data[] = array('snap_name' => $snapinName, 'snap_state' => $snapinState, 'snap_return' => $snapinReturn, 'snap_detail' => $snapinDetail, 'snap_create' => $snapinCreateDate, 'snap_time' => $snapinCreateTime); $ReportMaker->addCSVCell($hostID); $ReportMaker->addCSVCell($hostName); $ReportMaker->addCSVCell($HostMac); $ReportMaker->addCSVCell($snapinID); $ReportMaker->addCSVCell($snapinName); $ReportMaker->addCSVCell($snapinDesc); $ReportMaker->addCSVCell($snapinFile); $ReportMaker->addCSVCell($snapinArgs); $ReportMaker->addCSVCell($snapinRw); $ReportMaker->addCSVCell($snapinRwa); $ReportMaker->addCSVCell($snapinState); $ReportMaker->addCSVCell($snapinReturn); $ReportMaker->addCSVCell($snapinDetail); $ReportMaker->addCSVCell($snapinCreateDate); $ReportMaker->addCSVCell($snapinCreateTime); $ReportMaker->addCSVCell($jobCreateDate); $ReportMaker->addCSVCell($jobCreateTime); $ReportMaker->addCSVCell($TaskCheckinDate); $ReportMaker->addCSVCell($TaskCheckinTime); $ReportMaker->endCSVLine(); } // This is for the pdf. $ReportMaker->appendHTML($this->process()); $ReportMaker->outputReport(false); $_SESSION['foglastreport'] = serialize($ReportMaker); }
/** add_post() Actually add's the host. */ public function add_post() { // Hook $this->HookManager->processEvent('HOST_ADD_POST'); // POST ? try { // Error checking if (empty($_REQUEST['host'])) { throw new Exception(_('Hostname is required')); } if (!$this->getClass('HostManager')->isHostnameSafe($_REQUEST['host'])) { throw new Exception(_('Please enter a valid hostname')); } if (empty($_REQUEST['mac'])) { throw new Exception(_('MAC Address is required')); } $MAC = new MACAddress($_REQUEST['mac']); if (!$MAC || !$MAC->isValid()) { throw new Exception(_('MAC Format is invalid')); } // Check if host exists with MAC Address. $Host = $this->getClass('HostManager')->getHostByMacAddresses($MAC); if ($Host && $Host->isValid()) { throw new Exception(_('A host with this MAC already exists with Hostname: ') . $Host->get('name')); } if ($this->getClass('HostManager')->exists($_REQUEST['host'])) { throw new Exception(_('Hostname already exists')); } // Get all the service id's so they can be enabled. $ModuleIDs = $this->getClass('ModuleManager')->find('', '', '', '', '', '', '', 'id'); $password = $_REQUEST['domainpassword']; if ($this->FOGCore->getSetting('FOG_NEW_CLIENT') && $_REQUEST['domainpassword']) { $password = $this->encryptpw($_REQUEST['domainpassword']); } // Define new Image object with data provided $Host = new Host(array('name' => $_REQUEST['host'], 'description' => $_REQUEST['description'], 'imageID' => $_REQUEST['image'], 'kernel' => $_REQUEST['kern'], 'kernelArgs' => $_REQUEST['args'], 'kernelDevice' => $_REQUEST['dev'], 'useAD' => $_REQUEST["domain"] == "on" ? '1' : '0', 'ADDomain' => $_REQUEST['domainname'], 'ADOU' => $_REQUEST['ou'], 'ADUser' => $_REQUEST['domainuser'], 'ADPass' => $password, 'productKey' => base64_encode($_REQUEST['key']))); $Host->addModule($ModuleIDs); $Host->addPriMAC($MAC); $useAD = isset($_REQUEST['domain']); $domain = trim($_REQUEST['domainname']); $ou = trim($_REQUEST['ou']); $user = trim($_REQUEST['domainuser']); $pass = trim($_REQUEST['domainpassword']); $Host->setAD($useAD, $domain, $ou, $user, $pass, true, true); // Save to database if ($Host->save()) { // Hook $this->HookManager->processEvent('HOST_ADD_SUCCESS', array('Host' => &$Host)); // Log History event $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', _('Host added'), $Host->get('id'), $Host->get('name'))); // Set session message $this->FOGCore->setMessage(_('Host added')); // Redirect to new entry $this->FOGCore->redirect(sprintf('?node=%s&sub=edit&%s=%s', $this->REQUEST['node'], $this->id, $Host->get('id'))); } else { throw new Exception('Database update failed'); } } catch (Exception $e) { // Hook $this->HookManager->processEvent('HOST_ADD_FAIL', array('Host' => &$Host)); // Log History event $this->FOGCore->logHistory(sprintf('%s add failed: Name: %s, Error: %s', 'Host', $_REQUEST['name'], $e->getMessage())); // Set session message $this->FOGCore->setMessage($e->getMessage()); // Redirect to new entry $this->FOGCore->redirect($this->formAction); } }
if ($Host->createImagePackage(1, 'AutoRegTask')) { print _('Done, with imaging!'); } else { print _('Done, but unable to create task!'); } } else { print _('Done!'); } } else { $realhost = $macsimple; if (!$Host || !$Host->isValid()) { $Host = new Host(array('name' => $realhost, 'description' => sprintf('%s %s', _('Created by FOG Reg on'), date('F j, Y, g:i a')), 'createdTime' => $FOGCore->formatTime('now', 'Y-m-d H:i:s'), 'createdBy' => 'FOGREG')); $Host->addPriMAC($PriMAC); $Host->addAddMAC($MACs); $Host->addModule($ids); if (!$Host->save()) { throw new Exception(_('Failed to save new Host!')); } print _('Done'); } else { print _('Already registered as') . ': ' . $Host->get('name'); } } } else { print _('Already registered as') . ': ' . $Host->get('name'); } } } catch (Exception $e) { print $e->getMessage(); } }
private function commonOutput() { try { $DateInterval = $this->nice_date('-30 minutes'); foreach ($this->getClass('HostManager')->find() as $Host) { if ($Host && $Host->isValid()) { if ($this->validDate($Host->get('sec_time'))) { $DateTime = $this->nice_date($Host->get('sec_time')); if ($DateTime->format('Y-m-d H:i:s') >= $DateInterval->format('Y-m-d H:i:s')) { $Host->set('pub_key', null)->set('sec_time', null)->save(); } } } } $Tasks = $this->getClass('TaskManager')->find(array('stateID' => 1, 'typeID' => array(1, 15, 17))); if ($Tasks) { $this->outall(sprintf(" * %s active task(s) awaiting check-in sending WOL request(s).", $this->getClass('TaskManager')->count(array('stateID' => 1, 'typeID' => array(1, 15, 17))))); foreach ($Tasks as $Task) { $Host = new Host($Task->get('hostID')); $this->FOGCore->wakeOnLan($Host->get('mac')); $this->outall(sprintf("\t\t- Host: %s WOL sent using MAC: %s", $Host->get('name'), $Host->get('mac'))); usleep(500000); } } else { $this->outall(" * 0 active task(s) awaiting check-in."); } $Tasks = $this->getClass('ScheduledTaskManager')->find(array('isActive' => 1)); if ($Tasks) { $this->outall(sprintf(" * %s task(s) found.", count($Tasks))); foreach ($Tasks as $Task) { $deploySnapin = ($Task->get('taskType') == 12 || $Task->get('taskType') == 13) && $Task->get('taskType') != 17 ? $Task->get('other2') : false; $Timer = $Task->getTimer(); $this->outall(sprintf(" * Task run time: %s", $Timer->toString())); if ($Timer->shouldRunNow()) { $this->outall(" * Found a task that should run..."); if ($Task->isGroupBased()) { $this->outall(sprintf("\t\t - Is a group based task.")); $Group = $Task->getGroup(); if ($Task->get('taskType') == 8) { $this->outall("\t\t - Multicast task found!"); $this->outall(sprintf("\t\t - Group %s", $Group->get('name'))); $i = 0; foreach ((array) $Group->get('hosts') as $Host) { $Host->createImagePackage($Task->get('taskType'), $Task->get('name'), $Task->get('shutdown'), false, true, 'FOG_SCHED'); $this->outall(sprintf("\t\t - Task Started for host %s!", $Host->get('name'))); } if ($Timer->isSingleRun()) { if ($this->FOGCore->stopScheduledTask($Task)) { $this->outall("\t\t - Scheduled Task cleaned."); } else { $this->outall("\t\t - failed to clean task."); } } else { $this->outall("\t\t - Cron style - No cleaning!"); } } else { $this->outall("\t\t - Regular task found!"); $this->outall(sprintf("\t\t - Group %s", $Group->get('name'))); foreach ((array) $Group->get('hosts') as $Host) { $Host->createImagePackage($Task->get('taskType'), $Task->get('name'), $Task->get('shutdown'), false, $deploySnapin, true, $Task->get('other3')); $this->outall(sprintf("\t\t - Task Started for host %s!", $Host->get('name'))); } if ($Timer->isSingleRun()) { if ($this->FOGCore->stopScheduledTask($Task)) { $this->outall("\t\t - Scheduled Task cleaned."); } else { $this->outall("\t\t - failed to clean task."); } } else { $this->outall("\t\t - Cron style - No cleaning!"); } } } else { $this->outall("\t\t - Is a host based task."); $Host = $Task->getHost(); $Host->createImagePackage($Task->get('taskType'), $Task->get('name'), $Task->get('shutdown'), false, $deploySnapin, false, $Task->get('other3')); $this->outall(sprintf("\t\t - Task Started for host %s!", $Host->get('name'))); if ($Timer->isSingleRun()) { if ($this->FOGCore->stopScheduledTask($Task)) { $this->outall("\t\t - Scheduled Task cleaned."); } else { $this->outall("\t\t - failed to clean task."); } } else { $this->outall("\t\t - Cron style - No cleaning!"); } } } else { $this->outall(" * Task doesn't run now."); } } } else { $this->outall(" * No tasks found!"); } } catch (Exception $e) { $this->outall("\t\t - " . $e->getMessage()); } }
public function updateDefault($hostid, $onoff) { foreach ((array) $hostid as $id) { $Host = new Host($id); if ($Host && $Host->isValid()) { $Host->updateDefault($this->get('id'), in_array($Host->get('id'), $onoff)); } } return $this; }
public function active_snapins_post() { if (isset($_REQUEST['rmid'])) { // Get the snapin task. $SnapinTask = new SnapinTask($_REQUEST['rmid']); // Get the job associated with the task. $SnapinJob = new SnapinJob($SnapinTask->get('jobID')); // Get the referenced host. $Host = new Host($SnapinJob->get('hostID')); // Get the active task. $Task = current($this->getClass('TaskManager')->find(array('hostID' => $Host->get('id'), 'stateID' => array(1, 2, 3)))); // Check the Jobs to Snapin tasks to verify if this is the only one. $SnapinJobManager = $this->getClass('SnapinTaskManager')->find(array('jobID' => $SnapinJob->get('id'))); // This task is the last task, destroy the job and the task if (count($SnapinJobManager) <= 1) { $SnapinJob->destroy(); if ($Task) { $Task->cancel(); } } // Destroy the individual task. $SnapinTask->destroy(); // Redirect to the current page. $this->FOGCore->redirect("?node=" . $this->node . "&sub=active-snapins"); } }
/** * * @param \webignition\Url\Host\Host $comparator * @return boolean */ public function equals(Host $comparator) { return $this->get() == $comparator->get(); }