Esempio n. 1
0
 /** {@inheritdoc} */
 public function showMain()
 {
     if (!is_writable($this->app['configPath'])) {
         $this->addMessage("Configuration file doesn't seem to be writable.", self::MSG_ERROR);
     }
     $config = $this->app->openConfiguration();
     $pages = PagePeer::getSelect();
     $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('enabled' => array('checkbox', array('label' => 'Enable domain mapping', 'value' => $config->domainMapping->enabled)), 'default_base_page' => array('select', array('label' => 'Default base page', 'description' => 'The default base page will only be used if there are no other domains matching and domain mapping is enabled', 'value' => $config->domainMapping->default, 'multiOptions' => array('' => '[ None ]') + $pages)))));
     $domainForm = new Curry_Form_Dynamic(array('legend' => 'Domain', 'elements' => array('domain' => array('text', array('label' => 'Domain', 'description' => 'You can use default as a wildcard to fetch unmatched domains.', 'required' => true)), 'base_page' => array('select', array('label' => 'Base page', 'multiOptions' => array('' => '[ None ]') + $pages, 'required' => true)), 'include_www' => array('checkbox', array('label' => 'Include www')))));
     $form->addSubForm(new Curry_Form_MultiForm(array('legend' => '', 'cloneTarget' => $domainForm, 'defaults' => $config->domainMapping->domains ? $config->domainMapping->domains->toArray() : array())), 'domainMapping');
     $form->addElement('submit', 'save', array('label' => 'Save'));
     if (isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         if (!$config->domainMapping) {
             $config->domainMapping = array();
         }
         $config->domainMapping->enabled = count($values['domainMapping']) ? (bool) $values['enabled'] : false;
         $config->domainMapping->default = $values['default_base_page'];
         $config->domainMapping->domains = $values['domainMapping'];
         try {
             $this->app->writeConfiguration($config);
             $this->addMessage("Settings saved.", self::MSG_SUCCESS);
         } catch (Exception $e) {
             $this->addMessage($e->getMessage(), self::MSG_ERROR);
         }
     }
     $this->addMainContent($form);
 }
Esempio n. 2
0
 /** {@inheritdoc} */
 public function showMain()
 {
     $this->addMainMenu();
     $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('keywords' => array('text', array('label' => 'Keywords', 'required' => true)), 'search' => array('submit', array('label' => 'Search')))));
     // Validate
     if (isPost() && $form->isValid($_POST)) {
         $this->addMainContent($form);
         $index = $this->app->index;
         $hits = $index->find($form->keywords->getValue());
         $html = "";
         foreach ($hits as $hit) {
             $fieldNames = $hit->getDocument()->getFieldNames();
             $title = in_array('title', $fieldNames) ? (string) $hit->title : '<Untitled>';
             $url = in_array('url', $fieldNames) ? (string) $hit->url : null;
             $model = in_array('model', $fieldNames) ? (string) $hit->model : 'Unknown type';
             $item = $url !== null ? Html::tag('a', array('href' => $url), $title) : $title;
             $item .= ' (' . htmlspecialchars($model) . ')<br/>';
             $html .= '<li>' . $item . '<small>Fields: ' . htmlspecialchars(join(', ', $fieldNames)) . '</small></li>';
         }
         $html .= "<li>Hits: " . count($hits) . " / " . $index->numDocs() . "</li>";
         $this->addMainContent("<ul>" . $html . "</ul>");
     } else {
         $this->addMainContent($form);
     }
 }
Esempio n. 3
0
    public function showMain()
    {
        $this->flushConfigCache();
        $form = new Curry_Form(array('url' => url('', $_GET), 'method' => 'post', 'elements' => array('job_handler' => array('text', array('label' => 'Job handler', 'value' => Curry_Core::$config->modules->contrib->CurryGearman->jobHandler, 'placeholder' => 'Leave empty to use default')), 'token' => array('text', array('label' => 'Token', 'description' => 'To execute the listener from the browser, a hash is required.', 'value' => Curry_Core::$config->modules->contrib->CurryGearman->token, 'required' => true, 'placeholder' => 'Enter a random string')), 'save' => array('submit', array('label' => 'Save')))));
        if (isPost() && $form->isValid($_POST)) {
            $values = $form->getValues(true);
            $this->saveConfig($values);
            return;
        }
        $webWorkerUrl = url(Curry_Core::$config->curry->baseUrl . 'gearman_listener.php/', array('hash' => Common_Gearman_Listener::getHash()))->getAbsolute();
        $html = <<<HTML
{$form}
<p><a href="{$webWorkerUrl}" target="_blank">Click here to execute Gearman web worker.</a></p>
HTML;
        $this->addMainContent($html);
    }
