auth.php
4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
class auth extends client_service {
public function login(){
$params=$this->AuthInfo;
$username=$params['user'];
$passhash=$params['passhash'];
$token=$params['token'];
$app_type=$params['appType'];
$session_id=$params['session'];
$ip=$_SERVER['REMOTE_ADDR'];
$language=isset($params['language'])?$params['language']:'en';
$this->Response->setDebug('parameters',$params);
setcookie("kt_language", $language, 2147483647, '/');
$kt =& $this->KT;
if ($username != 'admin') {
//$this->addDebug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@','');
try{
if(class_exists('BaobabKeyUtil')){
if (!BaobabKeyUtil::checkIfLicensed(true)) {
$this->setResponse(array('authenticated'=> false, 'message'=> 'license_expired'));
$this->addError('Licence Expired');
return false;
}
}else{
$this->addError('Licence Utility could not be loaded. Appears to be a Community version.');
$this->setResponse(array('authenticated'=> false, 'message'=> 'Licence Utility could not be loaded. Appears to be a Community version.'));
return false;
}
}catch(Exception $e){
$this->addError('could not execute BaobabKeyUtil::checkIfLicensed');
$this->setResponse(array('authenticated'=> false, 'message'=> 'BaobabKeyUtil::checkIfLicensed error'));
return;
}
}
$user=$kt->get_user_object_by_username($username);
if(!PEAR::isError($user)){
$password=$user->getPassword();
$localPassHash=md5($password.$token);
if($localPassHash==$passhash){
$session=new stdClass();
$this->Response->setDebug('trying to start session with',array('username'=>$username,'password'=>$password));
$session = $kt->start_session($username, $params['pass'],NULL,$app_type);
if(!PEAR::isError($session)){
$this->Response->setStatus('session_id',$session->get_session());
}else{
$this->setResponse(array('authenticated'=> false, 'message'=> 'Invalid username and/or password.'));
$this->addDebug('failed login',print_r($session,true));
$this->addError('Unknown Login Error');
return false;
}
}else{
$this->addError('Incorrect Credentials');
//throw new Exception('Incorrect Credentials');
return false;
}
}else{
$this->addError('Incorrect Credentials');
//throw new Exception('Unrecognized User');
return false;
}
return true;
}
public function japiLogin(){
global $default;
$user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
$ret=array(
'fullName' =>PEAR::isError($user)?'':$user->getName()
);
$this->setResponse($ret);
return true;
}
public function pickup_session(){
$params=$this->AuthInfo;
$app_type=$params['appType'];
$session_id=$params['session'];
$ip=$_SERVER['REMOTE_ADDR'];
$session = $this->KT->get_active_session($session_id, $ip, $app_type);
if (PEAR::isError($session)){
return false;
}
$this->Response->setStatus('session_id',$session->get_session());
return true;
}
public function ping(){
global $default;
$user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
$versions=$this->handler->getServerVersions();
$bestVer=$versions[count($versions)-1];
$clientVer=$this->handler->getVersion();
$ret=array(
'response' =>'pong',
'loginLocation' => '/index.html',
'versionok' =>in_array($clientVer,$versions),
'fullName' =>PEAR::isError($user)?'':$user->getName(),
'serverVersions' =>$versions,
'serverBestVersion' =>$bestVer,
'clientVersion' =>$clientVer,
'canUpgradeClient' =>($clientVer<$bestVer?true:false),
'canUpgradeServer' =>($clientVer>$bestVer?true:false)
);
$this->setResponse($ret);
return true;
}
function logout($params){
$params=$this->AuthInfo;
$app_type=$params['appType'];
$session_id=$params['session'];
$ip=$_SERVER['REMOTE_ADDR'];
$session = $this->KT->get_active_session($session_id, $ip, $app_type);
if (PEAR::isError($session)){
return false;
}
$session->logout();
$this->setResponse(array('logout'=>true));
return true;
}
}
?>