/** 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
<?php

require_once '../commons/base.inc.php';
try {
    // Get the mode.
    if (trim($_REQUEST['mode']) != array('q', 's')) {
        throw new Exception(_('Invalid operational mode'));
    }
    // Get the info
    $string = explode(':', base64_decode($_REQUEST['string']));
    $vInfo = explode(' ', trim($string[1]));
    //Store the info.
    $Virus = new Virus(array('name' => trim($vInfo[0]), 'hostMAC' => strtolower($FOGCore->getHostItem(false)->get('mac')), 'file' => $string[0], 'date' => $FOGCore->formatTime('now', 'Y-m-d H:i:s'), 'mode' => $_REQUEST['mode']));
    if ($Virus->save()) {
        throw new Exception(_('Accepted'));
    } else {
        throw new Exception(_('Failed'));
    }
} catch (Exception $e) {
    print $e->getMessage();
}