public function getUsedSlotCount()
 {
     $UsedTasks = explode(',', $this->FOGCore->getSetting('FOG_USED_TASKS'));
     $countTasks = 0;
     if (in_array(8, (array) $UsedTasks)) {
         foreach ($UsedTasks as $ind => $val) {
             if ($val = 8) {
                 unset($UsedTasks[$ind]);
             }
         }
         foreach ($this->getClass('TaskManager')->find(array('stateID' => 3, 'typeID' => 8)) as $MulticastTask) {
             $Multicast = current($this->getClass('MulticastSessionsAssociationManager')->find(array('taskID' => $MulticastTask->get('id'))));
             if ($Multicast && $Multicast->isValid()) {
                 $MulticastJob = new MulticastSessions($Multicast->get('msID'));
                 if ($MulticastJob && $MulticastJob->isValid()) {
                     $MulticastJobID[] = $MulticastJob->get('id');
                 }
             }
         }
         $MulticastJobID = array_unique((array) $MulticastJobID);
         $countTasks = count($MulticastJobID);
         $UsedTasks = array_values((array) $UsedTasks);
     }
     $countTasks += $this->getClass('TaskManager')->count(array('stateID' => 3, 'typeID' => $UsedTasks, 'NFSMemberID' => $this->get('id')));
     return $countTasks;
 }
 public function stop()
 {
     if (is_numeric($_REQUEST['mcid']) && $_REQUEST['mcid'] > 0) {
         $MulticastSession = new MulticastSessions($_REQUEST['mcid']);
         foreach ((array) $this->getClass('MulticastSessionsAssociationManager')->find(array('msid' => $MulticastSession->get('id'))) as $MulticastAssoc) {
             $Task = new Task($MulticastAssoc->get('taskID'));
             $Task->cancel();
         }
         $MulticastSession->set('name', null)->set('stateID', 5)->save();
         $this->FOGCore->setMessage(_('Canceled task'));
         $this->FOGCore->redirect('?node=' . $this->node . '&sub=multicast');
     }
 }
 private function serviceLoop()
 {
     while (true) {
         try {
             $StorageNode = current($this->getClass('StorageNodeManager')->find(array('isMaster' => 1, 'isEnabled' => 1, 'ip' => $this->FOGCore->getIPAddress())));
             if (!$StorageNode || !$StorageNode->isValid()) {
                 throw new Exception(sprintf(" | This is not the master node"));
             }
             $myroot = $StorageNode->get('path');
             $allTasks = MulticastTask::getAllMulticastTasks($myroot);
             $this->FOGCore->out(sprintf(" | %s task(s) found", count($allTasks)), $this->dev);
             $RMTasks = $this->getMCTasksNotInDB($KnownTasks, $allTasks);
             $jobcancelled = false;
             if (count($RMTasks)) {
                 $this->outall(sprintf(" | Cleaning %s task(s) removed from FOG Database.", count($RMTasks)));
                 foreach ((array) $RMTasks as $RMTask) {
                     $this->outall(sprintf(" | Cleaning Task (%s) %s", $RMTask->getID(), $RMTask->getName()));
                     $Assocs = $this->getClass('MulticastSessionsAssociationManager')->find(array('msID' => $RMTask->getID()));
                     $curSession = new MulticastSessions($RMTask->getID());
                     foreach ($Assocs as $Assoc) {
                         if ($Assoc && $Assoc->isValid()) {
                             if ($this->getClass('Task', $Assoc->get('taskID'))->get('stateID') == 5) {
                                 $jobcancelled = true;
                             }
                         }
                     }
                     if ($jobcancelled || $this->getClass('MulticastSessions', $RMTask->getID())->get('stateID') == 5) {
                         $RMTask->killTask();
                         $KnownTasks = $this->removeFromKnownList($KnownTasks, $RMTask->getID());
                         $this->outall(sprintf(" | Task (%s) %s has been cleaned as cancelled.", $RMTask->getID(), $RMTask->getName()));
                         $this->getClass('MulticastSessionsAssociationManager')->destroy(array('msID' => $RMTask->getID()));
                     } else {
                         $KnownTasks = $this->removeFromKnownList($KnownTasks, $RMTask->getID());
                         $this->outall(sprintf(" | Task (%s) %s has been cleaned as complete.", $RMTask->getID(), $RMTask->getName()));
                         $this->getClass('MulticastSessionsAssociationManager')->destroy(array('msID' => $RMTask->getID()));
                     }
                 }
             } else {
                 if (!$allTasks) {
                     throw new Exception(' * No Tasks Found!');
                 }
             }
             foreach ((array) $allTasks as $curTask) {
                 if ($this->isMCTaskNew($KnownTasks, $curTask->getID())) {
                     $this->outall(sprintf(" | Task (%s) %s is new!", $curTask->getID(), $curTask->getName()));
                     if (file_exists($curTask->getImagePath())) {
                         $this->outall(sprintf(" | Task (%s) %s image file found.", $curTask->getID(), $curTask->getImagePath()));
                         if ($curTask->getClientCount() > 0) {
                             $this->outall(sprintf(" | Task (%s) %s client(s) found.", $curTask->getID(), $curTask->getClientCount()));
                             if (is_numeric($curTask->getPortBase()) && $curTask->getPortBase() % 2 == 0) {
                                 $this->outall(sprintf(" | Task (%s) %s sending on base port: %s", $curTask->getID(), $curTask->getName(), $curTask->getPortBase()));
                                 $this->outall(sprintf("CMD: %s", $curTask->getCMD()));
                                 if ($curTask->startTask()) {
                                     $this->outall(sprintf(" | Task (%s) %s has started.", $curTask->getID(), $curTask->getName()));
                                     $KnownTasks[] = $curTask;
                                 } else {
                                     $this->outall(sprintf(" | Task (%s) %s failed to start!", $curTask->getID(), $curTask->getName()));
                                     $this->outall(sprintf(" | * Don't panic, check all your settings!"));
                                     $this->outall(sprintf(" |       even if the interface is incorrect the task won't start."));
                                     $this->outall(sprintf(" |       If all else fails run the following command and see what it says:"));
                                     $this->outall(sprintf(" |  %s", $curTask->getCMD()));
                                     if ($curTask->killTask()) {
                                         $this->outall(sprintf(" | Task (%s) %s has been cleaned.", $curTask->getID(), $curTask->getName()));
                                     } else {
                                         $this->outall(sprintf(" | Task (%s) %s has NOT been cleaned.", $curTask->getID(), $curTask->getName()));
                                     }
                                 }
                             } else {
                                 $this->outall(sprintf(" | Task (%s) %s failed to execute, port must be even and numeric.", $curTask->getID(), $curTask->getName()));
                             }
                         } else {
                             $this->outall(sprintf(" | Task (%s) %s failed to execute, no clients are included!", $curTask->getID(), $curTask->getName()));
                         }
                     } else {
                         $this->outall(sprintf(" | Task (%s) %s failed to execute, image file:%s not found!", $curTask->getID(), $curTask->getName(), $curTask->getImagePath()));
                     }
                 } else {
                     $runningTask = $this->getMCExistingTask($KnownTasks, $curTask->getID());
                     $curSession = new MulticastSessions($runningTask->getID());
                     $Assocs = $this->getClass('MulticastSessionsAssociationManager')->find(array('msID' => $curSession->get('id')));
                     foreach ($Assocs as $Assoc) {
                         if ($Assoc && $Assoc->isValid()) {
                             $curTaskGet = new Task($Assoc->get('taskID'));
                             if ($curTaskGet->get('stateID') == 5) {
                                 $jobcancelled = true;
                             }
                         }
                     }
                     if ($runningTask->isRunning()) {
                         $this->outall(sprintf(" | Task (%s) %s is already running PID %s", $runningTask->getID(), $runningTask->getName(), $runningTask->getPID()));
                         $runningTask->updateStats();
                     } else {
                         $this->outall(sprintf(" | Task (%s) %s is no longer running.", $runningTask->getID(), $runningTask->getName()));
                         if ($jobcancelled || $curSession->get('stateID') == 5) {
                             if ($runningTask->killTask()) {
                                 $KnownTasks = $this->removeFromKnownList($KnownTasks, $runningTask->getID());
                                 $this->outall(sprintf(" | Task (%s) %s has been cleaned as cancelled.", $runningTask->getID(), $runningTask->getName()));
                             } else {
                                 $this->outall(sprintf(" | Failed to kill task (%s) %s!", $runningTask->getID(), $runningTask->getName()));
                             }
                         } else {
                             $curSession->set('clients', 0)->set('completetime', $this->nice_date()->format('Y-m-d H:i:s'))->set('name', '')->set('stateID', 4)->save();
                             $KnownTasks = $this->removeFromKnownList($KnownTasks, $runningTask->getID());
                             $this->outall(sprintf(" | Task (%s) %s has been cleaned as complete.", $runningTask->getID(), $runningTask->getName()));
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $this->outall($e->getMessage());
         }
         $this->FOGCore->out(sprintf(" +---------------------------------------------------------"), $this->dev);
         sleep(MULTICASTSLEEPTIME);
     }
 }
            $HookManager->processEvent('EMAIL_ITEMS', array('email' => &$email, 'Host' => &$Host));
            $emailMe = '';
            foreach ($email as $key => $val) {
                $emailMe .= $key . $val;
            }
            unset($email);
            $email = $emailMe;
            if (!$Inventory->get('other1')) {
                //if there isn't an existing call number in the system
                mail($to, $Host->get('name') . " - Image Task Completed", $email, $headers);
            } else {
                mail($to, "ISSUE=" . $Inventory->get('other1') . " PROJ=1", $email, $headers);
                mail($to, $Host->get('name') . " - Image Task Completed", "{$email} \nImaged For (Call): " . $Inventory->get('other1'), $headers);
                $Inventory->set('other1', '')->save();
                //clear call number otherwise if a new "existing" call exists later on down the line it'll just update original
            }
        }
    }
    ////============================== Email Notification End	==============================
    print '##';
    // If it's a multicast job, decrement the client count, though not fully needed.
    if ($Task->get('typeID') == 8) {
        $MyMulticastTask = current($FOGCore->getClass('MulticastSessionsAssociationManager')->find(array('taskID' => $Task->get('id'))));
        if ($MyMulticastTask && $MyMulticastTask->isValid()) {
            $MulticastSession = new MulticastSessions($MyMulticastTask->get('msID'));
            $MulticastSession->set('clients', $MulticastSession->get('clients') - 1)->save();
        }
    }
} catch (Exception $e) {
    print $e->getMessage();
}
 public function updateStats()
 {
     foreach ($this->getClass('MulticastSessionsAssociationManager')->find(array('msid' => $this->intID)) as $MultiSessAssoc) {
         $Task = new Task($MultiSessAssoc->get('taskID'));
         if ($Task && $Task->isValid()) {
             $TaskPercent[] = $Task->get('percent');
         }
     }
     $TaskPercent = array_unique((array) $TaskPercent);
     $MultiSess = new MulticastSessions($this->intID);
     $MultiSess->set('percent', max((array) $TaskPercent))->save();
 }
Example #6
0
<?php

require_once '../commons/base.inc.php';
try {
    // Get the Host
    $Host = $FOGCore->getHostItem(false);
    // Get the task
    $Task = $Host->get('task');
    if (!$Task->isValid()) {
        throw new Exception(sprintf('%s: %s (%s)', _('No Active Task found for Host'), $Host->get('name'), $MACAddress));
    }
    if ($Task->get('typeID') == 8) {
        // Get the current Multicast Session
        $MulticastAssociation = current($FOGCore->getClass('MulticastSessionsAssociationManager')->find(array('taskID' => $Task->get('id'))));
        $MultiSess = new MulticastSessions($MulticastAssociation->get('msID'));
    }
    if ($Task->get('stateID') == 1) {
        // Check In Task for Host
        $Task->set('stateID', 2)->set('checkInTime', $FOGCore->nice_date()->format('Y-m-d H:i:s'))->save();
        // If the state is queued, meaning the client has checked in increment clients
        $Task->get('typeID') == 8 ? $MultiSess->set('clients', $MultiSess->get('clients') + 1)->save() : null;
    }
    // Get the count of total associations.
    $Task->get('typeID') == 8 ? $MSAs = $FOGCore->getClass('MulticastSessionsAssociationManager')->count(array('msID' => $MultiSess->get('id'))) : null;
    // Set the task state for this host as in-progress.
    $Task->set('stateID', 3);
    if ($Task->get('typeID') == 8) {
        // If client count is equal, place session task in-progress as it will likely start soon.
        if ($MSAs == $MultiSess->get('clients') || $MultiSess->get('sessclients') > 0 && $MultiSess->get('clients') > 0) {
            $MultiSess->set('stateID', 3);
        } else {
 /** @function getTasking() Finds out if there's a tasking for the relevant host.
  * if there is, returns the printTasking, otherwise
  * presents the menu.
  * @return void
  */
 public function getTasking()
 {
     $Task = $this->Host->get('task');
     if (!$Task->isValid()) {
         if ($this->FOGCore->getSetting('FOG_NO_MENU')) {
             $this->noMenu();
         } else {
             $this->printDefault();
         }
     } else {
         if ($this->Host->get('mac')->isImageIgnored()) {
             $this->printImageIgnored();
         }
         $TaskType = new TaskType($Task->get('typeID'));
         $imagingTasks = array(1, 2, 8, 15, 16, 17, 24);
         if ($TaskType->isMulticast()) {
             $MulticastSessionAssoc = current($this->getClass('MulticastSessionsAssociationManager')->find(array('taskID' => $Task->get('id'))));
             $MulticastSession = new MulticastSessions($MulticastSessionAssoc->get('msID'));
             if ($MulticastSession && $MulticastSession->isValid()) {
                 $this->Host->set('imageID', $MulticastSession->get('image'));
             }
         }
         if (in_array($TaskType->get('id'), $imagingTasks)) {
             $Image = $Task->getImage();
             $StorageGroup = $Image->getStorageGroup();
             $StorageNode = $StorageGroup->getOptimalStorageNode();
             $this->HookManager->processEvent('BOOT_TASK_NEW_SETTINGS', array('Host' => &$this->Host, 'StorageNode' => &$StorageNode, 'StorageGroup' => &$StorageGroup));
             if ($TaskType->isUpload() || $TaskType->isMulticast()) {
                 $StorageNode = $StorageGroup->getMasterStorageNode();
             }
             $osid = $Image->get('osID');
             $storage = in_array($TaskType->get('id'), $imagingTasks) ? sprintf('%s:/%s/%s', $this->FOGCore->resolveHostname(trim($StorageNode->get('ip'))), trim($StorageNode->get('path'), '/'), $TaskType->isUpload() ? 'dev/' : '') : null;
         }
         if ($this->Host && $this->Host->isValid()) {
             $mac = $this->Host->get('mac');
         } else {
             $mac = $_REQUEST['mac'];
         }
         $clamav = in_array($TaskType->get('id'), array(21, 22)) ? sprintf('%s:%s', $this->FOGCore->resolveHostname(trim($StorageNode->get('ip'))), '/opt/fog/clamav') : null;
         $storageip = in_array($TaskType->get('id'), $imagingTasks) ? $this->FOGCore->resolveHostname($StorageNode->get('ip')) : null;
         $img = in_array($TaskType->get('id'), $imagingTasks) ? $Image->get('path') : null;
         $imgFormat = in_array($TaskType->get('id'), $imagingTasks) ? $Image->get('format') : null;
         $imgType = in_array($TaskType->get('id'), $imagingTasks) ? $Image->getImageType()->get('type') : null;
         $imgPartitionType = in_array($TaskType->get('id'), $imagingTasks) ? $Image->getImagePartitionType()->get('type') : null;
         $imgid = in_array($TaskType->get('id'), $imagingTasks) ? $Image->get('id') : null;
         $ftp = $this->FOGCore->resolveHostname($this->FOGCore->getSetting('FOG_TFTP_HOST'));
         $chkdsk = $this->FOGCore->getSetting('FOG_DISABLE_CHKDSK') == 1 ? 0 : 1;
         $PIGZ_COMP = in_array($TaskType->get('id'), $imagingTasks) ? $Image->get('compress') > -1 && is_numeric($Image->get('compress')) ? $Image->get('compress') : $this->FOGCore->getSetting('FOG_PIGZ_COMP') : $this->FOGCore->getSetting('FOG_PIGZ_COMP');
         $kernelArgsArray = array("mac={$mac}", "ftp={$ftp}", "storage={$storage}", "storageip={$storageip}", "web={$this->web}", "osid={$osid}", "consoleblank=0", "irqpoll", "hostname=" . $this->Host->get('name'), array('value' => "clamav={$clamav}", 'active' => in_array($TaskType->get('id'), array(21, 22))), array('value' => "chkdsk={$chkdsk}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "img={$img}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "imgType={$imgType}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "imgPartitionType={$imgPartitionType}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "imgid={$imgid}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "imgFormat={$imgFormat}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => "PIGZ_COMP=-{$PIGZ_COMP}", 'active' => in_array($TaskType->get('id'), $imagingTasks)), array('value' => 'shutdown=1', 'active' => $Task->get('shutdown')), array('value' => 'adon=1', 'active' => $this->Host->get('useAD')), array('value' => 'addomain=' . $this->Host->get('ADDomain'), 'active' => $this->Host->get('useAD')), array('value' => 'adou=' . $this->Host->get('ADOU'), 'active' => $this->Host->get('useAD')), array('value' => 'aduser='******'ADUser'), 'active' => $this->Host->get('useAD')), array('value' => 'adpass='******'ADPass'), 'active' => $this->Host->get('useAD')), array('value' => 'fdrive=' . $this->Host->get('kernelDevice'), 'active' => $this->Host->get('kernelDevice')), array('value' => 'hostearly=1', 'active' => $this->FOGCore->getSetting('FOG_CHANGE_HOSTNAME_EARLY') && in_array($TaskType->get('id'), $imagingTasks) ? true : false), array('value' => 'pct=' . (is_numeric($this->FOGCore->getSetting('FOG_UPLOADRESIZEPCT')) && $this->FOGCore->getSetting('FOG_UPLOADRESIZEPCT') >= 5 && $this->FOGCore->getSetting('FOG_UPLOADRESIZEPCT') < 100 ? $this->FOGCore->getSetting('FOG_UPLOADRESIZEPCT') : '5'), 'active' => $TaskType->isUpload() && in_array($TaskType->get('id'), $imagingTasks) ? true : false), array('value' => 'ignorepg=' . ($this->FOGCore->getSetting('FOG_UPLOADIGNOREPAGEHIBER') ? 1 : 0), 'active' => $TaskType->isUpload() && in_array($TaskType->get('id'), $imagingTasks) ? true : false), array('value' => 'port=' . ($TaskType->isMulticast() ? $MulticastSession->get('port') : null), 'active' => $TaskType->isMulticast()), array('value' => 'mining=1', 'active' => $this->FOGCore->getSetting('FOG_MINING_ENABLE')), array('value' => 'miningcores=' . $this->FOGCore->getSetting('FOG_MINING_MAX_CORES'), 'active' => $this->FOGCore->getSetting('FOG_MINING_ENABLE')), array('value' => 'winuser='******'passreset'), 'active' => $TaskType->get('id') == '11' ? true : false), array('value' => 'miningpath=' . $this->FOGCore->getSetting('FOG_MINING_PACKAGE_PATH'), 'active' => $this->FOGCore->getSetting('FOG_MINING_ENABLE')), array('value' => 'isdebug=yes', 'active' => $Task->get('isDebug')), array('value' => 'debug', 'active' => $this->FOGCore->getSetting('FOG_KERNEL_DEBUG')), $TaskType->get('kernelArgs'), $this->FOGCore->getSetting('FOG_KERNEL_ARGS'), $this->Host->get('kernelArgs'));
         if ($Task->get('typeID') == 12 || $Task->get('typeID') == 13) {
             $this->printDefault();
         } else {
             if ($Task->get('typeID') == 4) {
                 $Send['memtest'] = array("#!ipxe", "{$this->memdisk} iso raw", "{$this->memtest}", "boot");
                 $this->parseMe($Send);
             } else {
                 $this->printTasking($kernelArgsArray);
             }
         }
     }
 }
 public function remove_multicast_task()
 {
     try {
         // Remove task from associations and multicast sessions.
         $MSAs = $this->getClass('MulticastSessionsAssociationManager')->find(array('msID' => $_REQUEST['id']));
         $MulticastTask = new MulticastSessions($_REQUEST['id']);
         foreach ((array) $MSAs as $MSA) {
             $Task = new Task($MSA->get('taskID'));
             $Task->cancel();
         }
         $MulticastTask->set('completetime', $this->formatTime('now', 'Y-m-d H:i:s'))->set('stateID', 5)->save();
     } catch (Exception $e) {
     }
 }