Esempio n. 4
0
 public function showMainFilePerm()
 {
     // the primary key of the row that was clicked is available in the 'item' url parameter.
     $pk = $_GET['item'];
     $mf = ManagedfileQuery::create()->findPk($pk);
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('oread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('owner'))), 'owrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('owner'))), 'rread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('role'))), 'rwrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('role'))), 'wread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('world'))), 'wwrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('world'))))));
     $form->addDisplayGroup(array('oread', 'owrite'), 'grpOwner', array('legend' => 'Owner permissions'));
     $form->addDisplayGroup(array('rread', 'rwrite'), 'grpRole', array('legend' => 'Role permissions'));
     $form->addDisplayGroup(array('wread', 'wwrite'), 'grpWorld', array('legend' => 'World permissions'));
     $form->addElement('submit', 'save', array('label' => 'Update permisisons'));
     if (isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         $operm = array('read' => (bool) $values['oread'], 'write' => (bool) $values['owrite']);
         $rperm = array('read' => (bool) $values['rread'], 'write' => (bool) $values['rwrite']);
         $wperm = array('read' => (bool) $values['wread'], 'write' => (bool) $values['wwrite']);
         $mf->setPermission(Managedfile::getPermissionWord($operm, $rperm, $wperm))->save();
         $this->createModelUpdateEvent('Managedfile', $mf->getPrimaryKey(), 'update');
         return '';
     }
     $this->addMainContent($form);
 }
Esempio n. 5
0
 /**
  * Show remove package.
  */
 public function showRemove()
 {
     $packageName = $_GET['name'];
     // Check dependencies on installed packages
     $depend = array();
     $installedPackages = PackageQuery::create()->filterByName($packageName, Criteria::NOT_EQUAL)->find();
     foreach ($installedPackages as $installedPackage) {
         $dependencies = Curry_PackageManager::getPackageDependencies($installedPackage->getName(), $installedPackage->getVersion());
         foreach ($dependencies as $depName => $depVersion) {
             if ($depName == $packageName) {
                 $depend[] = $installedPackage->getName();
             }
         }
     }
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('simulate' => array('checkbox', array('label' => 'Simulate', 'description' => 'Run simulation, will not make any modifications to the system.')), 'submit' => array('submit', array('label' => 'Continue')))));
     if (isPost() && $form->isValid($_POST)) {
         $simulate = $form->simulate->isChecked();
         $status = Curry_PackageManager::removePackage($packageName, $simulate);
         if ($status) {
             $this->addMessage($packageName . ' successfully removed!', self::MSG_SUCCESS);
         } else {
             $this->addMessage('There was an error when uninstalling ' . $packageName, self::MSG_ERROR);
         }
     } else {
         $this->addMessage('The following package will be removed: ' . $packageName, self::MSG_WARNING);
         if (count($depend)) {
             $this->addMessage('The following packages depend on ' . $packageName . ': ' . join(', ', $depend), self::MSG_ERROR);
         }
         $this->addMainContent($form);
     }
 }
