@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
| 34 | 34 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 35 | 35 | $cmsComponent->storage->addBrick($request::$post); |
| 36 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
| 36 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
| 37 | 37 | exit; |
| 38 | 38 | } |
| 39 | 39 | } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $brick = $cmsComponent->storage->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 43 | 43 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 44 | 44 | $cmsComponent->storage->saveBrick($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
| 45 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
| 45 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
| 46 | 46 | exit; |
| 47 | 47 | } |
| 48 | 48 | $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $brick); |
| 49 | 49 | } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 50 | 50 | $cmsComponent->storage->deleteBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 51 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
| 51 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/bricks'); |
|
| 52 | 52 | exit; |
| 53 | 53 | } elseif ($relativeCmsUri == '/configuration/image-set') { |
| 54 | 54 | $cmsComponent->subTemplate = 'cms/configuration/image-set'; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $imageSet = $cmsComponent->storage->getImageSetBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 35 | 35 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 36 | 36 | $cmsComponent->storage->saveImageSet($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
| 37 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
| 37 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
| 38 | 38 | exit; |
| 39 | 39 | } |
| 40 | 40 | $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGE_SET, $imageSet); |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
| 44 | 44 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 45 | 45 | $cmsComponent->storage->addImageSet($request::$post); |
| 46 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
| 46 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
| 47 | 47 | exit; |
| 48 | 48 | } |
| 49 | 49 | } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 50 | 50 | $cmsComponent->storage->deleteImageSetBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 51 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/image-set'); |
|
| 51 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/image-set'); |
|
| 52 | 52 | exit; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
| 34 | 34 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 35 | 35 | $cmsComponent->storage->addApplicationComponent($request::$post); |
| 36 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
| 36 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
| 37 | 37 | exit; |
| 38 | 38 | } |
| 39 | 39 | } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | $applicationComponent = $cmsComponent->storage->getApplicationComponentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 43 | 43 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 44 | 44 | $cmsComponent->storage->saveApplicationComponent($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
| 45 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
| 45 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
| 46 | 46 | exit; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $cmsComponent->setParameter(CmsComponent::PARAMETER_APPLICATION_COMPONENT, $applicationComponent); |
| 50 | 50 | } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 51 | 51 | $cmsComponent->storage->deleteApplicationComponentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 52 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/application-components'); |
|
| 52 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/application-components'); |
|
| 53 | 53 | exit; |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $bricks = $cmsComponent->storage->getBricks(); |
| 35 | 35 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 36 | 36 | $cmsComponent->storage->addDocumentType($request::$post); |
| 37 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
| 37 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
| 38 | 38 | exit; |
| 39 | 39 | } |
| 40 | 40 | $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | $bricks = $cmsComponent->storage->getBricks(); |
| 46 | 46 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
| 47 | 47 | $cmsComponent->storage->saveDocumentType($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
| 48 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
| 48 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
| 49 | 49 | exit; |
| 50 | 50 | } |
| 51 | 51 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $documentType); |
| 52 | 52 | $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
| 53 | 53 | } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 54 | 54 | $cmsComponent->storage->deleteDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 55 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
| 55 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types'); |
|
| 56 | 56 | exit; |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
| 35 | 35 | if (isset($request::$post[CmsComponent::POST_PARAMETER_USERNAME])) { |
| 36 | 36 | $cmsComponent->storage->addUser($request::$post); |
| 37 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
| 37 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
| 38 | 38 | exit; |
| 39 | 39 | } |
| 40 | 40 | } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 41 | 41 | $cmsComponent->storage->deleteUserBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 42 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
| 42 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
| 43 | 43 | exit; |
| 44 | 44 | } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 45 | 45 | $cmsComponent->subTemplate = 'cms/configuration/users-form'; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $cmsComponent->setParameter(CmsComponent::PARAMETER_USER, $cmsComponent->storage->getUserBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
| 48 | 48 | if (isset($_POST[CmsComponent::POST_PARAMETER_USERNAME])) { |
| 49 | 49 | $cmsComponent->storage->saveUser($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
| 50 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/users'); |
|
| 50 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/users'); |
|
| 51 | 51 | exit; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -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 | } |