@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace PSFS\base; |
4 | 4 | |
5 | 5 | use PSFS\base\types\SingletonTrait; |
6 | -use PSFS\controller\UserController; |
|
7 | 6 | |
8 | 7 | |
9 | 8 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | } |
63 | 63 | $this->user = (array_key_exists(self::USER_ID_TOKEN, $this->session)) ? unserialize($this->session[self::USER_ID_TOKEN]) : NULL; |
64 | 64 | $this->admin = (array_key_exists(self::ADMIN_ID_TOKEN, $this->session)) ? unserialize($this->session[self::ADMIN_ID_TOKEN]) : NULL; |
65 | - if(null === $this->admin) { |
|
65 | + if (null === $this->admin) { |
|
66 | 66 | $this->checkAdmin(); |
67 | 67 | } |
68 | 68 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | public static function save($user) |
122 | 122 | { |
123 | 123 | $admins = array(); |
124 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
125 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
124 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
125 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
126 | 126 | } |
127 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
127 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
128 | 128 | $admins[$user['username']]['profile'] = $user['profile']; |
129 | 129 | |
130 | - return (FALSE !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
130 | + return (FALSE !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | public function getAdmins() |
162 | 162 | { |
163 | 163 | $admins = array(); |
164 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
165 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
164 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
165 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return $admins; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | Logger::log('Checking admin session'); |
183 | 183 | if (!$this->authorized && !$this->checked) { |
184 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
184 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
185 | 185 | $request = Request::getInstance(); |
186 | 186 | $admins = $this->getAdmins(); |
187 | 187 | //Sacamos las credenciales de la petición |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | } |
193 | 193 | if (!empty($user) && !empty($admins[$user])) { |
194 | 194 | $auth = $admins[$user]['hash']; |
195 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
196 | - if($this->authorized) { |
|
195 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
196 | + if ($this->authorized) { |
|
197 | 197 | $this->admin = array( |
198 | 198 | 'alias' => $user, |
199 | 199 | 'profile' => $admins[$user]['profile'], |
@@ -416,12 +416,12 @@ discard block |
||
416 | 416 | $axis = 0; |
417 | 417 | $parts = array(); |
418 | 418 | try { |
419 | - $partLength = floor(strlen($token) / 10); |
|
420 | - for ($i = 0, $ct = ceil(strlen($token) / $partLength); $i < $ct; $i++) { |
|
419 | + $partLength = floor(strlen($token)/10); |
|
420 | + for ($i = 0, $ct = ceil(strlen($token)/$partLength); $i < $ct; $i++) { |
|
421 | 421 | $parts[] = substr($token, $axis, $partLength); |
422 | 422 | $axis += $partLength; |
423 | 423 | } |
424 | - } catch (\Exception $e) { |
|
424 | + }catch (\Exception $e) { |
|
425 | 425 | $partLength = 0; |
426 | 426 | } |
427 | 427 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | $decoded = NULL; |
462 | 462 | list($partLength, $parts) = self::extractTokenParts($token); |
463 | 463 | list($ts, $mod) = self::extractTsAndMod($parts, $partLength); |
464 | - $hashMod = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
464 | + $hashMod = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
465 | 465 | if (time() - (integer)$ts < 300 && $hashMod === $mod) { |
466 | 466 | $decoded = implode('', $parts); |
467 | 467 | } |
@@ -478,16 +478,16 @@ discard block |
||
478 | 478 | public static function generateToken($secret, $module = 'PSFS') |
479 | 479 | { |
480 | 480 | $ts = time(); |
481 | - $hashModule = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
481 | + $hashModule = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
482 | 482 | $hash = hash('sha256', $secret); |
483 | - $insert = floor(strlen($hash) / strlen($ts)); |
|
483 | + $insert = floor(strlen($hash)/strlen($ts)); |
|
484 | 484 | $j = 0; |
485 | 485 | $token = ''; |
486 | 486 | for ($i = 0, $ct = strlen($ts); $i < $ct; $i++) { |
487 | - $token .= substr($ts, $i, 1) . substr($hash, $j, $insert) . substr($hashModule, $i, 2); |
|
487 | + $token .= substr($ts, $i, 1).substr($hash, $j, $insert).substr($hashModule, $i, 2); |
|
488 | 488 | $j += $insert; |
489 | 489 | } |
490 | - $token .= substr($hash, ($insert * strlen($ts)), strlen($hash) - ($insert * strlen($ts))); |
|
490 | + $token .= substr($hash, ($insert*strlen($ts)), strlen($hash) - ($insert*strlen($ts))); |
|
491 | 491 | return $token; |
492 | 492 | } |
493 | 493 |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | protected function init() |
49 | 49 | { |
50 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "config.json")) { |
|
50 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."config.json")) { |
|
51 | 51 | $this->loadConfigData(); |
52 | 52 | } |
53 | 53 | return $this; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getTemplatePath() |
119 | 119 | { |
120 | - $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; |
|
120 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; |
|
121 | 121 | return realpath($path); |
122 | 122 | } |
123 | 123 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | break; |
137 | 137 | } |
138 | 138 | } |
139 | - if(!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
139 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
140 | 140 | //Si no hay fichero de usuarios redirigimos directamente al gestor |
141 | 141 | return UserController::getInstance()->adminers(); |
142 | 142 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | $final_data = self::saveExtraParams($data); |
169 | 169 | $saved = false; |
170 | 170 | try { |
171 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "config.json", $final_data, Cache::JSON, true); |
|
171 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."config.json", $final_data, Cache::JSON, true); |
|
172 | 172 | Config::getInstance()->loadConfigData(); |
173 | 173 | $saved = true; |
174 | - } catch (ConfigException $e) { |
|
174 | + }catch (ConfigException $e) { |
|
175 | 175 | Logger::log($e->getMessage(), LOG_ERR); |
176 | 176 | } |
177 | 177 | return $saved; |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function getPropelParams() |
205 | 205 | { |
206 | - return Cache::getInstance()->getDataFromFile(__DIR__ . DIRECTORY_SEPARATOR . 'properties.json', Cache::JSON, true); |
|
206 | + return Cache::getInstance()->getDataFromFile(__DIR__.DIRECTORY_SEPARATOR.'properties.json', Cache::JSON, true); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | { |
216 | 216 | try { |
217 | 217 | if (!is_dir($dir) && @mkdir($dir, 0775, true) === false) { |
218 | - throw new \Exception(_('Can\'t create directory ') . $dir); |
|
218 | + throw new \Exception(_('Can\'t create directory ').$dir); |
|
219 | 219 | } |
220 | - } catch (\Exception $e) { |
|
220 | + }catch (\Exception $e) { |
|
221 | 221 | Logger::log($e->getMessage(), LOG_WARNING); |
222 | 222 | if (!file_exists(dirname($dir))) { |
223 | - throw new ConfigException($e->getMessage() . $dir); |
|
223 | + throw new ConfigException($e->getMessage().$dir); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | { |
233 | 233 | $rootDirs = array("css", "js", "media", "font"); |
234 | 234 | foreach ($rootDirs as $dir) { |
235 | - if (file_exists(WEB_DIR . DIRECTORY_SEPARATOR . $dir)) { |
|
235 | + if (file_exists(WEB_DIR.DIRECTORY_SEPARATOR.$dir)) { |
|
236 | 236 | try { |
237 | - @shell_exec("rm -rf " . WEB_DIR . DIRECTORY_SEPARATOR . $dir); |
|
238 | - } catch (\Exception $e) { |
|
237 | + @shell_exec("rm -rf ".WEB_DIR.DIRECTORY_SEPARATOR.$dir); |
|
238 | + }catch (\Exception $e) { |
|
239 | 239 | Logger::log($e->getMessage()); |
240 | 240 | } |
241 | 241 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function loadConfigData() |
249 | 249 | { |
250 | - $this->config = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "config.json", |
|
250 | + $this->config = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."config.json", |
|
251 | 251 | Cache::JSON, |
252 | 252 | TRUE) ?: []; |
253 | 253 | $this->debug = (array_key_exists('debug', $this->config)) ? (bool)$this->config['debug'] : FALSE; |