Esempio n. 6
0
 /**
  * Create an archive of the project.
  */
 public function showBundle()
 {
     $this->addMainMenu();
     $this->addMessage('You can install this bundle using <a href="' . url('', array('module', 'view' => 'InstallScript')) . '">this installation script</a>.', self::MSG_NOTICE, false);
     $form = new \Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('project' => array('checkbox', array('label' => 'Project', 'value' => true)), 'www' => array('checkbox', array('label' => 'WWW folder', 'value' => true)), 'vendor' => array('checkbox', array('label' => 'Vendor', 'value' => true)), 'database' => array('checkbox', array('label' => 'Database', 'value' => true)), 'compression' => array('select', array('label' => 'Compression', 'multiOptions' => array(Archive::COMPRESSION_NONE => 'None', Archive::COMPRESSION_GZ => 'Gzip'))), 'save' => array('submit', array('label' => 'Create bundle')))));
     if (isPost() && $form->isValid($_POST)) {
         // create archive
         @set_time_limit(0);
         $compression = $form->compression->getValue();
         $tar = new Archive('', $compression);
         // set up file list
         $options = array(array('pattern' => '*.svn*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '*.git*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '.DS_Store', 'skip' => true), array('pattern' => 'Thumbs.db', 'skip' => true), array('pattern' => '._*', 'skip' => true));
         if ($form->project->isChecked()) {
             $tar->add($this->app['projectPath'], 'cms/', array_merge($options, array(array('path' => 'data/', 'pattern' => 'data/*/*', 'pattern_subject' => 'path', 'skip' => true))));
         }
         if ($form->www->isChecked()) {
             $tar->add($this->app['wwwPath'], 'www/', $options);
         }
         if ($form->vendor->isChecked()) {
             $tar->add($this->app['projectPath'] . '/../vendor', 'vendor/', $options);
         }
         if ($form->database->isChecked()) {
             $fiveMBs = 5 * 1024 * 1024;
             $fp = fopen("php://temp/maxmemory:{$fiveMBs}", 'r+');
             if (!\Curry_Backend_DatabaseHelper::dumpDatabase($fp)) {
                 throw new \Exception('Aborting: There was an error when dumping the database.');
             }
             fseek($fp, 0);
             $tar->addString('db.txt', stream_get_contents($fp));
             fclose($fp);
         }
         $filename = str_replace(" ", "_", $this->app['name']) . "-bundle-" . date("Ymd") . ".tar" . ($compression ? ".{$compression}" : '');
         header("Content-type: " . Archive::getCompressionMimeType($compression));
         header("Content-disposition: attachment; filename=" . StringHelper::escapeQuotedString($filename));
         // do not use output buffering
         while (ob_end_clean()) {
         }
         $tar->stream();
         exit;
     }
     $this->addMainContent($form);
     return parent::render();
 }
Esempio n. 7
0
 /** {@inheritdoc} */
 public function showMain()
 {
     $rootPage = PageQuery::create()->findRoot();
     $code = Curry_Backend_PageSyncHelper::getPageCode($rootPage);
     $localChecksum = sha1(serialize($code));
     if (isPost('fetch')) {
         Curry_Application::returnJson($code);
     }
     $form = new Curry_Form(array('csrfCheck' => false, 'action' => (string) url('', $_GET), 'method' => 'post', 'elements' => array('url' => array('text', array('label' => 'URL', 'placeholder' => 'http://example.com/admin.php', 'value' => isset($_COOKIE['curry:remote_url']) ? $_COOKIE['curry:remote_url'] : '')), 'user' => array('text', array('label' => 'User', 'value' => isset($_COOKIE['curry:remote_user']) ? $_COOKIE['curry:remote_user'] : '******')), 'password' => array('password', array('label' => 'Password', 'value' => '')), 'submit' => array('submit', array('class' => 'btn btn-primary', 'label' => 'Fetch')))));
     if (isPost('code')) {
         // we have page-code
         if ($localChecksum !== $_POST['local_checksum']) {
             throw new Exception('Local pages were changed during synchronization process, aborting!');
         }
         $remoteCode = json_decode($_POST['code'], true);
         // Update selected pages
         if (isset($_POST['page'])) {
             $updatedPages = Curry_Backend_PageSyncHelper::restorePages($rootPage, $remoteCode, array_keys($_POST['page']));
             $this->addMessage(count($updatedPages) . ' pages updated!', self::MSG_SUCCESS);
         }
         // Delete selected pages
         if (isset($_POST['delete'])) {
             $pagesToDelete = array_keys($_POST['delete']);
             foreach ($pagesToDelete as $pageId) {
                 $page = PageQuery::create()->findPk($pageId);
                 if (!$page) {
                     throw new Exception('Unable to find page to delete.');
                 }
                 if (!$page->isLeaf()) {
                     $this->addMessage('Unable to delete page "' . $page->getName() . '" because it has subpages.', self::MSG_ERROR);
                     continue;
                 }
                 $dependantPages = $page->getDependantPages();
                 if (count($dependantPages)) {
                     $this->addMessage('Unable to delete page "' . $page->getName() . '" because other pages depend on it.', self::MSG_ERROR);
                     continue;
                 }
                 $page->delete();
                 $this->addMessage('Deleted page "' . $page->getName() . '"', self::MSG_WARNING);
             }
         }
     } else {
         if (isPost() && $form->isValid($_POST)) {
             // have user/password
             try {
                 $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query(array('login_username' => $form->user->getValue(), 'login_password' => $form->password->getValue(), 'fetch' => '1')))));
                 $remote = (string) url($form->url->getValue(), array('module' => 'Curry_Backend_PageSync'));
                 $remoteResponse = file_get_contents($remote, null, $context);
                 if ($remoteResponse === false) {
                     throw new Exception('Invalid response');
                 }
                 $remoteCode = json_decode($remoteResponse, true);
                 if ($remoteCode === null) {
                     throw new Exception('Invalid json: ' . $remoteResponse);
                 }
                 setcookie('curry:remote_url', $form->url->getValue(), time() + 86400 * 365);
                 setcookie('curry:remote_user', $form->user->getValue(), time() + 86400 * 365);
                 $this->addMainContent('<form action="' . url('', $_GET) . '" method="post" class="well">');
                 $this->addMainContent('<input type="hidden" name="code" value="' . htmlspecialchars($remoteResponse) . '" />');
                 $this->addMainContent('<input type="hidden" name="local_checksum" value="' . htmlspecialchars($localChecksum) . '" />');
                 $this->addMainContent('<ul>');
                 $this->comparePageCode($code, $remoteCode);
                 $this->addMainContent('</ul>');
                 $this->addMainContent('<button type="submit" class="btn btn-primary">Sync</button>');
                 $this->addMainContent('</form>');
             } catch (Exception $e) {
                 $this->addMainContent($form);
                 $this->addMessage($e->getMessage(), self::MSG_ERROR);
             }
         } else {
             $this->addMainContent(self::INTRO);
             $this->addMainContent($form);
         }
     }
 }
