if ($Inventory && $Inventory->isValid()) {
     $SnapinJob = $Host->get('snapinjob');
     //Get Snapin(s) Used/Queued
     if ($SnapinJob && $SnapinJob->isValid()) {
         $SnapinTasks = $FOGCore->getClass('SnapinTaskManager')->find(array('stateID' => array(-1, 0, 1), 'jobID' => $SnapinJob->get('id')));
         foreach ($SnapinTasks as $SnapinTask) {
             if ($SnapinTask && $SnapinTask->isValid()) {
                 $Snapin = new Snapin($SnapinTask->get('snapinID'));
                 if ($Snapin && $Snapin->isValid()) {
                     $SnapinNames[] = $Snapin->get('name');
                 }
             }
         }
     }
     $StorageNode = new StorageNode($Task->get('NFSMemberID'));
     $emailbinary = $FOGCore->getSetting('FOG_EMAIL_BINARY') ? preg_replace('#\\$\\{server-name\\}#', $StorageNode && $StorageNode->isValid() ? $StorageNode->get('name') : 'fogserver', $FOGCore->getSetting('FOG_EMAIL_BINARY')) : '/usr/sbin/sendmail -t -f noreply@fogserver.com -i';
     ini_set('sendmail_path', $emailbinary);
     $snpusd = implode(', ', (array) $SnapinNames);
     //to list snapins as 1, 2, 3,  etc
     $engineer = ucwords($Task->get('createdBy'));
     //ucwords purely aesthetics
     $puser = ucwords($Inventory->get('primaryUser'));
     //ucwords purely aesthetics
     $to = $FOGCore->getSetting('FOG_EMAIL_ADDRESS');
     //Email address(es) to be used
     $headers = 'From: ' . $FOGCore->getSetting('FOG_FROM_EMAIL') . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     $headers = preg_replace('#\\$\\{server-name\\}#', $StorageNode && $StorageNode->isValid() ? $StorageNode->get('name') : 'fogserver', $headers);
     //$Email - is just the context of the email put in variable saves repeating
     $email = array("Machine Details:-\n" => '', "\nHostName: " => $Host->get('name'), "\nComputer Model: " => $Inventory->get('sysproduct'), "\nSerial Number: " => $Inventory->get('sysserial'), "\nMAC Address: " => $Host->get('mac')->__toString(), "\n" => '', "\nImage Used: " => $ImagingLog->get('image'), "\nSnapin Used: " => $snpusd, "\n" => '', "\nImaged By (Engineer): " => $engineer, $puser ? "\nImaged For (User): " : '' => $puser ? $puser : '');
     $HookManager->processEvent('EMAIL_ITEMS', array('email' => &$email, 'Host' => &$Host));
     $emailMe = '';
 public function add_storage_node_post()
 {
     // Hook
     $this->HookManager->processEvent('STORAGE_NODE_ADD_POST');
     // POST
     try {
         // Error checking
         if (empty($_REQUEST['name'])) {
             throw new Exception($this->foglang['StorageNameRequired']);
         }
         if ($this->getClass('StorageNodeManager')->exists($_REQUEST['name'])) {
             throw new Exception($this->foglang['StorageNameExists']);
         }
         if (empty($_REQUEST['ip'])) {
             throw new Exception($this->foglang['StorageIPRequired']);
         }
         if (empty($_REQUEST['maxClients'])) {
             throw new Exception($this->foglang['StorageClientsRequired']);
         }
         if (empty($_REQUEST['interface'])) {
             throw new Exception($this->foglang['StorageIntRequired']);
         }
         if (empty($_REQUEST['user'])) {
             throw new Exception($this->foglang['StorageUserRequired']);
         }
         if (empty($_REQUEST['pass'])) {
             throw new Exception($this->foglang['StoragePassRequired']);
         }
         if ((is_numeric($_REQUEST['bandwidth']) && $_REQUEST['bandwidth'] <= 0 || !is_numeric($_REQUEST['bandwidth'])) && $_REQUEST['bandwidth']) {
             throw new Exception(_('Bandwidth should be numeric and greater than 0'));
         }
         // Create new Object
         $StorageNode = new StorageNode(array('name' => $_REQUEST['name'], 'description' => $_REQUEST['description'], 'ip' => $_REQUEST['ip'], 'maxClients' => $_REQUEST['maxClients'], 'isMaster' => $_REQUEST['isMaster'] ? '1' : '0', 'storageGroupID' => $_REQUEST['storageGroupID'], 'path' => $_REQUEST['path'], 'snapinpath' => $_REQUEST['snapinpath'], 'interface' => $_REQUEST['interface'], 'isGraphEnabled' => $_REQUEST['isGraphEnabled'] ? '1' : '0', 'isEnabled' => $_REQUEST['isEnabled'] ? '1' : '0', 'user' => $_REQUEST['user'], 'pass' => $_REQUEST['pass'], 'bandwidth' => $_REQUEST['bandwidth']));
         // Save
         if ($StorageNode->save()) {
             if ($StorageNode->get('isMaster')) {
                 // Unset other Master Nodes in this Storage Group
                 foreach ((array) $this->getClass('StorageNodeManager')->find(array('isMaster' => '1', 'storageGroupID' => $StorageNode->get('storageGroupID'))) as $StorageNodeMaster) {
                     if ($StorageNode->get('id') != $StorageNodeMaster->get('id')) {
                         $StorageNodeMaster->set('isMaster', '0')->save();
                     }
                 }
             }
             // Hook
             $this->HookManager->processEvent('STORAGE_NODE_ADD_SUCCESS', array('StorageNode' => &$StorageNode));
             // Log History event
             $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', $this->foglang['SNCreated'], $StorageNode->get('id'), $StorageNode->get('name')));
             // Set session message
             $this->FOGCore->setMessage($this->foglang['SNCreated']);
             // Redirect to new entry
             $this->FOGCore->redirect(sprintf('?node=%s', $_REQUEST['node'], $this->id, $StorageNode->get('id')));
         } else {
             throw new Exception($this->foglang['DBupfailed']);
         }
     } catch (Exception $e) {
         // Hook
         $this->HookManager->processEvent('STORAGE_NODE_ADD_FAIL', array('StorageNode' => &$StorageNode));
         // Log History event
         $this->FOGCore->logHistory(sprintf('%s add failed: Name: %s, Error: %s', $this->foglang['SN'], $_REQUEST['name'], $e->getMessage()));
         // Set session message
         $this->FOGCore->setMessage($e->getMessage());
         // Redirect to new entry
         $this->FOGCore->redirect($this->formAction);
     }
 }
 public function home()
 {
     $StorageNode = new StorageNode($_REQUEST['id']);
     // Header Data
     unset($this->headerData);
     // Attributes
     $this->attributes = array(array(), array());
     // Templates
     $this->templates = array('${field}', '${input}');
     if ($StorageNode) {
         $webroot = $this->FOGCore->getSetting('FOG_WEB_ROOT') ? '/' . trim($this->FOGCore->getSetting('FOG_WEB_ROOT'), '/') . '/' : '/';
         $URL = sprintf('http://%s%sstatus/hw.php', $this->FOGCore->resolveHostname($StorageNode->get('ip')), $webroot);
         if ($ret = $this->FOGURLRequests->process($URL)) {
             $arRet = explode("\n", $ret[0]);
             $section = 0;
             //general
             $arGeneral = array();
             $arFS = array();
             $arNIC = array();
             foreach ((array) $arRet as $line) {
                 $line = trim($line);
                 if ($line == "@@start") {
                 } else {
                     if ($line == "@@general") {
                         $section = 0;
                     } else {
                         if ($line == "@@fs") {
                             $section = 1;
                         } else {
                             if ($line == "@@nic") {
                                 $section = 2;
                             } else {
                                 if ($line == "@@end") {
                                     $section = 3;
                                 } else {
                                     if ($section == 0) {
                                         $arGeneral[] = $line;
                                     } else {
                                         if ($section == 1) {
                                             $arFS[] = $line;
                                         } else {
                                             if ($section == 2) {
                                                 $arNIC[] = $line;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             for ($i = 0; $i < count($arNIC); $i++) {
                 $arNicParts = explode("\$\$", $arNIC[$i]);
                 if (count($arNicParts) == 5) {
                     $NICTransSized[] = $this->formatByteSize($arNicParts[2]);
                     $NICRecSized[] = $this->formatByteSize($arNicParts[1]);
                     $NICErrInfo[] = $arNicParts[3];
                     $NICDropInfo[] = $arNicParts[4];
                     $NICTrans[] = $arNicParts[0] . ' ' . _('TX');
                     $NICRec[] = $arNicParts[0] . ' ' . _('RX');
                     $NICErr[] = $arNicParts[0] . ' ' . _('Errors');
                     $NICDro[] = $arNicParts[0] . ' ' . _('Dropped');
                 }
             }
             if (count($arGeneral) >= 1) {
                 $fields = array('<b>' . _('General Information') => '&nbsp;', _('Storage Node') => $StorageNode->get('name'), _('IP') => $this->FOGCore->resolveHostname($StorageNode->get('ip')), _('Kernel') => $arGeneral[0], _('Hostname') => $arGeneral[1], _('Uptime') => $arGeneral[2], _('CPU Type') => $arGeneral[3], _('CPU Count') => $arGeneral[4], _('CPU Model') => $arGeneral[5], _('CPU Speed') => $arGeneral[6], _('CPU Cache') => $arGeneral[7], _('Total Memory') => $arGeneral[8], _('Used Memory') => $arGeneral[9], _('Free Memory') => $arGeneral[10], '<b>' . _('File System Information') . '</b>' => '&nbsp;', _('Total Disk Space') => $arFS[0], _('Used Disk Space') => $arFS[1], '<b>' . _('Network Information') . '</b>' => '&nbsp;');
                 $i = 0;
                 foreach ((array) $NICTrans as $txtran) {
                     $ethName = explode(' ', $NICTrans[$i]);
                     $fields['<b>' . $ethName[0] . ' ' . _('Information') . '</b>'] = '&nbsp;';
                     $fields[$NICTrans[$i]] = $NICTransSized[$i];
                     $fields[$NICRec[$i]] = $NICRecSized[$i];
                     $fields[$NICErr[$i]] = $NICErrInfo[$i];
                     $fields[$NICDro[$i]] = $NICDropInfo[$i];
                     $i++;
                 }
             }
             foreach ((array) $fields as $field => $input) {
                 $this->data[] = array('field' => $field, 'input' => $input);
             }
             // Hook
             $this->HookManager->processEvent('SERVER_INFO_DISP', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
             // Output
             $this->render();
         } else {
             print "\n\t\t\t" . '<p>' . _('Unable to pull server information!') . '</p>';
         }
     } else {
         print "\n\t\t\t" . '<p>' . _('Invalid Server Information!') . '</p>';
     }
 }
 /** clientCount()
 		Display's the current client count on the activity graph
 	*/
 public function clientcount()
 {
     $ActivityActive = $ActivityQueued = $ActivityTotalClients = 0;
     $StorageNode = new StorageNode($_REQUEST['id']);
     if ($StorageNode && $StorageNode->isValid()) {
         foreach ($this->getClass('StorageNodeManager')->find(array('isEnabled' => 1, 'storageGroupID' => $StorageNode->get('storageGroupID'))) as $SN) {
             if ($SN && $SN->isValid()) {
                 $ActivityActive += $SN->getUsedSlotCount();
                 $ActivityQueued += $SN->getQueuedSlotCount();
                 $ActivityTotalClients += $SN->get('maxClients') - $SN->getUsedSlotCount();
             }
         }
     }
     $data = array('ActivityActive' => $ActivityActive, 'ActivityQueued' => $ActivityQueued, 'ActivitySlots' => $ActivityTotalClients);
     print json_encode($data);
 }