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)  

route.class.php
Go to the documentation of this file.
1 <?php
22 class Route extends FOGBase
23 {
29  private static $_enabled = false;
35  private static $_token = '';
41  public static $router = null;
47  public static $matches = array();
53  public static $data;
59  public static $validClasses = array(
60  'clientupdater',
61  'dircleaner',
62  'greenfog',
63  'group',
64  'groupassociation',
65  'history',
66  'hookevent',
67  'host',
68  'hostautologout',
69  'hostscreensetting',
70  'image',
71  'imageassociation',
72  'imagepartitiontype',
73  'imagetype',
74  'imaginglog',
75  'inventory',
76  'ipxe',
77  'keysequence',
78  'macaddressassociation',
79  'module',
80  'moduleassociation',
81  'multicastsession',
82  'multicastsessionassociation',
83  'nodefailure',
84  'notifyevent',
85  'os',
86  'oui',
87  'plugin',
88  'powermanagement',
89  'printer',
90  'printerassociation',
91  'pxemenuoptions',
92  'scheduledtask',
93  'service',
94  'snapin',
95  'snapinassociation',
96  'snapingroupassociation',
97  'snapinjob',
98  'snapintask',
99  'storagegroup',
100  'storagenode',
101  'task',
102  'tasklog',
103  'taskstate',
104  'tasktype',
105  //'user',
106  'usercleanup',
107  'usertracking',
108  'virus'
109  );
115  public static $validTaskingClasses = array(
116  'group',
117  'host',
118  'multicastsession',
119  'scheduledtask',
120  'snapinjob',
121  'snapintask',
122  'task'
123  );
129  public static $validActiveTasks = array(
130  'multicastsession',
131  'scheduledtask',
132  'snapinjob',
133  'snapintask',
134  'task'
135  );
141  public function __construct()
142  {
143  list(
144  self::$_enabled,
145  self::$_token
147  'Service',
148  array(
149  'name' => array(
150  'FOG_API_ENABLED',
151  'FOG_API_TOKEN'
152  )
153  ),
154  'value'
155  );
159  if (!self::$_enabled) {
160  header(
161  sprintf(
162  'Location: %s://%s/fog/management/index.php',
163  self::$httpproto,
164  self::$httphost
165  )
166  );
167  exit;
168  }
169  if (!self::$FOGUser->isValid()) {
177  self::_testAuth();
178  }
182  ignore_user_abort(true);
183  session_write_close();
184  set_time_limit(0);
188  self::$HookManager
189  ->processEvent(
190  'API_VALID_CLASSES',
191  array(
192  'validClasses' => &self::$validClasses
193  )
194  );
195  self::$HookManager
196  ->processEvent(
197  'API_TASKING_CLASSES',
198  array(
199  'validTaskingClasses' => &self::$validTaskingClasses
200  )
201  );
202  self::$HookManager
203  ->processEvent(
204  'API_ACTIVE_TASK_CLASSES',
205  array(
206  'validActiveTasks' => &self::$validActiveTasks
207  )
208  );
213  if (self::$router) {
214  return;
215  }
216  self::$router = new AltoRouter(
217  array(),
218  '/fog'
219  );
224  }
230  protected static function defineRoutes()
231  {
232  $expanded = sprintf(
233  '/[%s:class]',
234  implode('|', self::$validClasses)
235  );
236  $expandedt = sprintf(
237  '/[%s:class]',
238  implode('|', self::$validTaskingClasses)
239  );
240  $expandeda = sprintf(
241  '/[%s:class]',
242  implode('|', self::$validActiveTasks)
243  );
244  self::$router
245  ->map(
246  'HEAD|GET',
247  '/system/[status|info]',
248  array(__CLASS__, 'status'),
249  'status'
250  )
251  ->get(
252  "${expandeda}/[current|active]",
253  array(__CLASS__, 'active'),
254  'active'
255  )
256  ->get(
257  "${expanded}/search/[*:item]",
258  array(__CLASS__, 'search'),
259  'search'
260  )
261  ->get(
262  "${expanded}/[list|all]?",
263  array(__CLASS__, 'listem'),
264  'list'
265  )
266  ->get(
267  "${expanded}/[details]/?[*:item]?",
268  array(__CLASS__, 'listdetails'),
269  'listdetails'
270  )
271  ->get(
272  "${expanded}/[i:id]/?[*:item]?",
273  array(__CLASS__, 'indiv'),
274  'indiv'
275  )
276  ->get(
277  "${expanded}/names/[*:whereItems]?",
278  array(__CLASS__, 'names'),
279  'names'
280  )
281  ->get(
282  "${expanded}/ids/[*:whereItems]?/[*:getField]?",
283  array(__CLASS__, 'ids'),
284  'ids'
285  )
286  ->put(
287  "${expanded}/[i:id]/[update|edit]?",
288  array(__CLASS__, 'edit'),
289  'update'
290  )
291  ->post(
292  "${expandedt}/[i:id]/[task]",
293  array(__CLASS__, 'task'),
294  'task'
295  )
296  ->post(
297  "${expanded}/[create|new]?",
298  array(__CLASS__, 'create'),
299  'create'
300  )
301  ->delete(
302  "${expandedt}/[i:id]?/[cancel]",
303  array(__CLASS__, 'cancel'),
304  'cancel'
305  )
306  ->delete(
307  "${expanded}/[i:id]/[delete|remove]?",
308  array(__CLASS__, 'delete'),
309  'delete'
310  );
311  }
317  public static function setMatches()
318  {
319  self::$matches = self::$router->match();
320  }
326  public static function getMatches()
327  {
328  return self::$matches;
329  }
335  public static function runMatches()
336  {
337  if (self::$matches
338  && is_callable(self::$matches['target'])
339  ) {
340  call_user_func_array(
341  self::$matches['target'],
342  self::$matches['params']
343  );
344  return;
345  }
348  );
349  }
355  private static function _testToken()
356  {
357  $passtoken = base64_decode(
358  filter_input(INPUT_SERVER, 'HTTP_FOG_API_TOKEN')
359  );
360  if ($passtoken !== self::$_token) {
363  );
364  }
365  }
371  private static function _testAuth()
372  {
373  $usertoken = base64_decode(
374  filter_input(INPUT_SERVER, 'HTTP_FOG_USER_TOKEN')
375  );
376  $pwtoken = self::getClass('User')
377  ->set('token', $usertoken)
378  ->load('token');
379  if ($pwtoken->isValid() && $pwtoken->get('api')) {
380  return;
381  }
382  $auth = self::$FOGUser->passwordValidate(
383  $_SERVER['PHP_AUTH_USER'],
384  $_SERVER['PHP_AUTH_PW']
385  );
386  if (!$auth) {
389  );
390  }
391  }
400  public static function sendResponse($code, $msg = false)
401  {
403  $code,
404  $msg
405  );
406  }
412  public static function status()
413  {
416  "success\n"
417  );
418  }
429  public static function listem(
430  $class,
431  $sortby = 'name',
432  $bypass = false,
433  $find = array(),
434  $item = ''
435  ) {
436  $classname = strtolower($class);
437  $classman = self::getClass($class)->getManager();
438  self::$data = array();
439  self::$data['count'] = 0;
440  self::$data[$classname.'s'] = array();
441  $find = self::fastmerge(
442  $find,
443  self::getsearchbody($classname)
444  );
445  switch ($classname) {
446  case 'plugin':
447  self::$data['count_active'] = 0;
448  self::$data['count_installed'] = 0;
449  self::$data['count_not_active'] = 0;
450  foreach (self::getClass('Plugin')->getPlugins() as $class) {
451  self::$data[$classname.'s'][] = self::getter(
452  $classname,
453  $class,
454  $item
455  );
456  if ($class->isActive() && !$class->isInstalled()) {
457  self::$data['count_active']++;
458  }
459  if ($class->isActive() && $class->isInstalled()) {
460  self::$data['count_installed']++;
461  }
462  if (!$class->isActive() && !$class->isInstalled()) {
463  self::$data['count_not_active']++;
464  }
465  self::$data['count']++;
466  unset($class);
467  }
468  break;
469  default:
470  foreach ((array)$classman->find($find, 'AND', $sortby) as &$class) {
471  $test = stripos(
472  $class->get('name'),
473  '_api_'
474  );
475  if (!$bypass && false != $test) {
476  continue;
477  }
478  self::$data[$classname.'s'][] = self::getter(
479  $classname,
480  $class,
481  $item
482  );
483  self::$data['count']++;
484  unset($class);
485  }
486  break;
487  }
488  self::$HookManager
489  ->processEvent(
490  'API_MASSDATA_MAPPING',
491  array(
492  'data' => &self::$data,
493  'classname' => &$classname,
494  'classman' => &$classman
495  )
496  );
497  }
508  public static function listdetails(
509  $class,
510  $item,
511  $sortby = 'name',
512  $bypass = false,
513  $find = array()
514  ) {
515  $item = empty($item) ? 'all' : $item;
516  self::listem($class, $sortby, $bypass, $find, $item);
517  }
526  public static function search($class, $item)
527  {
528  $classname = strtolower($class);
529  $classman = self::getClass($class)->getManager();
530  self::$data = array();
531  self::$data['count'] = 0;
532  self::$data[$classname.'s'] = array();
533  foreach ($classman->search($item, true) as &$class) {
534  if (false != stripos($class->get('name'), '_api_')) {
535  continue;
536  }
537  self::$data[$classname.'s'][] = self::getter(
538  $classname,
539  $class
540  );
541  self::$data['count']++;
542  unset($class);
543  }
544  self::$HookManager
545  ->processEvent(
546  'API_MASSDATA_MAPPING',
547  array(
548  'data' => &self::$data,
549  'classname' => &$classname,
550  'classman' => &$classman
551  )
552  );
553  }
562  public static function indiv($class, $id, $item = '')
563  {
564  $classname = strtolower($class);
565  $class = new $class($id);
566  if (!$class->isValid()) {
569  );
570  }
571  self::$data = array();
573  $classname,
574  $class,
575  $item
576  );
577  self::$HookManager
578  ->processEvent(
579  'API_INDIVDATA_MAPPING',
580  array(
581  'data' => &self::$data,
582  'classname' => &$classname,
583  'class' => &$class
584  )
585  );
586  }
595  public static function edit($class, $id)
596  {
597  $classname = strtolower($class);
598  $classVars = self::getClass(
599  $class,
600  '',
601  true
602  );
603  $class = new $class($id);
604  if (!$class->isValid()) {
607  );
608  }
609  $vars = json_decode(
610  file_get_contents('php://input')
611  );
612  $exists = self::getClass($classname)
613  ->getManager()
614  ->exists($vars->name);
615  if (strtolower($class->get('name')) != $vars->name
616  && $exists
617  ) {
619  _('Already created'),
621  );
622  }
623  foreach ($classVars['databaseFields'] as &$key) {
624  $key = $class->key($key);
625  if (!isset($vars->$key)) {
626  $val = $class->get($key);
627  } else {
628  $val = $vars->$key;
629  }
630  if ($key == 'id') {
631  continue;
632  }
633  $class->set($key, $val);
634  unset($key);
635  }
636  switch ($classname) {
637  case 'host':
638  if (isset($vars->macs)) {
639  $macsToAdd = array_diff(
640  (array)$vars->macs,
641  $class->getMyMacs()
642  );
643  $primac = array_shift($macsToAdd);
644  $macsToRem = array_diff(
645  $class->getMyMacs(),
646  (array)$vars->macs
647  );
648  $class
649  ->removeAddMAC($macsToRem)
650  ->addPriMAC($primac)
651  ->addAddMAC($macsToAdd);
652  }
653  if (isset($vars->snapins)) {
654  $snapinsToAdd = array_diff(
655  (array)$vars->snapins,
656  $class->get('snapins')
657  );
658  $snapinsToRem = array_diff(
659  $class->get('snapins'),
660  (array)$vars->snapins
661  );
662  $class
663  ->removeSnapin($snapinsToRem)
664  ->addSnapin($snapinsToAdd);
665  }
666  if (isset($vars->printers)) {
667  $printersToAdd = array_diff(
668  (array)$vars->printers,
669  $class->get('printers')
670  );
671  $printersToRem = array_diff(
672  $class->get('printers'),
673  (array)$vars->printers
674  );
675  $class
676  ->removePrinter($printersToRem)
677  ->addPrinter($printersToAdd);
678  }
679  if (isset($vars->modules)) {
680  $modulesToAdd = array_diff(
681  (array)$vars->modules,
682  $class->get('modules')
683  );
684  $modulesToRem = array_diff(
685  $class->get('modules'),
686  (array)$vars->modules
687  );
688  $class
689  ->removeModule($modulesToAdd)
690  ->addModule($modulesToRem);
691  }
692  if (isset($vars->groups)) {
693  $groupsToAdd = array_diff(
694  (array)$vars->groups,
695  $class->get('groups')
696  );
697  $groupsToRem = array_diff(
698  $class->get('groups'),
699  (array)$vars->groups
700  );
701  $class
702  ->removeGroup($groupsToRem)
703  ->addGroup($groupsToAdd);
704  }
705  break;
706  case 'group':
707  if (isset($vars->snapins)) {
708  Route::ids('snapin');
709  $snapins = json_decode(
710  Route::getData(),
711  true
712  );
713  $snapinsToRem = array_diff(
714  $snapins,
715  (array)$vars->snapins
716  );
717  $class
718  ->removeSnapin($snapinsToRem)
719  ->addSnapin($vars->snapins);
720  }
721  if (isset($vars->printers)) {
722  Route::ids('printer');
723  $printers = json_decode(
724  Route::getData(),
725  true
726  );
727  $printersToRem = array_diff(
728  $printers,
729  (array)$vars->printers
730  );
731  $class
732  ->removePrinter($printersToRem)
733  ->addPrinter($vars->printers);
734  }
735  if (isset($vars->modules)) {
736  Route::ids('module');
737  $modules = json_decode(
738  Route::getData(),
739  true
740  );
741  $modulesToRem = array_diff(
742  $modules,
743  (array)$vars->modules
744  );
745  $class
746  ->removeModule($modulesToRem)
747  ->addPrinter($vars->modules);
748  }
749  if (isset($vars->hosts)) {
750  $hostsToAdd = array_diff(
751  (array)$vars->hosts,
752  $class->get('hosts')
753  );
754  $hostsToRem = array_diff(
755  $class->get('hosts'),
756  (array)$vars->hosts
757  );
758  $class
759  ->removeHost($hostsToRem)
760  ->addHost($hostsToAdd);
761  }
762  if ($vars->imageID) {
763  $class
764  ->addImage($vars->imageID);
765  }
766  break;
767  case 'image':
768  case 'snapin':
769  if (isset($vars->hosts)) {
770  $hostsToAdd = array_diff(
771  (array)$vars->hosts,
772  $class->get('hosts')
773  );
774  $hostsToRem = array_diff(
775  $class->get('hosts'),
776  (array)$vars->hosts
777  );
778  $class
779  ->removeHost($hostsToRem)
780  ->addHost($hostsToAdd);
781  }
782  if (isset($vars->storagegroups)) {
783  $storageGroupsToAdd = array_diff(
784  (array)$vars->storagegroups,
785  $class->get('storagegroups')
786  );
787  $storageGroupsToRem = array_diff(
788  $class->get('storagegroups'),
789  (array)$vars->storagegroups
790  );
791  $class
792  ->removeGroup($storageGroupsToRem)
793  ->addgroup($storageGroupsToAdd);
794  }
795  break;
796  case 'printer':
797  if (isset($vars->hosts)) {
798  $hostsToAdd = array_diff(
799  (array)$vars->hosts,
800  $class->get('hosts')
801  );
802  $hostsToRem = array_diff(
803  $class->get('hosts'),
804  (array)$vars->hosts
805  );
806  $class
807  ->removeHost($hostsToRem)
808  ->addHost($hostsToAdd);
809  }
810  break;
811  }
812  // Store the data and recreate.
813  // If failed present so.
814  if ($class->save()) {
815  $class = new $class($id);
816  } else {
819  );
820  }
821  self::indiv($classname, $id);
822  }
831  public static function task($class, $id)
832  {
833  $classname = strtolower($class);
834  $class = new $class($id);
835  if (!$class->isValid()) {
838  );
839  }
840  $tids = self::getSubObjectIDs('TaskType');
841  $task = json_decode(
842  file_get_contents('php://input')
843  );
844  $TaskType = new TaskType($task->taskTypeID);
845  if (!$TaskType->isValid()) {
846  $message = _('Invalid tasking type passed');
848  $message,
850  );
851  }
852  try {
853  $class->createImagePackage(
854  $task->taskTypeID,
855  $task->taskName,
856  $task->shutdown,
857  $task->debug,
858  (
859  $task->deploySnapins === true ?
860  -1 :
861  (
862  (is_numeric($task->deploySnapins)
863  && $task->deploySnapins > 0)
864  || $task->deploySnapins == -1 ?
865  $task->deploySnapins :
866  false
867  )
868  ),
869  $class instanceof Group,
870  $_SERVER['PHP_AUTH_USER'],
871  $task->passreset,
872  $task->sessionjoin,
873  $task->wol
874  );
875  } catch (\Exception $e) {
877  $e->getMessage(),
879  );
880  }
881  }
889  public static function create($class)
890  {
891  $classname = strtolower($class);
892  $classVars = self::getClass(
893  $class,
894  '',
895  true
896  );
897  $class = new $class;
898  $vars = json_decode(
899  file_get_contents(
900  'php://input'
901  )
902  );
903  $exists = self::getClass($classname)
904  ->getManager()
905  ->exists($vars->name);
906  if ($exists) {
908  _('Already created'),
910  );
911  }
912  foreach ($classVars['databaseFields'] as &$key) {
913  $key = $class->key($key);
914  $val = $vars->$key;
915  if ($key == 'id'
916  || !$val
917  ) {
918  continue;
919  }
920  $class->set($key, $val);
921  unset($key);
922  }
923  switch ($classname) {
924  case 'host':
925  if (count($vars->macs)) {
926  $class
927  ->removeAddMAC($vars->macs)
928  ->addPriMAC(array_shift($vars->macs))
929  ->addAddMAC($vars->macs);
930  }
931  if (isset($vars->snapins)) {
932  $class
933  ->addSnapin($vars->snapins);
934  }
935  if (isset($vars->printers)) {
936  $class
937  ->addPrinter($vars->printers);
938  }
939  if (isset($vars->modules)) {
940  $class
941  ->addModule($vars->modules);
942  }
943  if (isset($vars->groups)) {
944  $class
945  ->addGroup($vars->groups);
946  }
947  break;
948  case 'group':
949  if (isset($vars->snapins)) {
950  $class
951  ->addSnapin($vars->snapins);
952  }
953  if (isset($vars->printers)) {
954  $class
955  ->addPrinter($vars->printers);
956  }
957  if (isset($vars->modules)) {
958  $class
959  ->addModule($vars->modules);
960  }
961  if (isset($vars->hosts)) {
962  $class
963  ->addHost($vars->hosts);
964  if (isset($vars->imageID)) {
965  $class
966  ->addImage($vars->imageID);
967  }
968  }
969  break;
970  case 'image':
971  case 'snapin':
972  if (isset($vars->hosts)) {
973  $class
974  ->addHost($vars->hosts);
975  }
976  if (isset($vars->storagegroups)) {
977  $class
978  ->addGroup($vars->storagegroups);
979  }
980  break;
981  case 'printer':
982  if (isset($vars->hosts)) {
983  $class
984  ->addHost($vars->hosts);
985  }
986  break;
987  }
988  foreach ($classVars['databaseFieldsRequired'] as &$key) {
989  $key = $class->key($key);
990  $val = $class->get($key);
991  if (!is_numeric($val) && !$val) {
993  self::$foglang['RequiredDB'],
995  );
996  }
997  }
998  // Store the data and recreate.
999  // If failed present so.
1000  if ($class->save()) {
1001  $id = $class->get('id');
1002  $class = new $class($id);
1003  } else {
1006  );
1007  }
1008  self::indiv($classname, $id);
1009  }
1018  public static function cancel($class, $id)
1019  {
1020  $classname = strtolower($class);
1021  $class = new $class($id);
1022  switch ($classname) {
1023  case 'group':
1024  if (!$class->isValid()) {
1027  );
1028  }
1029  foreach (self::getClass('HostManager')
1030  ->find(array('id' => $class->get('hosts'))) as &$Host
1031  ) {
1032  if ($Host->get('task') instanceof Task) {
1033  $Host->get('task')->cancel();
1034  }
1035  unset($Host);
1036  }
1037  break;
1038  case 'host':
1039  if (!$class->isValid()) {
1042  );
1043  }
1044  if ($class->get('task') instanceof Task) {
1045  $class->get('task')->cancel();
1046  }
1047  break;
1048  default:
1049  $states = self::fastmerge(
1050  (array)self::getQueuedStates(),
1051  (array)self::getProgressState()
1052  );
1053  if (!$class->isValid()) {
1054  $classman = $class->getManager();
1055  $find = self::getsearchbody($classname, $class);
1056  $find['stateID'] = $states;
1057  $ids = self::getSubObjectIDs(
1058  $classname,
1059  $find
1060  );
1061  $classman->cancel($ids);
1062  } else {
1063  if (in_array($class->get('stateID'), $states)) {
1064  $class->cancel();
1065  }
1066  }
1067  }
1068  }
1076  public static function getsearchbody($class)
1077  {
1078  $classVars = self::getClass(
1079  $class,
1080  '',
1081  true
1082  );
1083  $vars = json_decode(
1084  file_get_contents('php://input')
1085  );
1086  $find = array();
1087  $class = new $class;
1088  foreach ($classVars['databaseFields'] as &$key) {
1089  $key = $class->key($key);
1090  if (isset($vars->$key)) {
1091  $find[$key] = $vars->$key;
1092  }
1093  unset($key);
1094  }
1095  return $find;
1096  }
1104  public static function active($class)
1105  {
1106  $classname = strtolower($class);
1107  $classman = self::getClass($class)->getManager();
1108  $find = self::getsearchbody($classname);
1109  $states = self::fastmerge(
1110  (array)self::getQueuedStates(),
1111  (array)self::getProgressState()
1112  );
1113  switch ($classname) {
1114  case 'scheduledtask':
1115  $find['isActive'] = 1;
1116  break;
1117  case 'multicastsession':
1118  case 'snapinjob':
1119  case 'snapintask':
1120  case 'task':
1121  $find['stateID'] = $states;
1122  }
1123  self::$data = array();
1124  self::$data['count'] = 0;
1125  self::$data[$classname.'s'] = array();
1126  foreach ((array)$classman->find($find) as &$class) {
1127  self::$data[$classname.'s'][] = self::getter(
1128  $classname,
1129  $class
1130  );
1131  self::$data['count']++;
1132  unset($class);
1133  }
1134  }
1143  public static function delete($class, $id)
1144  {
1145  $classname = strtolower($class);
1146  $class = new $class($id);
1147  if (!$class->isValid()) {
1150  );
1151  }
1152  $class->destroy();
1153  self::$data = '';
1154  }
1163  public static function setErrorMessage($message, $code = false)
1164  {
1165  self::$data['error'] = $message;
1166  self::printer(self::$data, $code);
1167  }
1173  public static function getData()
1174  {
1175  $message = json_encode(
1176  self::$data,
1177  JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
1178  );
1179  self::$data = '';
1180  return $message;
1181  }
1190  public static function printer($data, $code = false)
1191  {
1192  $message = json_encode(
1193  $data,
1194  JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
1195  );
1196  if (false !== $code) {
1198  $code,
1199  $message
1200  );
1201  }
1204  $message
1205  );
1206  }
1216  public static function getter($classname, $class, $item = '')
1217  {
1218  if (!$class instanceof $classname) {
1219  return;
1220  }
1221  switch ($classname) {
1222  case 'host':
1223  $pass = $class->get('ADPass');
1225  if ($test_base64 = base64_decode($passtest)) {
1226  if (mb_detect_encoding($test_base64, 'utf-8', true)) {
1227  $pass = $test_base64;
1228  } elseif (mb_detect_encoding($passtest, 'utf-8', true)) {
1229  $pass = $passtest;
1230  }
1231  }
1232  $productKey = $class->get('productKey');
1234  if ($test_base64 = base64_decode($productKeytest)) {
1235  if (mb_detect_encoding($test_base64, 'utf-8', true)) {
1236  $productKey = $test_base64;
1237  } elseif (mb_detect_encoding($productKeytest, 'utf-8', true)) {
1239  }
1240  }
1242  $class->get(),
1243  array(
1244  'ADPass' => $pass,
1245  'productKey' => $productKey,
1246  'hostscreen' => $class->get('hostscreen')->get(),
1247  'hostalo' => $class->get('hostalo')->get(),
1248  'inventory' => self::getter(
1249  'inventory',
1250  $class->get('inventory')
1251  ),
1252  'image' => $class->get('imagename')->get(),
1253  'imagename' => $class->getImageName(),
1254  'pingstatus' => $class->getPingCodeStr(),
1255  'pingstatuscode' => (int)$class->get('pingstatus'),
1256  'pingstatustext' => socket_strerror((int)$class->get('pingstatus')),
1257  'primac' => $class->get('mac')->__toString(),
1258  'macs' => $class->getMyMacs()
1259  )
1260  );
1261  break;
1262  case 'inventory':
1264  $class->get(),
1265  array(
1266  'memory' => $class->getMem()
1267  )
1268  );
1269  break;
1270  case 'group':
1272  $class->get(),
1273  array(
1274  'hostcount' => $class->getHostCount()
1275  )
1276  );
1277  break;
1278  case 'image':
1280  $class->get(),
1281  array(
1282  'os' => $class->get('os')->get(),
1283  'imagepartitiontype' => $class->get('imagepartitiontype')->get(),
1284  'imagetype' => $class->get('imagetype')->get(),
1285  'imagetypename' => $class->getImageType()->get('name'),
1286  'imageparttypename' => $class->getImagePartitionType()->get(
1287  'name'
1288  ),
1289  'osname' => $class->getOS()->get('name'),
1290  'storagegroupname' => $class->getStorageGroup()->get('name')
1291  )
1292  );
1293  break;
1294  case 'snapin':
1296  $class->get(),
1297  array(
1298  'storagegroupname' => $class->getStorageGroup()->get('name')
1299  )
1300  );
1301  break;
1302  case 'storagenode':
1303  $extra = array();
1304  if ($item == 'all') {
1305  $extra = array(
1306  'logfiles' => (
1307  $class->get('online') ?
1308  $class->get('logfiles') :
1309  []
1310  ),
1311  'snapinfiles' => (
1312  $class->get('online') ?
1313  $class->get('snapinfiles') :
1314  []
1315  ),
1316  'images' => (
1317  $class->get('online') ?
1318  $class->get('images') :
1319  []
1320  )
1321  );
1322  } elseif (!empty($item)) {
1323  $extra = array(
1324  "$item" => (
1325  $class->get('online') ?
1326  $class->get($item) :
1327  []
1328  )
1329  );
1330  }
1332  $class->get(),
1333  $extra,
1334  array(
1335  'storagegroup' => self::getter(
1336  'storagegroup',
1337  $class->get('storagegroup')
1338  ),
1339  'clientload' => $class->getClientLoad(),
1340  'online' => $class->get('online')
1341  )
1342  );
1343  break;
1344  case 'storagegroup':
1346  $class->get(),
1347  array(
1348  'totalsupportedclients' => $class->getTotalSupportedClients(),
1349  'enablednodes' => $class->get('enablednodes'),
1350  'allnodes' => $class->get('allnodes')
1351  )
1352  );
1353  break;
1354  case 'task':
1356  $class->get(),
1357  array(
1358  'image' => $class->get('image')->get(),
1359  'host' => self::getter(
1360  'host',
1361  $class->get('host')
1362  ),
1363  'type' => $class->get('type')->get(),
1364  'state' => $class->get('state')->get(),
1365  'storagenode' => $class->get('storagenode')->get(),
1366  'storagegroup' => $class->get('storagegroup')->get()
1367  )
1368  );
1369  break;
1370  case 'plugin':
1372  $class->get(),
1373  array(
1374  'location' => $class->getPath(),
1375  'description' => $class->get('description'),
1376  'icon' => $class->getIcon(),
1377  'runinclude' => $class->getRuninclude(md5($class->get('name'))),
1378  'hash' => md5($class->get('name'))
1379  )
1380  );
1381  break;
1382  case 'imaginglog':
1384  $class->get(),
1385  array(
1386  'host' => self::getter(
1387  'host',
1388  $class->get('host')
1389  ),
1390  'image' => (
1391  $class->get('image')
1392  )
1393  )
1394  );
1395  unset($data['images']);
1396  break;
1397  case 'snapintask':
1399  $class->get(),
1400  array(
1401  'snapin' => $class->get('snapin')->get(),
1402  'snapinjob' => self::getter(
1403  'snapinjob',
1404  $class->get('snapinjob')
1405  ),
1406  'state' => $class->get('state')->get()
1407  )
1408  );
1409  break;
1410  case 'snapinjob':
1412  $class->get(),
1413  array(
1414  'host' => self::getter(
1415  'host',
1416  $class->get('host')
1417  ),
1418  'state' => $class->get('state')->get()
1419  )
1420  );
1421  break;
1422  case 'usertracking':
1424  $class->get(),
1425  array(
1426  'host' => self::getter(
1427  'host',
1428  $class->get('host')
1429  )
1430  )
1431  );
1432  break;
1433  case 'multicastsession':
1435  $class->get(),
1436  array(
1437  'imageID' => $class->get('image'),
1438  'image' => $class->get('imagename')->get(),
1439  'state' => $class->get('state')->get()
1440  )
1441  );
1442  unset($data['imagename']);
1443  break;
1444  case 'scheduledtask':
1446  $class->get(),
1447  array(
1448  (
1449  $class->isGroupBased() ?
1450  'group' :
1451  'host'
1452  ) => (
1453  $class->isGroupBased() ?
1454  self::getter(
1455  'group',
1456  $class->getGroup()
1457  ) :
1458  self::getter(
1459  'host',
1460  $class->getHost()
1461  )
1462  ),
1463  'tasktype' => $class->getTaskType()->get(),
1464  'runtime' => $class->getTime()
1465  )
1466  );
1467  break;
1468  case 'tasktype':
1470  $class->get(),
1471  array(
1472  'isSnapinTasking' => $class->isSnapinTasking()
1473  )
1474  );
1475  break;
1476  default:
1477  $data = $class->get();
1478  break;
1479  }
1480  self::$HookManager
1481  ->processEvent(
1482  'API_GETTER',
1483  array(
1484  'data' => &$data,
1485  'classname' => &$classname,
1486  'class' => &$class
1487  )
1488  );
1489  return $data;
1490  }
1499  public function names($class, $whereItems = [])
1500  {
1501  $data = [];
1502  $classname = strtolower($class);
1503  $classVars = self::getClass(
1504  $class,
1505  '',
1506  true
1507  );
1508 
1509  $sql = 'SELECT `'
1510  . $classVars['databaseFields']['id']
1511  . '`,`'
1512  . $classVars['databaseFields']['name']
1513  . '` FROM `'
1514  . $classVars['databaseTable']
1515  . '`';
1516 
1517  if (count($whereItems) > 0) {
1518  $where = '';
1519  foreach ($whereItems as $key => &$field) {
1520  if (!$where) {
1521  $where = ' WHERE `'
1522  . $classVars['databaseFields'][$key]
1523  . '`';
1524  } else {
1525  $where .= ' AND `'
1526  . $classVars['databaseFields'][$key]
1527  . '`';
1528  }
1529  if (is_array($field)) {
1530  $where .= " IN ('"
1531  . implode("','", $field)
1532  . "')";
1533  } else {
1534  $where .= " = '"
1535  . $field
1536  . "'";
1537  }
1538  }
1539  $sql .= $where;
1540  }
1541  $sql .= ' ORDER BY `'
1542  . (
1543  $classVars['databaseFields']['name'] ?:
1544  $classVars['databaseFields']['id']
1545  )
1546  . '` ASC';
1547  $vals = self::$DB->query($sql)->fetch('', 'fetch_all')->get();
1548  foreach ($vals as &$val) {
1549  $data[] = [
1550  'id' => $val[$classVars['databaseFields']['id']],
1551  'name' => $val[$classVars['databaseFields']['name']]
1552  ];
1553  unset($val);
1554  }
1555 
1556  self::$data = $data;
1557  }
1567  public function ids($class, $whereItems = [], $getField = 'id')
1568  {
1569  $data = [];
1570  $classname = strtolower($class);
1571  $classVars = self::getClass(
1572  $class,
1573  '',
1574  true
1575  );
1576  $vars = json_decode(
1577  file_get_contents('php://input')
1578  );
1579 
1580  $sql = 'SELECT `'
1581  . $classVars['databaseFields'][$getField]
1582  . '` FROM `'
1583  . $classVars['databaseTable']
1584  . '`';
1585 
1586  if (count($whereItems) > 0) {
1587  $where = '';
1588  foreach ($whereItems as $key => &$field) {
1589  if (!$where) {
1590  $where = ' WHERE `'
1591  . $classVars['databaseFields'][$key]
1592  . '`';
1593  } else {
1594  $where .= ' AND `'
1595  . $classVars['databaseFields'][$key]
1596  . '`';
1597  }
1598  if (is_array($field)) {
1599  $where .= " IN ('"
1600  . implode("','", $field)
1601  . "')";
1602  } else {
1603  $where .= " = '"
1604  . $field
1605  . "'";
1606  }
1607  }
1608  $sql .= $where;
1609  }
1610  $sql .= ' ORDER BY `'
1611  . (
1612  $classVars['databaseFields']['name'] ?:
1613  $classVars['databaseFields']['id']
1614  )
1615  . '` ASC';
1616  $vals = self::$DB->query($sql)->fetch('', 'fetch_all')->get();
1617  foreach ($vals as &$val) {
1618  $data[] = $val[$classVars['databaseFields'][$getField]];
1619  unset($val);
1620  }
1621  self::$data = $data;
1622  }
1631  public static function deletemass($class, $whereItems = [])
1632  {
1633  $data = [];
1634  $classname = strtolower($class);
1635  $classVars = self::getClass(
1636  $class,
1637  '',
1638  true
1639  );
1640  $vars = json_decode(
1641  file_get_contents('php://input')
1642  );
1643 
1644  $sql = 'DELETE FROM `'
1645  . $classVars['databaseTable']
1646  . '`';
1647 
1648  if (count($whereItems) > 0) {
1649  $where = '';
1650  foreach ($whereItems as $key => &$field) {
1651  if (!$where) {
1652  $where = ' WHERE `'
1653  . $classVars['databaseFields'][$key]
1654  . '`';
1655  } else {
1656  $where .= ' AND `'
1657  . $classVars['databaseFields'][$key]
1658  . '`';
1659  }
1660  if (is_array($field)) {
1661  $where .= " IN ('"
1662  . implode("','", $field)
1663  . "')";
1664  } else {
1665  $where .= " = '"
1666  . $field
1667  . "'";
1668  }
1669  }
1670  $sql .= $where;
1671  }
1672 
1673  return self::$DB->query($sql);
1674  }
1675 }
Route\cancel
static cancel($class, $id)
Definition: route.class.php:1018
Route\__construct
__construct()
Definition: route.class.php:141
exit
exit
Definition: download.php:102
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGBase\fastmerge
static fastmerge($array1)
Definition: fogbase.class.php:2415
Route\active
static active($class)
Definition: route.class.php:1104
TaskType
Definition: tasktype.class.php:23
Route\getter
static getter($classname, $class, $item='')
Definition: route.class.php:1216
HTTPResponseCodes\HTTP_NOT_IMPLEMENTED
const HTTP_NOT_IMPLEMENTED
Definition: httpresponsecodes.class.php:80
Route\indiv
static indiv($class, $id, $item='')
Definition: route.class.php:562
Route\setMatches
static setMatches()
Definition: route.class.php:317
$test
$test
Definition: freespace.php:37
HTTPResponseCodes\breakHead
static breakHead($code, $msg='')
Definition: httpresponsecodes.class.php:240
$exists
$exists
Definition: check_node_exists.php:26
Route\$router
static $router
Definition: route.class.php:41
Route\$validActiveTasks
static $validActiveTasks
Definition: route.class.php:129
$val
$val
Definition: check_node_exists.php:25
Route\$matches
static $matches
Definition: route.class.php:47
$passtest
$passtest
Definition: hostinfo.php:162
Route\$validTaskingClasses
static $validTaskingClasses
Definition: route.class.php:115
HTTPResponseCodes\HTTP_UNAUTHORIZED
const HTTP_UNAUTHORIZED
Definition: httpresponsecodes.class.php:51
Route\sendResponse
static sendResponse($code, $msg=false)
Definition: route.class.php:400
Route\search
static search($class, $item)
Definition: route.class.php:526
Route\task
static task($class, $id)
Definition: route.class.php:831
Route\_testToken
static _testToken()
Definition: route.class.php:355
AltoRouter
Route\deletemass
static deletemass($class, $whereItems=[])
Definition: route.class.php:1631
Task
Definition: task.class.php:23
Route\$validClasses
static $validClasses
Definition: route.class.php:59
Route\runMatches
static runMatches()
Definition: route.class.php:335
Route\getMatches
static getMatches()
Definition: route.class.php:326
HTTPResponseCodes\HTTP_SUCCESS
const HTTP_SUCCESS
Definition: httpresponsecodes.class.php:29
$TaskType
if(FOGCore::$useragent) if(! $Task->isValid()) $TaskType
Definition: hostinfo.php:33
Route\ids
ids($class, $whereItems=[], $getField='id')
Definition: route.class.php:1567
Route\names
names($class, $whereItems=[])
Definition: route.class.php:1499
Route\listdetails
static listdetails( $class, $item, $sortby='name', $bypass=false, $find=array())
Definition: route.class.php:508
Route\defineRoutes
static defineRoutes()
Definition: route.class.php:230
FOGBase\aesdecrypt
static aesdecrypt( $encdata, $key=false, $enctype='aes-128-cbc')
Definition: fogbase.class.php:1536
Route\$_token
static $_token
Definition: route.class.php:35
Route\setErrorMessage
static setErrorMessage($message, $code=false)
Definition: route.class.php:1163
FOGBase
Definition: fogbase.class.php:25
Group
Definition: group.class.php:23
$productKeytest
$productKeytest
Definition: hostinfo.php:171
Route\getData
static getData()
Definition: route.class.php:1173
Route\getsearchbody
static getsearchbody($class)
Definition: route.class.php:1076
HTTPResponseCodes\HTTP_INTERNAL_SERVER_ERROR
const HTTP_INTERNAL_SERVER_ERROR
Definition: httpresponsecodes.class.php:79
HTTPResponseCodes\HTTP_FORBIDDEN
const HTTP_FORBIDDEN
Definition: httpresponsecodes.class.php:53
Route
Definition: route.class.php:23
Route\listem
static listem( $class, $sortby='name', $bypass=false, $find=array(), $item='')
Definition: route.class.php:429
HTTPResponseCodes\HTTP_NOT_FOUND
const HTTP_NOT_FOUND
Definition: httpresponsecodes.class.php:54
Route\status
static status()
Definition: route.class.php:412
Route\$data
static $data
Definition: route.class.php:53
Route\_testAuth
static _testAuth()
Definition: route.class.php:371
$data
$data
Definition: freespace.php:47
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
FOGBase\$Host
static $Host
Definition: fogbase.class.php:312
$foglang
$foglang['Display']
Definition: text.php:22
Route\create
static create($class)
Definition: route.class.php:889
$msg
if($Host->isValid()) $msg
Definition: hostnameloop.php:42
$productKey
if($test_base64=base64_decode($passtest)) $productKey
Definition: hostinfo.php:170
Route\$_enabled
static $_enabled
Definition: route.class.php:29
$pass
$pass
Definition: hostinfo.php:161
FOGController\isValid
isValid()
Definition: fogcontroller.class.php:865
Route\printer
static printer($data, $code=false)
Definition: route.class.php:1190
HTTPResponseCodes\HTTP_EXPECTATION_FAILED
const HTTP_EXPECTATION_FAILED
Definition: httpresponsecodes.class.php:67
Route\edit
static edit($class, $id)
Definition: route.class.php:595