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)  

host.class.php
Go to the documentation of this file.
1 <?php
22 class Host extends FOGController
23 {
29  protected $databaseTable = 'hosts';
35  protected $databaseFields = array(
36  'id' => 'hostID',
37  'name' => 'hostName',
38  'description' => 'hostDesc',
39  'ip' => 'hostIP',
40  'imageID' => 'hostImage',
41  'building' => 'hostBuilding',
42  'createdTime' => 'hostCreateDate',
43  'deployed' => 'hostLastDeploy',
44  'createdBy' => 'hostCreateBy',
45  'useAD' => 'hostUseAD',
46  'ADDomain' => 'hostADDomain',
47  'ADOU' => 'hostADOU',
48  'ADUser' => 'hostADUser',
49  'ADPass' => 'hostADPass',
50  'ADPassLegacy' => 'hostADPassLegacy',
51  'productKey' => 'hostProductKey',
52  'printerLevel' => 'hostPrinterLevel',
53  'kernelArgs' => 'hostKernelArgs',
54  'kernel' => 'hostKernel',
55  'kernelDevice' => 'hostDevice',
56  'init' => 'hostInit',
57  'pending' => 'hostPending',
58  'pub_key' => 'hostPubKey',
59  'sec_tok' => 'hostSecToken',
60  'sec_time' => 'hostSecTime',
61  'pingstatus' => 'hostPingCode',
62  'biosexit' => 'hostExitBios',
63  'efiexit' => 'hostExitEfi',
64  'enforce' => 'hostEnforce'
65  );
71  protected $databaseFieldsRequired = array(
72  'name'
73  );
79  protected $additionalFields = array(
80  'mac',
81  'primac',
82  'imagename',
83  'additionalMACs',
84  'pendingMACs',
85  'groups',
86  'groupsnotinme',
87  'hostscreen',
88  'hostalo',
89  'optimalStorageNode',
90  'printers',
91  'printersnotinme',
92  'snapins',
93  'snapinsnotinme',
94  'modules',
95  'inventory',
96  'task',
97  'snapinjob',
98  'users',
99  'fingerprint',
100  'powermanagementtasks'
101  );
108  'MACAddressAssociation' => array(
109  'hostID',
110  'id',
111  'primac',
112  array('primary' => 1)
113  ),
114  'Image' => array(
115  'id',
116  'imageID',
117  'imagename'
118  ),
119  'HostScreenSetting' => array(
120  'hostID',
121  'id',
122  'hostscreen'
123  ),
124  'HostAutoLogout' => array(
125  'hostID',
126  'id',
127  'hostalo'
128  ),
129  'Inventory' => array(
130  'hostID',
131  'id',
132  'inventory'
133  )
134  );
140  private static $_hostscreen = array();
146  private static $_hostalo = array();
156  public function set($key, $value)
157  {
158  $key = $this->key($key);
159  switch ($key) {
160  case 'mac':
161  if (!($value instanceof MACAddress)) {
162  $value = new MACAddress($value);
163  $value = $value->__toString();
164  }
165  break;
166  case 'additionalMACs':
167  case 'pendingMACs':
168  $newValue = array_map(
169  function (&$mac) {
170  return new MACAddress($mac);
171  },
172  (array)$value
173  );
174  $value = (array)$newValue;
175  break;
176  case 'snapinjob':
177  if (!($value instanceof SnapinJob)) {
178  $value = new SnapinJob($value);
179  }
180  break;
181  case 'task':
182  if (!($value instanceof Task)) {
183  $value = new Task($value);
184  }
185  break;
186  }
187  return parent::set($key, $value);
188  }
198  public function add($key, $value)
199  {
200  $key = $this->key($key);
201  switch ($key) {
202  case 'additionalMACs':
203  case 'pendingMACs':
204  if (!($value instanceof MACAddress)) {
205  $value = new MACAddress($value);
206  }
207  break;
208  }
209  return parent::add($key, $value);
210  }
219  public function destroy($key = 'id')
220  {
221  $find = array('hostID' => $this->get('id'));
222  self::getClass('NodeFailureManager')
223  ->destroy($find);
224  self::getClass('ImagingLogManager')
225  ->destroy($find);
226  self::getClass('SnapinTaskManager')
227  ->destroy(
228  array(
229  'jobID' => self::getSubObjectIDs(
230  'SnapinJob',
231  $find,
232  'id'
233  )
234  )
235  );
236  self::getClass('SnapinJobManager')
237  ->destroy($find);
238  self::getClass('TaskManager')
239  ->destroy($find);
240  self::getClass('ScheduledTaskManager')
241  ->destroy($find);
242  self::getClass('HostAutoLogoutManager')
243  ->destroy($find);
244  self::getClass('HostScreenSettingManager')
245  ->destroy($find);
246  self::getClass('GroupAssociationManager')
247  ->destroy($find);
248  self::getClass('SnapinAssociationManager')
249  ->destroy($find);
250  self::getClass('PrinterAssociationManager')
251  ->destroy($find);
252  self::getClass('ModuleAssociationManager')
253  ->destroy($find);
254  self::getClass('GreenFogManager')
255  ->destroy($find);
256  self::getClass('InventoryManager')
257  ->destroy($find);
258  self::getClass('UserTrackingManager')
259  ->destroy($find);
260  self::getClass('MACAddressAssociationManager')
261  ->destroy($find);
262  self::getClass('PowerManagementManager')
263  ->destroy($find);
264  self::$HookManager
265  ->processEvent(
266  'DESTROY_HOST',
267  array(
268  'Host' => &$this
269  )
270  );
271  return parent::destroy($key);
272  }
281  private static function _retValidMacs($macs, &$arr)
282  {
283  $addMacs = array();
284  foreach ((array)$macs as &$mac) {
285  if (!($mac instanceof MACAddress)) {
286  $mac = new MACAddress($mac);
287  }
288  if (!$mac->isValid()) {
289  continue;
290  }
291  $addMacs[] = $mac->__toString();
292  unset($mac);
293  }
294  return $arr = $addMacs;
295  }
301  public function save()
302  {
303  parent::save();
304  if ($this->isLoaded('mac')) {
305  if (!$this->get('mac')->isValid()) {
306  throw new Exception(self::$foglang['InvalidMAC']);
307  }
308  $RealPriMAC = $this->get('mac')->__toString();
309  $CurrPriMAC = self::getSubObjectIDs(
310  'MACAddressAssociation',
311  array(
312  'hostID' => $this->get('id'),
313  'primary' => 1
314  ),
315  'mac'
316  );
317  if (count($CurrPriMAC) === 1
318  && $CurrPriMAC[0] != $RealPriMAC
319  ) {
320  self::getClass('MACAddressAssociationManager')
321  ->destroy(
322  array(
323  'hostID' => $this->get('id'),
324  'mac' => $CurrPriMAC[0]
325  )
326  );
327  }
328  $HostWithMAC = array_diff(
329  (array)$this->get('id'),
330  (array)self::getSubObjectIDs(
331  'MACAddressAssociation',
332  array('mac' => $RealPriMAC),
333  'hostID'
334  )
335  );
336  if (count($HostWithMAC)
337  && !in_array($this->get('id'), (array)$HostWithMAC)
338  ) {
339  throw new Exception(_('This MAC Belongs to another host'));
340  }
341  $DBPriMACs = self::getSubObjectIDs(
342  'MACAddressAssociation',
343  array(
344  'hostID' => $this->get('id'),
345  'primary' => 1
346  ),
347  'mac'
348  );
349  $RemoveMAC = array_diff(
350  (array)$RealPriMAC,
351  (array)$DBPriMACs
352  );
353  if (count($RemoveMAC)) {
354  self::getClass('MACAddressAssociationManager')
355  ->destroy(
356  array('mac' => $RemoveMAC)
357  );
358  unset($RemoveMAC);
359  $DBPriMACs = self::getSubObjectIDs(
360  'MACAddressAssociation',
361  array(
362  'hostID' => $this->get('id'),
363  'primary' => 1
364  ),
365  'mac'
366  );
367  }
368  if (!in_array($RealPriMAC, $DBPriMACs)) {
369  self::getClass('MACAddressAssociation')
370  ->set('hostID', $this->get('id'))
371  ->set('mac', $RealPriMAC)
372  ->set('primary', 1)
373  ->save();
374  }
375  unset(
376  $DBPriMACs,
377  $RealPriMAC,
378  $RemoveMAC,
379  $HostWithMAC
380  );
381  }
382  if ($this->isLoaded('additionalMACs')) {
384  $this->get('additionalMACs'),
385  $addMacs
386  );
387  $RealAddMACs = array_filter($addMacs);
388  unset($addMacs);
389  $RealAddMACs = array_unique($RealAddMACs);
390  $RealAddMACs = array_filter($RealAddMACs);
391  $DBPriMACs = self::getSubObjectIDs(
392  'MACAddressAssociation',
393  array('primary' => 1),
394  'mac'
395  );
396  foreach ((array)$DBPriMACs as &$mac) {
397  if (self::arrayStrpos($mac, $RealAddMACs) !== false) {
398  throw new Exception(
399  _('Cannot add Primary mac as additional mac')
400  );
401  }
402  unset($mac);
403  }
404  unset($DBPriMACs);
405  $PreOwnedMACs = self::getSubObjectIDs(
406  'MACAddressAssociation',
407  array(
408  'hostID' => $this->get('id'),
409  'pending' => 1
410  ),
411  'mac',
412  true
413  );
414  $RealAddMACs = array_diff(
415  (array)$RealAddMACs,
416  (array)$PreOwnedMACs
417  );
418  unset($PreOwnedMACs);
419  $DBAddMACs = self::getSubObjectIDs(
420  'MACAddressAssociation',
421  array(
422  'hostID' => $this->get('id'),
423  'primary' => 0,
424  'pending' => 0
425  ),
426  'mac'
427  );
428  $RemoveAddMAC = array_diff(
429  (array)$DBAddMACs,
430  (array)$RealAddMACs
431  );
432  if (count($RemoveAddMAC)) {
433  self::getClass('MACAddressAssociationManager')
434  ->destroy(
435  array(
436  'hostID' => $this->get('id'),
437  'mac' => $RemoveAddMAC
438  )
439  );
440  $DBAddMACs = self::getSubObjectIDs(
441  'MACAddressAssociation',
442  array(
443  'hostID' => $this->get('id'),
444  'primary' => 0,
445  'pending' => 0,
446  'mac'
447  )
448  );
449  unset($RemoveAddMAC);
450  }
451  $insert_fields = array(
452  'hostID',
453  'mac',
454  'primary',
455  'pending'
456  );
457  $insert_values = array();
458  $RealAddMACs = array_diff(
459  (array)$RealAddMACs,
460  (array)$DBAddMACs
461  );
462  foreach ((array)$RealAddMACs as $index => &$mac) {
463  $insert_values[] = array(
464  $this->get('id'),
465  $mac,
466  0,
467  0
468  );
469  unset($mac);
470  }
471  if (count($insert_values) > 0) {
472  self::getClass('MACAddressAssociationManager')
473  ->insertBatch(
474  $insert_fields,
475  $insert_values
476  );
477  }
478  unset(
479  $DBAddMACs,
480  $RealAddMACs,
481  $RemoveAddMAC
482  );
483  }
484  if ($this->isLoaded('pendingMACs')) {
485  self::_retValidMacs($this->get('pendingMACs'), $pendMacs);
486  $RealPendMACs = array_filter($pendMacs);
487  unset($pendMacs);
488  $RealPendMACs = array_unique($RealPendMACs);
489  $RealPendMACs = array_filter($RealPendMACs);
490  $DBPriMACs = self::getSubObjectIDs(
491  'MACAddressAssociation',
492  array('primary' => 1),
493  'mac'
494  );
495  foreach ((array)$DBPriMACs as &$mac) {
496  if (self::arrayStrpos($mac, $RealPendMACs)) {
497  throw new Exception(
498  _('Cannot add a pre-existing primary mac')
499  );
500  }
501  unset($mac);
502  }
503  unset($DBPriMACs);
504  $PreOwnedMACs = self::getSubObjectIDs(
505  'MACAddressAssociation',
506  array(
507  'hostID' => $this->get('id'),
508  'pending' => 0,
509  'mac',
510  true
511  ),
512  'mac',
513  true
514  );
515  $RealPendMACs = array_diff(
516  (array)$RealPendMACs,
517  (array)$PreOwnedMACs
518  );
519  unset($PreOwnedMACs);
520  $DBPendMACs = self::getSubObjectIDs(
521  'MACAddressAssociation',
522  array(
523  'hostID' => $this->get('id'),
524  'primary' => 0,
525  'pending' => 1,
526  ),
527  'mac'
528  );
529  $RemovePendMAC = array_diff(
530  (array)$DBPendMACs,
531  (array)$RealPendMACs
532  );
533  if (count($RemovePendMAC)) {
534  self::getClass('MACAddressAssociationManager')
535  ->destroy(
536  array(
537  'hostID' => $this->get('id'),
538  'mac' => $RemovePendMAC
539  )
540  );
541  $DBPendMACs = self::getSubObjectIDs(
542  'MACAddressAssociation',
543  array(
544  'primary' => 0,
545  'pending' => 1,
546  ),
547  'mac'
548  );
549  unset($RemovePendMAC);
550  }
551  $insert_fields = array(
552  'hostID',
553  'mac',
554  'primary',
555  'pending'
556  );
557  $insert_values = array();
558  $RealPendMACs = array_diff(
559  (array)$RealPendMACs,
560  (array)$DBPendMACs
561  );
562  foreach ((array)$RealPendMACs as &$mac) {
563  $insert_values[] = array(
564  $this->get('id'),
565  $mac,
566  0,
567  1
568  );
569  unset($mac);
570  }
571  if (count($insert_values) > 0) {
572  self::getClass('MACAddressAssociationManager')
573  ->insertBatch(
574  $insert_fields,
575  $insert_values
576  );
577  }
578  unset(
579  $DBPendMACs,
580  $RealPendMACs,
581  $RemovePendMAC
582  );
583  }
584  if ($this->isLoaded('powermanagementtasks')) {
585  $DBPowerManagementIDs = self::getSubObjectIDs(
586  'PowerManagement',
587  array('hostID'=>$this->get('id'))
588  );
589  $RemovePowerManagementIDs = array_diff(
590  (array)$DBPowerManagementIDs,
591  (array)$this->get('powermanagementtasks')
592  );
593  if (count($RemovePowerManagementIDs)) {
594  self::getClass('PowerManagementManager')
595  ->destroy(
596  array(
597  'hostID' => $this->get('id'),
598  'id' => $RemovePowerManagementIDs
599  )
600  );
601  $DBPowerManagementIDs = self::getSubObjectIDs(
602  'PowerManagement',
603  array('hostID' => $this->get('id'))
604  );
605  unset($RemovePowerManagementIDs);
606  }
607  $objNeeded = false;
608  unset($DBPowerManagementIDs, $RemovePowerManagementIDs);
609  }
610  return $this
611  ->assocSetter('Module')
612  ->assocSetter('Printer')
613  ->assocSetter('Snapin')
614  ->assocSetter('Group')
615  ->load();
616  }
622  public function isValid()
623  {
624  return parent::isValid() && $this->isHostnameSafe();
625  }
633  public function isHostnameSafe($hostname = '')
634  {
635  if (empty($hostname)) {
636  $hostname = $this->get('name');
637  }
638  $pattern = '/^[\\w!@#$%^()\\-\'{}\\.~]{1,15}$/';
639  return (bool)preg_match($pattern, $hostname);
640  }
648  public function getDefault($printerid)
649  {
650  return (bool)self::getClass('PrinterAssociationManager')
651  ->count(
652  array(
653  'hostID' => $this->get('id'),
654  'printerID' => $printerid,
655  'isDefault' => 1
656  )
657  );
658  }
667  public function updateDefault($printerid, $onoff)
668  {
669  self::getClass('PrinterAssociationManager')
670  ->update(
671  array(
672  'printerID' => $this->get('printers'),
673  'hostID' => $this->get('id')
674  ),
675  '',
676  array('isDefault' => 0)
677  );
678  self::getClass('PrinterAssociationManager')
679  ->update(
680  array(
681  'printerID' => $printerid,
682  'hostID' => $this->get('id')
683  ),
684  '',
685  array('isDefault' => $onoff)
686  );
687  return $this;
688  }
694  private function _setDispVals()
695  {
696  if (count(self::$_hostscreen)) {
697  return;
698  }
699  if (!$this->get('hostscreen')->isValid()) {
700  list(
701  $refresh,
702  $width,
703  $height
705  'Service',
706  array(
707  'name' => array(
708  'FOG_CLIENT_DISPLAYMANAGER_R',
709  'FOG_CLIENT_DISPLAYMANAGER_X',
710  'FOG_CLIENT_DISPLAYMANAGER_Y'
711  )
712  ),
713  'value',
714  false,
715  'AND',
716  'name',
717  false,
718  false
719  );
720  } else {
721  $refresh = $this->get('hostscreen')->get('refresh');
722  $width = $this->get('hostscreen')->get('width');
723  $height = $this->get('hostscreen')->get('height');
724  }
725  self::$_hostscreen = array(
726  'refresh' => $refresh,
727  'width' => $width,
728  'height' => $height
729  );
730  }
738  public function getDispVals($key = '')
739  {
740  $this->_setDispVals();
741  return self::$_hostscreen[$key];
742  }
752  public function setDisp($x, $y, $r)
753  {
754  if (!$this->get('hostscreen')->isValid()) {
755  $this->get('hostscreen')
756  ->set('hostID', $this->get('id'));
757  }
758  $this->get('hostscreen')
759  ->set('width', $x)
760  ->set('height', $y)
761  ->set('refresh', $r)
762  ->save();
763  return $this;
764  }
770  private function _setAlo()
771  {
772  if (!empty(self::$_hostalo)) {
773  return;
774  }
775  if (!$this->get('hostalo')->isValid()) {
776  self::$_hostalo = self::getSetting('FOG_CLIENT_AUTOLOGOFF_MIN');
777  } else {
778  self::$_hostalo = $this->get('hostalo')->get('time');
779  }
780  return;
781  }
787  public function getAlo()
788  {
789  $this->_setAlo();
790  return self::$_hostalo;
791  }
799  public function setAlo($time)
800  {
801  return $this->get('hostalo')
802  ->set('hostID', $this->get('id'))
803  ->set('time', $time)
804  ->save();
805  }
811  protected function loadMac()
812  {
813  $mac = new MACAddress($this->get('primac'));
814  $this->set('mac', $mac);
815  }
821  protected function loadAdditionalMACs()
822  {
823  $macs = self::getSubObjectIDs(
824  'MACAddressAssociation',
825  array(
826  'hostID' => $this->get('id'),
827  'primary' => 0,
828  'pending' => 0,
829  ),
830  'mac'
831  );
832  $this->set('additionalMACs', (array)$macs);
833  }
839  protected function loadPendingMACs()
840  {
841  $macs = self::getSubObjectIDs(
842  'MACAddressAssociation',
843  array(
844  'hostID' => $this->get('id'),
845  'primary' => 0,
846  'pending' => 1,
847  ),
848  'mac'
849  );
850  $this->set('pendingMACs', (array)$macs);
851  }
857  protected function loadGroups()
858  {
859  $groups = self::getSubObjectIDs(
860  'GroupAssociation',
861  array('hostID' => $this->get('id')),
862  'groupID'
863  );
864  $groups = self::getSubObjectIDs(
865  'Group',
866  array('id' => $groups)
867  );
868  $this->set('groups', (array)$groups);
869  }
875  protected function loadGroupsnotinme()
876  {
877  $groups = array_diff(
878  self::getSubObjectIDs('Group'),
879  $this->get('groups')
880  );
881  $this->set('groupsnotinme', (array)$groups);
882  }
888  protected function loadPrinters()
889  {
890  $printers = self::getSubObjectIDs(
891  'PrinterAssociation',
892  array('hostID' => $this->get('id')),
893  'printerID'
894  );
895  $printers = self::getSubObjectIDs(
896  'Printer',
897  array('id' => $printers)
898  );
899  $this->set('printers', (array)$printers);
900  }
906  protected function loadPrintersnotinme()
907  {
908  $printers = array_diff(
909  self::getSubObjectIDs('Printer'),
910  $this->get('printers')
911  );
912  $this->set('printersnotinme', (array)$printers);
913  }
919  protected function loadSnapins()
920  {
921  $snapins = self::getSubObjectIDs(
922  'SnapinAssociation',
923  array('hostID' => $this->get('id')),
924  'snapinID'
925  );
926  $snapins = self::getSubObjectIDs(
927  'Snapin',
928  array('id' => $snapins)
929  );
930  $this->set('snapins', (array)$snapins);
931  }
937  protected function loadSnapinsnotinme()
938  {
939  $snapins = array_diff(
940  self::getSubObjectIDs('Snapin'),
941  $this->get('snapins')
942  );
943  $this->set('snapinsnotinme', (array)$snapins);
944  }
950  protected function loadModules()
951  {
952  $modules = self::getSubObjectIDs(
953  'ModuleAssociation',
954  array('hostID' => $this->get('id')),
955  'moduleID'
956  );
957  $modules = self::getSubObjectIDs(
958  'Module',
959  array('id' => $modules)
960  );
961  $this->set('modules', (array)$modules);
962  }
968  protected function loadPowermanagementtasks()
969  {
970  $pms = self::getSubObjectIDs(
971  'PowerManagement',
972  array('hostID' => $this->get('id'))
973  );
974  $this->set('powermanagementtasks', (array)$pms);
975  }
981  protected function loadUsers()
982  {
983  $users = self::getSubObjectIDs(
984  'UserTracking',
985  array('hostID' => $this->get('id'))
986  );
987  $this->set('users', (array)$users);
988  }
994  protected function loadSnapinjob()
995  {
996  $sjID = self::getSubObjectIDs(
997  'SnapinJob',
998  array(
999  'stateID' => self::fastmerge(
1000  self::getQueuedStates(),
1001  (array)self::getProgressState()
1002  ),
1003  'hostID' => $this->get('id')
1004  )
1005  );
1006  $SnapinJob = new SnapinJob(@min($sjID));
1007  $this->set('snapinjob', $SnapinJob);
1008  }
1014  protected function loadTask()
1015  {
1016  $find['hostID'] = $this->get('id');
1017  $find['stateID'] = self::fastmerge(
1018  self::getQueuedStates(),
1019  (array)self::getProgressState()
1020  );
1021  $types = array(
1022  'up',
1023  'down'
1024  );
1025  $type = filter_input(INPUT_POST, 'type');
1026  if (!$type) {
1027  $type = filter_input(INPUT_GET, 'type');
1028  }
1029  $type = trim($type);
1030  if (in_array($type, $types)) {
1031  if ($type === 'up') {
1032  $find['typeID'] = array(2, 16);
1033  } else {
1034  $find['typeID'] = array(
1035  1,
1036  8,
1037  15,
1038  17,
1039  24
1040  );
1041  }
1042  }
1043  $taskID = self::getSubObjectIDs(
1044  'Task',
1045  $find
1046  );
1047  $taskID = array_shift($taskID);
1048  $this->set('task', $taskID);
1049  unset($find);
1050  }
1056  protected function loadOptimalStorageNode()
1057  {
1058  $node = $this
1059  ->getImage()
1060  ->getStorageGroup()
1061  ->getOptimalStorageNode();
1062  $this->set('optimalStorageNode', $node);
1063  }
1069  public function getActiveTaskCount()
1070  {
1071  $find = array(
1072  'stateID' => self::fastmerge(
1073  self::getQueuedStates(),
1074  (array)self::getProgressState()
1075  ),
1076  'hostID' => $this->get('id')
1077  );
1078  $count = self::getClass('TaskManager')
1079  ->count($find);
1080  return (int)$count;
1081  }
1087  public function getOptimalStorageNode()
1088  {
1089  return $this->get('optimalStorageNode');
1090  }
1107  private function _createTasking(
1108  $taskName,
1109  $taskTypeID,
1110  $username,
1111  $groupID,
1112  $memID,
1113  $imagingTask = true,
1114  $shutdown = false,
1115  $passreset = false,
1116  $debug = false,
1117  $wol = false
1118  ) {
1119  $Task = self::getClass('Task')
1120  ->set('name', $taskName)
1121  ->set('createdBy', $username)
1122  ->set('hostID', $this->get('id'))
1123  ->set('isForced', 0)
1124  ->set('stateID', self::getQueuedState())
1125  ->set('typeID', $taskTypeID)
1126  ->set('storagegroupID', $groupID)
1127  ->set('storagenodeID', $memID)
1128  ->set('wol', (string)intval($wol))
1129  ->set('host', $this)
1130  ->set('image', $this->getImage())
1131  ->set('tasktype', new TaskType($taskTypeID))
1132  ->set('TaskState', new TaskState(self::getQueuedState()))
1133  ->set('StorageGroup', $this->getImage()->getStorageGroup())
1134  ->set('StorageNode', new StorageNode());
1135  if ($imagingTask) {
1136  $Task->set('imageID', $this->getImage()->get('id'));
1137  }
1138  if ($shutdown) {
1139  $Task->set('shutdown', $shutdown);
1140  }
1141  if ($debug) {
1142  $Task->set('isDebug', $debug);
1143  }
1144  if ($passreset) {
1145  $Task->set('passreset', $passreset);
1146  }
1147  return $Task;
1148  }
1154  private function _cancelJobsSnapinsForHost()
1155  {
1156  $SnapinJobs = self::getSubObjectIDs(
1157  'SnapinJob',
1158  array(
1159  'hostID' => $this->get('id'),
1160  'stateID' => self::fastmerge(
1161  self::getQueuedStates(),
1162  (array)self::getProgressState()
1163  )
1164  )
1165  );
1166  self::getClass('SnapinTaskManager')
1167  ->update(
1168  array(
1169  'jobID' => $SnapinJobs,
1170  'stateID' => self::fastmerge(
1171  self::getQueuedStates(),
1172  (array)self::getProgressState()
1173  )
1174  ),
1175  '',
1176  array(
1177  'return' => -9999,
1178  'details' => _('Cancelled due to new tasking.'),
1179  'stateID' => self::getCancelledState()
1180  )
1181  );
1182  self::getClass('SnapinJobManager')
1183  ->update(
1184  array('id' => $SnapinJobs),
1185  '',
1186  array('stateID' => self::getCancelledState())
1187  );
1188  $AllTasks = self::getSubObjectIDs(
1189  'Task',
1190  array(
1191  'stateID' => self::fastmerge(
1192  self::getQueuedStates(),
1193  (array)self::getProgressState()
1194  ),
1195  'hostID' => $this->get('id')
1196  )
1197  );
1198  $MyTask = $this->get('task')->get('id');
1199  self::getClass('TaskManager')
1200  ->update(
1201  array(
1202  'id' => array_diff(
1203  (array)$AllTasks,
1204  (array)$MyTask
1205  )
1206  ),
1207  '',
1208  array('stateID' => self::getCancelledState())
1209  );
1210  }
1220  private function _createSnapinTasking(
1221  $snapin = -1,
1222  $error = false,
1223  $Task = false
1224  ) {
1225  try {
1226  $SnapinJob = $this->get('snapinjob');
1227  if (!$SnapinJob->isValid()) {
1228  $SnapinJob
1229  ->set('hostID', $this->get('id'))
1230  ->set('stateID', self::getQueuedState())
1231  ->set(
1232  'createdTime',
1233  self::niceDate()
1234  ->format('Y-m-d H:i:s')
1235  );
1236  if (!$SnapinJob->save()) {
1237  throw new Exception(_('Failed to create Snapin Job'));
1238  }
1239  }
1240  $insert_fields = array('jobID', 'stateID', 'snapinID');
1241  $insert_values = array();
1242  if ($snapin == -1) {
1243  $snapin = $this->get('snapins');
1244  }
1245  foreach ((array)$snapin as &$snapinID) {
1246  $insert_values[] = array(
1247  $SnapinJob->get('id'),
1248  $this->getQUeuedState(),
1249  $snapinID
1250  );
1251  unset($snapinID);
1252  }
1253  if (count($insert_values) > 0) {
1254  self::getClass('SnapinTaskManager')
1255  ->insertBatch(
1256  $insert_fields,
1257  $insert_values
1258  );
1259  }
1260  } catch (Exception $e) {
1261  if ($error) {
1262  $Task->cancel();
1263  throw new Exception($e->getMessage());
1264  }
1265  }
1266  return $this;
1267  }
1284  public function createImagePackage(
1285  $taskTypeID,
1286  $taskName = '',
1287  $shutdown = false,
1288  $debug = false,
1289  $deploySnapins = false,
1290  $isGroupTask = false,
1291  $username = '',
1292  $passreset = '',
1293  $sessionjoin = false,
1294  $wol = false
1295  ) {
1296  if (!$sessionjoin) {
1297  $taskName .= ' - ' . $this->get('name');
1298  }
1299  try {
1300  if (!$this->isValid()) {
1301  throw new Exception(self::$foglang['HostNotValid']);
1302  }
1303  $Task = $this->get('task');
1304  $TaskType = new TaskType($taskTypeID);
1305  if (!$TaskType->isValid()) {
1306  throw new Exception(self::$foglang['TaskTypeNotValid']);
1307  }
1308  if ($Task->isValid()) {
1309  $iTaskType = $Task->getTaskType()->isImagingTask();
1310  if ($iTaskType) {
1311  throw new Exception(self::$foglang['InTask']);
1312  } elseif ($Task->isSnapinTasking()) {
1313  if ($TaskType->get('id') == '13') {
1314  $currSnapins = self::getSubObjectIDs(
1315  'SnapinTask',
1316  array(
1317  'jobID' => $this->get('snapinjob')->get('id'),
1318  'stateID' => self::fastmerge(
1319  (array)$this->getQueuedStates(),
1320  (array)$this->getProgressState()
1321  ),
1322  ),
1323  'snapinID'
1324  );
1325  if (!in_array($deploySnapins, $currSnapins)) {
1326  $Task
1327  ->set(
1328  'name',
1329  'Multiple Snapin task -- Altered after single'
1330  )
1331  ->set(
1332  'typeID',
1333  12
1334  )->save();
1335  }
1336  } elseif ($TaskType->get('id') == '12') {
1337  $this->_cancelJobsSnapinsForHost();
1338  } else {
1339  $Task->cancel();
1340  $Task = new Task(0);
1341  $this->set('task', $Task);
1342  }
1343  } else {
1344  $Task->cancel();
1345  $Task = new Task(0);
1346  $this->set('task', $Task);
1347  }
1348  }
1349  unset($iTaskType);
1350  $Image = $this->getImage();
1351  $imagingTypes = $TaskType->isImagingTask();
1352  if ($imagingTypes) {
1353  if (!$Image->isValid()) {
1354  throw new Exception(self::$foglang['ImageNotValid']);
1355  }
1356  if (!$Image->get('isEnabled')) {
1357  throw new Exception(_('Image is not enabled'));
1358  }
1359  $StorageGroup = $Image->getStorageGroup();
1360  if (!$StorageGroup->isValid()) {
1361  throw new Exception(self::$foglang['ImageGroupNotValid']);
1362  }
1363  if ($TaskType->isCapture()) {
1364  $StorageNode = $StorageGroup->getMasterStorageNode();
1365  } else {
1366  $StorageNode = $this->getOptimalStorageNode();
1367  }
1368  if (!$StorageNode->isValid()) {
1369  $msg = sprintf(
1370  '%s %s',
1371  _('Could not find any'),
1372  _('nodes containing this image')
1373  );
1374  throw new Exception($msg);
1375  }
1376  $imageTaskImgID = $this->get('imageID');
1377  $hostsWithImgID = self::getSubObjectIDs(
1378  'Host',
1379  array('imageID' => $imageTaskImgID)
1380  );
1381  $realImageID = self::getSubObjectIDs(
1382  'Host',
1383  array('id' => $this->get('id')),
1384  'imageID'
1385  );
1386  if (!in_array($this->get('id'), $hostsWithImgID)) {
1387  $this->set(
1388  'imageID',
1389  array_shift($realImageID)
1390  )->save();
1391  }
1392  $this->set('imageID', $imageTaskImgID);
1393  }
1394  $isCapture = $TaskType->isCapture();
1395  $username = ($username ? $username : self::$FOGUser->get('name'));
1396  if (!$Task->isValid()) {
1397  $Task = $this->_createTasking(
1398  $taskName,
1399  $taskTypeID,
1400  $username,
1401  $imagingTypes ? $StorageGroup->get('id') : 0,
1402  $imagingTypes ? $StorageNode->get('id') : 0,
1403  $imagingTypes,
1404  $shutdown,
1405  $passreset,
1406  $debug,
1407  $wol
1408  );
1409  $Task->set('imageID', $this->get('imageID'));
1410  if (!$Task->save()) {
1411  throw new Exception(self::$foglang['FailedTask']);
1412  }
1413  $this->set('task', $Task);
1414  }
1415  if ($TaskType->isSnapinTask()) {
1416  if ($deploySnapins === true) {
1417  $deploySnapins = -1;
1418  }
1419  $mac = $this->get('mac');
1420  if ($deploySnapins) {
1421  $this->_createSnapinTasking(
1422  $deploySnapins,
1424  $Task
1425  );
1426  }
1427  }
1428  if ($TaskType->isMulticast()) {
1429  $multicastTaskReturn = function (&$MulticastSession) {
1430  if (!$MulticastSession->isValid()) {
1431  return;
1432  }
1433  return $MulticastSession;
1434  };
1435  $assoc = false;
1436  $showStates = self::fastmerge(
1437  self::getQueuedStates(),
1438  (array)self::getProgressState()
1439  );
1440  if ($sessionjoin) {
1441  $MCSessions = self::getClass('MulticastSessionManager')
1442  ->find(
1443  array(
1444  'name' => $taskName,
1445  'stateID' => $showStates
1446  )
1447  );
1448  $assoc = true;
1449  } else {
1450  $MCSessions = self::getClass('MulticastSessionManager')
1451  ->find(
1452  array(
1453  'image' => $Image->get('id'),
1454  'stateID' => $showStates
1455  )
1456  );
1457  }
1458  $MultiSessJoin = array_map(
1459  $multicastTaskReturn,
1460  $MCSessions
1461  );
1462  $MultiSessJoin = array_filter($MultiSessJoin);
1463  $MultiSessJoin = array_values($MultiSessJoin);
1464  if (is_array($MultiSessJoin) && count($MultiSessJoin)) {
1465  $MulticastSession = array_shift($MultiSessJoin);
1466  }
1467  unset($MultiSessJoin);
1468  if ($MulticastSession instanceof MulticastSession
1469  && $MulticastSession->isValid()
1470  ) {
1471  $assoc = true;
1472  } else {
1473  $port = self::getSetting('FOG_UDPCAST_STARTINGPORT');
1474  $portOverride = self::getSetting('FOG_MULTICAST_PORT_OVERRIDE');
1475  $MulticastSession = self::getClass('MulticastSession')
1476  ->set('name', $taskName)
1477  ->set('port', ($portOverride ? $portOverride : $port))
1478  ->set('logpath', $this->getImage()->get('path'))
1479  ->set('image', $this->getImage()->get('id'))
1480  ->set('interface', $StorageNode->get('interface'))
1481  ->set('stateID', 0)
1482  ->set('starttime', self::niceDate()->format('Y-m-d H:i:s'))
1483  ->set('percent', 0)
1484  ->set('isDD', $this->getImage()->get('imageTypeID'))
1485  ->set('storagegroupID', $StorageNode->get('storagegroupID'))
1486  ->set('clients', -1);
1487  if ($MulticastSession->save()) {
1488  $assoc = true;
1489  if (!self::getSetting('FOG_MULTICAST_PORT_OVERRIDE')) {
1490  $randomnumber = mt_rand(24576, 32766)*2;
1491  while ($randomnumber
1492  == $MulticastSession->get('port')
1493  ) {
1494  $randomnumber = mt_rand(24576, 32766)*2;
1495  }
1497  'FOG_UDPCAST_STARTINGPORT',
1498  $randomnumber
1499  );
1500  }
1501  }
1502  }
1503  if ($assoc) {
1504  self::getClass('MulticastSessionAssociation')
1505  ->set('msID', $MulticastSession->get('id'))
1506  ->set('taskID', $Task->get('id'))
1507  ->save();
1508  }
1509  }
1510  if ($wol) {
1511  $this->wakeOnLAN();
1512  }
1513  } catch (Exception $e) {
1514  throw new Exception($e->getMessage());
1515  }
1516  if ($taskTypeID == 14) {
1517  $Task->destroy();
1518  }
1519  $str = '<li>';
1520  $str .= '<a href="#">';
1521  $str .= $this->get('name');
1522  $str .= ' &ndash; ';
1523  $str .= $this->getImage()->get('name');
1524  $str .= '</a>';
1525  $str .= '</li>';
1526  return $str;
1527  }
1533  public function getImageMemberFromHostID()
1534  {
1535  try {
1536  $Image = $this->getImage();
1537  if (!$Image->isValid()) {
1538  throw new Exception(_('No valid Image defined for this host'));
1539  }
1540  if (!$Image->get('isEnabled')) {
1541  throw new Exception(_('Image is not enabled'));
1542  }
1543  $StorageGroup = $Image->getStorageGroup();
1544  if (!$StorageGroup->isValid()) {
1545  throw new Exception('No StorageGroup defined for this host');
1546  }
1547  $Task = self::getClass('Task')
1548  ->set('hostID', $this->get('id'))
1549  ->set('storagegroupID', $StorageGroup->get('id'))
1550  ->set(
1551  'storagenodeID',
1552  $StorageGroup
1554  ->get('id')
1555  )
1556  ->set('imageID', $Image->get('id'));
1557  } catch (Exception $e) {
1558  self::error(
1559  sprintf(
1560  '%s():xError: %s',
1561  __FUNCTION__,
1562  $e->getMessage()
1563  )
1564  );
1565  $Task = false;
1566  }
1567  return $Task;
1568  }
1574  public function clearAVRecordsForHost()
1575  {
1576  self::getClass('VirusManager')
1577  ->destroy(
1578  array('mac' => $this->getMyMacs())
1579  );
1580  return $this;
1581  }
1587  public function wakeOnLAN()
1588  {
1589  self::wakeUp($this->getMyMacs());
1590  return $this;
1591  }
1600  public function addAddMAC($addArray, $pending = false)
1601  {
1602  $addArray = array_map('strtolower', (array)$addArray);
1603  $addArray = self::parseMacList($addArray);
1604  $addTo = $pending ? 'pendingMACs' : 'additionalMACs';
1605  foreach ((array)$addArray as &$mac) {
1606  $this->add($addTo, $mac);
1607  unset($mac);
1608  }
1609  return $this;
1610  }
1618  public function addPendtoAdd($addArray = false)
1619  {
1620  $lowerAndTrim = function (&$MAC) {
1621  return trim(strtolower($MAC));
1622  };
1623  $PendMACs = array_map($lowerAndTrim, (array)$this->get('pendingMACs'));
1624  $MACs = array_map($lowerAndTrim, (array)$addArray);
1625  if ($addArray === false) {
1626  $matched = array_intersect(
1627  (array)$PendMACs,
1628  (array)$MACs
1629  );
1630  } else {
1631  $matched = $PendMACs;
1632  }
1633  unset($MACs, $PendMACs);
1634  return $this->addAddMAC($matched)->removePendMAC($matched);
1635  }
1643  public function removeAddMAC($removeArray)
1644  {
1645  foreach ((array)$removeArray as &$mac) {
1646  if (!$mac instanceof MACAddress) {
1647  $mac = new MACAddress($mac);
1648  }
1649  if (!$mac->isValid()) {
1650  continue;
1651  }
1652  $this->remove('additionalMACs', $mac);
1653  unset($mac);
1654  }
1655  return $this;
1656  }
1664  public function removePendMAC($removeArray)
1665  {
1666  foreach ((array)$removeArray as &$mac) {
1667  if (!$mac instanceof MACAddress) {
1668  $mac = new MACAddress($mac);
1669  }
1670  if (!$mac->isValid()) {
1671  continue;
1672  }
1673  $this->remove('pendingMACs', $mac);
1674  unset($mac);
1675  }
1676  return $this;
1677  }
1685  public function addPriMAC($mac)
1686  {
1688  if (count($mac) < 1) {
1689  throw new Exception(_('No viable macs to use'));
1690  }
1691  if (is_array($mac) && count($mac) > 0) {
1692  $mac = array_shift($mac);
1693  }
1694  $host = $mac->getHost();
1695  if ($host instanceof Host && $host->isValid()) {
1696  throw new Exception(
1697  sprintf(
1698  "%s: %s",
1699  _('MAC address is already in use by another host'),
1700  $host->get('name')
1701  )
1702  );
1703  }
1704  return $this->set('mac', $mac);
1705  }
1713  public function addPendMAC($mac)
1714  {
1715  return $this->addAddMAC($mac, true);
1716  }
1724  public function addPrinter($addArray)
1725  {
1726  return $this->addRemItem(
1727  'printers',
1728  (array)$addArray,
1729  'merge'
1730  );
1731  }
1739  public function removePrinter($removeArray)
1740  {
1741  return $this->addRemItem(
1742  'printers',
1743  (array)$removeArray,
1744  'diff'
1745  );
1746  }
1755  public function addSnapin($addArray)
1756  {
1757  $limit = self::getSetting('FOG_SNAPIN_LIMIT');
1758  if ($limit > 0) {
1759  $snapinCount = self::getClass('SnapinManager')
1760  ->count(
1761  array('id' => $this->get('snapins'))
1762  );
1763  if ($snapinCount >= $limit || count($addArray) > $limit) {
1764  $limitstr = sprintf(
1765  '%s%s %s',
1766  _('snapin'),
1767  $limit == 1 ? '' : 's',
1768  _('per host')
1769  );
1770  throw new Exception(
1771  sprintf(
1772  '%s %d %s',
1773  _('You are only allowed to assign'),
1774  $limit,
1775  $limitstr
1776  )
1777  );
1778  }
1779  }
1780  return $this->addRemItem(
1781  'snapins',
1782  (array)$addArray,
1783  'merge'
1784  );
1785  }
1793  public function removeSnapin($removeArray)
1794  {
1795  return $this->addRemItem(
1796  'snapins',
1797  (array)$removeArray,
1798  'diff'
1799  );
1800  }
1808  public function addModule($addArray)
1809  {
1810  return $this->addRemItem(
1811  'modules',
1812  (array)$addArray,
1813  'merge'
1814  );
1815  }
1823  public function removeModule($removeArray)
1824  {
1825  return $this->addRemItem(
1826  'modules',
1827  (array)$removeArray,
1828  'diff'
1829  );
1830  }
1838  public function addPowerManagement($addArray)
1839  {
1840  return $this->addRemItem(
1841  'powermanagementtasks',
1842  (array)$addArray,
1843  'merge'
1844  );
1845  }
1853  public function removePowerManagement($removeArray)
1854  {
1855  return $this->addRemItem(
1856  'powermanagementtasks',
1857  (array)$removeArray,
1858  'diff'
1859  );
1860  }
1868  public function getMyMacs($justme = true)
1869  {
1870  if ($justme) {
1871  return self::getSubObjectIDs(
1872  'MACAddressAssociation',
1873  array('hostID' => $this->get('id')),
1874  'mac'
1875  );
1876  }
1877  return self::getSubObjectIDs(
1878  'MACAddressAssociation',
1879  '',
1880  'mac'
1881  );
1882  }
1891  public function ignore($imageIgnore, $clientIgnore)
1892  {
1893  $MyMACs = $this->getMyMacs();
1894  $myMACs = $igMACs = $cgMACs = array();
1895  $macaddress = function (&$mac) {
1896  if (!$mac instanceof MACAddress) {
1897  $mac = new MACAddress($mac);
1898  }
1899  if (!$mac->isValid()) {
1900  return;
1901  }
1902  return $mac->__toString();
1903  };
1904  $myMACs = array_map($macaddress, (array)$MyMACs);
1905  $igMACs = array_map($macaddress, (array)$imageIgnore);
1906  $cgMACs = array_map($macaddress, (array)$clientIgnore);
1907  $myMACs = array_filter($myMACs);
1908  $igMACs = array_filter($igMACs);
1909  $cgMACs = array_filter($cgMACs);
1910  $myMACs = array_unique($myMACs);
1911  $igMACs = array_unique($igMACs);
1912  $cgMACs = array_unique($cgMACs);
1913  self::getClass('MACAddressAssociationManager')
1914  ->update(
1915  array(
1916  'mac' => array_diff(
1917  (array)$myMACs,
1918  (array)$igMACs
1919  ),
1920  'hostID' => $this->get('id')
1921  ),
1922  '',
1923  array('imageIgnore' => 0)
1924  );
1925  self::getClass('MACAddressAssociationManager')
1926  ->update(
1927  array(
1928  'mac' => array_diff(
1929  (array)$myMACs,
1930  (array)$cgMACs
1931  ),
1932  'hostID'=>$this->get('id')
1933  ),
1934  '',
1935  array('clientIgnore' => 0)
1936  );
1937  if (count($igMACs) > 0) {
1938  self::getClass('MACAddressAssociationManager')
1939  ->update(
1940  array(
1941  'mac' => $igMACs,
1942  'hostID' => $this->get('id')
1943  ),
1944  '',
1945  array('imageIgnore' => 1)
1946  );
1947  }
1948  if (count($cgMACs) > 0) {
1949  self::getClass('MACAddressAssociationManager')
1950  ->update(
1951  array(
1952  'mac' => $cgMACs,
1953  'hostID'=>$this->get('id')
1954  ),
1955  '',
1956  array('clientIgnore' => 1)
1957  );
1958  }
1959  }
1968  public function addGroup($addArray)
1969  {
1970  return $this->addHost($addArray);
1971  }
1980  public function removeGroup($removeArray)
1981  {
1982  return $this->removeHost($removeArray);
1983  }
1991  public function addHost($addArray)
1992  {
1993  return $this->addRemItem(
1994  'groups',
1995  (array)$addArray,
1996  'merge'
1997  );
1998  }
2006  public function removeHost($removeArray)
2007  {
2008  return $this->addRemItem(
2009  'groups',
2010  (array)$removeArray,
2011  'diff'
2012  );
2013  }
2021  public function clientMacCheck($mac = false)
2022  {
2023  if ($mac) {
2024  if (!$mac instanceof MACAddress) {
2025  $mac = new MACAddress($mac);
2026  }
2027  if ($mac->isClientIgnored()) {
2028  return ' checked';
2029  }
2030  return '';
2031  }
2032  return $this->get('mac')->isClientIgnored() ? ' checked' : '';
2033  }
2041  public function imageMacCheck($mac = false)
2042  {
2043  if ($mac) {
2044  if (!$mac instanceof MACAddress) {
2045  $mac = new MACAddress($mac);
2046  }
2047  if ($mac->isImageIgnored()) {
2048  return ' checked';
2049  }
2050  return '';
2051  }
2052  return $this->get('mac')->isImageIgnored() ? ' checked' : '';
2053  }
2070  public function setAD(
2071  $useAD = '',
2072  $domain = '',
2073  $ou = '',
2074  $user = '',
2075  $pass = '',
2076  $override = false,
2077  $nosave = false,
2078  $legacy = '',
2079  $productKey = '',
2080  $enforce = ''
2081  ) {
2082  $adpasspat = "/^\*{32}$/";
2083  $pass = (preg_match($adpasspat, $pass) ? $this->get('ADPass') : $pass);
2084  if ($this->get('id')) {
2085  if (!$override) {
2086  if (empty($useAD)) {
2087  $useAD = $this->get('useAD');
2088  }
2089  if (empty($domain)) {
2090  $domain = trim($this->get('ADDomain'));
2091  }
2092  if (empty($ou)) {
2093  $ou = trim($this->get('ADOU'));
2094  }
2095  if (empty($user)) {
2096  $user = trim($this->get('ADUser'));
2097  }
2098  if (empty($pass)) {
2099  $pass = trim($this->get('ADPass'));
2100  }
2101  if (empty($legacy)) {
2102  $legacy = trim($this->get('ADPassLegacy'));
2103  }
2104  if (empty($productKey)) {
2105  $productKey = trim($this->get('productKey'));
2106  }
2107  if (empty($enforce)) {
2108  $enforce = (int)$this->get('enforce');
2109  }
2110  }
2111  }
2112  if ($pass) {
2113  $pass = trim($pass);
2114  }
2115  $this->set('useAD', $useAD)
2116  ->set('ADDomain', trim($domain))
2117  ->set('ADOU', trim($ou))
2118  ->set('ADUser', trim($user))
2119  ->set('ADPass', $pass)
2120  ->set('ADPassLegacy', $legacy)
2121  ->set('productKey', trim($productKey))
2122  ->set('enforce', (string)$enforce);
2123  return $this;
2124  }
2130  public function getImage()
2131  {
2132  return $this->get('imagename');
2133  }
2139  public function getImageName()
2140  {
2141  return $this
2142  ->get('imagename')
2143  ->get('name');
2144  }
2150  public function getOS()
2151  {
2152  return $this->getImage()->getOS()->get('name');
2153  }
2159  public function getActiveSnapinJob()
2160  {
2161  return $this->get('snapinjob');
2162  }
2168  public function getPingCodeStr()
2169  {
2170  $val = (int)$this->get('pingstatus');
2171  $socketstr = socket_strerror($val);
2172  $strtoupdate = '<i class="icon-ping-%s fa fa-%s %s'
2173  . '" data-toggle="tooltip" '
2174  . 'data-placement="right" '
2175  . 'title="%s'
2176  . '"></i>';
2177 
2178  ob_start();
2179  switch ($val) {
2180  case 0:
2181  printf($strtoupdate, 'windows', 'windows', 'green', 'Windows');
2182  break;
2183  case 111:
2184  $taskID = self::getSubObjectIDs(
2185  'Task',
2186  array('hostID' => $this->get('id'),
2187  'stateID' => 2
2188  ),
2189  'id'
2190  );
2191  if (is_null($taskID)) {
2192  printf($strtoupdate, 'linux', 'linux', 'blue', 'Linux');
2193  } else {
2194  printf($strtoupdate, 'fos', 'cogs', 'green', 'FOS');
2195  }
2196 
2197  break;
2198  default:
2199  printf($strtoupdate, 'down', 'exclamation-circle', 'red', 'Unknown');
2200  }
2201  return ob_get_clean();
2202  }
2203 }
Host\getAlo
getAlo()
Definition: host.class.php:787
Host\getImageMemberFromHostID
getImageMemberFromHostID()
Definition: host.class.php:1533
Host\updateDefault
updateDefault($printerid, $onoff)
Definition: host.class.php:667
Host\addHost
addHost($addArray)
Definition: host.class.php:1991
Host\_setAlo
_setAlo()
Definition: host.class.php:770
Host\$_hostscreen
static $_hostscreen
Definition: host.class.php:140
Host\addPowerManagement
addPowerManagement($addArray)
Definition: host.class.php:1838
Host\_createSnapinTasking
_createSnapinTasking( $snapin=-1, $error=false, $Task=false)
Definition: host.class.php:1220
Host\clearAVRecordsForHost
clearAVRecordsForHost()
Definition: host.class.php:1574
FOGController\addRemItem
addRemItem($key, $array, $array_type)
Definition: fogcontroller.class.php:823
Host\loadOptimalStorageNode
loadOptimalStorageNode()
Definition: host.class.php:1056
Host\_cancelJobsSnapinsForHost
_cancelJobsSnapinsForHost()
Definition: host.class.php:1154
Host\loadGroupsnotinme
loadGroupsnotinme()
Definition: host.class.php:875
Host\createImagePackage
createImagePackage( $taskTypeID, $taskName='', $shutdown=false, $debug=false, $deploySnapins=false, $isGroupTask=false, $username='', $passreset='', $sessionjoin=false, $wol=false)
Definition: host.class.php:1284
TaskType\isCapture
isCapture($nums=false)
Definition: tasktype.class.php:150
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGBase\fastmerge
static fastmerge($array1)
Definition: fogbase.class.php:2415
TaskType
Definition: tasktype.class.php:23
Host\removeAddMAC
removeAddMAC($removeArray)
Definition: host.class.php:1643
Host\loadSnapinjob
loadSnapinjob()
Definition: host.class.php:994
Host\isValid
isValid()
Definition: host.class.php:622
Host\addModule
addModule($addArray)
Definition: host.class.php:1808
Host\loadGroups
loadGroups()
Definition: host.class.php:857
Host\ignore
ignore($imageIgnore, $clientIgnore)
Definition: host.class.php:1891
Host\getDispVals
getDispVals($key='')
Definition: host.class.php:738
Host\add
add($key, $value)
Definition: host.class.php:198
Host\$databaseFieldsRequired
$databaseFieldsRequired
Definition: host.class.php:71
FOGBase\error
static error($txt, $data=array())
Definition: fogbase.class.php:721
Host\removePrinter
removePrinter($removeArray)
Definition: host.class.php:1739
Host\isHostnameSafe
isHostnameSafe($hostname='')
Definition: host.class.php:633
Host\loadSnapinsnotinme
loadSnapinsnotinme()
Definition: host.class.php:937
Host\_retValidMacs
static _retValidMacs($macs, &$arr)
Definition: host.class.php:281
Host\removePendMAC
removePendMAC($removeArray)
Definition: host.class.php:1664
Host\getMyMacs
getMyMacs($justme=true)
Definition: host.class.php:1868
MulticastSession
Definition: multicastsession.class.php:23
Host\removeHost
removeHost($removeArray)
Definition: host.class.php:2006
Host\setAlo
setAlo($time)
Definition: host.class.php:799
$SnapinJob
if(!FOGCore::$Host->isValid()) $SnapinJob
Definition: snapcheck.php:28
Host\set
set($key, $value)
Definition: host.class.php:156
Host\addPrinter
addPrinter($addArray)
Definition: host.class.php:1724
$user
$user
Definition: advanced.php:38
$val
$val
Definition: check_node_exists.php:25
FOGBase\getQueuedStates
static getQueuedStates()
Definition: fogbase.class.php:2106
FOGController\get
get($key='')
Definition: fogcontroller.class.php:207
TaskType\isImagingTask
isImagingTask()
Definition: tasktype.class.php:136
Host\$additionalFields
$additionalFields
Definition: host.class.php:79
Host\wakeOnLAN
wakeOnLAN()
Definition: host.class.php:1587
Host\_setDispVals
_setDispVals()
Definition: host.class.php:694
$mac
$mac
Definition: hostinfo.php:151
FOGController\key
key(&$key)
Definition: fogcontroller.class.php:770
Host\removePowerManagement
removePowerManagement($removeArray)
Definition: host.class.php:1853
Host\getImageName
getImageName()
Definition: host.class.php:2139
StorageNode
Definition: storagenode.class.php:23
Host\loadSnapins
loadSnapins()
Definition: host.class.php:919
Task
Definition: task.class.php:23
Host\getImage
getImage()
Definition: host.class.php:2130
Host\removeSnapin
removeSnapin($removeArray)
Definition: host.class.php:1793
Host\getActiveTaskCount
getActiveTaskCount()
Definition: host.class.php:1069
$TaskType
if(FOGCore::$useragent) if(! $Task->isValid()) $TaskType
Definition: hostinfo.php:33
Host\getOptimalStorageNode
getOptimalStorageNode()
Definition: host.class.php:1087
Host\getOS
getOS()
Definition: host.class.php:2150
TaskState
Definition: taskstate.class.php:23
FOGBase\getProgressState
static getProgressState()
Definition: fogbase.class.php:2133
Host\loadPrinters
loadPrinters()
Definition: host.class.php:888
Host\loadPendingMACs
loadPendingMACs()
Definition: host.class.php:839
Host\loadModules
loadModules()
Definition: host.class.php:950
$MACs
$MACs
Definition: hostinfo.php:152
Host\loadPrintersnotinme
loadPrintersnotinme()
Definition: host.class.php:906
FOGBase\parseMacList
static parseMacList( $stringlist, $image=false, $client=false)
Definition: fogbase.class.php:1696
$str
if(! $Image->isValid()) $str
Definition: progress.php:41
Host\_createTasking
_createTasking( $taskName, $taskTypeID, $username, $groupID, $memID, $imagingTask=true, $shutdown=false, $passreset=false, $debug=false, $wol=false)
Definition: host.class.php:1107
Host\loadAdditionalMACs
loadAdditionalMACs()
Definition: host.class.php:821
FOGController
Definition: fogcontroller.class.php:29
Host\clientMacCheck
clientMacCheck($mac=false)
Definition: host.class.php:2021
FOGBase\wakeUp
static wakeUp($macs)
Definition: fogbase.class.php:2340
$count
$count
Definition: locationcheck.php:25
Host\addSnapin
addSnapin($addArray)
Definition: host.class.php:1755
Host\destroy
destroy($key='id')
Definition: host.class.php:219
Host\imageMacCheck
imageMacCheck($mac=false)
Definition: host.class.php:2041
Host\save
save()
Definition: host.class.php:301
TaskType\isMulticast
isMulticast($nums=false)
Definition: tasktype.class.php:285
Host\addPendMAC
addPendMAC($mac)
Definition: host.class.php:1713
Host\addPriMAC
addPriMAC($mac)
Definition: host.class.php:1685
Host\$_hostalo
static $_hostalo
Definition: host.class.php:146
Host\getDefault
getDefault($printerid)
Definition: host.class.php:648
Host\loadTask
loadTask()
Definition: host.class.php:1014
Host\loadPowermanagementtasks
loadPowermanagementtasks()
Definition: host.class.php:968
Host\$databaseFields
$databaseFields
Definition: host.class.php:35
$Image
$Image
Definition: hostinfo.php:37
$Task
$Task
Definition: hostinfo.php:26
Host\addPendtoAdd
addPendtoAdd($addArray=false)
Definition: host.class.php:1618
Host\addAddMAC
addAddMAC($addArray, $pending=false)
Definition: host.class.php:1600
FOGBase\$debug
static $debug
Definition: fogbase.class.php:133
Host\$databaseFieldClassRelationships
$databaseFieldClassRelationships
Definition: host.class.php:107
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
$username
$username
Definition: checkcredentials.php:25
$foglang
$foglang['Display']
Definition: text.php:22
MACAddress
Definition: macaddress.class.php:23
Host\setDisp
setDisp($x, $y, $r)
Definition: host.class.php:752
FOGBase\isLoaded
isLoaded($key)
Definition: fogbase.class.php:969
$msg
if($Host->isValid()) $msg
Definition: hostnameloop.php:42
FOGController\__toString
__toString()
Definition: fogcontroller.class.php:172
Host\getPingCodeStr
getPingCodeStr()
Definition: host.class.php:2168
TaskType\isSnapinTask
isSnapinTask()
Definition: tasktype.class.php:229
SnapinJob
Definition: snapinjob.class.php:23
$productKey
if($test_base64=base64_decode($passtest)) $productKey
Definition: hostinfo.php:170
Host\loadMac
loadMac()
Definition: host.class.php:811
Host\$databaseTable
$databaseTable
Definition: host.class.php:29
Host\removeGroup
removeGroup($removeArray)
Definition: host.class.php:1980
$pass
$pass
Definition: hostinfo.php:161
FOGBase\setSetting
static setSetting($key, $value)
Definition: fogbase.class.php:2093
FOGBase\getSetting
static getSetting($key)
Definition: fogbase.class.php:2063
Host\setAD
setAD( $useAD='', $domain='', $ou='', $user='', $pass='', $override=false, $nosave=false, $legacy='', $productKey='', $enforce='')
Definition: host.class.php:2070
Host\addGroup
addGroup($addArray)
Definition: host.class.php:1968
Host\loadUsers
loadUsers()
Definition: host.class.php:981
FOGController\isValid
isValid()
Definition: fogcontroller.class.php:865
TaskType\isSnapinTasking
isSnapinTasking($nums=false)
Definition: tasktype.class.php:207
Host\getActiveSnapinJob
getActiveSnapinJob()
Definition: host.class.php:2159
Host\removeModule
removeModule($removeArray)
Definition: host.class.php:1823
$host
$host
Definition: hostnameloop.php:27
Host
Definition: host.class.php:23