Esempio n. 8
0
 /**
  * Copy/paste pages.
  */
 public function showCopyPaste()
 {
     $ses = new \Zend\Session\Container(__CLASS__);
     $ses->pageView = 'CopyPaste';
     $page = self::getPage(PageAccessPeer::PERM_MODULES);
     $copyForm = new Curry_Form(array('action' => url('', array('view', 'page_id')), 'method' => 'post', 'elements' => array('copy_code' => array('textarea', array('label' => 'Page Code', 'value' => json_encode(Curry_Backend_PageSyncHelper::getPageCode($page)), 'onclick' => 'select()', 'rows' => 3)))));
     $form = new Curry_Form(array('action' => url('', array('view', 'page_id')), 'method' => 'post', 'elements' => array('code' => array('textarea', array('label' => 'Paste code', 'onclick' => 'select()', 'rows' => 3)), 'subpages' => array('checkbox', array('label' => 'Subpages', 'value' => true)), 'submit' => array('submit', array('label' => 'Paste')))));
     if (isPost() && $form->isValid($_POST)) {
         $pageData = json_decode($form->code->getValue(), true);
         $subpages = (bool) $form->subpages->getValue();
         if ($pageData && $pageData['name']) {
             unset($pageData['name']);
             $pages = Curry_Backend_PageSyncHelper::restorePages($page, $pageData, $subpages);
             $this->addMessage('Pasted ' . count($pages) . ' page(s) successfully.', self::MSG_SUCCESS);
         }
     }
     $this->addPageMenu($page);
     $this->addMainContent($copyForm);
     $this->addMainContent($form);
 }
Esempio n. 9
0
 public function showDelete(PageModuleWrapper $wrapper, $backend)
 {
     if ($wrapper->isInherited() && !$this->pagePermission[PageAccessPeer::PERM_MODULES]) {
         $backend->addMessage('You do not have permission to delete inherited modules.', AbstractBackend::MSG_ERROR);
         return;
     }
     if (!$this->pagePermission[PageAccessPeer::PERM_CREATE_MODULE]) {
         $backend->addMessage('You do not have permission to delete modules.', AbstractBackend::MSG_ERROR);
         return;
     }
     $form = new Curry_Form(array('action' => url('', $_GET), 'elements' => array('delete' => array('submit', array('label' => 'Delete')))));
     if (isPost() && $form->isValid($_POST)) {
         $pageModule = $wrapper->getPageModule();
         $pk = $pageModule->getPrimaryKey();
         $revisionModule = RevisionModuleQuery::create()->findPk(array($pageModule->getPageModuleId(), $wrapper->getOriginPage()->getWorkingPageRevisionId()));
         if (!$revisionModule) {
             throw new Exception('Unable to find RevisionModule to delete.');
         }
         $revisionModule->delete();
         $backend->addMessage('The module has been deleted!', AbstractBackend::MSG_SUCCESS);
         $backend->createModelUpdateEvent('PageModule', $pk, 'delete');
         $backend->addBodyClass('live-edit-close');
     } else {
         $msg = 'Do you really want to delete this module?';
         $originPage = $wrapper->getOriginPage();
         $dependencies = $originPage->getDependantPages();
         if ($wrapper->isInherited()) {
             $backend->addMessage('This module is inherited and will be removed from ' . $originPage . '. It will also be removed from the following subpages: ' . join(", ", $dependencies), AbstractBackend::MSG_WARNING);
         } else {
             if (count($dependencies)) {
                 $backend->addMessage('This module is inherited to subpages and will ' . 'also be removed from the following subpages: ' . join(", ", $dependencies), AbstractBackend::MSG_WARNING);
             }
         }
         $backend->addMessage($msg);
         $backend->addMainContent($form);
     }
 }
