@@ -5,270 +5,270 @@ |
||
5 | 5 | use library\components\cms\DocumentRouting; |
6 | 6 | use library\components\cms\FilesRouting; |
7 | 7 | use library\components\cms\ImagesRouting; |
8 | - use library\components\cms\SitemapRouting; |
|
9 | - use library\crypt\Crypt; |
|
10 | - use library\storage\Storage; |
|
8 | + use library\components\cms\SitemapRouting; |
|
9 | + use library\crypt\Crypt; |
|
10 | + use library\storage\Storage; |
|
11 | 11 | |
12 | 12 | class CmsComponent extends BaseComponent |
13 | - { |
|
14 | - /* |
|
13 | + { |
|
14 | + /* |
|
15 | 15 | * var \library\storage\Storage |
16 | 16 | */ |
17 | 17 | |
18 | 18 | |
19 | 19 | public $storage; |
20 | 20 | |
21 | - const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
21 | + const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
22 | 22 | |
23 | - const MAIN_NAV_CLASS = 'default'; |
|
23 | + const MAIN_NAV_CLASS = 'default'; |
|
24 | 24 | |
25 | 25 | const PARAMETER_APPLICATION_COMPONENT = 'applicationComponent'; |
26 | 26 | const PARAMETER_APPLICATION_COMPONENTS = 'applicationComponents'; |
27 | - const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
28 | - const PARAMETER_BODY = 'body'; |
|
29 | - const PARAMETER_BRICK = 'brick'; |
|
30 | - const PARAMETER_BRICKS = 'bricks'; |
|
31 | - const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
27 | + const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
28 | + const PARAMETER_BODY = 'body'; |
|
29 | + const PARAMETER_BRICK = 'brick'; |
|
30 | + const PARAMETER_BRICKS = 'bricks'; |
|
31 | + const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
32 | 32 | const PARAMETER_CONFIGURATION = 'configuration'; |
33 | - const PARAMETER_DOCUMENT = 'document'; |
|
34 | - const PARAMETER_DOCUMENTS = 'documents'; |
|
35 | - const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
36 | - const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
37 | - const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
38 | - const PARAMETER_FILES = 'files'; |
|
39 | - const PARAMETER_FOLDER = 'folder'; |
|
40 | - const PARAMETER_IMAGE = 'image'; |
|
41 | - const PARAMETER_IMAGES = 'images'; |
|
42 | - const PARAMETER_IMAGE_SET = 'imageSet'; |
|
43 | - const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
44 | - const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
45 | - const PARAMETER_SITEMAP = 'sitemap'; |
|
46 | - const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
47 | - const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
48 | - const PARAMETER_STATIC = 'static'; |
|
49 | - const PARAMETER_USER = 'user'; |
|
50 | - const PARAMETER_USERS = 'users'; |
|
51 | - const PARAMETER_USER_RIGHTS = 'userRights'; |
|
52 | - const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
53 | - |
|
54 | - const POST_PARAMETER_COMPONENT = 'component'; |
|
55 | - const POST_PARAMETER_PASSWORD = 'password'; |
|
56 | - const POST_PARAMETER_SAVE = 'save'; |
|
57 | - const POST_PARAMETER_TEMPLATE = 'template'; |
|
58 | - const POST_PARAMETER_TITLE = 'title'; |
|
59 | - const POST_PARAMETER_USERNAME = 'username'; |
|
60 | - |
|
61 | - const GET_PARAMETER_PATH = 'path'; |
|
62 | - const GET_PARAMETER_SLUG = 'slug'; |
|
63 | - |
|
64 | - const FILES_PARAMETER_FILE = 'file'; |
|
65 | - |
|
66 | - const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
67 | - |
|
68 | - const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
69 | - |
|
70 | - const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
71 | - |
|
72 | - public $subTemplate = null; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param \library\storage\Storage $storage |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function run(Storage $storage) |
|
81 | - { |
|
82 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
83 | - $this->storage = $storage; |
|
84 | - |
|
85 | - $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
86 | - $this->checkWhiteList($remoteAddress); |
|
87 | - $this->checkBlackList($remoteAddress); |
|
88 | - |
|
89 | - $this->checkLogin(); |
|
90 | - |
|
91 | - $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
92 | - |
|
93 | - $this->routing(); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * See if a user is logged or wants to log in and |
|
98 | - * takes appropriate actions. |
|
99 | - * |
|
100 | - * @throws \Exception |
|
101 | - */ |
|
102 | - protected function checkLogin() |
|
103 | - { |
|
104 | - $request = $this->request; |
|
105 | - |
|
106 | - if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
107 | - if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
108 | - $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
109 | - $crypt = new Crypt(); |
|
110 | - if (empty($user)) { |
|
111 | - $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
112 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
113 | - $this->showLogin(); |
|
114 | - } else { |
|
115 | - $salt = $user->salt; |
|
116 | - $password = $user->password; |
|
117 | - |
|
118 | - $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
119 | - |
|
120 | - if ($passwordCorrect) { |
|
121 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
122 | - } else { |
|
123 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
124 | - $this->showLogin(); |
|
125 | - } |
|
126 | - } |
|
127 | - } else { |
|
128 | - $this->showLogin(); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Overrides normal behaviour and only renders the |
|
135 | - * login screen |
|
136 | - * |
|
137 | - * @throws \Exception |
|
138 | - */ |
|
139 | - protected function showLogin() |
|
140 | - { |
|
141 | - $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
142 | - $this->renderTemplate($loginTemplatePath); |
|
143 | - ob_end_flush(); |
|
144 | - exit; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * As an exception, to keep the initial file structure simple |
|
149 | - * the cms implements it's own routing, apart from the regular sitemap functionality |
|
150 | - * |
|
151 | - * @throws \Exception |
|
152 | - */ |
|
153 | - protected function routing() |
|
154 | - { |
|
155 | - $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
156 | - |
|
157 | - $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
158 | - |
|
159 | - if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
160 | - $this->subTemplate = 'cms/dashboard'; |
|
161 | - } |
|
162 | - |
|
163 | - $this->logOffRouting($this->request, $relativeCmsUri); |
|
164 | - |
|
165 | - $this->apiRouting($relativeCmsUri); |
|
166 | - |
|
167 | - if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
168 | - new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
169 | - } |
|
170 | - |
|
171 | - if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
172 | - new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
173 | - } |
|
174 | - |
|
175 | - if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
176 | - new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
177 | - } |
|
178 | - |
|
179 | - if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
180 | - new FilesRouting($this->request, $relativeCmsUri, $this); |
|
181 | - } |
|
182 | - |
|
183 | - if (in_array('configuration', $userRights)) { |
|
184 | - new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
185 | - } |
|
186 | - |
|
187 | - if ($this->subTemplate !== null) { |
|
188 | - $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param $remoteAddress |
|
194 | - * @throws \Exception |
|
195 | - */ |
|
196 | - private function checkWhiteList($remoteAddress) |
|
197 | - { |
|
198 | - if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
199 | - $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
200 | - $whitelistIps = array_map("trim", $whitelistIps); |
|
201 | - if (!in_array($remoteAddress, $whitelistIps)) { |
|
202 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param $remoteAddress |
|
209 | - * @throws \Exception |
|
210 | - */ |
|
211 | - private function checkBlackList($remoteAddress) |
|
212 | - { |
|
213 | - if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
214 | - $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
215 | - $blacklistIps = array_map("trim", $blacklistIps); |
|
216 | - if (in_array($remoteAddress, $blacklistIps)) { |
|
217 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param $request |
|
224 | - * @return mixed|string |
|
225 | - */ |
|
226 | - private function getRelativeCmsUri($request) |
|
227 | - { |
|
228 | - // TODO Use regex match parameter instead of calculating relative uri |
|
229 | - $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
230 | - $relativeCmsUri = '/'; |
|
231 | - if ($pos !== false) { |
|
232 | - $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
233 | - } |
|
234 | - return $relativeCmsUri; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param $relativeCmsUri |
|
239 | - */ |
|
240 | - private function apiRouting($relativeCmsUri) |
|
241 | - { |
|
242 | - if ($relativeCmsUri == '/images.json') { |
|
243 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
244 | - die(json_encode($this->storage->getImages())); |
|
245 | - } elseif ($relativeCmsUri == '/files.json') { |
|
246 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
247 | - die(json_encode($this->storage->getFiles())); |
|
248 | - } elseif ($relativeCmsUri == '/documents.json') { |
|
249 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
250 | - die(json_encode($this->storage->getDocuments())); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - private function logOffRouting($request, $relativeCmsUri) |
|
255 | - { |
|
256 | - if ($relativeCmsUri == '/log-off') { |
|
257 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
258 | - unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
259 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
260 | - exit; |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - public function setParameter($parameterName, $parameterValue) |
|
265 | - { |
|
266 | - $this->parameters[$parameterName] = $parameterValue; |
|
267 | - } |
|
268 | - |
|
269 | - public function getParameter($parameterName) |
|
270 | - { |
|
271 | - return $this->parameters[$parameterName]; |
|
272 | - } |
|
273 | - } |
|
33 | + const PARAMETER_DOCUMENT = 'document'; |
|
34 | + const PARAMETER_DOCUMENTS = 'documents'; |
|
35 | + const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
36 | + const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
37 | + const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
38 | + const PARAMETER_FILES = 'files'; |
|
39 | + const PARAMETER_FOLDER = 'folder'; |
|
40 | + const PARAMETER_IMAGE = 'image'; |
|
41 | + const PARAMETER_IMAGES = 'images'; |
|
42 | + const PARAMETER_IMAGE_SET = 'imageSet'; |
|
43 | + const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
44 | + const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
45 | + const PARAMETER_SITEMAP = 'sitemap'; |
|
46 | + const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
47 | + const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
48 | + const PARAMETER_STATIC = 'static'; |
|
49 | + const PARAMETER_USER = 'user'; |
|
50 | + const PARAMETER_USERS = 'users'; |
|
51 | + const PARAMETER_USER_RIGHTS = 'userRights'; |
|
52 | + const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
53 | + |
|
54 | + const POST_PARAMETER_COMPONENT = 'component'; |
|
55 | + const POST_PARAMETER_PASSWORD = 'password'; |
|
56 | + const POST_PARAMETER_SAVE = 'save'; |
|
57 | + const POST_PARAMETER_TEMPLATE = 'template'; |
|
58 | + const POST_PARAMETER_TITLE = 'title'; |
|
59 | + const POST_PARAMETER_USERNAME = 'username'; |
|
60 | + |
|
61 | + const GET_PARAMETER_PATH = 'path'; |
|
62 | + const GET_PARAMETER_SLUG = 'slug'; |
|
63 | + |
|
64 | + const FILES_PARAMETER_FILE = 'file'; |
|
65 | + |
|
66 | + const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
67 | + |
|
68 | + const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
69 | + |
|
70 | + const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
71 | + |
|
72 | + public $subTemplate = null; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param \library\storage\Storage $storage |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function run(Storage $storage) |
|
81 | + { |
|
82 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
83 | + $this->storage = $storage; |
|
84 | + |
|
85 | + $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
86 | + $this->checkWhiteList($remoteAddress); |
|
87 | + $this->checkBlackList($remoteAddress); |
|
88 | + |
|
89 | + $this->checkLogin(); |
|
90 | + |
|
91 | + $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
92 | + |
|
93 | + $this->routing(); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * See if a user is logged or wants to log in and |
|
98 | + * takes appropriate actions. |
|
99 | + * |
|
100 | + * @throws \Exception |
|
101 | + */ |
|
102 | + protected function checkLogin() |
|
103 | + { |
|
104 | + $request = $this->request; |
|
105 | + |
|
106 | + if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
107 | + if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
108 | + $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
109 | + $crypt = new Crypt(); |
|
110 | + if (empty($user)) { |
|
111 | + $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
112 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
113 | + $this->showLogin(); |
|
114 | + } else { |
|
115 | + $salt = $user->salt; |
|
116 | + $password = $user->password; |
|
117 | + |
|
118 | + $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
119 | + |
|
120 | + if ($passwordCorrect) { |
|
121 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
122 | + } else { |
|
123 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
124 | + $this->showLogin(); |
|
125 | + } |
|
126 | + } |
|
127 | + } else { |
|
128 | + $this->showLogin(); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Overrides normal behaviour and only renders the |
|
135 | + * login screen |
|
136 | + * |
|
137 | + * @throws \Exception |
|
138 | + */ |
|
139 | + protected function showLogin() |
|
140 | + { |
|
141 | + $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
142 | + $this->renderTemplate($loginTemplatePath); |
|
143 | + ob_end_flush(); |
|
144 | + exit; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * As an exception, to keep the initial file structure simple |
|
149 | + * the cms implements it's own routing, apart from the regular sitemap functionality |
|
150 | + * |
|
151 | + * @throws \Exception |
|
152 | + */ |
|
153 | + protected function routing() |
|
154 | + { |
|
155 | + $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
156 | + |
|
157 | + $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
158 | + |
|
159 | + if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
160 | + $this->subTemplate = 'cms/dashboard'; |
|
161 | + } |
|
162 | + |
|
163 | + $this->logOffRouting($this->request, $relativeCmsUri); |
|
164 | + |
|
165 | + $this->apiRouting($relativeCmsUri); |
|
166 | + |
|
167 | + if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
168 | + new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
169 | + } |
|
170 | + |
|
171 | + if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
172 | + new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
173 | + } |
|
174 | + |
|
175 | + if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
176 | + new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
177 | + } |
|
178 | + |
|
179 | + if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
180 | + new FilesRouting($this->request, $relativeCmsUri, $this); |
|
181 | + } |
|
182 | + |
|
183 | + if (in_array('configuration', $userRights)) { |
|
184 | + new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
185 | + } |
|
186 | + |
|
187 | + if ($this->subTemplate !== null) { |
|
188 | + $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param $remoteAddress |
|
194 | + * @throws \Exception |
|
195 | + */ |
|
196 | + private function checkWhiteList($remoteAddress) |
|
197 | + { |
|
198 | + if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
199 | + $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
200 | + $whitelistIps = array_map("trim", $whitelistIps); |
|
201 | + if (!in_array($remoteAddress, $whitelistIps)) { |
|
202 | + throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param $remoteAddress |
|
209 | + * @throws \Exception |
|
210 | + */ |
|
211 | + private function checkBlackList($remoteAddress) |
|
212 | + { |
|
213 | + if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
214 | + $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
215 | + $blacklistIps = array_map("trim", $blacklistIps); |
|
216 | + if (in_array($remoteAddress, $blacklistIps)) { |
|
217 | + throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param $request |
|
224 | + * @return mixed|string |
|
225 | + */ |
|
226 | + private function getRelativeCmsUri($request) |
|
227 | + { |
|
228 | + // TODO Use regex match parameter instead of calculating relative uri |
|
229 | + $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
230 | + $relativeCmsUri = '/'; |
|
231 | + if ($pos !== false) { |
|
232 | + $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
233 | + } |
|
234 | + return $relativeCmsUri; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param $relativeCmsUri |
|
239 | + */ |
|
240 | + private function apiRouting($relativeCmsUri) |
|
241 | + { |
|
242 | + if ($relativeCmsUri == '/images.json') { |
|
243 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
244 | + die(json_encode($this->storage->getImages())); |
|
245 | + } elseif ($relativeCmsUri == '/files.json') { |
|
246 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
247 | + die(json_encode($this->storage->getFiles())); |
|
248 | + } elseif ($relativeCmsUri == '/documents.json') { |
|
249 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
250 | + die(json_encode($this->storage->getDocuments())); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + private function logOffRouting($request, $relativeCmsUri) |
|
255 | + { |
|
256 | + if ($relativeCmsUri == '/log-off') { |
|
257 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
258 | + unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
259 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
260 | + exit; |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + public function setParameter($parameterName, $parameterValue) |
|
265 | + { |
|
266 | + $this->parameters[$parameterName] = $parameterValue; |
|
267 | + } |
|
268 | + |
|
269 | + public function getParameter($parameterName) |
|
270 | + { |
|
271 | + return $this->parameters[$parameterName]; |
|
272 | + } |
|
273 | + } |
|
274 | 274 | } |
275 | 275 | \ No newline at end of file |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
200 | 200 | $whitelistIps = array_map("trim", $whitelistIps); |
201 | 201 | if (!in_array($remoteAddress, $whitelistIps)) { |
202 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
202 | + throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist'); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
215 | 215 | $blacklistIps = array_map("trim", $blacklistIps); |
216 | 216 | if (in_array($remoteAddress, $blacklistIps)) { |
217 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
217 | + throw new \Exception('Ip address '.$remoteAddress.' is on blacklist'); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | if ($relativeCmsUri == '/log-off') { |
257 | 257 | $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
258 | 258 | unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
259 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
259 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
260 | 260 | exit; |
261 | 261 | } |
262 | 262 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
56 | 56 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
57 | 57 | $cmsComponent->storage->addBrick($request::$post); |
58 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
58 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
59 | 59 | exit; |
60 | 60 | } |
61 | 61 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $brick = $cmsComponent->storage->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
72 | 72 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
73 | 73 | $cmsComponent->storage->saveBrick($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
74 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
74 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
75 | 75 | exit; |
76 | 76 | } |
77 | 77 | $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $brick); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | private function deleteRoute($request, $cmsComponent) |
85 | 85 | { |
86 | 86 | $cmsComponent->storage->deleteBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
87 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
87 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
88 | 88 | exit; |
89 | 89 | } |
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $imageSet = $cmsComponent->storage->getImageSetBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
57 | 57 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
58 | 58 | $cmsComponent->storage->saveImageSet($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
59 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
59 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
60 | 60 | exit; |
61 | 61 | } |
62 | 62 | $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGE_SET, $imageSet); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
73 | 73 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
74 | 74 | $cmsComponent->storage->addImageSet($request::$post); |
75 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
75 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
76 | 76 | exit; |
77 | 77 | } |
78 | 78 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | private function deleteRoute($request, $cmsComponent) |
85 | 85 | { |
86 | 86 | $cmsComponent->storage->deleteImageSetBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
87 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
87 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
88 | 88 | exit; |
89 | 89 | } |
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
56 | 56 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
57 | 57 | $cmsComponent->storage->addApplicationComponent($request::$post); |
58 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
58 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
59 | 59 | exit; |
60 | 60 | } |
61 | 61 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $applicationComponent = $cmsComponent->storage->getApplicationComponentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
72 | 72 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
73 | 73 | $cmsComponent->storage->saveApplicationComponent($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
74 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
74 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
75 | 75 | exit; |
76 | 76 | } |
77 | 77 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | private function deleteRoute($request, $cmsComponent) |
86 | 86 | { |
87 | 87 | $cmsComponent->storage->deleteApplicationComponentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
88 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
88 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
89 | 89 | exit; |
90 | 90 | } |
91 | 91 | } |
92 | 92 | \ No newline at end of file |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $bricks = $cmsComponent->storage->getBricks(); |
57 | 57 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
58 | 58 | $cmsComponent->storage->addDocumentType($request::$post); |
59 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
59 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
60 | 60 | exit; |
61 | 61 | } |
62 | 62 | $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $bricks = $cmsComponent->storage->getBricks(); |
75 | 75 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
76 | 76 | $cmsComponent->storage->saveDocumentType($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
77 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
77 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
78 | 78 | exit; |
79 | 79 | } |
80 | 80 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $documentType); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | private function deleteRoute($request, $cmsComponent) |
89 | 89 | { |
90 | 90 | $cmsComponent->storage->deleteDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
91 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
91 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
92 | 92 | exit; |
93 | 93 | } |
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
57 | 57 | if (isset($request::$post[CmsComponent::POST_PARAMETER_USERNAME])) { |
58 | 58 | $cmsComponent->storage->addUser($request::$post); |
59 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
59 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
60 | 60 | exit; |
61 | 61 | } |
62 | 62 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | private function deleteRoute($request, $cmsComponent) |
69 | 69 | { |
70 | 70 | $cmsComponent->storage->deleteUserBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
71 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
71 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
72 | 72 | exit; |
73 | 73 | } |
74 | 74 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $cmsComponent->setParameter(CmsComponent::PARAMETER_USER, $cmsComponent->storage->getUserBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
84 | 84 | if (isset($_POST[CmsComponent::POST_PARAMETER_USERNAME])) { |
85 | 85 | $cmsComponent->storage->saveUser($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
86 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
86 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
87 | 87 | exit; |
88 | 88 | } |
89 | 89 | } |