Пример #1
0
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) {
Пример #2
0
 public function isValid()
 {
     return $this->get('id') && HostManager::isHostnameSafe($this->get('name')) && $this->getMACAddress();
 }
Пример #3
0
 /** 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;
     }
 }