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)  

dashboardpage.class.php
Go to the documentation of this file.
1 <?php
22 class DashboardPage extends FOGPage
23 {
29  private static $_tftp = '';
35  private static $_bandwidthtime = 1;
41  private static $_nodeURLs = array();
47  private static $_nodeNames = array();
53  private static $_nodeOpts;
59  private static $_groupOpts;
65  public $node = 'home';
73  public function __construct($name = '')
74  {
75  $this->name = self::$foglang['Dashboard'];
76  parent::__construct($this->name);
77  $this->menu = array();
78  global $sub;
79  global $id;
80  $objName = 'StorageNode';
81  switch ($sub) {
82  case 'clientcount':
83  $this->obj = new StorageGroup($id);
84  break;
85  case 'diskusage':
86  $this->obj = new StorageNode($id);
87  break;
88  default:
89  $this->obj = new StorageNode();
90  }
91  if (self::$ajax) {
92  return;
93  }
94  $find = array(
95  'isEnabled' => 1,
96  'isGraphEnabled' => 1
97  );
99  'storagenode',
100  'name',
101  false,
102  $find
103  );
104  $Nodes = json_decode(
106  );
107  $Nodes = $Nodes->storagenodes;
108  foreach ((array)$Nodes as &$StorageNode) {
109  if (!self::getClass('StorageNode', $StorageNode->id)->get('online')) {
110  continue;
111  }
112  $ip = $StorageNode->ip;
113  $url = sprintf(
114  '%s/%s/',
115  $ip,
116  $StorageNode->webroot
117  );
118  $url = preg_replace(
119  '#/+#',
120  '/',
121  $url
122  );
123  $url = self::$httpproto.'://' . $url;
124  unset($ip);
125  self::$_nodeOpts[] = sprintf(
126  '<option value="%s" urlcall="%s">%s%s ()</option>',
127  $StorageNode->id,
128  sprintf(
129  '%sservice/getversion.php',
130  $url
131  ),
132  $StorageNode->name,
133  (
134  $StorageNode->isMaster ?
135  ' *' :
136  ''
137  )
138  );
139  self::$_nodeNames[] = $StorageNode->name;
140  self::$_nodeURLs[] = sprintf(
141  '%sstatus/bandwidth.php?dev=%s',
142  $url,
143  $StorageNode->interface
144  );
145  unset($StorageNode);
146  }
147  Route::listem('storagegroup');
148  $Groups = json_decode(
150  );
151  $Groups = $Groups->storagegroups;
152  foreach ((array)$Groups as &$StorageGroup) {
153  self::$_groupOpts .= sprintf(
154  '<option value="%s">%s</option>',
155  $StorageGroup->id,
156  $StorageGroup->name
157  );
158  unset($StorageGroup);
159  }
160  self::$_nodeOpts = implode((array)self::$_nodeOpts);
161  list(
162  self::$_bandwidthtime,
163  self::$_tftp
165  'Service',
166  array(
167  'name' => array(
168  'FOG_BANDWIDTH_TIME',
169  'FOG_TFTP_HOST'
170  )
171  ),
172  'value'
173  );
174  }
180  public function index()
181  {
182  $pendingInfo = '<i></i>'
183  . '&nbsp;%s&nbsp;%s <a href="?node=%s&sub=%s"><b>%s</b></a> %s';
184  $hostPend = sprintf(
185  $pendingInfo,
186  _('Pending hosts'),
187  _('Click'),
188  'host',
189  'pending',
190  _('here'),
191  _('to review.')
192  );
193  $macPend = sprintf(
194  $pendingInfo,
195  _('Pending macs'),
196  _('Click'),
197  'report',
198  'file&f=cGVuZGluZyBtYWMgbGlzdA==',
199  _('here'),
200  _('to review.')
201  );
202  $setMesg = '';
203  if (self::$pendingHosts > 0) {
204  $setMesg = $hostPend;
205  }
206  if (self::$pendingMACs > 0) {
207  if (empty($setMesg)) {
208  $setMesg = $macPend;
209  } else {
210  $setMesg .= "<br/>$macPend";
211  }
212  }
213  if (!empty($setMesg)) {
214  self::setMessage($setMesg);
215  }
216  $SystemUptime = self::$FOGCore->systemUptime();
217  $fields = array(
218  _('Username') => self::$FOGUser->get('name'),
219  _('Web Server') => filter_input(
220  INPUT_SERVER,
221  'SERVER_ADDR'
222  ),
223  _('Load Average') => $SystemUptime['load'],
224  _('System Uptime') => $SystemUptime['uptime']
225  );
226  $this->templates = array(
227  '${field}',
228  '${input}'
229  );
230  $this->attributes = array(
231  array('class' => 'col-xs-4'),
232  array('class' => 'col-xs-8')
233  );
234  array_walk($fields, $this->fieldsToData);
235  self::$HookManager
236  ->processEvent(
237  'DashboardData',
238  array(
239  'data' => &$this->data,
240  'templates' => &$this->templates,
241  'attributes' => &$this->attributes
242  )
243  );
244  // Dashboard boxes row.
245  echo '<div class="row">';
246  // Overview
247  echo '<div class="col-md-4">';
248  echo '<div class="panel panel-info">';
249  echo '<div class="panel-heading text-center">';
250  echo '<h4 class="title">';
251  echo _('System Overview');
252  echo '</h4>';
253  echo '<p class="category">';
254  echo _('Server information at a glance.');
255  echo '</p>';
256  echo '</div>';
257  echo '<div class="panel-body">';
258  $this->render();
259  echo '</div>';
260  echo '</div>';
261  unset(
262  $this->data,
263  $this->templates,
264  $this->attributes,
265  $fields,
266  $SystemUptime,
267  $tftp
268  );
269  echo '</div>';
270  // Activity
271  echo '<div class="col-md-4">';
272  echo '<div class="panel panel-info">';
273  echo '<div class="panel-heading text-center">';
274  echo '<h4 class="title">';
275  echo _('Storage Group Activity');
276  echo '</h4>';
277  echo '<p class="category">';
278  echo _('Selected groups\'s current activity');
279  echo '</p>';
280  echo '</div>';
281  echo '<div class="panel-body">';
282  echo '<div class="graph pie-graph fogdashbox" id="graph-activity"></div>';
283  echo '<div class="graph-selectors" id="graph-activity-selector">';
284  printf(
285  '<select name="groupsel">%s</select>',
286  self::$_groupOpts
287  );
288  echo '<div id="ActivityActive"></div>';
289  echo '<div id="ActivityQueued"></div>';
290  echo '<div id="ActivitySlots"></div>';
291  echo '</div>';
292  echo '</div>';
293  echo '</div>';
294  echo '</div>';
295  // Disk usage
296  echo '<div class="col-md-4">';
297  echo '<div class="panel panel-info">';
298  echo '<div class="panel-heading text-center">';
299  echo '<h4 class="title">';
300  echo _('Storage Node Disk Usage');
301  echo '</h4>';
302  echo '<p class="category">';
303  echo _('Selected node\'s disk usage');
304  echo '</p>';
305  echo '</div>';
306  echo '<div class="panel-body">';
307  echo '<a href="?node=hwinfo">';
308  echo '<div class="graph pie-graph fogdashbox" id="graph-diskusage"></div>';
309  echo '</a>';
310  echo '<div class="graph-selectors" id="diskusage-selector">';
311  printf(
312  '<select name="nodesel">%s</select>',
313  self::$_nodeOpts
314  );
315  echo '</div>';
316  echo '</div>';
317  echo '</div>';
318  echo '</div>';
319  echo '</div>';
320  // 30 day row.
321  echo '<div class="row">';
322  echo '<div class="col-xs-12">';
323  echo '<div class="panel panel-info">';
324  echo '<div class="panel-heading">';
325  echo '<div class="row text-center">';
326  echo '<h4 class="title">';
327  echo _('Imaging Over the last 30 days');
328  echo '</h4>';
329  echo '</div>';
330  echo '</div>';
331  echo '<div class="panel-body">';
332  echo '<div id="graph-30day" class="graph fogdashbox"></div>';
333  echo '<div class="fog-variable" id="Graph30dayData"></div>';
334  echo '</div>';
335  echo '</div>';
336  echo '</div>';
337  echo '</div>';
338  $datapointshour = 3600;
339  $datapointshalf = 1800;
340  $datapointsten = 600;
341  $datapointstwo = 120;
342  // 30 day row.
343  echo '<div class="row">';
344  echo '<div class="col-xs-12">';
345  printf(
346  '<input type="hidden" id="bandwidthUrls" type="hidden" value="%s"/>'
347  . '<input type="hidden" id="nodeNames" type="hidden" value="%s"/>',
348  implode(',', self::$_nodeURLs),
349  implode(',', self::$_nodeNames)
350  );
351  echo '<div class="panel panel-info">';
352  echo '<div class="panel-heading">';
353  echo '<h4 class="title">';
354  echo self::$foglang['Bandwidth'];
355  echo '</h4>';
356  echo '<div id="graph-bandwidth-filters-type">';
357  echo '<div class="col-xs-2">';
358  echo '<p class="category" id="graph-bandwidth-title">';
359  echo self::$foglang['Bandwidth'];
360  echo ' - ';
361  echo '<span>';
362  echo self::$foglang['Transmit'];
363  echo '</span>';
364  echo '</p>';
365  echo '</div>';
366  echo '<div class="col-xs-2">';
367  echo '<a href="#" id="graph-bandwidth-filters-transmit" '
368  . 'class="type-filters graph-filters active">';
369  echo self::$foglang['Transmit'];
370  echo '</a>';
371  echo '<a href="#" id="graph-bandwidth-filters-receive" class='
372  . '"type-filters graph-filters">';
373  echo self::$foglang['Receive'];
374  echo '</a>';
375  echo '</div>';
376  echo '</div>';
377  echo '<div class="row">';
378  echo '<div id="graph-bandwidth-filters-time">';
379  echo '<div class="col-xs-2">';
380  echo '<p class="category" id="graph-bandwidth-time">';
381  echo _('Time');
382  echo ' - ';
383  echo '<span>';
384  echo _('2 Minutes');
385  echo '</span>';
386  echo '</p>';
387  echo '</div>';
388  echo '<div class="col-xs-4">';
389  echo '<a href="#" rel="'
390  . $datapointstwo
391  . '" class="time-filters graph-filters active">';
392  echo _('2 Minutes');
393  echo '</a>';
394  echo '<a href="#" rel="'
395  . $datapointsten
396  . '" class="time-filters graph-filters">';
397  echo _('10 Minutes');
398  echo '</a>';
399  echo '<a href="#" rel="'
400  . $datapointshalf
401  . '" class="time-filters graph-filters">';
402  echo _('30 Minutes');
403  echo '</a>';
404  echo '<a href="#" rel="'
405  . $datapointshour
406  . '" class="time-filters graph-filters">';
407  echo _('1 Hour');
408  echo '</a>';
409  echo '</div>';
410  echo '</div>';
411  echo '</div>';
412  echo '</div>';
413  echo '<div class="panel-body">';
414  echo '<div id="graph-bandwidth" class="graph fogdashbox"></div>';
415  echo '</div>';
416  echo '</div>';
417  echo '</div>';
418  echo '</div>';
419  }
425  public function clientcount()
426  {
427  header('Content-type: application/json');
428  $ActivityActive = $ActivityQueued = $ActivityTotalClients = 0;
429  $ActivityTotalClients = $this->obj->getTotalAvailableSlots();
430  $ActivityQueued = $this->obj->getQueuedSlots();
431  $ActivityActive = $this->obj->getUsedSlots();
432  if (!$ActivityActive && !$ActivityTotalClients && !$ActivityQueued) {
433  $error = _('No activity information available for this group');
434  }
435  $data = [
436  '_labels' => [
437  _('Free'),
438  _('Queued'),
439  _('Active')
440  ],
441  'ActivityActive' => &$ActivityActive,
442  'ActivityQueued' => &$ActivityQueued,
443  'ActivitySlots' => &$ActivityTotalClients
444  ];
445  if ($error) {
446  $data['error'] = $error;
447  $data['title'] = _('No Data Available');
448  }
449  unset(
450  $ActivityActive,
451  $ActivityQueued,
452  $ActivityTotalClients
453  );
454  http_response_code(HTTPResponseCodes::HTTP_SUCCESS);
455  echo json_encode($data);
456  unset($data);
457  exit;
458  }
464  public function diskusage()
465  {
466  $url = sprintf(
467  '%s://%s/fog/status/freespace.php?path=%s',
468  self::$httpproto,
469  $this->obj->get('ip'),
470  base64_encode($this->obj->get('path'))
471  );
472  if (!$this->obj->get('online')) {
473  echo json_encode(
474  [
475  '_labels' => [
476  _('Free'),
477  _('used')
478  ],
479  'free' => 0,
480  'used' => 0,
481  'error' => _('Node is unavailable'),
482  'title' => _('Node Offline')
483  ]
484  );
485  exit;
486  }
487  $data = self::$FOGURLRequests
488  ->process($url);
489  $data = json_decode(
490  array_shift($data)
491  );
492  $datatmp = [
493  '_labels' => [
494  _('Free'),
495  _('Used')
496  ],
497  'free' => $data->free,
498  'used' => $data->used
499  ];
500  if ($data->error) {
501  $datatmp['error'] = $data->error;
502  $datatmp['title'] = $data->title;
503  }
504  unset($url);
505  http_response_code(HTTPResponseCodes::HTTP_SUCCESS);
506  echo json_encode($datatmp);
507  unset($data);
508  exit;
509  }
515  public function get30day()
516  {
517  session_write_close();
518  ignore_user_abort(true);
519  set_time_limit(0);
520  $start = self::niceDate()
521  ->setTime(00, 00, 00)
522  ->modify('-30 days');
523  $end = self::niceDate()
524  ->setTime(23, 59, 59);
525  $int = new DateInterval('P1D');
526  $period = new DatePeriod($start, $int, $end);
527  $dates = iterator_to_array($period);
528  unset(
529  $start,
530  $end,
531  $int,
532  $period
533  );
534  foreach ((array)$dates as $index => &$date) {
535  $count = self::getClass('ImagingLogManager')
536  ->count(
537  [
538  'start' => $date->format('Y-m-d%'),
539  'finish' => $date->format('Y-m-d%')
540  ],
541  'OR'
542  );
543  $data[] = [
544  ($date->getTimestamp() * 1000),
545  $count
546  ];
547  unset($date);
548  }
549  http_response_code(HTTPResponseCodes::HTTP_SUCCESS);
550  echo json_encode($data);
551  exit;
552  }
558  public function bandwidth()
559  {
560  header('Content-type: application/json');
561  $sent = filter_input(
562  INPUT_POST,
563  'url',
564  FILTER_DEFAULT,
565  FILTER_REQUIRE_ARRAY
566  );
567  $names = filter_input(
568  INPUT_POST,
569  'names',
570  FILTER_DEFAULT,
571  FILTER_REQUIRE_ARRAY
572  );
573  $urls = [];
574  foreach ((array)$sent as &$url) {
575  $urls[] = $url;
576  unset($url);
577  }
578  $urls = array_values(
579  array_filter($urls)
580  );
581  $datas = self::$FOGURLRequests->process($urls);
582  $dataSet = [];
583  foreach ((array)$datas as $i => &$data) {
584  $d = json_decode($data);
585  $data = [
586  'dev' => $d->dev,
587  'name' => $names[$i],
588  'rx' => $d->rx,
589  'tx' => $d->tx
590  ];
591  $dataSet[] = $data;
592  unset($data, $d);
593  }
594  http_response_code(HTTPResponseCodes::HTTP_SUCCESS);
595  echo json_encode($dataSet);
596  exit;
597  }
603  public function testUrls()
604  {
605  header('Content-type: application/json');
606  $sent = filter_input(
607  INPUT_POST,
608  'url',
609  FILTER_DEFAULT,
610  FILTER_REQUIRE_ARRAY
611  );
612  $names = filter_input(
613  INPUT_POST,
614  'names',
615  FILTER_DEFAULT,
616  FILTER_REQUIRE_ARRAY
617  );
618  $testurls = [];
619  foreach ((array)$sent as &$url) {
620  $testurls[] = parse_url($url, PHP_URL_HOST);
621  unset($url);
622  }
623  $tests = self::$FOGURLRequests->isAvailable($testurls, 1);
624  unset($testurls);
625  foreach ($tests as $index => &$test) {
626  if (!$test) {
627  unset(
628  $sent[$index],
629  $names[$index]
630  );
631  }
632  unset($test);
633  }
634  $names = array_values(
635  array_filter($names)
636  );
637 
638  $sent = array_values(
639  array_filter($sent)
640  );
641 
642  http_response_code(HTTPResponseCodes::HTTP_SUCCESS);
643  echo json_encode(
644  [
645  'names' => $names,
646  'urls' => $sent
647  ]
648  );
649  exit;
650  }
651 }
FOGBase\niceDate
static niceDate($date='now', $utc=false)
Definition: fogbase.class.php:1105
DashboardPage\get30day
get30day()
Definition: dashboardpage.class.php:515
FOGPage\render
render($colsize=9)
Definition: fogpage.class.php:605
exit
exit
Definition: download.php:102
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
$urls
$urls
Definition: mainversion.php:28
DashboardPage\$node
$node
Definition: dashboardpage.class.php:65
$test
$test
Definition: freespace.php:37
DashboardPage\bandwidth
bandwidth()
Definition: dashboardpage.class.php:558
FOGPage\$data
$data
Definition: fogpage.class.php:79
DashboardPage
Definition: dashboardpage.class.php:23
FOGPage\$name
$name
Definition: fogpage.class.php:31
DashboardPage\$_groupOpts
static $_groupOpts
Definition: dashboardpage.class.php:59
DashboardPage\index
index()
Definition: dashboardpage.class.php:180
StorageNode
Definition: storagenode.class.php:23
HTTPResponseCodes\HTTP_SUCCESS
const HTTP_SUCCESS
Definition: httpresponsecodes.class.php:29
DashboardPage\clientcount
clientcount()
Definition: dashboardpage.class.php:425
DashboardPage\testUrls
testUrls()
Definition: dashboardpage.class.php:603
FOGPage
Definition: fogpage.class.php:25
Route\getData
static getData()
Definition: route.class.php:1173
$count
$count
Definition: locationcheck.php:25
FOGPage\$id
$id
Definition: fogpage.class.php:43
Route\listem
static listem( $class, $sortby='name', $bypass=false, $find=array(), $item='')
Definition: route.class.php:429
DashboardPage\__construct
__construct($name='')
Definition: dashboardpage.class.php:73
DashboardPage\diskusage
diskusage()
Definition: dashboardpage.class.php:464
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
StorageGroup
Definition: storagegroup.class.php:23
DashboardPage\$_tftp
static $_tftp
Definition: dashboardpage.class.php:29
$foglang
$foglang['Display']
Definition: text.php:22
$url
$url
Definition: kernelvers.php:27
FOGBase\setMessage
static setMessage($txt, $data=array())
Definition: fogbase.class.php:784
DashboardPage\$_bandwidthtime
static $_bandwidthtime
Definition: dashboardpage.class.php:35
$ip
if(!(isset($_POST['ip']) &&is_string($_POST['ip']))) if(!(isset($_POST['file']) &&is_string($_POST['file']))) if(!(isset($_POST['lines']) &&is_numeric($_POST['lines']))) if(!(isset($_POST['reverse']) &&is_numeric($_POST['reverse']))) $ip
Definition: logtoview.php:149
DashboardPage\$_nodeNames
static $_nodeNames
Definition: dashboardpage.class.php:47
DashboardPage\$_nodeOpts
static $_nodeOpts
Definition: dashboardpage.class.php:53
DashboardPage\$_nodeURLs
static $_nodeURLs
Definition: dashboardpage.class.php:41