Esempio n. 10
0
 /**
  * Restore database.
  */
 public function showRestore()
 {
     $this->showMainMenu();
     $tables = array();
     $selectedTables = array();
     $disabledTables = array();
     foreach (Curry_Propel::getModels() as $package => $classes) {
         $tables[$package] = array();
         foreach ($classes as $table) {
             $tables[$package][$table] = $table;
             if (method_exists($table, 'save')) {
                 $selectedTables[] = $table;
             } else {
                 $disabledTables[] = $table;
             }
         }
     }
     $files = array('' => '-- Select file --', 'upload' => '[ Upload from computer ]', 'remote' => '[ From remote server ]');
     $path = Curry_Backend_DatabaseHelper::createBackupName('*.txt');
     foreach (array_reverse(glob($path)) as $file) {
         $files[$file] = basename($file) . ' (' . Curry_Util::humanReadableBytes(filesize($file)) . ')';
     }
     $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'enctype' => 'multipart/form-data', 'elements' => array('tables' => array('multiselect', array('label' => 'Tables', 'multiOptions' => $tables, 'value' => $selectedTables, 'disable' => $disabledTables, 'size' => 15)), 'file' => array('select', array('label' => 'From file', 'multiOptions' => $files, 'class' => 'trigger-change', 'onchange' => "\$('#uploadfile-label').next().andSelf()[this.value == 'upload'?'show':'hide']();" . "\$('#remote-label').next().andSelf()[this.value == 'remote'?'show':'hide']();")), 'uploadfile' => array('file', array('label' => 'Upload file', 'valueDisabled' => true)), 'remote' => array('text', array('label' => 'Remote')), 'max_execution_time' => array('text', array('label' => 'Max execution time', 'value' => '', 'description' => 'Input time in seconds to allow interruption if the time taken to restore would exceed the maximum execution time.')))));
     $form->addElement('submit', 'Go');
     if (isPost() && $form->isValid($_POST)) {
         if ($form->file->getValue() == 'upload') {
             if (!$form->uploadfile->isUploaded()) {
                 throw new Exception('No file was uploaded.');
             }
             $fileinfo = $form->uploadfile->getFileInfo();
             Curry_Backend_DatabaseHelper::restoreFromFile($fileinfo['uploadfile']['tmp_name'], $form->tables->getValue(), 0, 0, $this);
         } else {
             if ($form->file->getValue() == 'remote') {
                 if (!$form->remote->getValue()) {
                     throw new Exception('No remote URL set');
                 }
                 $url = url($form->remote->getValue());
                 $post = array('login_username' => $url->getUser(), 'login_password' => $url->getPassword(), 'tables' => '*', 'name' => 'db.txt', 'type' => 'local');
                 $url->setUser(null)->setPassword(null)->setPath('/admin.php')->add(array('module' => 'Curry_Backend_Database', 'view' => 'Backup'));
                 $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($post))));
                 $fp = fopen($url, 'r', false, $context);
                 Curry_Backend_DatabaseHelper::restoreFromFile($fp, $form->tables->getValue(), 0, 0, $this);
                 fclose($fp);
             } else {
                 if ($form->file->getValue()) {
                     Curry_Backend_DatabaseHelper::restoreFromFile($form->file->getValue(), $form->tables->getValue(), (int) $form->max_execution_time->getValue(), 0, $this);
                 }
             }
         }
     }
     $this->addMainContent($form);
 }