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)  

processlogin.class.php
Go to the documentation of this file.
1 <?php
22 class ProcessLogin extends FOGPage
23 {
29  private $_username;
35  private $_password;
41  private $_langMenu;
47  private $_lang;
55  public function __construct($name = '')
56  {
57  parent::__construct($name);
58  require __DIR__ . '/../../commons/text.php';
59  $this->_lang = self::$locale;
60  $this->setLang();
61  }
67  public function index()
68  {
69  if (self::$FOGUser->isValid()) {
70  self::redirect('../management/index.php?node=home');
71  }
72  }
78  private function _getLanguages()
79  {
80  $translang = $this->_transLang();
81  ob_start();
82  foreach ((array)self::$foglang['Language'] as &$lang) {
83  printf(
84  '<option value="%s"%s>%s</option>',
85  $lang,
86  ($translang == $lang ? ' selected' : ''),
87  $lang
88  );
89  unset($lang);
90  }
91  $this->_langMenu = ob_get_clean();
92  }
98  private function _defaultLang()
99  {
100  return $this->_lang;
101  }
107  private function _transLang()
108  {
109  switch ($this->_lang) {
110  case 'de_DE':
111  return self::$foglang['Language']['de'];
112  case 'en_US':
113  return self::$foglang['Language']['en'];
114  case 'es_ES':
115  return self::$foglang['Language']['es'];
116  case 'fr_FR':
117  return self::$foglang['Language']['fr'];
118  case 'it_IT':
119  return self::$foglang['Language']['it'];
120  case 'pt_BR':
121  return self::$foglang['Language']['pt'];
122  case 'zh_CN':
123  return self::$foglang['Language']['zh'];
124  default:
125  return self::$foglang['Language'][$this->_defaultLang()];
126  }
127  }
133  private function _specLang()
134  {
135  $ulang = filter_input(INPUT_POST, 'ulang');
136  if (isset($ulang)) {
137  $this->_lang = self::$locale = $ulang;
138  } else {
139  $this->_lang = self::$locale = $this->_transLang();
140  }
141  switch ($this->_lang) {
142  case self::$foglang['Language']['de']:
143  $this->_lang = self::$locale = 'de_DE';
144  break;
145  case self::$foglang['Language']['en']:
146  $this->_lang = self::$locale = 'en_US';
147  break;
148  case self::$foglang['Language']['es']:
149  $this->_lang = self::$locale = 'es_ES';
150  break;
151  case self::$foglang['Language']['fr']:
152  $this->_lang = self::$locale = 'fr_FR';
153  break;
154  case self::$foglang['Language']['it']:
155  $this->_lang = self::$locale = 'it_IT';
156  break;
157  case self::$foglang['Language']['pt']:
158  $this->_lang = self::$locale = 'pt_BR';
159  break;
160  case self::$foglang['Language']['zh']:
161  $this->_lang = self::$locale = 'zh_CN';
162  break;
163  default:
164  $this->_lang = self::$locale = $this->_transLang();
165  }
166  }
172  public function setLang()
173  {
174  $this->_specLang();
175  $domain = 'messages';
176  putenv('LANG=' . $this->_lang.'.UTF-8');
177  setlocale(
178  LC_ALL,
179  sprintf(
180  '%s.UTF-8',
181  $this->_lang
182  )
183  );
184  $path = __DIR__ . '/../../management/languages/';
185  bindtextdomain(
186  $domain,
187  $path
188  );
189  bind_textdomain_codeset(
190  $domain,
191  'UTF-8'
192  );
193  textdomain($domain);
194  }
200  private function _setRedirMode()
201  {
202  foreach ($_GET as $key => &$value) {
203  $redirect[$key] = $value;
204  unset($value);
205  }
206  unset($redirect['upass'], $redirect['uname'], $redirect['ulang']);
207  if (in_array($redirect['node'], array('login', 'logout'))) {
208  unset($redirect['node']);
209  }
210  foreach ((array)$redirect as $key => &$value) {
211  if (!$value) {
212  continue;
213  }
214  $http_query[$key] = $value;
215  unset($value);
216  }
217  if (count($http_query) < 1) {
218  unset($redirect['login']);
219  self::redirect('index.php');
220  }
221  $query = trim(http_build_query($http_query));
222  $redir = 'index.php';
223  if ($query) {
224  $redir .= "?$query";
225  }
226  self::redirect($redir);
227  }
233  public function processMainLogin()
234  {
235  global $currentUser;
236  $uname = filter_input(INPUT_POST, 'uname');
237  $upass = filter_input(INPUT_POST, 'upass');
238  $this->_username = $uname;
239  $this->_password = $upass;
240  $type = self::$FOGUser->get('type');
241  self::$HookManager
242  ->processEvent(
243  'USER_TYPE_HOOK',
244  array('type' => &$type)
245  );
246  if (!isset($_POST['login'])) {
247  return;
248  }
249  if (!$this->_username) {
250  self::setMessage(self::$foglang['InvalidLogin']);
251  self::redirect('index.php?node=logout');
252  }
253  self::$FOGUser = self::attemptLogin(
254  $this->_username,
255  $this->_password
256  );
257  if (!self::$FOGUser->isValid()) {
258  $this->_setRedirMode();
259  }
260  self::$HookManager
261  ->processEvent(
262  'LoginSuccess',
263  array(
264  'username' => $this->_username,
265  'password' => $this->_password
266  )
267  );
268  $this->_setRedirMode();
269  }
275  public function mainLoginForm()
276  {
277  $this->setLang();
278  global $node;
279  if (in_array($node, array('login', 'logout'))) {
280  if (session_status() != PHP_SESSION_NONE) {
281  self::setMessage($_SESSION['FOG_MESSAGES']);
282  }
283  unset($_GET['login']);
284  self::redirect('index.php');
285  }
286  $this->_getLanguages();
287  $logininfo = self::getSetting('FOG_LOGIN_INFO_DISPLAY');
288  $extra = '';
289  if ($logininfo) {
290  $extra = '<div id="login-form-info">'
291  . '<p>'
292  . self::$foglang['FOGSites']
293  . ': <b>'
294  . '<i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i>'
295  . '</b>'
296  . '</p>'
297  . '<p>'
298  . self::$foglang['LatestVer']
299  . ': <b>'
300  . '<i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i>'
301  . '</b>'
302  . '</p>'
303  . '<p>'
304  . self::$foglang['LatestDevVer']
305  . ': <b>'
306  . '<i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i>'
307  . '</b>'
308  . '</p>'
309  . '</div>';
310  }
311  // Login form
312  echo '<div class="form-signin">';
313  echo '<form class="form-horizontal" method="post" action="';
314  echo $this->formAction;
315  echo '">';
316  echo '<h3 class="form-signin-heading text-center">';
317  echo '<span class="col-xs-1">';
318  echo '<img src="../favicon.ico" class="logoimg" alt="'
319  . self::$foglang['Slogan']
320  . '"/>';
321  echo '</span>';
322  echo _('FOG Project');
323  echo '</h3>';
324  echo '<hr/>';
325  // Username
326  echo '<div class="form-group">';
327  echo '<label class="control-label col-md-2" for="uname">';
328  echo self::$foglang['Username'];
329  echo '</label>';
330  echo '<div class="col-md-10">';
331  echo '<input type="text" class="form-control" name="uname" '
332  . 'required="" autofocus="" id="uname"/>';
333  echo '</div>';
334  echo '</div>';
335  // Password
336  echo '<div class="form-group">';
337  echo '<label class="control-label col-md-2" for="upass">';
338  echo self::$foglang['Password'];
339  echo '</label>';
340  echo '<div class="col-md-10">';
341  echo '<input type="password" class="form-control" name="upass" '
342  . 'required="" id="upass"/>';
343  echo '</div>';
344  echo '</div>';
345  // Language
346  echo '<div class="form-group">';
347  echo '<label class="control-label col-md-2" for="ulang">';
348  echo self::$foglang['LanguagePhrase'];
349  echo '</label>';
350  echo '<div class="col-md-10">';
351  echo '<select class="form-control" name="ulang" id="ulang">';
352  echo $this->_langMenu;
353  echo '</select>';
354  echo '</div>';
355  echo '</div>';
356  // Submit button
357  echo '<div class="form-group">';
358  echo '<div class="col-md-offset-2 col-md-10">';
359  echo '<button class="btn btn-default btn-block" '
360  . 'type="submit" name="login">';
361  echo self::$foglang['Login'];
362  echo '</button>';
363  echo '</div>';
364  echo '</div>';
365  echo '</form>';
366  echo '<hr/>';
367  // Login information
368  echo '<div class="row">';
369  echo '<div class="form-group">';
370  echo $extra;
371  echo '</div>';
372  echo '</div>';
373  echo '</div>';
374  }
380  public static function getLocale()
381  {
382  $lang = explode('_', self::$locale);
383  $lang = $lang[0];
384  return $lang;
385  }
386 }
ProcessLogin\getLocale
static getLocale()
Definition: processlogin.class.php:380
ProcessLogin\$_password
$_password
Definition: processlogin.class.php:35
FOGPage\$formAction
$formAction
Definition: fogpage.class.php:141
ProcessLogin\$_username
$_username
Definition: processlogin.class.php:29
ProcessLogin\_defaultLang
_defaultLang()
Definition: processlogin.class.php:98
ProcessLogin\__construct
__construct($name='')
Definition: processlogin.class.php:55
FOGPage\$node
$node
Definition: fogpage.class.php:37
ProcessLogin\$_lang
$_lang
Definition: processlogin.class.php:47
ProcessLogin\index
index()
Definition: processlogin.class.php:67
FOGPage\$name
$name
Definition: fogpage.class.php:31
ProcessLogin\$_langMenu
$_langMenu
Definition: processlogin.class.php:41
FOGBase\$locale
static $locale
Definition: fogbase.class.php:31
$redirect
$redirect
Definition: dbrunning.php:27
FOGBase\attemptLogin
static attemptLogin($username, $password)
Definition: fogbase.class.php:2465
ProcessLogin\setLang
setLang()
Definition: processlogin.class.php:172
ProcessLogin
Definition: processlogin.class.php:23
ProcessLogin\_setRedirMode
_setRedirMode()
Definition: processlogin.class.php:200
FOGBase\redirect
static redirect($url='')
Definition: fogbase.class.php:831
FOGPage
Definition: fogpage.class.php:25
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
ProcessLogin\_specLang
_specLang()
Definition: processlogin.class.php:133
ProcessLogin\processMainLogin
processMainLogin()
Definition: processlogin.class.php:233
$foglang
$foglang['Display']
Definition: text.php:22
ProcessLogin\mainLoginForm
mainLoginForm()
Definition: processlogin.class.php:275
FOGBase\setMessage
static setMessage($txt, $data=array())
Definition: fogbase.class.php:784
FOGBase\getSetting
static getSetting($key)
Definition: fogbase.class.php:2063
ProcessLogin\_transLang
_transLang()
Definition: processlogin.class.php:107
ProcessLogin\_getLanguages
_getLanguages()
Definition: processlogin.class.php:78