1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cAuthHandlerBackend extends cAuthHandlerAbstract {
24:
25: 26: 27: 28: 29: 30:
31: public function __construct() {
32: $cfg = cRegistry::getConfig();
33: $this->_lifetime = (int) $cfg['backend']['timeout'];
34: if ($this->_lifetime == 0) {
35: $this->_lifetime = 15;
36: }
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46:
47: public function preAuthorize() {
48: return false;
49: }
50:
51: 52: 53: 54: 55: 56:
57: public function displayLoginForm() {
58:
59:
60:
61:
62: if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '') {
63: $oAjax = new cAjaxRequest();
64: $sReturn = $oAjax->handle('authentication_fail');
65: echo $sReturn;
66: } else {
67: include(cRegistry::getBackendPath() . 'main.loginform.php');
68: }
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78: 79:
80: public function validateCredentials() {
81: $username = $_POST['username'];
82: $password = $_POST['password'];
83: $formtimestamp = $_POST['formtimestamp'];
84:
85:
86: if (cRegistry::getConfigValue('simulate_magic_quotes') !== true) {
87:
88: $password = addslashes($password);
89:
90: $username = addslashes($username);
91: }
92:
93: $groupPerm = array();
94:
95: if ($password == '') {
96: return false;
97: }
98:
99: if (($formtimestamp + (60 * 15)) < time()) {
100: return false;
101: }
102:
103: if (isset($username)) {
104: $this->auth['uname'] = $username;
105: } else if ($this->_defaultNobody == true) {
106: $uid = $this->auth['uname'] = $this->auth['uid'] = self::AUTH_UID_NOBODY;
107:
108: return $uid;
109: }
110:
111: $uid = false;
112: $perm = false;
113: $pass = false;
114: $salt = false;
115:
116: $userColl = new cApiUserCollection();
117: $where = "username = '" . $username . "'";
118: $where .= " AND (valid_from <= NOW() OR valid_from = '0000-00-00 00:00:00' OR valid_from is NULL)";
119: $where .= " AND (valid_to >= NOW() OR valid_to = '0000-00-00 00:00:00' OR valid_to is NULL)";
120:
121: $maintenanceMode = getSystemProperty('maintenance', 'mode');
122: if ($maintenanceMode == 'enabled') {
123: $where .= " AND perms = 'sysadmin'";
124: }
125:
126: $userColl->select($where);
127:
128: while (($item = $userColl->next()) !== false) {
129: $uid = $item->get('user_id');
130: $perm = $item->get('perms');
131:
132: $pass = $item->get('password');
133: $salt = $item->get("salt");
134: }
135:
136: if ($uid == false || hash("sha256", md5($password) . $salt) != $pass) {
137:
138: sleep(5);
139:
140: return false;
141: }
142:
143: if ($perm != '') {
144: $groupPerm[] = $perm;
145: }
146:
147: $groupColl = new cApiGroupCollection();
148: $groups = $groupColl->fetchByUserID($uid);
149: foreach ($groups as $group) {
150: $groupPerm[] = $group->get('perms');
151: }
152:
153: $perm = implode(',', $groupPerm);
154:
155: $this->auth['perm'] = $perm;
156:
157: return $uid;
158: }
159:
160: 161: 162: 163: 164:
165: public function logSuccessfulAuth() {
166: global $client, $lang, $saveLoginTime;
167:
168: $perm = new cPermission();
169:
170:
171: $clientLangColl = new cApiClientLanguageCollection();
172: $clientLangColl->select();
173:
174: $bFound = false;
175: while ($bFound == false) {
176: if (($item = $clientLangColl->next()) === false) {
177: break;
178: }
179:
180: $iTmpClient = $item->get('idclient');
181: $iTmpLang = $item->get('idlang');
182:
183: if ($perm->have_perm_client_lang($iTmpClient, $iTmpLang)) {
184: $client = $iTmpClient;
185: $lang = $iTmpLang;
186: $bFound = true;
187: }
188: }
189:
190: if (!is_numeric($client) || !is_numeric($lang)) {
191: return;
192: }
193:
194: $idaction = $perm->getIDForAction('login');
195:
196: $authInfo = $this->getAuthInfo();
197: $uid = $authInfo['uid'];
198:
199:
200: $actionLogCol = new cApiActionlogCollection();
201: $actionLogCol->create($uid, $client, $lang, $idaction, 0);
202:
203: $sess = cRegistry::getSession();
204: $sess->register('saveLoginTime');
205: $saveLoginTime = true;
206: }
207:
208: 209: 210: 211: 212: 213:
214: public function isLoggedIn() {
215: $authInfo = $this->getAuthInfo();
216:
217: if(isset($authInfo['uid'])) {
218: $user = new cApiUser($authInfo['uid']);
219:
220: return $user->get('user_id') != '';
221: } else {
222: return false;
223: }
224: }
225:
226: }
227: