@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | foreach ($this->compiled_files as $file) { |
198 | 198 | echo "\t\t<script type='text/javascript' src='{$file}'></script>\n"; |
199 | 199 | } |
200 | - } else { |
|
200 | + }else { |
|
201 | 201 | echo "\t\t<script type='text/javascript' src='/js/".$this->hash.".js'></script>\n"; |
202 | 202 | } |
203 | 203 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | foreach ($this->compiled_files as $file) { |
212 | 212 | echo "\t\t<link href='{$file}' rel='stylesheet' media='screen, print'>"; |
213 | 213 | } |
214 | - } else { |
|
214 | + }else { |
|
215 | 215 | echo "\t\t<link href='/css/".$this->hash.".css' rel='stylesheet' media='screen, print'>"; |
216 | 216 | } |
217 | 217 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $this->log->infoLog("$orig copiado a $dest"); |
237 | 237 | } |
238 | 238 | } |
239 | - } catch (\Exception $e) { |
|
239 | + }catch (\Exception $e) { |
|
240 | 240 | $this->log->errorLog($e->getMessage()); |
241 | 241 | } |
242 | 242 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | if ($this->debug) { |
266 | 266 | $data = file_get_contents($file); |
267 | 267 | $this->storeContents($base.$file_path, $data); |
268 | - } else { |
|
268 | + }else { |
|
269 | 269 | $data .= file_get_contents($file); |
270 | 270 | } |
271 | 271 | $this->compiled_files[] = "/css/".$file_path; |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | public static function save($user) |
98 | 98 | { |
99 | 99 | $admins = array(); |
100 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
101 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
100 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
101 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
102 | 102 | } |
103 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
103 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
104 | 104 | $admins[$user['username']]['profile'] = $user['profile']; |
105 | 105 | |
106 | - return (FALSE !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
106 | + return (FALSE !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function saveUser($user) { |
115 | 115 | $saved = false; |
116 | - if(!empty($user)) { |
|
116 | + if (!empty($user)) { |
|
117 | 117 | $saved = static::save($user); |
118 | 118 | } |
119 | 119 | return $saved; |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | public function getAdmins() |
137 | 137 | { |
138 | 138 | $admins = array(); |
139 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
140 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
139 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
140 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $admins; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | Logger::log('Checking admin session'); |
158 | 158 | if (!$this->authorized) { |
159 | 159 | $request = Request::getInstance(); |
160 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
160 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
161 | 161 | //Si no hay fichero de usuarios redirigimos directamente al gestor |
162 | 162 | return Router::getInstance()->getAdmin()->adminers(); |
163 | 163 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | if (!empty($user) && !empty($admins[$user])) { |
172 | 172 | $auth = $admins[$user]['hash']; |
173 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
173 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
174 | 174 | $this->admin = array( |
175 | 175 | 'alias' => $user, |
176 | 176 | 'profile' => $admins[$user]['profile'], |
@@ -389,12 +389,12 @@ discard block |
||
389 | 389 | $axis = 0; |
390 | 390 | $parts = array(); |
391 | 391 | try { |
392 | - $partLength = floor(strlen($token) / 10); |
|
393 | - for ($i = 0, $ct = ceil(strlen($token) / $partLength); $i < $ct; $i++) { |
|
392 | + $partLength = floor(strlen($token)/10); |
|
393 | + for ($i = 0, $ct = ceil(strlen($token)/$partLength); $i < $ct; $i++) { |
|
394 | 394 | $parts[] = substr($token, $axis, $partLength); |
395 | 395 | $axis += $partLength; |
396 | 396 | } |
397 | - } catch(\Exception $e) { |
|
397 | + }catch (\Exception $e) { |
|
398 | 398 | $partLength = 0; |
399 | 399 | } |
400 | 400 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | $decoded = NULL; |
435 | 435 | list($partLength, $parts) = self::extractTokenParts($token); |
436 | 436 | list($ts, $mod) = self::extractTsAndMod($parts, $partLength); |
437 | - $hashMod = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
437 | + $hashMod = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
438 | 438 | if (time() - (integer)$ts < 300 && $hashMod === $mod) { |
439 | 439 | $decoded = implode('', $parts); |
440 | 440 | } |
@@ -451,16 +451,16 @@ discard block |
||
451 | 451 | public static function generateToken($secret, $module = 'PSFS') |
452 | 452 | { |
453 | 453 | $ts = time(); |
454 | - $hashModule = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
454 | + $hashModule = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
455 | 455 | $hash = hash('sha256', $secret); |
456 | - $insert = floor(strlen($hash) / strlen($ts)); |
|
456 | + $insert = floor(strlen($hash)/strlen($ts)); |
|
457 | 457 | $j = 0; |
458 | 458 | $token = ''; |
459 | 459 | for ($i = 0, $ct = strlen($ts); $i < $ct; $i++) { |
460 | - $token .= substr($ts, $i, 1) . substr($hash, $j, $insert) . substr($hashModule, $i, 2); |
|
460 | + $token .= substr($ts, $i, 1).substr($hash, $j, $insert).substr($hashModule, $i, 2); |
|
461 | 461 | $j += $insert; |
462 | 462 | } |
463 | - $token .= substr($hash, ($insert * strlen($ts)), strlen($hash) - ($insert * strlen($ts))); |
|
463 | + $token .= substr($hash, ($insert*strlen($ts)), strlen($hash) - ($insert*strlen($ts))); |
|
464 | 464 | return $token; |
465 | 465 | } |
466 | 466 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use PSFS\base\Logger; |
14 | 14 | use PSFS\base\Singleton; |
15 | 15 | |
16 | - require_once __DIR__ . DIRECTORY_SEPARATOR . "bootstrap.php"; |
|
16 | + require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php"; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Class Dispatcher |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | private function setLocale() |
75 | 75 | { |
76 | 76 | $this->locale = $this->config->get("default_language"); |
77 | - Logger::log('Set locale to project [' . $this->locale . ']'); |
|
77 | + Logger::log('Set locale to project ['.$this->locale.']'); |
|
78 | 78 | // Load translations |
79 | - putenv("LC_ALL=" . $this->locale); |
|
79 | + putenv("LC_ALL=".$this->locale); |
|
80 | 80 | setlocale(LC_ALL, $this->locale); |
81 | 81 | // Load the locale path |
82 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
83 | - Logger::log('Set locale dir ' . $locale_path); |
|
82 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
83 | + Logger::log('Set locale dir '.$locale_path); |
|
84 | 84 | Config::createDir($locale_path); |
85 | 85 | bindtextdomain('translations', $locale_path); |
86 | 86 | textdomain('translations'); |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | if (!$this->parser->isFile()) { |
101 | 101 | return $this->router->execute($this->actualUri); |
102 | 102 | } |
103 | - } else { |
|
103 | + }else { |
|
104 | 104 | return $this->router->getAdmin()->config(); |
105 | 105 | } |
106 | - } catch (ConfigException $c) { |
|
106 | + }catch (ConfigException $c) { |
|
107 | 107 | return $this->dumpException($c); |
108 | - } catch (SecurityException $s) { |
|
108 | + }catch (SecurityException $s) { |
|
109 | 109 | return $this->security->notAuthorized($this->actualUri); |
110 | - } catch (RouterException $r) { |
|
110 | + }catch (RouterException $r) { |
|
111 | 111 | return $this->router->httpNotFound($r); |
112 | - } catch (\Exception $e) { |
|
112 | + }catch (\Exception $e) { |
|
113 | 113 | return $this->dumpException($e); |
114 | 114 | } |
115 | 115 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $use /= 1024; |
152 | 152 | break; |
153 | 153 | case "MBytes": |
154 | - $use /= (1024 * 1024); |
|
154 | + $use /= (1024*1024); |
|
155 | 155 | break; |
156 | 156 | case "Bytes": |
157 | 157 | default: |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | if ($this->config->getDebugMode()) { |
178 | 178 | Logger::log('Added handlers for errors'); |
179 | 179 | //Warning & Notice handler |
180 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
180 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
181 | 181 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline]); |
182 | 182 | throw new \Exception($errstr, 500); |
183 | 183 | }); |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | private function initiateStats() |
191 | 191 | { |
192 | 192 | Logger::log('Initialicing stats (mem + ts)'); |
193 | - if(null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
|
193 | + if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
|
194 | 194 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
195 | - } else { |
|
195 | + }else { |
|
196 | 196 | $this->ts = $this->parser->getTs(); |
197 | 197 | } |
198 | 198 | $this->mem = memory_get_usage(); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use PSFS\controller\Admin; |
7 | 7 | use Symfony\Component\Finder\Finder; |
8 | 8 | |
9 | - class AdminServices extends Service{ |
|
9 | + class AdminServices extends Service { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @Inyectable |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function setAdminHeaders() |
32 | 32 | { |
33 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
33 | + if ("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
34 | 34 | $platform = trim(Config::getInstance()->get("platform_name")); |
35 | 35 | header('HTTP/1.1 401 Unauthorized'); |
36 | - header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
|
36 | + header('WWW-Authenticate: Basic Realm="'.$platform.'"'); |
|
37 | 37 | echo _("Zona restringida"); |
38 | 38 | exit(); |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | public function getAdmins() |
46 | 46 | { |
47 | 47 | $admins = $this->security->getAdmins(); |
48 | - if(!empty($admins)) |
|
48 | + if (!empty($admins)) |
|
49 | 49 | { |
50 | - if(!$this->security->checkAdmin()) |
|
50 | + if (!$this->security->checkAdmin()) |
|
51 | 51 | { |
52 | 52 | $this->setAdminHeaders(); |
53 | 53 | } |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function parseAdmins(&$admins) |
64 | 64 | { |
65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
65 | + if (!empty($admins)) foreach ($admins as &$admin) |
|
66 | 66 | { |
67 | - if(isset($admin["profile"])) |
|
67 | + if (isset($admin["profile"])) |
|
68 | 68 | { |
69 | - switch($admin["profile"]) { |
|
69 | + switch ($admin["profile"]) { |
|
70 | 70 | case sha1('admin'): $admin['class'] = 'warning'; break; |
71 | 71 | case sha1('superadmin'): $admin['class'] = 'info'; break; |
72 | 72 | default: |
73 | 73 | case sha1('user'): $admin['class'] = 'primary'; break; |
74 | 74 | } |
75 | - }else{ |
|
75 | + }else { |
|
76 | 76 | $admin["class"] = "primary"; |
77 | 77 | } |
78 | 78 | } |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | $files->files()->in(LOG_DIR)->name("*.log")->sortByModifiedTime(); |
89 | 89 | $logs = array(); |
90 | 90 | /** @var \SplFileInfo $file */ |
91 | - foreach($files as $file) |
|
91 | + foreach ($files as $file) |
|
92 | 92 | { |
93 | - $size = $file->getSize() / 8 / 1024; |
|
93 | + $size = $file->getSize()/8/1024; |
|
94 | 94 | $time = date("c", $file->getMTime()); |
95 | 95 | $dateTime = new \DateTime($time); |
96 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
96 | + if (!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
97 | 97 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
98 | 98 | "filename" => $file->getFilename(), |
99 | 99 | "size" => round($size, 3) |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | $files->files()->in(LOG_DIR)->name($selectedLog); |
118 | 118 | $file = null; |
119 | 119 | $log = array(); |
120 | - foreach($files as $match) |
|
120 | + foreach ($files as $match) |
|
121 | 121 | { |
122 | 122 | $file = $match; |
123 | 123 | break; |
124 | 124 | } |
125 | 125 | /** @var \SplFileInfo $file */ |
126 | - if(!empty($file)) |
|
126 | + if (!empty($file)) |
|
127 | 127 | { |
128 | 128 | $time = date("c", $file->getMTime()); |
129 | 129 | $dateTime = new \DateTime($time); |
130 | 130 | $monthOpen = $dateTime->format("m"); |
131 | - $content = file($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename()); |
|
131 | + $content = file($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()); |
|
132 | 132 | krsort($content); |
133 | 133 | $detailLog = array(); |
134 | - foreach($content as &$line) |
|
134 | + foreach ($content as &$line) |
|
135 | 135 | { |
136 | 136 | list($line, $detail) = $this->parseLogLine($line, $match); |
137 | 137 | $detailLog[] = array_merge(array( |
138 | 138 | "log" => $line, |
139 | 139 | ), $detail); |
140 | - if(count($detailLog) >= 1000) break; |
|
140 | + if (count($detailLog) >= 1000) break; |
|
141 | 141 | } |
142 | 142 | $log = $detailLog; |
143 | 143 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
168 | 168 | $type = explode(".", $type); |
169 | - $type = count($type)>1 ? $type[1] : $type[0]; |
|
169 | + $type = count($type) > 1 ? $type[1] : $type[0]; |
|
170 | 170 | switch ($type) { |
171 | 171 | case 'INFO': |
172 | 172 | $detail["type"] = "success"; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | break; |
183 | 183 | } |
184 | 184 | |
185 | - } catch (\Exception $e) { |
|
185 | + }catch (\Exception $e) { |
|
186 | 186 | $detail = array( |
187 | 187 | "type" => "danger", |
188 | 188 | ); |
@@ -30,7 +30,9 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function setAdminHeaders() |
32 | 32 | { |
33 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
33 | + if("login" === $this->config->get("admin_login")) { |
|
34 | + return Admin::getInstance()->adminLogin("admin-setup"); |
|
35 | + } |
|
34 | 36 | $platform = trim(Config::getInstance()->get("platform_name")); |
35 | 37 | header('HTTP/1.1 401 Unauthorized'); |
36 | 38 | header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
@@ -62,17 +64,20 @@ discard block |
||
62 | 64 | */ |
63 | 65 | private function parseAdmins(&$admins) |
64 | 66 | { |
65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
67 | + if(!empty($admins)) { |
|
68 | + foreach($admins as &$admin) |
|
66 | 69 | { |
67 | 70 | if(isset($admin["profile"])) |
68 | 71 | { |
69 | 72 | switch($admin["profile"]) { |
70 | - case sha1('admin'): $admin['class'] = 'warning'; break; |
|
73 | + case sha1('admin'): $admin['class'] = 'warning'; |
|
74 | + } |
|
75 | + break; |
|
71 | 76 | case sha1('superadmin'): $admin['class'] = 'info'; break; |
72 | 77 | default: |
73 | 78 | case sha1('user'): $admin['class'] = 'primary'; break; |
74 | 79 | } |
75 | - }else{ |
|
80 | + } else{ |
|
76 | 81 | $admin["class"] = "primary"; |
77 | 82 | } |
78 | 83 | } |
@@ -93,7 +98,9 @@ discard block |
||
93 | 98 | $size = $file->getSize() / 8 / 1024; |
94 | 99 | $time = date("c", $file->getMTime()); |
95 | 100 | $dateTime = new \DateTime($time); |
96 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
101 | + if(!isset($logs[$dateTime->format("Y")])) { |
|
102 | + $logs[$dateTime->format("Y")] = array(); |
|
103 | + } |
|
97 | 104 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
98 | 105 | "filename" => $file->getFilename(), |
99 | 106 | "size" => round($size, 3) |
@@ -137,7 +144,9 @@ discard block |
||
137 | 144 | $detailLog[] = array_merge(array( |
138 | 145 | "log" => $line, |
139 | 146 | ), $detail); |
140 | - if(count($detailLog) >= 1000) break; |
|
147 | + if(count($detailLog) >= 1000) { |
|
148 | + break; |
|
149 | + } |
|
141 | 150 | } |
142 | 151 | $log = $detailLog; |
143 | 152 | } |
@@ -161,7 +170,9 @@ discard block |
||
161 | 170 | |
162 | 171 | $detail = json_decode($match[0][0], TRUE); |
163 | 172 | } |
164 | - if (empty($detail)) $detail = array(); |
|
173 | + if (empty($detail)) { |
|
174 | + $detail = array(); |
|
175 | + } |
|
165 | 176 | preg_match_all('/\>\ (.*):/i', $line, $match); |
166 | 177 | |
167 | 178 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |