Пример #1
0
 private static function initWebRenderer($options)
 {
     $renderer = new WebRenderer($options);
     $renderer->provide('pageURL', function ($path, $params = array()) {
         return Page::getURL($path, $params)->build();
     });
     $renderer->provide('theUser', Authorization::user());
     $renderer->provide('theNonce', Authorization::getNonce());
     return $renderer;
 }
Пример #2
0
 private function tryProcessPostData($postData)
 {
     $reqfields = array('link_path', 'link_target', 'link_priority');
     if (!$postData->hasValues($reqfields)) {
         $this->errorMessage = 'Please specify:
                                <ul>
                                  <li>Path</li>
                                  <li>Target</li>
                                  <li>Priority</li>
                                </ul>';
         return;
     }
     $fields = $reqfields;
     extract($postData->filter($fields));
     $link_priority = intval($link_priority);
     if ($link_priority < 0 || $link_priority > 1000) {
         $this->errorMessage = 'Priority must be between 0 and 1000';
         return;
     }
     $dbc = Application::dbConnection();
     $entry = $dbc->links()->addLink('regex', $link_path, $link_target, Authorization::user()->id);
     if (!$entry) {
         $this->errorMessage = 'An internal error occurred while creating the short URL. Please try again or ask an administrator for help.';
         return;
     }
     $success = $dbc->links()->setPriority($entry->id, $link_priority);
     if (!$success) {
         $url = self::getURL('links/details', array('link' => $entry->id));
         $this->errorMessage = 'The link was created, but the priority could not be set. Please <a href="' . WebRenderer::escapeAttr($url) . '">try again</a>';
         return;
     }
     self::redirectTo('links/details', array('link' => $entry->id));
     exit;
 }
Пример #3
0
 private function tryProcessPostData($postData)
 {
     $reqfields = array('target_link');
     if (!$postData->hasValues($reqfields)) {
         $this->errorMessage = 'Please enter a target link.';
         return;
     }
     $fields = $reqfields;
     $fields[] = 'use_custom_path';
     $fields[] = 'custom_path';
     $fields[] = 'override_wildcards';
     extract($postData->filter($fields));
     if ($override_wildcards) {
         if (!self::hasPermission('link.override_wildcards')) {
             $this->errorMessage = 'You are not permitted to override wildcards.';
             return;
         }
     }
     $dbc = Application::dbConnection();
     $opts = $dbc->options()->getOptions(array('linkgen_chars', 'linkgen_length', 'custom_links_regex'));
     extract($opts);
     if ($use_custom_path) {
         if (!$custom_path) {
             $this->errorMessage = 'Please enter a valid short path or uncheck the custom path option.';
             return;
         }
         if (!self::hasPermission('link.custom_path')) {
             $this->errorMessage = 'You are not permitted to use custom paths.';
             return;
         }
         if (!preg_match("/{$custom_links_regex}/", $custom_path)) {
             $this->errorMessage = 'The chosen short path is not allowed due to administrative restrictions.';
             return;
         }
         $shortpath = $custom_path;
     } else {
         $linkgen_length = intval($linkgen_length);
         $shortpath = $dbc->links()->findAvailablePath($linkgen_length, $linkgen_chars);
     }
     $conflict = $dbc->links()->checkConflictsStatic($shortpath);
     $this->allowOverrideWildcards = !!$conflict && self::hasPermission('link.override_wildcards');
     if ($conflict) {
         if ($conflict->type === 'static') {
             $this->errorMessage = 'Another link with the same path or a conflicting path already exists.';
             return;
         }
         if ($conflict->type === 'regex' && !$override_wildcards) {
             $url = self::getURL('links/details', array('link' => $conflict->id))->build();
             $this->errorMessage = 'This path would override <a href="' . WebRenderer::escapeAttr($url) . '">a defined wildcard</a>.';
             return;
         }
     }
     $entry = $dbc->links()->addLink('static', $shortpath, $target_link, Authorization::user()->id);
     if (!$entry) {
         $this->errorMessage = 'An internal error occurred while creating the short URL. Please try again or ask an administrator for help.';
         return;
     }
     self::redirectTo('links/details', array('link' => $entry->id));
     exit;
 }
Пример #4
0
 private function tryProcessPostData($postData)
 {
     $reqfields = array('server', 'port', 'username', 'password', 'dbname', 'adminpath', 'requrlkey');
     if (!$postData->hasValues($reqfields)) {
         $this->errorMessage = 'Please specify at least:
                                <ul>
                                  <li>MySQL host, port, username, password and database name</li>
                                  <li>WebUI path</li>
                                  <li>Secret .htaccess key</li>
                                </ul>';
         return;
     }
     $fields = $reqfields;
     $fields[] = 'tblprefix';
     extract($postData->filter($fields));
     $result = DatabaseConnection::test($server, $port, $dbname, $username, $password);
     if ($result !== true) {
         $this->errorMessage = 'Unable to connect to database:
                                <pre>' . WebRenderer::escapeHtml($result->getMessage()) . '</pre>';
         return;
     }
     $result = Installer::testRequiredPermissions();
     if (!$result) {
         $this->errorMessage = 'Insufficient file system permissions';
         return;
     }
     $htaccessCode = Installer::createHtaccessCode($requrlkey);
     Installer::saveHtaccessFile($htaccessCode);
     $configCode = Installer::createConfigCode($server, $port, $username, $password, $dbname, $tblprefix, $adminpath, $requrlkey);
     Installer::saveConfigFile($configCode);
     define('TI_ADMIN_PATH', $adminpath);
     define('TI_URLBASEPATH', $urlbasepath);
     define('TI_ROUTING_ENABLED', true);
     $this->redirectTo('installation', 'database');
     exit;
 }
Пример #5
0
 private function tryProcessEditPostData($postData)
 {
     $regex = $this->linkInfo->type === 'regex';
     $reqfields = array('link_path', 'link_target');
     if ($regex) {
         $reqfields[] = 'link_priority';
     }
     if (!$postData->hasValues($reqfields)) {
         $this->errorMessage = 'Please fill out all required fields.';
         return;
     }
     $fields = $reqfields;
     $fields[] = 'override_wildcards';
     extract($postData->filter($fields));
     if ($override_wildcards) {
         if (!self::hasPermission('link.override_wildcards')) {
             $this->errorMessage = 'You are not permitted to override wildcards.';
             return;
         }
     }
     $dbc = Application::dbConnection();
     $opts = $dbc->options()->getOptions(array('custom_links_regex'));
     extract($opts);
     if (!$regex && $this->linkInfo->path !== $link_path) {
         if (!preg_match("/{$custom_links_regex}/", $link_path)) {
             $this->errorMessage = 'The chosen short path is not allowed due to administrative restrictions.';
             return;
         }
         $conflict = $dbc->links()->checkConflictsStatic($link_path);
         if ($conflict) {
             if ($conflict->type === 'static') {
                 $this->errorMessage = 'Another link with the same path or a conflicting path already exists.';
                 return;
             }
             if ($conflict->type === 'regex') {
                 $this->allowOverrideWildcards = self::hasPermission('link.override_wildcards');
                 if (!$override_wildcards || !$this->allowOverrideWildcards) {
                     $url = self::getURL('links/details', array('link' => $conflict->id))->build();
                     $this->errorMessage = 'This path would override <a href="' . WebRenderer::escapeAttr($url) . '">a defined wildcard</a>.';
                     return;
                 }
             }
         }
     }
     if ($this->linkInfo->path !== $link_path || $this->linkInfo->target !== $link_target) {
         if (!self::hasPermission('link.custom_path')) {
             $this->errorMessage = 'You are not permitted to use custom paths.';
             return;
         }
         $success = $dbc->links()->updateLink($this->linkInfo->id, $link_path, $link_target);
         if (!$success) {
             $this->errorMessage = 'An internal error occurred while saving the changes. Please try again or ask an administrator for help.';
             return;
         }
     }
     if ($regex && $this->linkInfo->priority !== $link_priority) {
         $s = $dbc->links()->setPriority($this->linkInfo->id, $link_priority);
         if (!$s) {
             $this->errorMessage = 'The priority could not be changed.';
             return;
         }
     }
     self::redirectTo('links/details', array('link' => $this->linkInfo->id));
     exit;
 }