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)  

init.php
Go to the documentation of this file.
1 <?php
34 class Initiator
35 {
41  private static $_sanitizeItems;
47  public function __construct()
48  {
57  self::$_sanitizeItems = function (&$val, &$key) use (&$value) {
58  if (is_string($val)) {
59  $value[$key] = htmlspecialchars(
60  $val,
61  ENT_QUOTES | ENT_HTML401,
62  'utf-8'
63  );
64  }
65  if (is_array($val)) {
66  array_walk($val, self::$_sanitizeItems);
67  }
68  unset($val, $key);
69  return $value;
70  };
74  $self = false === stripos(
75  filter_input(INPUT_SERVER, 'PHP_SELF'),
76  'service'
77  );
81  $useragent = false;
85  $useragent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
89  define('DS', addslashes(DIRECTORY_SEPARATOR));
90  define('BASEPATH', self::_determineBasePath());
94  $regext = '#^.*\.(report|event|class|hook)\.php$#';
98  $RecursiveDirectoryIterator = new RecursiveDirectoryIterator(
99  BASEPATH,
100  FileSystemIterator::SKIP_DOTS
101  );
105  $RecursiveIteratorIterator = new RecursiveIteratorIterator(
106  $RecursiveDirectoryIterator
107  );
111  $RegexIterator = new RegexIterator(
112  $RecursiveIteratorIterator,
113  $regext,
114  RegexIterator::GET_MATCH
115  );
119  $paths = iterator_to_array($RegexIterator, true);
120  unset(
121  $RecursiveDirectoryIterator,
122  $RecursiveIteratorIterator,
123  $RegexIterator
124  );
128  $allpaths = array();
132  foreach ((array)$paths as &$element) {
133  $allpaths[] = dirname($element[0]);
134  unset($element);
135  }
139  set_include_path(
140  sprintf(
141  '%s%s%s',
142  implode(
143  PATH_SEPARATOR,
144  $allpaths
145  ),
146  PATH_SEPARATOR,
147  get_include_path()
148  )
149  );
150  spl_autoload_extensions('.class.php,.event.php,.hook.php,.report.php');
154  spl_autoload_register();
161  $script = filter_input(INPUT_SERVER, 'SCRIPT_NAME');
162  if ($self
163  && $useragent
164  && file_exists(BASEPATH . $script)
165  && session_status() == PHP_SESSION_NONE
166  //&& false === stripos($script, '/api/')
167  ) {
168  session_start();
169  }
170  }
179  public static function storeInSession($key, $value)
180  {
184  if (session_status() != PHP_SESSION_NONE) {
185  return;
186  }
187  $_SESSION[$key] = $value;
188  }
196  public static function unsetSession($key)
197  {
198  if (session_status() != PHP_SESSION_NONE) {
199  return;
200  }
201  $_SESSION[$key] = ' ';
202  unset($_SESSION[$key]);
203  }
211  public static function getFromSession($key)
212  {
213  if (session_status() != PHP_SESSION_NONE) {
214  return;
215  }
216  return $_SESSION[$key];
217  }
225  public static function csrfGenToken($formname)
226  {
227  $token = FOGCore::createSecToken();
228  self::storeInSession($formname, $token);
229  }
235  private static function _determineBasePath()
236  {
237  return sprintf(
238  '%s%s',
239  dirname(__DIR__),
240  DS
241  );
242  }
248  public static function startInit()
249  {
253  error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
257  new self();
261  self::_verCheck();
265  self::_extCheck();
270  $globalVars = array(
271  'newService',
272  'json',
273  'node',
274  'sub',
275  'printertype',
276  'id',
277  'groupid',
278  'sub',
279  'crit',
280  'sort',
281  'confirm',
282  'tab',
283  'type',
284  );
288  foreach ($globalVars as &$x) {
289  global $$x;
290  if (isset($_REQUEST[$x])) {
291  $_REQUEST[$x] = $$x = trim($_REQUEST[$x]);
292  }
293  unset($x);
294  }
298  new System();
302  new Config();
303  }
311  public static function sanitizeItems(&$value = '')
312  {
318  if (!count((array)$value)) {
319  $process = array(
320  &$_GET,
321  &$_POST,
322  &$_COOKIE,
323  &$_REQUEST,
324  &$_SESSION
325  );
326  array_walk($process, self::$_sanitizeItems);
327  } else {
328  if (is_array($value)) {
329  array_walk($value, self::$_sanitizeItems);
330  } else {
331  $value = htmlspecialchars(
332  $value,
333  ENT_QUOTES | ENT_HTML401,
334  'utf-8'
335  );
336  }
337  }
338  return $value;
339  }
345  private static function _verCheck()
346  {
347  try {
351  if (!version_compare(phpversion(), '5.5.0', '>=')) {
352  throw new Exception(
353  sprintf(
354  'FOG Requires PHP v5.5.0 or higher. You have PHP v%s',
355  phpversion()
356  )
357  );
358  }
359  } catch (Exception $e) {
360  echo $e->getMessage();
361  exit;
362  }
363  }
370  private static function _extCheck()
371  {
375  $requiredExtensions = array(
376  'gettext',
377  'mysqli'
378  );
382  $loadedExtensions = get_loaded_extensions();
386  $has = array_intersect(
387  $requiredExtensions,
388  $loadedExtensions
389  );
393  if (count($has) < count($requiredExtensions)) {
394  throw new Exception(_('Missing one or more extensions.'));
395  }
396  }
404  public static function sanitizeOutput($buffer)
405  {
409  $search = array(
410  '/>[^\S ]+/s', //strip whitespaces after tags, except space
411  '/[^\S ]+</s', //strip whitespaces before tags, except space
412  '/(\s)+/s', // shorten multiple whitespace sequences
413  );
417  $replace = array(
418  '>',
419  '<',
420  '\\1',
421  );
425  $buffer = preg_replace(
426  $search,
427  $replace,
428  $buffer
429  );
433  return $buffer;
434  }
435 }
Initiator\_extCheck
static _extCheck()
Definition: init.php:370
exit
exit
Definition: download.php:102
Initiator\getFromSession
static getFromSession($key)
Definition: init.php:211
Initiator\sanitizeOutput
static sanitizeOutput($buffer)
Definition: init.php:404
$val
$val
Definition: check_node_exists.php:25
Initiator\storeInSession
static storeInSession($key, $value)
Definition: init.php:179
Initiator\unsetSession
static unsetSession($key)
Definition: init.php:196
System
Definition: system.class.php:25
Initiator\csrfGenToken
static csrfGenToken($formname)
Definition: init.php:225
Initiator\_determineBasePath
static _determineBasePath()
Definition: init.php:235
Initiator\sanitizeItems
static sanitizeItems(&$value='')
Definition: init.php:311
Initiator\startInit
static startInit()
Definition: init.php:248
Initiator
Definition: init.php:35
FOGBase\createSecToken
static createSecToken()
Definition: fogbase.class.php:1445
$paths
$paths
Definition: getfiles.php:37
Initiator\$_sanitizeItems
static $_sanitizeItems
Definition: init.php:41
Initiator\__construct
__construct()
Definition: init.php:47
$process
$process
Definition: logtoview.php:179
Initiator\_verCheck
static _verCheck()
Definition: init.php:345