fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bootmenu.class.php
Go to the documentation of this file.
1 <?php
22 class BootMenu extends FOGBase
23 {
29  private $_kernel;
35  private $_initrd;
41  private $_booturl;
47  private $_memdisk;
53  private $_memtest;
59  private $_web;
65  private $_defaultChoice;
71  private $_bootexittype;
77  private $_loglevel;
83  private $_storage;
89  private $_shutdown;
95  private $_path;
101  private $_hiddenmenu;
107  private $_timeout;
113  private $_KS;
119  private static $_exitTypes = array();
125  public function __construct()
126  {
127  parent::__construct();
128  $grubChain = 'chain -ar ${boot-url}/service/ipxe/grub.exe '
129  . '--config-file="%s"';
130  $sanboot = 'sanboot --no-describe --drive 0x80';
131  $refind = sprintf(
132  'imgfetch ${boot-url}/service/ipxe/refind.conf%s'
133  . 'chain -ar ${boot-url}/service/ipxe/refind_x64.efi',
134  "\n"
135  );
136 
137  if (stripos($_REQUEST['arch'], 'i386') !== false) {
138  //user i386 boot loaders instead
139  $refind = sprintf(
140  'imgfetch ${boot-url}/service/ipxe/refind.conf%s'
141  . 'chain -ar ${boot-url}/service/ipxe/refind_ia32.efi',
142  "\n"
143  );
144  }
145 
146  if (stripos($_REQUEST['arch'], 'arm') !== false) {
147  //use arm boot loaders instead
148  $refind = 'chain -ar ${boot-url}/service/ipxe/refind_aa64.efi';
149  }
150 
151  $grub = array(
152  'basic' => sprintf(
153  $grubChain,
154  'rootnoverify (hd0);chainloader +1'
155  ),
156  '1cd' => sprintf(
157  $grubChain,
158  'cdrom --init;map --hook;root (cd0);chainloader (cd0)"'
159  ),
160  '1fw' => sprintf(
161  $grubChain,
162  'find --set-root /BOOTMGR;chainloader /BOOTMGR"'
163  )
164  );
165  self::$_exitTypes = array(
166  'sanboot' => $sanboot,
167  'grub' => $grub['basic'],
168  'grub_first_hdd' => $grub['basic'],
169  'grub_first_cdrom' => $grub['1cd'],
170  'grub_first_found_windows' => $grub['1fw'],
171  'refind_efi' => $refind,
172  'exit' => 'exit',
173  );
174  list(
175  $webserver,
176  $curroot
178  'Service',
179  array(
180  'name' => array(
181  'FOG_WEB_HOST',
182  'FOG_WEB_ROOT',
183  )
184  ),
185  'value',
186  false,
187  'AND',
188  'name',
189  false,
190  ''
191  );
192  $curroot = trim($curroot, '/');
193  $webroot = '/fog/';
194  $this->_web = sprintf('%s://%s%s', self::$httpproto, $webserver, $webroot);
195  $Send['booturl'] = array(
196  '#!ipxe',
197  "set fog-ip $webserver",
198  sprintf('set fog-webroot %s', basename($curroot)),
199  'set boot-url '
200  . self::$httpproto
201  . '://${fog-ip}/${fog-webroot}',
202  );
203  $this->_parseMe($Send);
204  if (self::$Host->isValid()) {
205  if (!self::$Host->get('inventory')->get('sysuuid')) {
207  ->get('inventory')
208  ->set('sysuuid', $_REQUEST['sysuuid'])
209  ->set('hostID', self::$Host->get('id'))
210  ->save();
211  }
212  }
213  $host_field_test = 'biosexit';
214  $global_field_test = 'FOG_BOOT_EXIT_TYPE';
215  if ($_REQUEST['platform'] == 'efi') {
216  $host_field_test = 'efiexit';
217  $global_field_test = 'FOG_EFI_BOOT_EXIT_TYPE';
218  }
219  $StorageNodeID = @min(
220  self::getSubObjectIDs(
221  'StorageNode',
222  array(
223  'isEnabled' => 1,
224  'isMaster' => 1,
225  )
226  )
227  );
228  $StorageNode = new StorageNode($StorageNodeID);
229  $serviceNames = array(
230  'FOG_EFI_BOOT_EXIT_TYPE',
231  'FOG_KERNEL_ARGS',
232  'FOG_KERNEL_DEBUG',
233  'FOG_KERNEL_LOGLEVEL',
234  'FOG_KERNEL_RAMDISK_SIZE',
235  'FOG_KEYMAP',
236  'FOG_KEY_SEQUENCE',
237  'FOG_MEMTEST_KERNEL',
238  'FOG_PXE_BOOT_IMAGE',
239  'FOG_PXE_BOOT_IMAGE_32',
240  'FOG_PXE_HIDDENMENU_TIMEOUT',
241  'FOG_PXE_MENU_HIDDEN',
242  'FOG_PXE_MENU_TIMEOUT',
243  'FOG_TFTP_PXE_KERNEL',
244  'FOG_TFTP_PXE_KERNEL_32',
245  );
246  list(
247  $exit,
248  $kernelArgs,
249  $kernelDebug,
250  $kernelLogLevel,
251  $kernelRamDisk,
252  $keymap,
253  $keySequence,
254  $memtest,
255  $imagefile,
256  $init_32,
257  $hiddenTimeout,
258  $hiddenmenu,
259  $menuTimeout,
260  $bzImage,
261  $bzImage32
263  'Service',
264  array(
265  'name' => $serviceNames
266  ),
267  'value',
268  false,
269  'AND',
270  'name',
271  false,
272  ''
273  );
274  $memdisk = 'memdisk';
275  $loglevel = $kernelLogLevel;
276  $ramsize = $kernelRamDisk;
277  $timeout = (
278  $hiddenmenu > 0 && !$_REQUEST['menuAccess'] ?
279  $hiddenTimeout :
280  $menuTimeout
281  ) * 1000;
282  $keySequence = (
283  $hiddenmenu > 0 && !$_REQUEST['menuAccess'] ?
284  $keySequence :
285  ''
286  );
287  if ($_REQUEST['arch'] != 'x86_64') {
288  $bzImage = $bzImage32;
289  $imagefile = $init_32;
290  }
291  $kernel = $bzImage;
292  if (self::$Host->get('kernel')) {
293  $bzImage = trim(
294  self::$Host->get('kernel')
295  );
296  }
297  if (self::$Host->get('init')) {
298  $imagefile = trim(
299  self::$Host->get('init')
300  );
301  }
302  $StorageGroup = $StorageNode->getStorageGroup();
303  $exit = trim(
304  (
305  self::$Host->get($host_field_test) ?:
306  self::getSetting($global_field_test)
307  )
308  );
309  if (!$exit || !in_array($exit, array_keys(self::$_exitTypes))) {
310  $exit = 'sanboot';
311  }
312  $initrd = $imagefile;
313  if (self::$Host->isValid()) {
314  self::$HookManager->processEvent(
315  'BOOT_ITEM_NEW_SETTINGS',
316  array(
317  'Host' => &self::$Host,
318  'StorageGroup' => &$StorageGroup,
319  'StorageNode' => &$StorageNode,
320  'webserver' => &$webserver,
321  'webroot' => &$webroot,
322  'memtest' => &$memtest,
323  'memdisk' => &$memdisk,
324  'bzImage' => &$bzImage,
325  'imagefile' => &$imagefile,
326  'initrd' => &$initrd,
327  'loglevel' => &$loglevel,
328  'ramsize' => &$ramsize,
329  'keymap' => &$keymap,
330  'timeout' => &$timeout,
331  'keySequence' => &$keySequence,
332  )
333  );
334  }
335  $kernel = $bzImage;
336  $initrd = $imagefile;
337  $this->_timeout = $timeout;
338  $this->_hiddenmenu = ($hiddenmenu && !$_REQUEST['menuAccess']);
339  $this->_bootexittype = self::$_exitTypes[$exit];
340  $this->_loglevel = "loglevel=$loglevel";
341  $this->_KS = self::getClass('KeySequence', $keySequence);
342  $this->_booturl = self::$httpproto
343  . "://{$webserver}/fog/service";
344  $this->_memdisk = "kernel $memdisk initrd=$memtest";
345  $this->_memtest = "initrd $memtest";
346  $StorageNodes = (array)self::getClass('StorageNodeManager')
347  ->find(
348  array(
349  'ip' => array(
350  $webserver,
351  self::resolveHostname($webserver)
352  )
353  )
354  );
355  if (count($StorageNodes) < 1) {
356  $StorageNodes = (array)self::getClass('StorageNodeManager')
357  ->find();
358  foreach ($StorageNodes as $StorageNode) {
359  $hostname = self::resolveHostname($StorageNode->get('ip'));
360  if ($hostname == $webserver
361  || $hostname == self::resolveHostname($webserver)
362  ) {
363  break;
364  }
365  $StorageNode = new StorageNode(0);
366  }
367  if (!$StorageNode->isValid()) {
368  $storageNodeIDs = (array)self::getSubObjectIDs(
369  'StorageNode',
370  array('isMaster' => 1)
371  );
372  if (count($storageNodeIDs) < 1) {
373  $storageNodeIDs = (array)self::getSubObjectIDs(
374  'StorageNode'
375  );
376  }
377  $StorageNode = new StorageNode(@min($storageNodeIDs));
378  }
379  } else {
380  $StorageNode = current($StorageNodes);
381  }
382  if ($StorageNode->isValid()) {
383  $this->_storage = sprintf(
384  'storage=%s:/%s/ storageip=%s',
385  trim($StorageNode->get('ip')),
386  trim($StorageNode->get('path'), '/'),
387  trim($StorageNode->get('ip'))
388  );
389  }
390  $this->_kernel = sprintf(
391  'kernel %s %s initrd=%s root=/dev/ram0 rw '
392  . 'ramdisk_size=%s%sweb=%s consoleblank=0%s rootfstype=ext4%s%s '
393  . '%s nvme_core.default_ps_max_latency_us=0',
394  $bzImage,
395  $this->_loglevel,
396  basename($initrd),
397  $ramsize,
398  strlen($keymap) ? sprintf(' keymap=%s ', $keymap) : ' ',
399  $this->_web,
400  $kernelDebug ? ' debug' : ' ',
401  $kernelArgs ? sprintf(' %s', $kernelArgs) : '',
402  (
403  self::$Host->isValid() && self::$Host->get('kernelArgs') ?
404  sprintf(' %s', self::$Host->get('kernelArgs')) :
405  ''
406  ),
407  $this->_storage
408  );
409  $this->_initrd = "imgfetch $imagefile";
410  self::$HookManager
411  ->processEvent('BOOT_MENU_ITEM');
412  $PXEMenuID = @max(
413  self::getSubObjectIDs(
414  'PXEMenuOptions',
415  array(
416  'default' => 1
417  )
418  )
419  );
420  $defaultMenu = new PXEMenuOptions($PXEMenuID);
421  $menuname = (
422  $defaultMenu->isValid() ?
423  trim($defaultMenu->get('name')) :
424  'fog.local'
425  );
426  unset($defaultMenu);
428  $this->_timeout,
429  $menuname,
430  $this->_defaultChoice
431  );
432  $this->_ipxeLog();
433  if (self::$Host->isValid() && self::$Host->get('task')->isValid()) {
434  $this->getTasking();
435  exit;
436  }
437  self::$HookManager->processEvent(
438  'ALTERNATE_BOOT_CHECKS'
439  );
440  if (isset($_REQUEST['username'])) {
441  $this->verifyCreds();
442  } elseif ($_REQUEST['delconf']) {
443  $this->_delHost();
444  } elseif ($_REQUEST['key']) {
445  $this->keyset();
446  } elseif ($_REQUEST['sessname']) {
447  $this->sesscheck();
448  } elseif ($_REQUEST['aprvconf']) {
449  $this->_approveHost();
450  } elseif (!self::$Host->isValid()) {
451  $this->printDefault();
452  } else {
453  $this->getTasking();
454  }
455  }
465  private static function _getDefaultMenu($timeout, $name, &$default)
466  {
467  $default = sprintf(
468  'choose --default %s --timeout %s target && goto ${target}',
469  $name,
470  $timeout
471  );
472  }
478  private function _ipxeLog()
479  {
480  $filename = trim(basename($_REQUEST['filename']));
481  $product = trim($_REQUEST['product']);
482  $manufacturer = trim($_REQUEST['manufacturer']);
483  $findWhere = array(
484  'file' => sprintf('%s', $filename ? $filename : ''),
485  'product' => sprintf('%s', $product ? $product : ''),
486  'manufacturer' => sprintf('%s', $manufacturer ? $manufacturer : ''),
487  'mac' => (
488  self::$Host->isValid() ?
489  self::$Host->get('mac')->__toString() :
490  ''
491  ),
492  );
493  $id = @max(self::getSubObjectIDs('iPXE', $findWhere));
494  self::getClass('iPXE', $id)
495  ->set('product', $findWhere['product'])
496  ->set('manufacturer', $findWhere['manufacturer'])
497  ->set('mac', $findWhere['mac'])
498  ->set('success', 1)
499  ->set('failure', 0)
500  ->set('file', $findWhere['file'])
501  ->set('version', trim($_REQUEST['ipxever']))
502  ->save();
503  }
512  private function _chainBoot($debug = false, $shortCircuit = false)
513  {
514  $debug = $debug;
515  if (!$this->_hiddenmenu || $shortCircuit) {
516  $Send['chainnohide'] = array(
517  'cpuid --ext 29 && set arch x86_64 || set arch i386',
518  'params',
519  'param mac0 ${net0/mac}',
520  'param arch ${arch}',
521  'param platform ${platform}',
522  'param menuAccess 1',
523  "param debug $debug",
524  'param sysuuid ${uuid}',
525  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
526  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
527  ':bootme',
528  "chain -ar $this->_booturl/ipxe/boot.php##params",
529  );
530  } else {
531  $KSKey = (
532  $this->_KS->isValid() ?
533  trim($this->_KS->get('ascii')) :
534  '0x1b'
535  );
536  $KSName = (
537  $this->_KS->isValid() ?
538  trim($this->_KS->get('name')) :
539  'Escape'
540  );
541  $Send['chainhide'] = array(
542  'cpuid --ext 29 && set arch x86_64 || set arch i386',
543  "iseq \${platform} efi && set key 0x1b || set key $KSKey",
544  "iseq \${platform} efi && set keyName ESC || "
545  . "set keyName $KSName",
546  "prompt --key \${key} --timeout $this->_timeout "
547  . "Booting... (Press \${keyName} to access the menu) && "
548  . "goto menuAccess || $this->_bootexittype",
549  ':menuAccess',
550  'login',
551  'params',
552  'param mac0 ${net0/mac}',
553  'param arch ${arch}',
554  'param platform ${platform}',
555  'param username ${username}',
556  'param password ${password}',
557  'param menuaccess 1',
558  "param debug $debug",
559  'param sysuuid ${uuid}',
560  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
561  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
562  ':bootme',
563  "chain -ar $this->_booturl/ipxe/boot.php##params",
564  );
565  }
566  $this->_parseMe($Send);
567  }
573  private function _delHost()
574  {
575  if (self::$Host->destroy()) {
576  $Send['delsuccess'] = array(
577  'echo Host deleted successfully',
578  'sleep 3'
579  );
580  } else {
581  $Send['delfail'] = array(
582  'echo Failed to destroy Host!',
583  'sleep 3',
584  );
585  }
586  $this->_parseMe($Send);
587  $this->_chainBoot();
588  }
594  private function _printImageIgnored()
595  {
596  $Send['ignored'] = array(
597  'echo The MAC Address is set to be ignored for imaging tasks',
598  'sleep 15',
599  );
600  $this->_parseMe($Send);
601  $this->printDefault();
602  }
608  private function _approveHost()
609  {
610  if (self::$Host->set('pending', null)->save()) {
611  $Send['approvesuccess'] = array(
612  'echo Host approved successfully',
613  'sleep 3'
614  );
615  $shutdown = stripos(
616  'shutdown=1',
617  $_REQUEST['extraargs']
618  );
619  $isdebug = preg_match(
620  '#isdebug=yes|mode=debug|mode=onlydebug#i',
621  $_REQUEST['extraargs']
622  );
623  self::$Host->createImagePackage(
624  10,
625  'Inventory',
626  $shutdown,
627  $isdebug,
628  false,
629  false,
630  $_REQUEST['username']
631  );
632  } else {
633  $Send['approvefail'] = array(
634  'echo Host approval failed',
635  'sleep 3'
636  );
637  }
638  $this->_parseMe($Send);
639  $this->_chainBoot();
640  }
648  private function _printTasking($kernelArgsArray)
649  {
650  $kernelArgs = array();
651  foreach ((array)$kernelArgsArray as &$arg) {
652  if (empty($arg)) {
653  continue;
654  }
655  if (is_array($arg)) {
656  if (!(isset($arg['value']) && $arg['value'])) {
657  continue;
658  }
659  if (!(isset($arg['active']) && $arg['active'])) {
660  continue;
661  }
662  $kernelArgs[] = preg_replace(
663  '#mode=debug|mode=onlydebug#i',
664  'isdebug=yes',
665  $arg['value']
666  );
667  } else {
668  $kernelArgs[] = preg_replace(
669  '#mode=debug|mode=onlydebug#i',
670  'isdebug=yes',
671  $arg
672  );
673  }
674  unset($arg);
675  }
676  $kernelArgs = array_filter($kernelArgs);
677  $kernelArgs = array_unique($kernelArgs);
678  $kernelArgs = array_values($kernelArgs);
679  $kernelArgs = implode(' ', (array)$kernelArgs);
680  $Send['task'][(
681  self::$Host->isValid() ?
682  self::$Host->get('task')->get('typeID') :
683  1
684  )] = array(
685  "$this->_kernel $kernelArgs",
686  $this->_initrd,
687  'boot',
688  );
689  $this->_parseMe($Send);
690  }
696  public function delConf()
697  {
698  $Send['delconfirm'] = array(
699  'cpuid --ext 29 && set arch x86_64 || set arch i386',
700  'prompt --key y Would you like to delete this host? (y/N): &&',
701  'params',
702  'param mac0 ${net0/mac}',
703  'param arch ${arch}',
704  'param platform ${platform}',
705  'param delconf 1',
706  'param sysuuid ${uuid}',
707  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
708  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
709  ':bootme',
710  "chain -ar $this->_booturl/ipxe/boot.php##params",
711  );
712  $this->_parseMe($Send);
713  }
719  public function aprvConf()
720  {
721  $Send['aprvconfirm'] = array(
722  'cpuid --ext 29 && set arch x86_64 || set arch i386',
723  'prompt --key y Would you like to approve this host? (y/N): &&',
724  'params',
725  'param mac0 ${net0/mac}',
726  'param arch ${arch}',
727  'param platform ${platform}',
728  'param aprvconf 1',
729  'param sysuuid ${uuid}',
730  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
731  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
732  ':bootme',
733  "chain -ar $this->_booturl/ipxe/boot.php##params",
734  );
735  $this->_parseMe($Send);
736  }
742  public function keyreg()
743  {
744  $Send['keyreg'] = array(
745  'cpuid --ext 29 && set arch x86_64 || set arch i386',
746  'echo -n Please enter the product key : ',
747  'read key',
748  'params',
749  'param mac0 ${net0/mac}',
750  'param arch ${arch}',
751  'param platform ${platform}',
752  'param key ${key}',
753  'param sysuuid ${uuid}',
754  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
755  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
756  ':bootme',
757  "chain -ar $this->_booturl/ipxe/boot.php##params",
758  );
759  $this->_parseMe($Send);
760  }
767  public function sesscheck()
768  {
769  $findWhere = array(
770  'name' => trim($_REQUEST['sessname']),
771  'stateID' => self::fastmerge(
772  self::getQueuedStates(),
773  (array)self::getProgressState()
774  ),
775  );
776  foreach ((array)self::getClass('MulticastSessionManager')
777  ->find($findWhere) as &$MulticastSession
778  ) {
779  if (!$MulticastSession->isValid()
780  || $MulticastSession->get('sessclients') < 1
781  ) {
782  $MulticastSessionID = 0;
783  unset($MulticastSession);
784  continue;
785  }
786  $MulticastSessionID = $MulticastSession->get('id');
787  unset($MulticastSession);
788  break;
789  }
790  $MulticastSession = new MulticastSession($MulticastSessionID);
791  if (!$MulticastSession->isValid()) {
792  $Send['checksession'] = array(
793  'echo No session found with that name.',
794  'clear sessname',
795  'sleep 3',
796  'cpuid --ext 29 && set arch x86_64 || set arch i386',
797  'params',
798  'param mac0 ${net0/mac}',
799  'param arch ${arch}',
800  'param platform ${platform}',
801  'param sessionJoin 1',
802  'param sysuuid ${uuid}',
803  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
804  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
805  ':bootme',
806  "chain -ar $this->_booturl/ipxe/boot.php##params",
807  );
808  $this->_parseMe($Send);
809  return;
810  }
811  $this->multijoin($MulticastSession->get('id'));
812  }
818  public function sessjoin()
819  {
820  $Send['joinsession'] = array(
821  'cpuid --ext 29 && set arch x86_64 || set arch i386',
822  'echo -n Please enter the session name to join > ',
823  'read sessname',
824  'params',
825  'param mac0 ${net0/mac}',
826  'param arch ${arch}',
827  'param platform ${platform}',
828  'param sessname ${sessname}',
829  'param sysuuid ${uuid}',
830  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
831  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
832  ':bootme',
833  "chain -ar $this->_booturl/ipxe/boot.php##params",
834  );
835  $this->_parseMe($Send);
836  }
847  public function falseTasking($mc = false, $Image = false)
848  {
849  $this->_kernel = str_replace(
850  $this->_storage,
851  '',
852  $this->_kernel
853  );
854  $TaskType = new TaskType(1);
855  if ($mc) {
856  $Image = $mc->getImage();
857  $TaskType = new TaskType(8);
858  }
859  $serviceNames = array(
860  'FOG_DISABLE_CHKDSK',
861  'FOG_KERNEL_ARGS',
862  'FOG_KERNEL_DEBUG',
863  'FOG_MULTICAST_RENDEZVOUS',
864  'FOG_NONREG_DEVICE'
865  );
866  list(
867  $chkdsk,
868  $kargs,
869  $kdebug,
870  $mcastrdv,
871  $nondev
873  'Service',
874  array(
875  'name' => $serviceNames
876  ),
877  'value',
878  false,
879  'AND',
880  'name',
881  false,
882  ''
883  );
884  $shutdown = false !== stripos(
885  'shutdown=1',
886  $TaskType->get('kernelArgs')
887  );
888  if (!$shutdown && isset($_REQUEST['extraargs'])) {
889  $shutdown = false !== stripos(
890  'shutdown=1',
891  $_REQUEST['extraargs']
892  );
893  }
894  $StorageGroup = $Image->getStorageGroup();
895  $StorageNode = $StorageGroup->getOptimalStorageNode();
896  $osid = $Image->get('osID');
897  $storage = escapeshellcmd(
898  sprintf(
899  '%s:/%s/%s',
900  trim($StorageNode->get('ip')),
901  trim($StorageNode->get('path'), '/'),
902  ''
903  )
904  );
905  $storageip = $StorageNode->get('ip');
906  $img = escapeshellcmd($Image->get('path'));
907  $imgFormat = (int)$Image->get('format');
908  $imgType = $Image->getImageType()->get('type');
909  $imgPartitionType = $Image->getPartitionType();
910  $imgid = $Image->get('id');
911  $chkdsk = $chkdsk == 1 ? 0 : 1;
912  $ftp = $StorageNode->get('ip');
913  $port = ($mc ? $mc->get('port') : null);
914  $kernelArgsArray = array(
915  "mac=$mac",
916  "ftp=$ftp",
917  "storage=$storage",
918  "storageip=$storageip",
919  "osid=$osid",
920  "irqpoll",
921  "chkdsk=$chkdsk",
922  "img=$img",
923  "imgType=$imgType",
924  "imgPartitionType=$imgPartitionType",
925  "imgid=$imgid",
926  "imgFormat=$imgFormat",
927  array(
928  'value' => 'shutdown=1',
929  'active' => $shutdown
930  ),
931  array(
932  'value' => "mcastrdv=$mcastrdv",
933  'active' => !empty($mcastrdv)
934  ),
935  array(
936  'value' => "capone=1",
937  'active' => !self::$Host || !self::$Host->isValid(),
938  ),
939  array(
940  'value' => "port=$port mc=yes",
941  'active' => $mc,
942  ),
943  array(
944  'value' => 'debug',
945  'active' => $kdebug,
946  ),
947  array(
948  'value' => 'fdrive='.$nondev,
949  'active' => $nondev,
950  ),
951  $TaskType->get('kernelArgs'),
952  $kargs
953  );
954  $this->_printTasking($kernelArgsArray);
955  }
961  public function printImageList()
962  {
963  $Send['ImageListing'] = array(
964  'goto MENU',
965  ':MENU',
966  'menu',
967  );
968  $defItem = 'choose target && goto ${target}';
972  $imgFind = array('isEnabled' => 1);
973  if (!self::getSetting('FOG_IMAGE_LIST_MENU')) {
974  if (!self::$Host->isValid()
975  || !self::$Host->getImage()->isValid()
976  ) {
977  $imgFind = false;
978  } else {
979  $imgFind['id'] = self::$Host->getImage()->get('id');
980  }
981  }
982  if ($imgFind === false) {
983  $Images = false;
984  } else {
985  $Images = self::getClass('ImageManager')->find($imgFind);
986  }
987  if (!$Images) {
988  $Send['NoImages'] = array(
989  'echo Host is not valid, host has no image assigned, or'
990  . ' there are no images defined on the server.',
991  'sleep 3',
992  );
993  $this->_parseMe($Send);
994  $this->_chainBoot();
995  } else {
996  array_map(
997  function (&$Image) use (&$Send, &$defItem) {
998  if (!$Image->isValid()) {
999  return;
1000  }
1001  array_push(
1002  $Send['ImageListing'],
1003  sprintf(
1004  'item %s %s (%s)',
1005  $Image->get('path'),
1006  $Image->get('name'),
1007  $Image->get('id')
1008  )
1009  );
1010  if (!self::$Host->isValid()) {
1011  return;
1012  }
1013  if (!self::$Host->getImage()->isValid()) {
1014  return;
1015  }
1016  if (self::$Host->getImage()->get('id') === $Image->get('id')) {
1017  $defItem = sprintf(
1018  'choose --default %s --timeout %d target && '
1019  . 'goto ${target}',
1020  $Image->get('path'),
1021  $this->_timeout
1022  );
1023  }
1024  unset($Image);
1025  },
1026  (array)$Images
1027  );
1028  array_push(
1029  $Send['ImageListing'],
1030  'item return Return to menu'
1031  );
1032  array_push(
1033  $Send['ImageListing'],
1034  $defItem
1035  );
1036  array_map(
1037  function (&$Image) use (&$Send) {
1038  if (!$Image->isValid()) {
1039  return;
1040  }
1041  $Send[sprintf(
1042  'pathofimage%s',
1043  $Image->get('name')
1044  )] = array(
1045  sprintf(
1046  ':%s',
1047  $Image->get('path')
1048  ),
1049  sprintf(
1050  'set imageID %d',
1051  $Image->get('id')
1052  ),
1053  'params',
1054  'param mac0 ${net0/mac}',
1055  'param arch ${arch}',
1056  'param imageID ${imageID}',
1057  'param qihost 1',
1058  'param username ${username}',
1059  'param password ${password}',
1060  'param sysuuid ${uuid}',
1061  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
1062  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
1063  );
1064  unset($Image);
1065  },
1066  (array)$Images
1067  );
1068  $Send['returnmenu'] = array(
1069  ':return',
1070  'params',
1071  'param mac0 ${net0/mac}',
1072  'param arch ${arch}',
1073  'param sysuuid ${uuid}',
1074  'isset ${net1/mac} && param mac1 ${net1/mac} || goto bootme',
1075  'isset ${net2/mac} && param mac2 ${net2/mac} || goto bootme',
1076  );
1077  $Send['bootmefunc'] = array(
1078  ':bootme',
1079  "chain -ar $this->_booturl/ipxe/boot.php##params",
1080  'goto MENU',
1081  );
1082  $this->_parseMe($Send);
1083  }
1084  }
1092  public function multijoin($msid)
1093  {
1094  $MultiSess = new MulticastSession($msid);
1095  if (!$MultiSess->isValid()) {
1096  return;
1097  }
1098  $msImage = $MultiSess->getImage()->get('id');
1099  if (self::$Host->isValid() && !self::$Host->get('pending')) {
1100  $h_Image = 0;
1101  $Image = self::$Host->getImage();
1102  if ($Image instanceof Image) {
1103  $h_Image = self::$Host->getImage()->get('id');
1104  }
1105  if ($msImage != $h_Image) {
1106  self::$Host
1107  ->set('imagename', $MultiSess->getImage())
1108  ->set('imageID', $msImage);
1109  }
1110  }
1111  $shutdown = stripos(
1112  'shutdown=1',
1113  $_REQUEST['extraargs']
1114  );
1115  $isdebug = preg_match(
1116  '#isdebug=yes|mode=debug|mode=onlydebug#i',
1117  $_REQUEST['extraargs']
1118  );
1119  if (self::$Host->isValid() && !self::$Host->get('pending')) {
1120  self::$Host->createImagePackage(
1121  8,
1122  $MultiSess->get('name'),
1123  $shutdown,
1124  $isdebug,
1125  -1,
1126  false,
1127  $_REQUEST['username'],
1128  '',
1129  true,
1130  true
1131  );
1132  $this->_chainBoot(false, true);
1133  } else {
1134  $this->falseTasking($MultiSess);
1135  }
1136  }
1142  public function keyset()
1143  {
1144  if (!self::$Host->isValid()) {
1145  return;
1146  }
1147  self::$Host->set('productKey', $_REQUEST['key']);
1148  if (!self::$Host->save()) {
1149  return;
1150  }
1151  $Send['keychangesuccess'] = array(
1152  'echo Successfully changed key',
1153  'sleep 3',
1154  );
1155  $this->_parseMe($Send);
1156  $this->_chainBoot();
1157  }
1165  private function _parseMe($Send)
1166  {
1167  self::$HookManager->processEvent(
1168  'IPXE_EDIT',
1169  array(
1170  'ipxe' => &$Send,
1171  'Host' => &self::$Host,
1172  'kernel' => &$this->_kernel,
1173  'initrd' => &$this->_initrd,
1174  'booturl' => &$this->_booturl,
1175  'memdisk' => &$this->_memdisk,
1176  'memtest' => &$this->_memtest,
1177  'web' => &$this->_web,
1178  'defaultChoice' => &$this->_defaultChoice,
1179  'bootexittype' => &$this->_bootexittype,
1180  'storage' => &$this->_storage,
1181  'shutdown' => &$this->_shutdown,
1182  'path' => &$this->_path,
1183  'timeout' => &$this->_timeout,
1184  'KS' => $this->ks
1185  )
1186  );
1187  if (count($Send) > 0) {
1188  array_walk_recursive(
1189  $Send,
1190  function (&$val, &$key) {
1191  printf('%s%s', implode("\n", (array)$val), "\n");
1192  unset($val, $key);
1193  }
1194  );
1195  }
1196  }
1202  public function advLogin()
1203  {
1204  $Send['advancedlogin'] = array(
1205  "chain -ar $this->_booturl/ipxe/advanced.php",
1206  );
1207  $this->_parseMe($Send);
1208  }
1214  private function _debugAccess()
1215  {
1216  $Send['debugaccess'] = array(
1217  "$this->_kernel isdebug=yes",
1218  "$this->_initrd",
1219  "boot",
1220  );
1221  $this->_parseMe($Send);
1222  }
1228  public function verifyCreds()
1229  {
1230  list($advLogin, $noMenu) = self::getSubObjectIDs(
1231  'Service',
1232  array(
1233  'name' => array(
1234  'FOG_ADVANCED_MENU_LOGIN',
1235  'FOG_NO_MENU',
1236  )
1237  ),
1238  'value',
1239  false,
1240  'AND',
1241  'name',
1242  false,
1243  ''
1244  );
1245  if ($noMenu) {
1246  $this->noMenu();
1247  }
1248  $tmpUser = self::attemptLogin(
1249  $_REQUEST['username'],
1250  $_REQUEST['password']
1251  );
1252  if ($tmpUser->isValid()) {
1253  self::$HookManager
1254  ->processEvent('ALTERNATE_LOGIN_BOOT_MENU_PARAMS');
1255  if ($advLogin && $_REQUEST['advLog']) {
1256  $this->advLogin();
1257  }
1258  if ($_REQUEST['delhost']) {
1259  $this->delConf();
1260  } elseif ($_REQUEST['keyreg']) {
1261  $this->keyreg();
1262  } elseif ($_REQUEST['qihost']) {
1263  $this->setTasking($_REQUEST['imageID']);
1264  } elseif ($_REQUEST['sessionJoin']) {
1265  $this->sessjoin();
1266  } elseif ($_REQUEST['approveHost']) {
1267  $this->aprvConf();
1268  } elseif ($_REQUEST['menuaccess']) {
1269  unset($this->_hiddenmenu);
1270  $this->_chainBoot(true);
1271  } elseif ($_REQUEST['debugAccess']) {
1272  $this->_debugAccess();
1273  } else {
1274  $this->printDefault();
1275  }
1276  } else {
1277  $Send['invalidlogin'] = array(
1278  "echo Invalid login!",
1279  "clear username",
1280  "clear password",
1281  "sleep 3",
1282  );
1283  $this->_parseMe($Send);
1284  $this->_chainBoot();
1285  }
1286  }
1294  public function setTasking($imgID = '')
1295  {
1296  $shutdown = stripos(
1297  'shutdown=1',
1298  $_REQUEST['extraargs']
1299  );
1300  $isdebug = preg_match(
1301  '#isdebug=yes|mode=debug|mode=onlydebug#i',
1302  $_REQUEST['extraargs']
1303  );
1304  if (!$imgID) {
1305  $this->printImageList();
1306  return;
1307  }
1308  if (!self::$Host->isValid()) {
1309  $this->falseTasking('', self::getClass('Image', $imgID));
1310  return;
1311  }
1312  if (self::$Host->getImage()->get('id') != $imgID) {
1313  self::$Host
1314  ->set('imageID', $imgID)
1315  ->set('imagename', new Image($imgID));
1316  }
1317  if (!self::$Host->getImage()->isValid()) {
1318  return;
1319  }
1320  try {
1321  self::$Host->createImagePackage(
1322  1,
1323  'AutoRegTask',
1324  $shutdown,
1325  $isdebug,
1326  -1,
1327  false,
1328  $_REQUEST['username']
1329  );
1330  $this->_chainBoot(false, true);
1331  } catch (Exception $e) {
1332  $Send['fail'] = array(
1333  '#!ipxe',
1334  sprintf('echo %s', $e->getMessage()),
1335  'sleep 3',
1336  );
1337  $this->_parseMe($Send);
1338  }
1339  }
1345  public function noMenu()
1346  {
1347  $Send['nomenu'] = array(
1348  "$this->_bootexittype",
1349  );
1350  $this->_parseMe($Send);
1351  exit;
1352  }
1358  public function getTasking()
1359  {
1360  $Task = self::$Host->get('task');
1361  if (!$Task->isValid() || $Task->isSnapinTasking()) {
1362  $this->printDefault();
1363  } else {
1364  if (self::$Host->get('mac')->isImageIgnored()) {
1365  $this->_printImageIgnored();
1366  }
1367  $this->_kernel = str_replace(
1368  $this->_storage,
1369  '',
1370  $this->_kernel
1371  );
1372  $TaskType = $Task->getTaskType();
1374  if ($TaskType->isMulticast()) {
1375  $msaID = @max(
1376  self::getSubObjectIDs(
1377  'MulticastSessionAssociation',
1378  array(
1379  'taskID' => $Task->get('id')
1380  )
1381  )
1382  );
1383  $MulticastSessionAssoc = new MulticastSessionAssociation($msaID);
1384  $MulticastSession = $MulticastSessionAssoc->getMulticastSession();
1385  if ($MulticastSession && $MulticastSession->isValid()) {
1386  self::$Host->set('imageID', $MulticastSession->get('image'));
1387  }
1388  }
1389  if ($TaskType->isInitNeededTasking()) {
1390  $Image = $Task->getImage();
1391  $StorageGroup = null;
1392  $StorageNode = null;
1393  self::$HookManager->processEvent(
1394  'BOOT_TASK_NEW_SETTINGS',
1395  array(
1396  'Host' => &self::$Host,
1397  'StorageNode' => &$StorageNode,
1398  'StorageGroup' => &$StorageGroup,
1399  'TaskType' => &$TaskType
1400  )
1401  );
1402  if (!$StorageGroup || !$StorageGroup->isValid()) {
1403  $StorageGroup = $Image->getStorageGroup();
1404  }
1405  $getter = 'getOptimalStorageNode';
1406  if ($Task->isCapture()
1407  || $TaskType->isCapture()
1408  ) {
1409  $StorageGroup = $Image->getPrimaryStorageGroup();
1410  $getter = 'getMasterStorageNode';
1411  }
1412  if ($TaskType->isMulticast()) {
1413  $getter = 'getMasterStorageNode';
1414  }
1415  if (!$StorageNode || !$StorageNode->isValid()) {
1416  $StorageNode = $StorageGroup->{$getter}();
1417  }
1418  if ($Task->get('storagenodeID') != $StorageNode->get('id')) {
1419  $Task->set('storagenodeID', $StorageNode->get('id'));
1420  }
1421  if ($Task->get('storagegroupID') != $StorageGroup->get('id')) {
1422  $Task->set('storagegroupID', $StorageGroup->get('id'));
1423  }
1424  $Task->save();
1425  self::$HookManager->processEvent(
1426  'BOOT_TASK_NEW_SETTINGS',
1427  array(
1428  'Host' => &self::$Host,
1429  'StorageNode' => &$StorageNode,
1430  'StorageGroup' => &$StorageGroup,
1431  'TaskType' => &$TaskType
1432  )
1433  );
1434  $osid = (int)$Image->get('osID');
1435  $storage = '';
1436  $img = '';
1437  $imgFormat = '';
1438  $imgType = '';
1439  $imgPartitionType = '';
1440  $serviceNames = array(
1441  'FOG_CAPTUREIGNOREPAGEHIBER',
1442  'FOG_CAPTURERESIZEPCT',
1443  'FOG_CHANGE_HOSTNAME_EARLY',
1444  'FOG_DISABLE_CHKDSK',
1445  'FOG_KERNEL_ARGS',
1446  'FOG_KERNEL_DEBUG',
1447  'FOG_MULTICAST_RENDEZVOUS',
1448  'FOG_PIGZ_COMP',
1449  'FOG_TFTP_HOST',
1450  'FOG_WIPE_TIMEOUT'
1451  );
1452  list(
1453  $cappage,
1454  $capresz,
1455  $hosterl,
1456  $chkdsk,
1457  $kargs,
1458  $kdebug,
1459  $mcastrdv,
1460  $pigz,
1461  $tftp,
1462  $timeout
1464  'Service',
1465  array(
1466  'name' => $serviceNames
1467  ),
1468  'value',
1469  false,
1470  'AND',
1471  'name',
1472  false,
1473  ''
1474  );
1475  $shutdown = false !== stripos(
1476  'shutdown=1',
1477  $TaskType->get('kernelArgs')
1478  );
1479  if (!$shutdown && isset($_REQUEST['extraargs'])) {
1480  $shutdown = false !== stripos(
1481  'shutdown=1',
1482  $_REQUEST['extraargs']
1483  );
1484  }
1485  $globalPIGZ = $pigz;
1486  $PIGZ_COMP = $globalPIGZ;
1487  if ($StorageNode instanceof StorageNode && $StorageNode->isValid()) {
1488  $ip = trim($StorageNode->get('ip'));
1489  $ftp = $ip;
1490  }
1491  if ($imagingTasks) {
1492  if (!($StorageNode instanceof StorageNode
1493  && $StorageNode->isValid())
1494  ) {
1495  throw new Exception(_('No valid storage nodes found'));
1496  }
1497  $storage = escapeshellcmd(
1498  sprintf(
1499  '%s:/%s/%s',
1500  $ip,
1501  trim($StorageNode->get('path'), '/'),
1502  (
1503  $TaskType->isCapture() ?
1504  'dev/' :
1505  ''
1506  )
1507  )
1508  );
1509  $storageip = $ip;
1510  $img = escapeshellcmd(
1511  $Image->get('path')
1512  );
1513  $imgFormat = (int)$Image
1514  ->get('format');
1515  $imgType = $Image
1516  ->getImageType()
1517  ->get('type');
1518  $imgPartitionType = $Image
1519  ->getPartitionType();
1520  $imgid = $Image
1521  ->get('id');
1522  $image_PIGZ = $Image->get('compress');
1523  if (is_numeric($image_PIGZ) && $image_PIGZ > -1) {
1524  $PIGZ_COMP = $image_PIGZ;
1525  }
1526  if (in_array($imgFormat, array('',null,0,1,2,3,4))) {
1527  if ($PIGZ_COMP > 9) {
1528  $PIGZ_COMP = 9;
1529  }
1530  }
1531  } else {
1532  // These setup so postinit scripts can operate.
1533  if ($StorageNode instanceof StorageNode
1534  && $StorageNode->isValid()
1535  ) {
1536  $ip = trim($StorageNode->get('ip'));
1537  $ftp = $ip;
1538  } else {
1539  $ip = $tftp;
1540  $ftp = $tftp;
1541  }
1542  $storage = escapeshellcmd(
1543  sprintf(
1544  '%s:/%s/dev/',
1545  $ip,
1546  trim($StorageNode->get('path'), '/')
1547  )
1548  );
1549  $storageip = $ip;
1550  }
1551  }
1552  if (self::$Host->isValid()) {
1553  $mac = self::$Host->get('mac');
1554  } else {
1555  $mac = $_REQUEST['mac'];
1556  }
1557  $clamav = '';
1558  if (in_array($TaskType->get('id'), array(21, 22))) {
1559  $clamav = sprintf(
1560  '%s:%s',
1561  $ip,
1562  '/opt/fog/clamav'
1563  );
1564  }
1565  $chkdsk = $chkdsk == 1 ? 0 : 1;
1566  $MACs = self::$Host->getMyMacs();
1567  $clientMacs = array_filter(
1568  (array)self::parseMacList(
1569  implode(
1570  '|',
1571  (array)$MACs
1572  ),
1573  false,
1574  true
1575  )
1576  );
1577  if (self::$Host->get('useAD')) {
1578  $addomain = preg_replace(
1579  '#\s#',
1580  '+_+',
1581  self::$Host->get('ADDomain')
1582  );
1583  $adou = str_replace(
1584  ';',
1585  '',
1586  preg_replace(
1587  '#\s#',
1588  '+_+',
1589  self::$Host->get('ADOU')
1590  )
1591  );
1592  $aduser = preg_replace(
1593  '#\s#',
1594  '+_+',
1595  self::$Host->get('ADUser')
1596  );
1597  $adpass = preg_replace(
1598  '#\s#',
1599  '+_+',
1600  self::$Host->get('ADPass')
1601  );
1602  }
1603  $fdrive = self::$Host->get('kernelDevice');
1604  $kernelArgsArray = array(
1605  "mac=$mac",
1606  "ftp=$ftp",
1607  "storage=$storage",
1608  "storageip=$storageip",
1609  "osid=$osid",
1610  "irqpoll",
1611  array(
1612  'value' => "mcastrdv=$mcastrdv",
1613  'active' => !empty($mcastrdv)
1614  ),
1615  array(
1616  'value' => "hostname=" . self::$Host->get('name'),
1617  'active' => count($clientMacs) > 0,
1618  ),
1619  array(
1620  'value' => "clamav=$clamav",
1621  'active' => in_array($TaskType->get('id'), array(21, 22)),
1622  ),
1623  array(
1624  'value' => "chkdsk=$chkdsk",
1625  'active' => $imagingTasks,
1626  ),
1627  array(
1628  'value' => "img=$img",
1629  'active' => $imagingTasks,
1630  ),
1631  array(
1632  'value' => "imgType=$imgType",
1633  'active' => $imagingTasks,
1634  ),
1635  array(
1636  'value' => "imgPartitionType=$imgPartitionType",
1637  'active' => $imagingTasks,
1638  ),
1639  array(
1640  'value' => "imgid=$imgid",
1641  'active' => $imagingTasks,
1642  ),
1643  array(
1644  'value' => "imgFormat=$imgFormat",
1645  'active' => $imagingTasks,
1646  ),
1647  array(
1648  'value' => "PIGZ_COMP=-$PIGZ_COMP",
1649  'active' => $imagingTasks,
1650  ),
1651  array(
1652  'value' => 'shutdown=1',
1653  'active' => $Task->get('shutdown') || $shutdown,
1654  ),
1655  array(
1656  'value' => "adon=1 addomain=\"$addomain\" "
1657  . "adou=\"$adou\" aduser=\"$aduser\" "
1658  . "adpass=\"$adpass\"",
1659  'active' => self::$Host->get('useAD'),
1660  ),
1661  array(
1662  'value' => "fdrive=$fdrive",
1663  'active' => self::$Host->get('kernelDevice'),
1664  ),
1665  array(
1666  'value' => 'hostearly=1',
1667  'active' => (
1668  $hosterl
1669  && $imagingTasks ?
1670  true :
1671  false
1672  ),
1673  ),
1674  array(
1675  'value' => sprintf(
1676  'pct=%d',
1677  (
1678  is_numeric($capresz)
1679  && $capresz >= 5
1680  && $capresz < 100 ?
1681  $capresz :
1682  '5'
1683  )
1684  ),
1685  'active' => $imagingTasks && $TaskType->isCapture(),
1686  ),
1687  array(
1688  'value' => sprintf(
1689  'ignorepg=%d',
1690  (
1691  $cappage ?
1692  1 :
1693  0
1694  )
1695  ),
1696  'active' => $imagingTasks && $TaskType->isCapture(),
1697  ),
1698  array(
1699  'value' => sprintf(
1700  'port=%s',
1701  (
1702  $TaskType->isMulticast() ?
1703  $MulticastSession->get('port') :
1704  null
1705  )
1706  ),
1707  'active' => $TaskType->isMulticast(),
1708  ),
1709  array(
1710  'value' => sprintf(
1711  'winuser=%s',
1712  $Task->get('passreset')
1713  ),
1714  'active' => $TaskType->get('id') == '11',
1715  ),
1716  array(
1717  'value' => 'isdebug=yes',
1718  'active' => $Task->get('isDebug'),
1719  ),
1720  array(
1721  'value' => 'debug',
1722  'active' => $kdebug,
1723  ),
1724  array(
1725  'value' => 'seconds='.$timeout,
1726  'active' => in_array($TaskType->get('id'), range(18, 20)),
1727  ),
1728  $TaskType->get('kernelArgs'),
1729  $kargs,
1730  self::$Host->get('kernelArgs'),
1731  );
1732  if ($Task->get('typeID') == 4) {
1733  $Send['memtest'] = array(
1734  "$this->_memdisk iso raw",
1735  "$this->_memtest",
1736  "boot",
1737  );
1738  $this->_parseMe($Send);
1739  } else {
1740  $this->_printTasking($kernelArgsArray);
1741  }
1742  }
1743  }
1752  private function _menuItem($option, $desc)
1753  {
1754  $name = preg_replace('#[\s]+#', '_', $option->get('name'));
1755  $hotkey = ' ';
1756  if ($option->get('hotkey')) {
1757  if ($option->get('keysequence')) {
1758  $hotkey = sprintf(
1759  ' --key %s ',
1760  $option->get('keysequence')
1761  );
1762  }
1763  }
1764  return array("item${hotkey}${name} ${desc}");
1765  }
1774  private function _menuOpt($option, $type)
1775  {
1776  $name = preg_replace('#[\s]+#', '_', $option->get('name'));
1777  $name = trim(":$name");
1778  $type = trim($type);
1779  $Send = array($name);
1780  $params = array_filter(
1781  array_map(
1782  'trim',
1783  explode(
1784  "\n",
1785  $option->get('params')
1786  )
1787  )
1788  );
1789  if (count($params)) {
1790  if ($type) {
1791  $index = array_search('params', $params);
1792  if ($index !== false && is_numeric($index)) {
1793  self::arrayInsertAfter(
1794  $index,
1795  $params,
1796  'extra',
1797  "param extraargs \"$type\""
1798  );
1799  }
1800  }
1801  $params = trim(implode("\n", (array)$params));
1802  $params .= "\n"
1803  . 'param sysuuid ${uuid}';
1804  $Send = self::fastmerge($Send, array($params));
1805  }
1806  switch ($option->get('id')) {
1807  case 1:
1808  $Send = self::fastmerge(
1809  $Send,
1810  array("$this->_bootexittype || goto MENU")
1811  );
1812  break;
1813  case 2:
1814  $Send = self::fastmerge(
1815  $Send,
1816  array(
1817  "$this->_memdisk iso raw",
1818  $this->_memtest,
1819  'boot || goto MENU'
1820  )
1821  );
1822  break;
1823  case 11:
1824  $Send = self::fastmerge(
1825  $Send,
1826  array(
1827  "chain -ar $this->_booturl/ipxe/advanced.php || "
1828  . "goto MENU"
1829  )
1830  );
1831  break;
1832  default:
1833  if (!$params) {
1834  $Send = self::fastmerge(
1835  $Send,
1836  array(
1837  "$this->_kernel $this->_loglevel $type",
1838  $this->_initrd,
1839  'boot || goto MENU'
1840  )
1841  );
1842  }
1843  }
1844  return $Send;
1845  }
1851  public function printDefault()
1852  {
1853  if (self::$Host->isValid()
1854  && self::getSetting('FOG_NO_MENU')
1855  ) {
1856  $this->noMenu();
1857  }
1858  if ($this->_hiddenmenu) {
1859  $this->_chainBoot(true);
1860  return;
1861  }
1862  $Menus = self::getClass('PXEMenuOptionsManager')->find('', '', 'id');
1863  $ipxeGrabs = array(
1864  'FOG_ADVANCED_MENU_LOGIN',
1865  'FOG_IPXE_BG_FILE',
1866  'FOG_IPXE_HOST_CPAIRS',
1867  'FOG_IPXE_INVALID_HOST_COLOURS',
1868  'FOG_IPXE_MAIN_COLOURS',
1869  'FOG_IPXE_MAIN_CPAIRS',
1870  'FOG_IPXE_MAIN_FALLBACK_CPAIRS',
1871  'FOG_IPXE_VALID_HOST_COLOURS',
1872  'FOG_PXE_ADVANCED',
1873  'FOG_REGISTRATION_ENABLED',
1874  );
1875  list(
1876  $AdvLogin,
1877  $bgfile,
1878  $hostCpairs,
1879  $hostInvalid,
1880  $mainColors,
1881  $mainCpairs,
1882  $mainFallback,
1883  $hostValid,
1884  $Advanced,
1885  $regEnabled
1886  ) = self::getSubObjectIDs(
1887  'Service',
1888  array(
1889  'name' => $ipxeGrabs
1890  ),
1891  'value',
1892  false,
1893  'AND',
1894  'name',
1895  false,
1896  ''
1897  );
1898  $Send['head'] = self::fastmerge(
1899  array(
1900  'cpuid --ext 29 && set arch x86_64 || set arch i386',
1901  'goto get_console',
1902  ':console_set',
1903  ),
1904  explode("\n", $mainColors),
1905  explode("\n", $mainCpairs),
1906  array(
1907  'goto MENU',
1908  ':alt_console'
1909  ),
1910  explode("\n", $mainFallback),
1911  array(
1912  'goto MENU',
1913  ':get_console',
1914  "console --picture $this->_booturl/ipxe/$bgfile --left 100 "
1915  . "--right 80 && goto console_set || goto alt_console",
1916  )
1917  );
1918  $showDebug = isset($_REQUEST['debug']);
1919  $hostRegColor = self::$Host->isValid() ? $hostValid : $hostInvalid;
1920  $reg_string = 'NOT registered!';
1921  if (self::$Host->isValid()) {
1922  $reg_string = (
1923  self::$Host->get('pending') ?
1924  'pending approval!' :
1925  'registered as ' . self::$Host->get('name') . '!'
1926  );
1927  }
1928  $Send['menustart'] = self::fastmerge(
1929  array(
1930  ':MENU',
1931  'menu',
1932  $hostRegColor,
1933  ),
1934  explode("\n", $hostCpairs),
1935  array(
1936  "item --gap Host is $reg_string",
1937  'item --gap -- -------------------------------------',
1938  )
1939  );
1940  $RegArrayOfStuff = array(
1941  (
1942  self::$Host->isValid() ?
1943  (
1944  self::$Host->get('pending') ?
1945  6 :
1946  1
1947  ) :
1948  0
1949  ),
1950  2
1951  );
1952  if (!$regEnabled) {
1953  $RegArrayOfStuff = array_diff($RegArrayOfStuff, array(0));
1954  }
1955  if ($showDebug) {
1956  array_push($RegArrayOfStuff, 3);
1957  }
1958  if ($Advanced) {
1959  array_push($RegArrayOfStuff, ($AdvLogin ? 5 : 4));
1960  }
1961  $Menus = self::getClass('PXEMenuOptionsManager')->find(
1962  array(
1963  'regMenu' => $RegArrayOfStuff
1964  ),
1965  '',
1966  'id'
1967  );
1968  array_map(
1969  function (&$Menu) use (&$Send) {
1970  $Send["item-". $Menu->get('name')] = $this->_menuItem(
1971  $Menu,
1972  trim($Menu->get('description'))
1973  );
1974  unset($Menu);
1975  },
1976  (array)$Menus
1977  );
1978  $Send['default'] = array($this->_defaultChoice);
1979  array_map(
1980  function (&$Menu) use (&$Send) {
1981  $Send["choice-".$Menu->get('name')] = $this->_menuOpt(
1982  $Menu,
1983  trim($Menu->get('args'))
1984  );
1985  unset($Menu);
1986  },
1987  (array)$Menus
1988  );
1989  $Send['bootme'] = array(
1990  ':bootme',
1991  "chain -ar $this->_booturl/ipxe/boot.php##params ||",
1992  'goto MENU',
1993  'autoboot',
1994  );
1995  $this->_parseMe($Send);
1996  }
1997 }
BootMenu\setTasking
setTasking($imgID='')
Definition: bootmenu.class.php:1294
BootMenu\$_kernel
$_kernel
Definition: bootmenu.class.php:29
BootMenu\_printImageIgnored
_printImageIgnored()
Definition: bootmenu.class.php:594
BootMenu\noMenu
noMenu()
Definition: bootmenu.class.php:1345
exit
exit
Definition: download.php:102
BootMenu\verifyCreds
verifyCreds()
Definition: bootmenu.class.php:1228
BootMenu\$_timeout
$_timeout
Definition: bootmenu.class.php:107
BootMenu\_chainBoot
_chainBoot($debug=false, $shortCircuit=false)
Definition: bootmenu.class.php:512
BootMenu\_ipxeLog
_ipxeLog()
Definition: bootmenu.class.php:478
TaskType\isCapture
isCapture($nums=false)
Definition: tasktype.class.php:150
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
BootMenu\$_memtest
$_memtest
Definition: bootmenu.class.php:53
TaskType
Definition: tasktype.class.php:23
BootMenu\$_path
$_path
Definition: bootmenu.class.php:95
BootMenu\$_KS
$_KS
Definition: bootmenu.class.php:113
BootMenu\getTasking
getTasking()
Definition: bootmenu.class.php:1358
BootMenu
Definition: bootmenu.class.php:23
$clientMacs
$clientMacs
Definition: hostinfo.php:154
MulticastSessionAssociation
Definition: multicastsessionassociation.class.php:23
Image
Definition: image.class.php:23
FOGBase\__toString
__toString()
Definition: fogbase.class.php:424
MulticastSession
Definition: multicastsession.class.php:23
BootMenu\falseTasking
falseTasking($mc=false, $Image=false)
Definition: bootmenu.class.php:847
$val
$val
Definition: check_node_exists.php:25
$fdrive
if($TaskType->isInitNeededTasking()) $fdrive
Definition: hostinfo.php:147
TaskType\isInitNeededTasking
isInitNeededTasking($nums=false)
Definition: tasktype.class.php:180
BootMenu\_approveHost
_approveHost()
Definition: bootmenu.class.php:608
FOGController\get
get($key='')
Definition: fogcontroller.class.php:207
TaskType\isImagingTask
isImagingTask()
Definition: tasktype.class.php:136
BootMenu\$_initrd
$_initrd
Definition: bootmenu.class.php:35
BootMenu\$_memdisk
$_memdisk
Definition: bootmenu.class.php:47
BootMenu\$_bootexittype
$_bootexittype
Definition: bootmenu.class.php:71
FOGBase\attemptLogin
static attemptLogin($username, $password)
Definition: fogbase.class.php:2465
$mac
$mac
Definition: hostinfo.php:151
StorageNode
Definition: storagenode.class.php:23
BootMenu\_parseMe
_parseMe($Send)
Definition: bootmenu.class.php:1165
BootMenu\keyset
keyset()
Definition: bootmenu.class.php:1142
BootMenu\aprvConf
aprvConf()
Definition: bootmenu.class.php:719
FOGBase\resolveHostname
static resolveHostname($host)
Definition: fogbase.class.php:2497
$TaskType
if(FOGCore::$useragent) if(! $Task->isValid()) $TaskType
Definition: hostinfo.php:33
BootMenu\_printTasking
_printTasking($kernelArgsArray)
Definition: bootmenu.class.php:648
$Host
$Host
Definition: hostnameloop.php:30
PXEMenuOptions
Definition: pxemenuoptions.class.php:23
BootMenu\$_defaultChoice
$_defaultChoice
Definition: bootmenu.class.php:65
$MACs
$MACs
Definition: hostinfo.php:152
BootMenu\_delHost
_delHost()
Definition: bootmenu.class.php:573
FOGBase
Definition: fogbase.class.php:25
BootMenu\$_shutdown
$_shutdown
Definition: bootmenu.class.php:89
TaskType\isMulticast
isMulticast($nums=false)
Definition: tasktype.class.php:285
BootMenu\sessjoin
sessjoin()
Definition: bootmenu.class.php:818
BootMenu\__construct
__construct()
Definition: bootmenu.class.php:125
BootMenu\$_exitTypes
static $_exitTypes
Definition: bootmenu.class.php:119
$Image
$Image
Definition: hostinfo.php:37
$Task
$Task
Definition: hostinfo.php:26
FOGBase\$debug
static $debug
Definition: fogbase.class.php:133
BootMenu\_menuOpt
_menuOpt($option, $type)
Definition: bootmenu.class.php:1774
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
BootMenu\$_booturl
$_booturl
Definition: bootmenu.class.php:41
BootMenu\multijoin
multijoin($msid)
Definition: bootmenu.class.php:1092
BootMenu\printDefault
printDefault()
Definition: bootmenu.class.php:1851
BootMenu\advLogin
advLogin()
Definition: bootmenu.class.php:1202
BootMenu\_getDefaultMenu
static _getDefaultMenu($timeout, $name, &$default)
Definition: bootmenu.class.php:465
BootMenu\$_web
$_web
Definition: bootmenu.class.php:59
BootMenu\$_storage
$_storage
Definition: bootmenu.class.php:83
BootMenu\_debugAccess
_debugAccess()
Definition: bootmenu.class.php:1214
BootMenu\keyreg
keyreg()
Definition: bootmenu.class.php:742
BootMenu\delConf
delConf()
Definition: bootmenu.class.php:696
$ip
if(!(isset($_POST['ip']) &&is_string($_POST['ip']))) if(!(isset($_POST['file']) &&is_string($_POST['file']))) if(!(isset($_POST['lines']) &&is_numeric($_POST['lines']))) if(!(isset($_POST['reverse']) &&is_numeric($_POST['reverse']))) $ip
Definition: logtoview.php:149
BootMenu\printImageList
printImageList()
Definition: bootmenu.class.php:961
FOGController\isValid
isValid()
Definition: fogcontroller.class.php:865
if
if( $exists)
Definition: check_node_exists.php:28
BootMenu\_menuItem
_menuItem($option, $desc)
Definition: bootmenu.class.php:1752
BootMenu\$_loglevel
$_loglevel
Definition: bootmenu.class.php:77
BootMenu\sesscheck
sesscheck()
Definition: bootmenu.class.php:767
$imagingTasks
$imagingTasks
Definition: progress.php:42
BootMenu\$_hiddenmenu
$_hiddenmenu
Definition: bootmenu.class.php:101