public function init()
 {
     // Disable plugin if the allowed domain is not yet set
     $settingDomain = WebsiteSetting::getByName("subdomainAdmin");
     if (!is_object($settingDomain) || $settingDomain->getData() == "") {
         return;
     }
     // Create temporary request object - not available yet in front controller
     $currentUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     $request = new \Zend_Controller_Request_Http($currentUrl);
     // Disable main domain setting to allow admin access on another domain
     $conf = Config::getSystemConfig();
     $mainDomain = $conf->general->domain;
     if (Tool::isRequestToAdminBackend($request) && Tool::isDomainAllowedToAdminBackend($request)) {
         $confArr = $conf->toArray();
         $mainDomain = $confArr['general']['domain'];
         $confArr['general']['domain'] = "";
         Config::setSystemConfig(new \Zend_Config($confArr));
     }
     // Register plugin
     \Pimcore::getEventManager()->attach("system.startup", function ($event) use(&$mainDomain) {
         $front = \Zend_Controller_Front::getInstance();
         $frontControllerPlugin = new FrontControllerPlugin();
         $front->registerPlugin($frontControllerPlugin);
         // Restore main domain
         $conf = Config::getSystemConfig();
         $confArr = $conf->toArray();
         $confArr['general']['domain'] = $mainDomain;
         Config::setSystemConfig(new \Zend_Config($confArr));
     });
 }
 public function preDispatch(\Zend_Controller_Request_Http $request)
 {
     parent::preDispatch($request);
     if (Tool::isRequestToAdminBackend($request) && !Tool::isDomainAllowedToAdminBackend($request)) {
         $this->handleErrorPage();
     }
 }
 public function testIsDomainAllowedToAdminBackend()
 {
     $_SERVER['HTTP_HOST'] = "www.domain.com";
     $request = new Zend_Controller_Request_Http("http://www.domain.com/test/admin/test");
     $this->assertFalse(SubdomainAdmin\Tool::isDomainAllowedToAdminBackend($request));
     $_SERVER['HTTP_HOST'] = \SubdomainAdmin\Tool::getAllowedDomain();
     $request = new Zend_Controller_Request_Http("https://" . \SubdomainAdmin\Tool::getAllowedDomain() . "/test/admin/test");
     $this->assertTrue(\SubdomainAdmin\Tool::isDomainAllowedToAdminBackend($request));
 }