/** edit_post()
 		Actually saves the data.
 	*/
 public function edit_post()
 {
     // Find
     $Host = $this->obj;
     $HostManager = $this->getClass('HostManager');
     $Inventory = $Host->get('inventory');
     // Hook
     $this->HookManager->processEvent('HOST_EDIT_POST', array('Host' => &$Host));
     // POST
     try {
         // Tabs
         switch ($_REQUEST['tab']) {
             case 'host-general':
                 // Error checking
                 if (empty($_REQUEST['mac'])) {
                     throw new Exception('MAC Address is required');
                 }
                 if ($Host->get('name') != $_REQUEST['host'] && $HostManager->exists($_REQUEST['host'])) {
                     throw new Exception('Hostname Exists already');
                 }
                 if ($Host->get('name') != $_REQUEST['host'] && !$this->getClass('HostManager')->isHostnameSafe($_REQUEST['host'])) {
                     throw new Exception(_('Please enter a valid hostname'));
                 }
                 // Variables
                 $mac = new MACAddress($_REQUEST['mac']);
                 // Task variable.
                 $Task = $Host->get('task');
                 // Error checking
                 if (!$mac->isValid()) {
                     throw new Exception(_('MAC Address is not valid'));
                 }
                 if (!$_REQUEST['image'] && $Task && $Task->isValid() || $_REQUEST['image'] && $_REQUEST['image'] != $Host->get('imageID') && $Task && $Task->isValid()) {
                     throw new Exception('Cannot unset image.<br />Host is currently in a tasking.');
                 }
                 // Define new Image object with data provided
                 $Host->set('name', $_REQUEST['host'])->set('description', $_REQUEST['description'])->set('imageID', $_REQUEST['image'])->set('kernel', $_REQUEST['kern'])->set('kernelArgs', $_REQUEST['args'])->set('kernelDevice', $_REQUEST['dev'])->set('productKey', base64_encode($_REQUEST['key']));
                 if (strtolower($Host->get('mac')->__toString()) != strtolower($mac->__toString())) {
                     $Host->set('mac', strtolower($mac->__toString()));
                 }
                 $MyMACs = $AddMe = array();
                 foreach ((array) $_REQUEST['additionalMACs'] as $MAC) {
                     $MAC = !$MAC instanceof MACAddress ? $this->getClass('MACAddress', $MAC) : $MAC;
                     if ($MAC && $MAC->isValid()) {
                         $AddMe[] = strtolower($MAC->__toString());
                     }
                 }
                 foreach ((array) $Host->get('additionalMACs') as $MyMAC) {
                     if ($MyMAC instanceof MACAddress && $MyMAC->isValid()) {
                         $MyMACs[] = strtolower($MyMAC->__toString());
                     }
                 }
                 if (isset($_REQUEST['primaryMAC'])) {
                     $AddMe[] = strtolower($mac->__toString());
                     $Host->removeAddMAC($_REQUEST['primaryMAC'])->set('mac', strtolower($_REQUEST['primaryMAC']));
                 }
                 $AddMe = array_diff((array) $AddMe, (array) $MyMACs);
                 if (count($AddMe)) {
                     $Host->addAddMAC($AddMe);
                 }
                 if (isset($_REQUEST['additionalMACsRM'])) {
                     $Host->removeAddMAC($_REQUEST['additionalMACsRM']);
                 }
                 break;
             case 'host-grouprel':
                 if (isset($_REQUEST['addGroups'])) {
                     $Host->addGroup($_REQUEST['group']);
                 }
                 if (isset($_REQUEST['remgroups'])) {
                     $Host->removeGroup(array_unique($_REQUEST['groupdel']));
                 }
                 break;
             case 'host-active-directory':
                 $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);
                 break;
             case 'host-printers':
                 $PrinterManager = $this->getClass('PrinterAssociationManager');
                 // Set printer level for Host
                 if (isset($_REQUEST['level'])) {
                     $Host->set('printerLevel', $_REQUEST['level']);
                 }
                 // Add
                 if (isset($_REQUEST['updateprinters'])) {
                     $Host->addPrinter($_REQUEST['printer']);
                     // Set Default
                     foreach ($_REQUEST['printerid'] as $printerid) {
                         $Printer = new Printer($printerid);
                         $Host->updateDefault($_REQUEST['default'], isset($_REQUEST['default']));
                     }
                 }
                 // Remove
                 if (isset($_REQUEST['printdel'])) {
                     $Host->removePrinter($_REQUEST['printerRemove']);
                 }
                 break;
             case 'host-snapins':
                 // Add
                 if (!isset($_REQUEST['snapinRemove'])) {
                     $Host->addSnapin($_REQUEST['snapin']);
                 }
                 // Remove
                 if (isset($_REQUEST['snaprem'])) {
                     $Host->removeSnapin($_REQUEST['snapinRemove']);
                 }
                 break;
             case 'host-service':
                 // be set to the default values within the system.
                 $x = is_numeric($_REQUEST['x']) ? $_REQUEST['x'] : $this->FOGCore->getSetting('FOG_SERVICE_DISPLAYMANAGER_X');
                 $y = is_numeric($_REQUEST['y']) ? $_REQUEST['y'] : $this->FOGCore->getSetting('FOG_SERVICE_DISPLAYMANAGER_Y');
                 $r = is_numeric($_REQUEST['r']) ? $_REQUEST['r'] : $this->FOGCore->getSetting('FOG_SERVICE_DISPLAYMANAGER_R');
                 $tme = is_numeric($_REQUEST['tme']) ? $_REQUEST['tme'] : $this->FOGCore->getSetting('FOG_SERVICE_AUTOLOGOFF_MIN');
                 if (isset($_REQUEST['updatestatus'])) {
                     $modOn = $_REQUEST['modules'];
                     $modOff = $this->getClass('ModuleManager')->find(array('id' => $modOn), '', '', '', '', '', true, 'id');
                     $Host->addModule($modOn);
                     $Host->removeModule($modOff);
                 }
                 if (isset($_REQUEST['updatedisplay'])) {
                     $Host->setDisp($x, $y, $r);
                 }
                 if (isset($_REQUEST['updatealo'])) {
                     $Host->setAlo($tme);
                 }
                 break;
             case 'host-hardware-inventory':
                 $pu = trim($_REQUEST['pu']);
                 $other1 = trim($_REQUEST['other1']);
                 $other2 = trim($_REQUEST['other2']);
                 if ($_REQUEST["update"] == "1") {
                     $Inventory->set('primaryUser', trim($_REQUEST['pu']))->set('other1', trim($_REQUEST['other1']))->set('other2', trim($_REQUEST['other2']))->save();
                 }
                 break;
             case 'host-login-history':
                 $this->FOGCore->redirect("?node=host&sub=edit&id=" . $Host->get('id') . "&dte=" . $_REQUEST['dte'] . "#" . $this->REQUEST['tab']);
                 break;
             case 'host-virus-history':
                 if (isset($_REQUEST["delvid"])) {
                     $Virus = new Virus($_REQUEST['delvid']);
                     $Virus->destroy();
                 }
                 if (isset($_REQUEST['delvid']) && $_REQUEST['delvid'] == 'all') {
                     $Host->clearAVRecordsForHost();
                     $this->FOGCore->redirect('?node=host&sub=edit&id=' . $Host->get('id') . '#' . $this->REQUEST['tab']);
                 }
                 break;
         }
         // Save to database
         if ($Host->save()) {
             $Host->setAD();
             if ($_REQUEST['tab'] == 'host-general') {
                 $Host->ignore($_REQUEST['igimage'], $_REQUEST['igclient']);
             }
             // Hook
             $this->HookManager->processEvent('HOST_EDIT_SUCCESS', array('Host' => &$Host));
             // Log History event
             $this->FOGCore->logHistory('Host updated: ID: ' . $Host->get('id') . ', Name: ' . $Host->get('name') . ', Tab: ' . $this->REQUEST['tab']);
             // Set session message
             $this->FOGCore->setMessage('Host updated!');
             // Redirect to new entry
             $this->FOGCore->redirect(sprintf('?node=%s&sub=edit&%s=%s#%s', $this->REQUEST['node'], $this->id, $Host->get('id'), $this->REQUEST['tab']));
         } else {
             throw new Exception('Host update failed');
         }
     } catch (Exception $e) {
         // Hook
         $this->HookManager->processEvent('HOST_EDIT_FAIL', array('Host' => &$Host));
         // Log History event
         $this->FOGCore->logHistory('Host update failed: Name: ' . $_REQUEST['name'] . ', Tab: ' . $this->REQUEST['tab'] . ', Error: ' . $e->getMessage());
         // Set session message
         $this->FOGCore->setMessage($e->getMessage());
         // Redirect
         $this->FOGCore->redirect('?node=host&sub=edit&id=' . $Host->get('id') . '#' . $this->REQUEST['tab']);
     }
 }
