"Fossies" - the Fresh Open Source Software Archive

Member "fogproject-1.5.9/packages/web/service/hostinfo.php" (13 Sep 2020, 8363 Bytes) of package /linux/misc/fogproject-1.5.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hostinfo.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.8_vs_1.5.9.

    1 <?php
    2 /**
    3  * Hostinfo returns the host information
    4  *
    5  * PHP version 5
    6  *
    7  * @category Hostinfo
    8  * @package  FOGProject
    9  * @author   Tom Elliott <tommygunsster@gmail.com>
   10  * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
   11  * @link     https://fogproject.org
   12  */
   13 /**
   14  * Hostinfo returns the host information
   15  *
   16  * @category Hostinfo
   17  * @package  FOGProject
   18  * @author   Tom Elliott <tommygunsster@gmail.com>
   19  * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
   20  * @link     https://fogproject.org
   21  */
   22 require '../commons/base.inc.php';
   23 header('Content-Type: text/plain');
   24 try {
   25     FOGCore::getHostItem(false);
   26     $Task = FOGCore::$Host->get('task');
   27     if (FOGCore::$useragent) {
   28         throw new Exception(_('Cannot view from browser'));
   29     }
   30     if (!$Task->isValid()) {
   31         throw new Exception(_('Invalid tasking!'));
   32     }
   33     $TaskType = FOGCore::getClass(
   34         'TaskType',
   35         $Task->get('typeID')
   36     );
   37     $Image = $Task->getImage();
   38     if ($TaskType->isInitNeededTasking()) {
   39         if ($TaskType->isMulticast()) {
   40             $MulticastSession = FOGCore::getClass(
   41                 'MulticastSession',
   42                 @max(
   43                     FOGCore::getSubObjectIDs(
   44                         'MulticastSessionAssociation',
   45                         array('taskID' => $Task->get('id')),
   46                         'msID'
   47                     )
   48                 )
   49             );
   50             $taskImgID = $Task->get('imageID');
   51             $mcImgID = $MulticastSession->get('image');
   52             if ($taskImgID != $mcImgID) {
   53                 $Task
   54                     ->set('imageID', $mcImgID)
   55                     ->save();
   56                 FOGCore::$Host
   57                     ->set('imageID', $mcImgID);
   58                 $Image = new Image($mcImgID);
   59             }
   60             $port = $MulticastSession->get('port');
   61         }
   62         $StorageGroup = $StorageNode = null;
   63         $HookManager->processEvent(
   64             'BOOT_TASK_NEW_SETTINGS',
   65             array(
   66                 'Host' => &FOGCore::$Host,
   67                 'StorageNode' => &$StorageNode,
   68                 'StorageGroup' => &$StorageGroup
   69             )
   70         );
   71         if (!$StorageGroup || !$StorageGroup->isValid()) {
   72             $StorageGroup = $Image->getStorageGroup();
   73         }
   74         if (!$StorageNode || !$StorageNode->isValid()) {
   75             $StorageNode = $StorageGroup->getOptimalStorageNode();
   76         }
   77         $osid = $Image->get('osID');
   78         $storage = sprintf(
   79             '%s:/%s/%s',
   80             trim($StorageNode->get('ip')),
   81             trim($StorageNode->get('path'), '/'),
   82             (
   83                 $TaskType->isCapture() ?
   84                 'dev/' :
   85                 ''
   86             )
   87         );
   88         $storageip = FOGCore::resolveHostname(
   89             $StorageNode
   90             ->get('ip')
   91         );
   92         $img = $Image
   93             ->get('path');
   94         $imgFormat = $Image
   95             ->get('format');
   96         $imgType = $Image
   97             ->getImageType()
   98             ->get('type');
   99         $imgPartitionType = $Image
  100             ->getImagePartitionType()
  101             ->get('type');
  102         $imgid = $Image
  103             ->get('id');
  104         $PIGZ_COMP = $Image
  105             ->get('compress');
  106         $shutdown = intval(
  107             (bool)$Task
  108             ->get('shutdown')
  109         );
  110         list(
  111             $ignorepg,
  112             $pct,
  113             $hostearly,
  114             $ftp
  115         ) = FOGCore::getSubObjectIDs(
  116             'Service',
  117             array(
  118                 'name' => array(
  119                     'FOG_CAPTUREIGNOREPAGEHIBER',
  120                     'FOG_CAPTURERESIZEPCT',
  121                     'FOG_CHANGE_HOSTNAME_EARLY',
  122                     'FOG_TFTP_HOST'
  123                 )
  124             ),
  125             'value',
  126             false,
  127             'AND',
  128             'name',
  129             false,
  130             ''
  131         );
  132         $ftp = (
  133             $StorageNode->isValid() ?
  134             $StorageNode->get('ip') :
  135             $ftp
  136         );
  137         if (!$pct < 100
  138             && !$pct > 4
  139         ) {
  140             $pct = 5;
  141         }
  142         if ($TaskType->get('id') === 11) {
  143             $winuser = $Task
  144                 ->get('passreset');
  145         }
  146     }
  147     $fdrive = FOGCore::$Host
  148         ->get('kernelDevice');
  149     $Inventory = FOGCore::$Host
  150         ->get('inventory');
  151     $mac = $_REQUEST['mac'];
  152     $MACs = FOGCore::$Host
  153         ->getMyMacs();
  154     $clientMacs = array_filter(
  155         (array)FOGCore::parseMacList(
  156             implode('|', (array)$MACs),
  157             false,
  158             true
  159         )
  160     );
  161     $pass = FOGCore::$Host->get('ADPass');
  162     $passtest = FOGCore::aesdecrypt($pass);
  163     if ($test_base64 = base64_decode($passtest)) {
  164         if (mb_detect_encoding($test_base64, 'utf-8', true)) {
  165             $pass = $test_base64;
  166         } elseif (mb_detect_encoding($passtest, 'utf-8', true)) {
  167             $pass = $passtest;
  168         }
  169     }
  170     $productKey = FOGCore::$Host->get('productKey');
  171     $productKeytest = FOGCore::aesdecrypt($productKey);
  172     if ($test_base64 = base64_decode($productKeytest)) {
  173         if (mb_detect_encoding($test_base64, 'utf-8', true)) {
  174             $productKey = $test_base64;
  175         } elseif (mb_detect_encoding($productKeytest, 'utf-8', true)) {
  176             $productKey = $productKeytest;
  177         }
  178     }
  179     $repFields = array(
  180         // Imaging items to set
  181         'mac' => $mac,
  182         'ftp' => $ftp,
  183         'osid' => $osid,
  184         'storage' => $storage,
  185         'storageip' => $storageip,
  186         'img' => $img,
  187         'imgFormat' => $imgFormat,
  188         'imgType' => $imgType,
  189         'imgPartitionType' => $imgPartitionType,
  190         'imgid' => $imgid,
  191         'PIGZ_COMP' => sprintf(
  192             '-%s',
  193             $PIGZ_COMP
  194         ),
  195         'shutdown' => $shutdown,
  196         'hostearly' => $hostearly,
  197         'pct' => $pct,
  198         'ignorepg' => $ignorepg,
  199         'winuser' => $winuser,
  200         // Really only needed for multicast
  201         'port' => $port,
  202         // Implicit device to use
  203         'fdrive' => $fdrive,
  204         // Exposed other elements
  205         'hostname' => FOGCore::$Host->get('name'),
  206         'hostdesc' => FOGCore::$Host->get('description'),
  207         'hostip' => FOGCore::$Host->get('ip'),
  208         'hostimageid' => FOGCore::$Host->get('imageID'),
  209         'hostbuilding' => FOGCore::$Host->get('building'),
  210         'hostusead' => FOGCore::$Host->get('useAD'),
  211         'hostaddomain' => FOGCore::$Host->get('ADDomain'),
  212         'hostaduser' => FOGCore::$Host->get('ADUser'),
  213         'hostadpass' => trim($pass),
  214         'hostadou' => str_replace(';', '', FOGCore::$Host->get('ADOU')),
  215         'hostproductkey' => trim($productKey),
  216         'imagename' => $Image->get('name'),
  217         'imagedesc' => $Image->get('description'),
  218         'imageosid' => $osid,
  219         'imagepath' => $img,
  220         'primaryuser' => $Inventory->get('primaryUser'),
  221         'othertag' => $Inventory->get('other1'),
  222         'othertag1' => $Inventory->get('other2'),
  223         'sysman' => $Inventory->get('sysman'),
  224         'sysproduct' => $Inventory->get('sysproduct'),
  225         'sysserial' => $Inventory->get('sysserial'),
  226         'mbman' => $Inventory->get('mbman'),
  227         'mbserial' => $Inventory->get('mbserial'),
  228         'mbasset' => $Inventory->get('mbasset'),
  229         'mbproductname' => $Inventory->get('mbproductname'),
  230         'caseman' => $Inventory->get('caseman'),
  231         'caseserial' => $Inventory->get('caseserial'),
  232         'caseasset' => $Inventory->get('caseasset'),
  233     );
  234     $TaskArgs = preg_split(
  235         '#[\s]+#',
  236         trim($TaskType->get('kernelArgs'))
  237     );
  238     foreach ((array)$TaskArgs as $key => &$val) {
  239         $val = trim($val);
  240         if (strpos($val, '=') === false) {
  241             continue;
  242         }
  243         $nums = explode('=', $val);
  244         if (count($nums) > 0) {
  245             $repFields[$nums[0]] = $nums[1];
  246         }
  247         unset($val);
  248     }
  249     $HookManager->processEvent(
  250         'HOST_INFO_EXPOSE',
  251         array(
  252             'repFields' => &$repFields,
  253             'Host'=>&FOGCore::$Host
  254         )
  255     );
  256     foreach ((array)$repFields as $key => &$val) {
  257         printf(
  258             "[[ -z $%s ]] && export %s=%s\n",
  259             $key,
  260             $key,
  261             escapeshellarg($val)
  262         );
  263         unset($val);
  264     }
  265 } catch (Exception $e) {
  266     echo $e->getMessage();
  267     exit(1);
  268 }