13 protected $log=array();
14 protected $status=array();
16 public function __construct($DBHost,$DBName,$DBUser,$DBPass)
18 parent::__construct($DBHost,$DBName,$DBUser,$DBPass);
19 $this->
log[
'server']=$_SERVER[
'SERVER_NAME'];
20 $this->
log[
'request']=$_SERVER[
'REQUEST_URI'];
21 $this->
log[
'port']=$_SERVER[
'REMOTE_PORT'];
22 $this->
log[
'agent']=$_SERVER[
'HTTP_USER_AGENT'];
23 $this->
log[
'referer']=$_SERVER[
'HTTP_REFERER'];
24 $this->
log[
'external_ip']=$_SERVER[
'REMOTE_ADDR'];
26 'called'=>$_POST[
'atype'],
27 'date'=>date(
'Y-m-d'),
32 $this->
log[
'database']=array(
'host'=>$this->DBHost,
33 'name'=>$this->DBName,
34 'user'=>$this->DBUser,
35 'pass'=>$this->DBPass);
40 die(
"<b>login.management.logman: MySQL connection failed!</b>".mysql_error());
66 $this->createTable(
"users");
67 $email=$this->output(
"`function`='superemail'",
"`id` ASC",1);
68 $name=$this->output(
"`function`='superuser'",
"`id` ASC",1);
69 $pass=$this->output(
"`function`='superpass'",
"`id` ASC",1);
70 $this->
createSuperUser($email[
'line'][0][0],$name[
'line'][0][0],$pass[
'line'][0][0]);
87 final public function editPerm($login=null,$perm=null)
91 if((is_numeric($perm))&&($perm<=1111))
93 $this->
set(
"perm",$perm);
94 $this->update(
"`login`=".$this->
log[
'user']);
95 unset($this->
log[
'perm']);
96 $this->
log[
'perm']=$perm;
97 return $this->
log[
'perm'];
106 $this->
set(
"perm",$perm);
107 $this->update(
"`login`=".$login);
118 return $this->
log[
'perm'];
131 if(filter_var($email,FILTER_VALIDATE_EMAIL))
133 $user=$this->output(
"`login`='".$name.
"'",
"`id` ASC",1);
134 if($user[
'line'][1][0]==null)
138 $this->insert(
"'first_use',0,'".strtolower($name).
"','".$pass.
"','".strtolower($email).
"','','',1111,'".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"','".$this->
log[
'agent'].
"',DATE(NOW()),TIME(NOW())");
139 $this->status[
'status']=
'ok';
140 $this->status[
'code']=200;
144 $this->status[
'status']=
'failed';
145 $this->status[
'code']=417;
150 $this->status[
'status']=
'exist';
151 $this->status[
'code']=409;
156 $this->status[
'status']=
'invalid';
157 $this->status[
'code']=403;
159 return $this->status;
172 if(filter_var($_POST[
'email'],FILTER_VALIDATE_EMAIL))
174 $user=$this->output(
"`login`='".$_POST[
'email'].
"'",
"`id` ASC",1);
175 if($user[
'line'][1][0]==null)
179 $this->insert(
"'first_use',0,'".strtolower($_POST[
'email']).
"',MD5('".$_POST[
'pass'].
"'),'".strtolower($_POST[
'email']).
"','".$this->
clean(ucwords(strtolower($_POST[
'fname']))).
"','".$this->
clean(ucwords(strtolower($_POST[
'lname']))).
"',1000,'".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"','".$this->
log[
'agent'].
"',DATE(NOW()),TIME(NOW())");
180 $this->status[
'status']=
'ok';
181 $this->status[
'code']=200;
185 $this->status[
'status']=
'failed';
186 $this->status[
'code']=417;
191 $this->status[
'status']=
'exist';
192 $this->status[
'code']=409;
197 $this->status[
'status']=
'invalid';
198 $this->status[
'code']=403;
200 return $this->status;
213 if(filter_var($ajax[
'email'],FILTER_VALIDATE_EMAIL))
215 if($this->output(
"`login`='".strtolower($ajax[
'email']).
"' AND `pass`=MD5('".$ajax[
'pass'].
"')",
"`id` ASC",1)!=
false)
217 $this->status[
'status']=
'authorized';
218 $this->status[
'code']=202;
219 $this->status[
'user']=$this->output(
"`login`='".strtolower($ajax[
'email']).
"' AND `pass`=MD5('".$ajax[
'pass'].
"')",
"`id` ASC",1);
221 $this->
addSessionData(
'userid',$this->status[
'user'][
'line'][1][0]);
222 $this->
addSessionData(
'login',$this->status[
'user'][
'line'][1][3]);
223 $this->
addSessionData(
'email',$this->status[
'user'][
'line'][1][5]);
224 $this->
addSessionData(
'perm',$this->status[
'user'][
'line'][1][8]);
227 if($this->status[
'user'][
'line'][1][1]==
'first_use')
235 $this->update(
'`id`='.$this->status[
'user'][
'line'][1][0],
"`sign`='".$this->
getSessionData(
'sessionid').
"',`ip`='".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"',`agent`='".$this->
log[
'agent'].
"',`date`='".$this->status[
'date'].
"',`time`='".$this->status[
'time'].
"'");
237 unset($this->status[
'user'][
'line']);
241 $this->status[
'status']=
'unauthorized';
242 $this->status[
'code']=404;
247 $this->status[
'status']=
'invalid';
248 $this->status[
'code']=403;
250 return $this->status;
262 $browser = ($this->
getSessionData(
'sessionid') ? array(
"code"=>200) : $this->
login($_POST));
267 return (($server[
'line'][1][1]===$this->
getSessionData(
'sessionid'))&&($browser[
"code"]<300)&&($server[
'line'][1][8]===$this->
getSessionData(
'perm')) ?
true :
false);
271 return (($server[
'line'][1][1]===$this->
getSessionData(
'sessionid'))&&($browser[
"code"]<300)&&($server[
'line'][1][8]===$this->
getSessionData(
'perm')) ? $browser : array(
"code"=>404));
284 if((is_object($translate))&&(is_object($seo)))
291 define(
'LOGIN_ERRMSG',
"000:".$_SESSION[
'sessionid']);
292 define(
'LOGIN_ACTION',
'/login');
294 require_once
'fw_templates/login.default.screen.php';
298 $seo->custom(
'<script type="text/javascript">console.log("Login status:'.$status[
"code"].
'");</script>');
299 switch($status[
'code'])
304 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":ok:user:".$this->
getSessionData(
'userid'));
306 require_once
'fw_templates/account.dafault.screen.php';
311 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":failed");
312 define(
'LOGIN_ACTION',
'/login');
314 require_once
'fw_templates/login.default.screen.php';
321 define(
'LOGIN_ACTION',
'/registration');
322 $status = $this->
ereg();
323 define(
'LOGIN_ERRMSG',$status[
'code'].
":ereg");
325 require_once
'fw_templates/ereg.default.screen.php';
328 return $status[
'code'];
345 if((is_object($translate))&&(is_object($seo)))
353 $seo->custom(
'<script type="text/javascript">console.log("Login status:'.$status[
"code"].
'");</script>');
354 switch($status[
'code'])
359 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":ok:user:".$this->
getSessionData(
'userid'));
361 require_once
'fw_templates/account.dafault.screen.php';
366 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":failed");
367 define(
'LOGIN_ACTION',
'/login');
369 require_once
'fw_templates/login.default.screen.php';
373 return $status[
'code'];
388 $this->status[$name]=$data;
396 print json_encode($this->status);
399 final public function addNewUser($pass,$perm)
410 $this->
log[
'session']=array(
'exist'=>session_start(),
411 'id'=>hash(
"sha512",session_id().date(
"YmdHis")),
412 'date'=>date(
'Y-m-d'),
413 'time'=>date(
'H:i:s'));
414 return $this->
log[
'session'];
422 $this->update(
'`id`='.$this->
getSessionData(
'userid'),
"`sign`=NULL");
423 unset($this->
log[
'session']);
435 $_SESSION[$name]=$data;
446 return $_SESSION[$name];
449 final public function signIn($pass)
464 final public function signOut()
474 final public function clean($string)
476 return preg_replace(
'/[^A-Za-z0-9\-]/',
'', $string);
adminLogin($translate, $seo)
addSessionData($name, $data=null)
createSuperUser($email, $name, $pass)
newColumn($name, $type="INT")
basicLogin($translate, $seo)
editPerm($login=null, $perm=null)
addToMainArray($name, $data)
checkSession($signal=false)