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)  

pluginmanagementpage.class.php
Go to the documentation of this file.
1 <?php
23 {
29  private static $_plugintype = 'activate';
35  private static $_plugins = array();
41  public $node = 'plugin';
49  public function __construct($name = '')
50  {
51  $this->name = 'Plugin Management';
52  parent::__construct($this->name);
53  Route::listem('plugin');
54  self::$_plugins = json_decode(
56  );
57  self::$_plugins = self::$_plugins->plugins;
58  $this->menu = array(
59  'home'=>self::$foglang['Home'],
60  'activate'=>self::$foglang['ActivatePlugins'],
61  'install'=>self::$foglang['InstallPlugins'],
62  'installed'=>self::$foglang['InstalledPlugins'],
63  );
64  self::$HookManager->processEvent(
65  'SUB_MENULINK_DATA',
66  array(
67  'menu' => &$this->menu,
68  'submenu' => &$this->subMenu,
69  'id' => &$this->id,
70  'notes' => &$this->notes
71  )
72  );
73  $this->headerData = array(
74  _('Plugin Name'),
75  _('Description'),
76  _('Location'),
77  );
78  $this->templates = array(
79  '<a href="?node=plugin&sub=${type}&run=${encname}&${type}'
80  . '=${encname}" class="icon" title="Plugin: ${name}">${icon}'
81  . '<br/><small>${name}</small></a>',
82  '${desc}',
83  '${location}',
84  );
85  $this->attributes = array(
86  array(
87  'width' => 66,
88  'height' => 66
89  ),
90  array('class' => 'col-xs-8'),
91  array('class' => 'col-xs-3'),
92  );
93  global $sub;
94  $subs = array('installed', 'install');
95  if (in_array($sub, $subs)) {
96  array_unshift(
97  $this->headerData,
98  '<label for="toggler">'
99  . '<input type="checkbox" name="toggle-checkbox" '
100  . 'class="toggle-checkboxAction" id="toggler"/>'
101  . '</label>'
102  );
103  array_unshift(
104  $this->templates,
105  '<label for="pluginrm-${name}">'
106  . '<input type="checkbox" name="pluginrm[]" '
107  . 'value="${id}" class="toggle-action" id="pluginrm-${name}"/>'
108  . '</label>'
109  );
110  array_unshift(
111  $this->attributes,
112  array(
113  'class' => 'filter-false form-group',
114  'width' => 16
115  )
116  );
117  }
125  self::$returnData = function (&$Plugin) {
126  switch (self::$_plugintype) {
127  case 'install':
128  if (!$Plugin->state || $Plugin->installed) {
129  return;
130  }
131  break;
132  case 'installed':
133  if (!$Plugin->state || !$Plugin->installed) {
134  return;
135  }
136  break;
137  case 'activate':
138  if ($Plugin->state || $Plugin->installed) {
139  return;
140  }
141  break;
142  }
143  $this->data[] = array(
144  'type' => self::$_plugintype,
145  'encname' => md5($Plugin->name),
146  'id' => $Plugin->id,
147  'name' => $Plugin->name,
148  'icon' => $Plugin->icon,
149  'desc' => $Plugin->description,
150  'location' => $Plugin->location
151  );
152  unset($Plugin);
153  };
154  }
160  public function index()
161  {
162  $this->activate();
163  }
169  public function activate()
170  {
171  $this->title = _('Activate Plugins');
172  self::$_plugintype = 'activate';
173  array_walk(self::$_plugins, static::$returnData);
174  self::$HookManager->processEvent(
175  'PLUGIN_DATA',
176  array(
177  'headerData' => &$this->headerData,
178  'data' => &$this->data,
179  'templates' => &$this->templates,
180  'attributes' => &$this->attributes
181  )
182  );
183  echo '<div class="col-xs-9">';
184  $this->indexDivDisplay();
185  echo '</div>';
186  $activate = filter_input(INPUT_GET, 'activate');
187  if ($activate) {
188  self::getClass('Plugin')->activatePlugin($activate);
189  self::redirect($this->formAction);
190  }
191  }
197  public function install()
198  {
199  $this->title = _('Install Plugins');
200  self::$_plugintype = 'install';
201  array_walk(self::$_plugins, static::$returnData);
202  self::$HookManager->processEvent(
203  'PLUGIN_DATA',
204  array(
205  'headerData' => &$this->headerData,
206  'data' => &$this->data,
207  'templates' => &$this->templates,
208  'attributes' => &$this->attributes
209  )
210  );
211  $runset = trim(
212  filter_input(INPUT_GET, 'run')
213  );
214  echo '<div class="col-xs-9">';
215  if ($runset) {
216  $this->indexDivDisplay();
217  foreach (self::$_plugins as &$Plugin) {
218  $hash = trim($Plugin->hash);
219  $name = $Plugin->name;
220  if ($hash !== $runset) {
221  continue;
222  }
223  list(
224  $name,
225  $runner
226  ) = $Plugin->runinclude;
227  if (!file_exists($runner)) {
228  $this->run($Plugin);
229  echo '</div>';
230  return;
231  }
232  include $runner;
233  break;
234  unset($Plugin);
235  }
236  }
237  $this->indexDivDisplay(true, false, true);
238  echo '</div>';
239  }
245  public function installed()
246  {
247  $this->title = _('Installed Plugins');
248  self::$_plugintype = 'installed';
249  array_walk(self::$_plugins, static::$returnData);
250  self::$HookManager->processEvent(
251  'PLUGIN_DATA',
252  array(
253  'headerData' => &$this->headerData,
254  'data' => &$this->data,
255  'templates' => &$this->templates,
256  'attributes' => &$this->attributes
257  )
258  );
259  $runset = trim(
260  filter_input(INPUT_GET, 'run')
261  );
262  echo '<div class="col-xs-9">';
263  if ($runset) {
264  $this->indexDivDisplay();
265  foreach (self::$_plugins as &$Plugin) {
266  $hash = trim($Plugin->hash);
267  $name = $Plugin->name;
268  if ($hash !== $runset) {
269  continue;
270  }
271  list(
272  $name,
273  $runner
274  ) = $Plugin->runinclude;
275  if (!file_exists($runner)) {
276  $this->run($Plugin);
277  echo '</div>';
278  return;
279  }
280  include $runner;
281  break;
282  unset($Plugin);
283  }
284  }
285  $this->indexDivDisplay(true, false, true);
286  echo '</div>';
287  }
295  public function run($plugin)
296  {
297  try {
298  if (!$plugin) {
299  throw new Exception(_('Unable to determine plugin details.'));
300  }
301  $this->title = _('Plugin')
302  . ' '
303  . $plugin->name;
304  unset(
305  $this->data,
306  $this->form,
307  $this->headerData,
308  $this->templates,
309  $this->attributes
310  );
311  $this->templates = array(
312  '${field}',
313  '${input}'
314  );
315  $this->attributes = array(
316  array('class' => 'col-xs-4'),
317  array('class' => 'col-xs-8 form-group')
318  );
319  $fields = array(
320  _('Plugin Description') => $plugin->description
321  );
322  if (!$plugin->installed) {
323  $fields = self::fastmerge(
324  (array)$fields,
325  array(
326  _('Plugin Installation') => _('This plugin is not installed')
327  . ', '
328  . _('would you ilke to install it now')
329  . '?'
330  ),
331  array(
332  '<label for="installplugin">'
333  . _('Install Plugin')
334  . '</label>' => '<button class="btn btn-info btn-block" '
335  . 'id="installplugin" name="installplugin" type="submit">'
336  . _('Install')
337  . '</button>'
338  )
339  );
340  array_walk($fields, $this->fieldsToData);
341  echo '<form class="form-horizontal" method="post" action="'
342  . $this->formAction
343  . '&run='
344  . $plugin->hash
345  . '">';
346  $this->indexDivDisplay(true, false, true);
347  echo '</form>';
348  } else {
349  array_walk($fields, $this->fieldsToData);
350  $this->indexDivDisplay(true, false, true);
351  $run = filter_input(INPUT_GET, 'run');
352  if ('capone' === $plugin->name && $run === $plugin->hash) {
353  echo '<form class="form-horizontal" method="post" action="'
354  . $this->formAction
355  . '&run='
356  . $plugin->hash
357  . '">';
358  $dmiFields = array(
359  'bios-vendor',
360  'bios-version',
361  'bios-release-date',
362  'system-manufacturer',
363  'system-product-name',
364  'system-version',
365  'system-serial-number',
366  'system-uuid',
367  'baseboard-manufacturer',
368  'baseboard-product-name',
369  'baseboard-version',
370  'baseboard-serial-number',
371  'baseboard-asset-tag',
372  'chassis-manufacturer',
373  'chassis-type',
374  'chassis-version',
375  'chassis-serial-number',
376  'chassis-asset-tag',
377  'processor-family',
378  'processor-manufacturer',
379  'processor-version',
380  'processor-frequency',
381  );
382  $actionFields = array(
383  _('Reboot after deploy'),
384  _('Shutdown after deploy'),
385  );
386  unset(
387  $this->data,
388  $this->form,
389  $this->headerData,
390  $this->templates,
391  $this->attributes
392  );
393  $this->title = _('Basic Settings');
394  $this->templates = array(
395  '${field}',
396  '${input}'
397  );
398  $this->attributes = array(
399  array('class' => 'col-xs-4'),
400  array('class' => 'col-xs-8 form-group')
401  );
402  list(
403  $dmifield,
404  $shutdown
406  'Service',
407  array(
408  'name' => array(
409  'FOG_PLUGIN_CAPONE_DMI',
410  'FOG_PLUGIN_CAPONE_SHUTDOWN',
411  )
412  ),
413  'value'
414  );
415  $dmiSel = self::selectForm(
416  'dmifield',
417  $dmiFields,
418  $dmifield
419  );
420  $actionSel = self::selectForm(
421  'shutdown',
422  $actionFields,
423  $shutdown,
424  true
425  );
426  $fields = array(
427  '<label for="dmifield">'
428  . _('DMI Field')
429  . '</label>' => $dmiSel,
430  '<label for="shutdown">'
431  . _('After image Action')
432  . '</label>' => $actionSel,
433  '<label for="basics">'
434  . _('Make Changes?')
435  . '</label>' => '<button class="btn btn-info btn-block" '
436  . 'name="basics" id="basics">'
437  . _('Update')
438  . '</button>'
439  );
440  array_walk($fields, $this->fieldsToData);
441  $this->indexDivDisplay();
442  unset(
443  $fields,
444  $this->data,
445  $this->form,
446  $this->headerData
447  );
448  $images = self::getClass('ImageManager')->buildSelectBox();
449  $this->title = _('Image Associations');
450  $fields = array(
451  '<label for="image">'
452  . _('Image Definition')
453  . '</label>' => $images,
454  '<label for="dmiresult">'
455  . _('DMI Result')
456  . '</label>' => '<div class="input-group">'
457  . '<input class="form-control" '
458  . 'type="text" name="key" id="dmiresult"/>'
459  . '</div>',
460  '<label for="addass">'
461  . _('Make Changes?')
462  . '</label>' => '<button class="btn btn-info btn-block" '
463  . 'name="addass" id="addass">'
464  . _('Update')
465  . '</button>'
466  );
467  array_walk($fields, $this->fieldsToData);
468  $this->indexDivDisplay();
469  unset(
470  $fields,
471  $images,
472  $this->data,
473  $this->form,
474  $this->headerData
475  );
476  $this->title = _('Image to DMI Mappings');
477  $this->headerData = array(
478  '<label for="toggler">'
479  . '<input type="checkbox" name="toggle-checkbox" '
480  . 'id="checkAll"/>'
481  . '</label>',
482  _('Image Name'),
483  _('OS Name'),
484  _('DMI Key')
485  );
486  $this->templates = array(
487  '<label for="kill-${id}">'
488  . '<input type="checkbox" name="kill[]" value="${id}" '
489  . 'id="kill-${id}" class="checkboxes"/>'
490  . '</label>',
491  '<a href="?node=image&sub=edit&id=${image_id}">'
492  . '${image_name}'
493  . '</a>',
494  '${os_name}',
495  '${capone_key}'
496  );
497  $this->attributes = array(
498  array(
499  'width' => 16,
500  'class' => 'filter-false'
501  ),
502  array(),
503  array(),
504  array(),
505  );
506  Route::listem('capone');
507  $Capones = json_decode(
509  );
510  $Capones = $Capones->capones;
511  foreach ($Capones as &$Capone) {
512  $this->data[] = array(
513  'image_name' => $Capone->image->name,
514  'image_id' => $Capone->image->id,
515  'os_name' => $Capone->os->name,
516  'capone_key' => $Capone->key,
517  'id' => $Capone->id
518  );
519  unset($Capone);
520  }
521  echo '<div class="panel panel-info">';
522  echo '<div class="panel-heading text-center">';
523  echo '<h4 class="title">';
524  echo $this->title;
525  echo '</h4>';
526  echo '</div>';
527  echo '<div class="panel-body">';
528  echo '<div class="panel panel-info">';
529  echo '<div class="panel-heading text-center">';
530  echo '<h4 class="title">';
531  echo _('Current Associations');
532  echo '</h4>';
533  echo '</div>';
534  echo '<div class="panel-body">';
535  $this->render(12);
536  echo '</div>';
537  echo '</div>';
538  unset(
539  $this->data,
540  $this->form,
541  $this->headerData,
542  $this->templates,
543  $this->attributes
544  );
545  $this->templates = array(
546  '${field}',
547  '${input}'
548  );
549  $this->attributes = array(
550  array('class' => 'col-xs-4'),
551  array('class' => 'col-xs-8 form-group')
552  );
553  $fields = array(
554  '<label for="delcapone">'
555  . _('Remove Selected?')
556  . '</label>' => '<button class="btn btn-danger btn-block" '
557  . 'type="submit" name="rmAssocs" id="delcapone">'
558  . _('Delete')
559  . '</button>'
560  );
561  array_walk($fields, $this->fieldsToData);
562  echo '<div class="panel panel-warning">';
563  echo '<div class="panel-heading text-center">';
564  echo '<h4 class="title">';
565  echo _('Remove Associations');
566  echo '</h4>';
567  echo '</div>';
568  echo '<div class="panel-body">';
569  $this->render(12);
570  echo '</div>';
571  echo '</div>';
572  echo '</div>';
573  echo '</div>';
574  echo '</form>';
575  }
576  }
577  } catch (Exception $e) {
578  echo self::setMessage($e->getMessage());
579  global $sub;
580  global $node;
581  $run = filter_input(INPUT_GET, 'run');
582  $url = sprintf(
583  '?node=%s&sub=%s&run=%s',
584  $node,
585  $sub,
586  $run
587  );
589  }
590  }
596  public function installPost()
597  {
598  $this->installedPost();
599  }
605  public function installedPost()
606  {
607  $run = filter_input(INPUT_GET, 'run');
608  $this->formAction .= '&run='
609  . $run;
610  list(
611  $pluginname,
612  $entrypoint
613  ) = self::getClass('Plugin')->getRunInclude($run);
614  $Plugin = self::getClass('Plugin')
615  ->set('name', $pluginname)
616  ->load('name');
617  try {
618  if (!$Plugin->isValid()) {
619  throw new Exception(_('Invalid Plugin Passed'));
620  }
621  if (isset($_POST['installplugin'])) {
622  if (!$Plugin->getManager()->install($pluginname)) {
623  $msg = sprintf(
624  '%s %s',
625  _('Failed to install plugin'),
626  $pluginname
627  );
628  throw new Exception($msg);
629  }
630  $Plugin
631  ->set('installed', 1)
632  ->set('version', 1);
633  if (!$Plugin->save()) {
634  $msg = sprintf(
635  '%s %s',
636  _('Failed to save plugin'),
637  $pluginname
638  );
639  throw new Exception($msg);
640  }
641  $this->formAction = sprintf(
642  '?node=plugin&sub=installed&run=%s',
643  $run
644  );
645  throw new Exception(_('Plugin Installed!'));
646  }
647  if (isset($_POST['basics'])) {
648  $dmifield = filter_input(INPUT_POST, 'dmifield');
649  $shutdown = (int)filter_input(INPUT_POST, 'shutdown');
650  self::getClass('Service')
651  ->set('name', 'FOG_PLUGIN_CAPONE_DMI')
652  ->load('name')
653  ->set('value', $dmifield)
654  ->save();
655  self::getClass('Service')
656  ->set('name', 'FOG_PLUGIN_CAPONE_SHUTDOWN')
657  ->load('name')
658  ->set('value', $shutdown)
659  ->save();
660  }
661  if (isset($_POST['addass'])) {
662  $key = filter_input(INPUT_POST, 'key');
663  $image = (int)filter_input(INPUT_POST, 'image');
664  $Image = new Image($image);
665  if (!$Image->isValid()) {
666  throw new Exception(_('Must have an image associated'));
667  }
668  $OS = $Image->getOS();
669  $Capone = self::getClass('Capone')
670  ->set('imageID', $image)
671  ->set('osID', $OS->get('id'))
672  ->set('key', $key);
673  if (!$Capone->save()) {
674  throw new Exception(_('Failed to save assignment'));
675  }
676  throw new Exception(_('Assignment saved successfully'));
677  }
678  if (isset($_POST['rmAssocs'])) {
679  $kill = filter_input_array(
680  INPUT_POST,
681  array(
682  'kill' => array(
683  'flags' => FILTER_REQUIRE_ARRAY
684  )
685  )
686  );
687  $kill = $kill['kill'];
688  self::getClass('CaponeManager')
689  ->destroy(array('id' => $kill));
690  if (count($kill) !== 1) {
691  throw new Exception(_('Destroyed assignments'));
692  } else {
693  throw new Exception(_('Destroyed assignment'));
694  }
695  }
696  } catch (Exception $e) {
697  self::setMessage($e->getMessage());
698  }
699  self::redirect($this->formAction);
700  }
701 }
PluginManagementPage\__construct
__construct($name='')
Definition: pluginmanagementpage.class.php:49
PluginManagementPage\$_plugins
static $_plugins
Definition: pluginmanagementpage.class.php:35
FOGPage\render
render($colsize=9)
Definition: fogpage.class.php:605
FOGPage\selectForm
static selectForm( $name, $items=array(), $selected='', $useidsel=false, $addClass='')
Definition: fogpage.class.php:4052
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGBase\fastmerge
static fastmerge($array1)
Definition: fogbase.class.php:2415
FOGPage\$title
$title
Definition: fogpage.class.php:49
PluginManagementPage\$node
$node
Definition: pluginmanagementpage.class.php:41
Image
Definition: image.class.php:23
PluginManagementPage\run
run($plugin)
Definition: pluginmanagementpage.class.php:295
PluginManagementPage\install
install()
Definition: pluginmanagementpage.class.php:197
FOGPage\$name
$name
Definition: fogpage.class.php:31
PluginManagementPage\activate
activate()
Definition: pluginmanagementpage.class.php:169
FOGPage\indexDivDisplay
indexDivDisplay( $delNeeded=false, $storage=false, $actionbox=false)
Definition: fogpage.class.php:4222
PluginManagementPage\index
index()
Definition: pluginmanagementpage.class.php:160
PluginManagementPage\installed
installed()
Definition: pluginmanagementpage.class.php:245
PluginManagementPage\$_plugintype
static $_plugintype
Definition: pluginmanagementpage.class.php:29
PluginManagementPage\installPost
installPost()
Definition: pluginmanagementpage.class.php:596
FOGBase\redirect
static redirect($url='')
Definition: fogbase.class.php:831
FOGPage
Definition: fogpage.class.php:25
Route\getData
static getData()
Definition: route.class.php:1173
Route\listem
static listem( $class, $sortby='name', $bypass=false, $find=array(), $item='')
Definition: route.class.php:429
PluginManagementPage\installedPost
installedPost()
Definition: pluginmanagementpage.class.php:605
$Image
$Image
Definition: hostinfo.php:37
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
$foglang
$foglang['Display']
Definition: text.php:22
$msg
if($Host->isValid()) $msg
Definition: hostnameloop.php:42
$url
$url
Definition: kernelvers.php:27
FOGBase\setMessage
static setMessage($txt, $data=array())
Definition: fogbase.class.php:784
PluginManagementPage
Definition: pluginmanagementpage.class.php:23