public function dispatch() { try { if (preg_match('/^sitemap-?([a-z0-9_]+)?(-([0-9]+))?.xml$/i', $this->config->getRequestUrl(true), $m)) { $app_id = isset($m[1]) ? $m[1] : 'webasyst'; if ($this->appExists($app_id)) { self::getInstance($app_id); $class = $app_id . 'SitemapConfig'; if (class_exists($class)) { /** * @var $sitemap waSitemapConfig */ $sitemap = new $class(); $n = ifempty($m[3]); if (!$n) { $n = 1; } $sitemap->display($n); } } else { throw new waException("Page not found", 404); } } elseif (preg_match('/^([a-z0-9_]+)?\\/?captcha\\.php$/i', $this->config->getRequestUrl(true, true), $m)) { $app_id = isset($m[1]) ? $m[1] : 'webasyst'; if ($this->appExists($app_id)) { $wa = self::getInstance($app_id, null, true); $captcha = $wa->getCaptcha(array('app_id' => $app_id)); $captcha->display(); } else { throw new waException("Page not found", 404); } } elseif (!strncmp($this->config->getRequestUrl(true), 'oauth.php', 9)) { $app_id = $this->getStorage()->get('auth_app', 'webasyst'); $app_system = self::getInstance($app_id); if (class_exists($app_id . 'OAuthController')) { $app_system->getFrontController()->execute(null, 'OAuth'); } else { wa('webasyst')->getFrontController()->execute(null, 'OAuth'); } } elseif (!strncmp($this->config->getRequestUrl(true), 'payments.php/', 13)) { $url = substr($this->config->getRequestUrl(true), 13); waRequest::setParam('module_id', strtok($url, '/?')); $webasyst_system = self::getInstance('webasyst'); $webasyst_system->getFrontController()->execute(null, 'payments', null, true); } elseif ($this->getEnv() == 'backend' && !$this->getUser()->isAuth()) { $webasyst_system = self::getInstance('webasyst', null, true); $webasyst_system->getFrontController()->execute(null, 'login', waRequest::get('action'), true); } elseif ($this->config instanceof waAppConfig) { if ($this->getEnv() == 'backend' && !$this->getUser()->getRights($this->getConfig()->getApplication(), 'backend')) { header("Location: " . $this->getConfig()->getBackendUrl(true)); exit; } $this->getFrontController()->dispatch(); } else { $app = null; $route = null; if ($this->getEnv() == 'frontend') { // logout if (null !== ($logout_url = waRequest::get('logout'))) { // for getting app $this->getRouting()->dispatch(); $app = waRequest::param('app'); // For logging logout action $data = array('app_id' => $app, 'contact_id' => $this->getUser()->getId(), 'datetime' => date("Y-m-d H:i:s"), 'action' => 'logout', 'params' => $this->getEnv()); // logout itself $this->getAuth()->clearAuth(); if (!$logout_url) { $logout_url = $this->config->getRequestUrl(false, true); } // logging logout if (!class_exists('waLogModel')) { wa('webasyst'); } $log_model = new waLogModel(); $log_model->insert($data); // make redirect after logout $this->getResponse()->redirect($logout_url); } if (!$this->getRouting()->dispatch()) { $this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302); } $app = waRequest::param('app'); } else { self::getInstance('webasyst'); $path = $this->getConfig()->getRequestUrl(true); if (($i = strpos($path, '?')) !== false) { $path = substr($path, 0, $i); } $url = explode("/", $path); $app = isset($url[1]) && $url[1] != 'index.php' ? $url[1] : 'webasyst'; } if (!$app) { $app = 'webasyst'; } $app_system = self::getInstance($app, null, true); if ($app != 'webasyst' && $this->getEnv() == 'backend' && !$this->getUser()->getRights($app_system->getConfig()->getApplication(), 'backend')) { //$this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302); throw new waRightsException('Access to this app denied', 403); } if ((waRequest::param('secure') || waRequest::param('auth')) && !$this->getUser()->isAuth()) { $auth = $this->getAuthConfig(); if (!empty($auth['app'])) { $app_system = self::getInstance($auth['app'], null, true); } $app_system->login(); } else { $app_system->getFrontController()->dispatch(); } } } catch (waApiException $e) { print $e; } catch (waException $e) { print $e; } catch (Exception $e) { if (waSystemConfig::isDebug()) { print $e; } else { $e = new waException($e->getMessage(), $e->getCode()); print $e; } } }
public function dispatch() { try { if (preg_match('/^sitemap-?([a-z0-9_]+)?.xml$/i', $this->config->getRequestUrl(true), $m)) { $app_id = isset($m[1]) ? $m[1] : 'webasyst'; if ($this->appExists($app_id)) { self::getInstance($app_id); $class = $app_id . 'SitemapConfig'; if (class_exists($class)) { /** * @var $sitemap waSitemapConfig */ $sitemap = new $class(); $sitemap->display(); } } else { throw new waException("Page not found", 404); } } elseif (preg_match('/^([a-z0-9_]+)?\\/?captcha\\.php$/i', $this->config->getRequestUrl(true, true), $m)) { $app_id = isset($m[1]) ? $m[1] : 'webasyst'; if ($this->appExists($app_id)) { $wa = self::getInstance($app_id, null, true); $captcha = $wa->getCaptcha(array('app_id' => $app_id)); $captcha->display(); } else { throw new waException("Page not found", 404); } } elseif (!strncmp($this->config->getRequestUrl(true), 'oauth.php', 9)) { $app_id = $this->getStorage()->get('auth_app', 'webasyst'); $app_system = self::getInstance($app_id); if (class_exists($app_id . 'OAuthController')) { $app_system->getFrontController()->execute(null, 'OAuth'); } else { wa('webasyst')->getFrontController()->execute(null, 'OAuth'); } } elseif (!strncmp($this->config->getRequestUrl(true), 'payments.php/', 13)) { $url = substr($this->config->getRequestUrl(true), 13); waRequest::setParam('module_id', strtok($url, '/?')); $webasyst_system = self::getInstance('webasyst'); $webasyst_system->getFrontController()->execute(null, 'payments', null, true); } elseif ($this->getEnv() == 'backend' && !$this->getUser()->isAuth()) { $webasyst_system = self::getInstance('webasyst', null, true); $webasyst_system->getFrontController()->execute(null, 'login', waRequest::get('action'), true); } elseif ($this->config instanceof waAppConfig) { if ($this->getEnv() == 'backend' && !$this->getUser()->getRights($this->getConfig()->getApplication(), 'backend')) { header("Location: " . $this->getConfig()->getBackendUrl(true)); exit; } $this->getFrontController()->dispatch(); } else { $app = null; $route = null; if ($this->getEnv() == 'frontend') { // logout if (null !== ($logout_url = waRequest::get('logout'))) { $this->getAuth()->clearAuth(); if (!$logout_url) { $logout_url = $this->config->getRequestUrl(false, true); } $this->getResponse()->redirect($logout_url); } if (!$this->getRouting()->dispatch()) { $routes = $this->getRouting()->getRoutes(); $redirect = true; $route = end($routes); if (isset($route['app'])) { $redirect = false; // set routing foreach ($route as $k => $v) { if ($k !== 'url') { waRequest::setParam($k, $v); } } waRequest::setParam('error', 404); } if ($redirect) { $this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302); } } $app = waRequest::param('app'); } else { self::getInstance('webasyst'); $path = $this->getConfig()->getRequestUrl(true); if (($i = strpos($path, '?')) !== false) { $path = substr($path, 0, $i); } $url = explode("/", $path); $app = isset($url[1]) && $url[1] != 'index.php' ? $url[1] : 'webasyst'; } if (!$app) { $app = 'webasyst'; } $app_system = self::getInstance($app, null, true); if ($app != 'webasyst' && $this->getEnv() == 'backend' && !$this->getUser()->getRights($app_system->getConfig()->getApplication(), 'backend')) { //$this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302); throw new waRightsException('Access to this app denied', 403); } if (waRequest::param('secure') && !$this->getUser()->isAuth()) { $app_system->login(); } else { $app_system->getFrontController()->dispatch(); } } } catch (waApiException $e) { print $e; } catch (waException $e) { print $e; } catch (Exception $e) { if (waSystemConfig::isDebug()) { print $e; } else { $e = new waException($e->getMessage(), $e->getCode()); print $e; } } }