Example #2
0
 public function ignore($imageIgnore, $clientIgnore)
 {
     $MyMACs = $this->getMyMacs();
     foreach ((array) $imageIgnore as $igMAC) {
         $igMACs[] = strtolower($igMAC);
     }
     foreach ((array) $clientIgnore as $cgMAC) {
         $cgMACs[] = strtolower($cgMAC);
     }
     foreach ((array) $MyMACs as $MAC) {
         $ignore = current((array) $this->getClass('MACAddressAssociationManager')->find(array('mac' => $MAC, 'hostID' => $this->get('id'))));
         $ME = new MACAddress($ignore);
         if ($ME->isValid()) {
             $mac = strtolower($MAC);
             $ignore->set('imageIgnore', in_array($mac, (array) $igMACs))->save();
             $ignore->set('clientIgnore', in_array($mac, (array) $cgMACs))->save();
         }
     }
 }
 /** parseMacList() function takes the string of the MAC addresses sent
  *     it then tests if they are each valid macs and returns just the mac's.
  * @param $stringlist the list of MACs to check.  Each mac is broken by a | character.
  * @return $MAClist, returns the list of valid MACs
  */
 public function parseMacList($stringlist, $image = false, $client = false)
 {
     $MACs = $this->getClass('MACAddressAssociationManager')->find(array('mac' => (array) explode('|', $stringlist)));
     if (count($MACs)) {
         foreach ($MACs as $MAC) {
             if ($MAC && $MAC->isValid()) {
                 if ($image && !$MAC->get('imageIgnore')) {
                     $MAC = new MACAddress($MAC);
                 } else {
                     if ($client && !$MAC->get('clientIgnore')) {
                         $MAC = new MACAddress($MAC);
                     }
                 }
                 if (!$image && !$client && !$MAC->get('pending')) {
                     $MAC = new MACAddress($MAC);
                 }
                 if ($MAC instanceof MACAddress) {
                     $MAClist[] = strtolower($MAC);
                 }
             }
         }
     }
     $MACs = explode('|', $stringlist);
     foreach ((array) $MACs as $MAC) {
         $MAC = new MACAddress($MAC);
         if ($MAC && $MAC->isValid()) {
             $MAClist[] = strtolower($MAC);
         }
     }
     $Ignore = explode(',', $this->getClass('FOGCore')->getSetting('FOG_QUICKREG_PENDING_MAC_FILTER'));
     if (count($ignore)) {
         foreach ((array) $Ignore as $ignore) {
             $matches = preg_grep("#{$ignore}#i", $MACs);
             if (count($matches)) {
                 $NewMatches = array_merge((array) $NewMatches, $matches);
                 unset($matches);
             }
         }
     }
     if (!count($MAClist)) {
         return false;
     }
     return array_unique(array_diff((array) $MAClist, (array) $NewMatches));
 }
 /** getmacman() get the mac manager information
  * @return void
  */
 public function getmacman()
 {
     try {
         if (!$_SESSION['AllowAJAXTasks']) {
             throw new Exception(_('FOG Session Invalid'));
         }
         $prefix = $_REQUEST['prefix'];
         if (!$prefix && strlen($prefix) >= 8) {
             throw new Exception(_('Unknown'));
         }
         if (!$this->FOGCore->getMACLookupCount() > 0) {
             throw new Exception('<a href="?node=about&sub=mac-list">' . _('Load MAC Vendors') . '</a>');
         }
         $MAC = new MACAddress($prefix);
         if ($MAC && $MAC->isValid()) {
             $Data = '<small>' . ($mac == 'n/a' ? _('Unknown') : $this->FOGCore->getMACManufacturer($MAC->getMACPrefix())) . '</small>';
         }
     } catch (Exception $e) {
         $Data = $e->getMessage();
     }
     print $Data;
 }