public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = DIR_APPLICATION . '/config/generated_overrides';
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     if ($namespace) {
         $path = "{$path}/{$namespace}";
         if (!$this->files->exists($path)) {
             $this->files->makeDirectory($path, 0777);
         } elseif (!$this->files->isDirectory($path)) {
             $this->files->delete($path);
             $this->files->makeDirectory($path, 0777);
         }
     }
     $file = "{$path}/{$group}.php";
     $current = array();
     if ($this->files->exists($file)) {
         $current = $this->files->getRequire($file);
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     return $this->files->put($file, $renderer->render()) !== false;
 }
Example #2
0
 public function testInvalidTypeObject()
 {
     $renderer = new Renderer(array('object' => $this));
     try {
         $renderer->render();
     } catch (RendererInvalidTypeException $e) {
         return;
     }
     $this->fail('Didn\'t detect invalid Closure type.');
 }
Example #3
0
 /**
  * Writes the core pointer into config/update.php.
  * 
  * @return true|int Returns true if the configuration file was updated, otherwise it returns the error code (one of the ApplicationUpdate::E_... constants)
  */
 public function apply()
 {
     $updates = array();
     $update_file = DIR_CONFIG_SITE . '/update.php';
     if (file_exists($update_file)) {
         if (!is_writable($update_file)) {
             return self::E_UPDATE_WRITE_CONFIG;
         }
         $updates = (array) (include $update_file);
     }
     $updates['core'] = $this->getUpdateIdentifier();
     \Config::clear('concrete.version');
     $renderer = new Renderer($updates);
     file_put_contents($update_file, $renderer->render());
     return true;
 }
Example #4
0
 public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = $this->getStorageDirectory();
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     $ns_string = 'null';
     if ($namespace) {
         $ns_string = $namespace;
         $path = "{$path}/{$namespace}";
         if (!$this->files->exists($path)) {
             $this->files->makeDirectory($path, 0777);
         } elseif (!$this->files->isDirectory($path)) {
             $this->files->delete($path);
             $this->files->makeDirectory($path, 0777);
         }
     }
     $file = $this->getFilename($group, $path);
     $current = array();
     if ($this->files->exists($file)) {
         if (\Config::get('concrete.config.temp_save', true)) {
             // Make sure that we miss cache.
             $temp_file = tempnam($path, $group . '_');
             $contents = $this->files->get($file);
             $this->files->put($temp_file, $contents);
             $current = $this->files->getRequire($temp_file);
             $this->files->delete($temp_file);
         } else {
             $current = $this->files->getRequire($file);
         }
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     $header = array("<?php", "", "/**", " * -----------------------------------------------------------------------------", " * Generated " . date(DATE_ATOM), " *", " * DO NOT EDIT THIS FILE DIRECTLY", " *", " * @item      {$item}", " * @group     {$group}", " * @namespace {$ns_string}", " * -----------------------------------------------------------------------------", " */", "return ");
     $rendered = $renderer->render(PHP_EOL, '    ', implode(PHP_EOL, $header));
     $result = $this->files->put($file, $rendered) !== false;
     if ($result) {
         OpCache::clear($file);
     }
     return $result;
 }
 public function finish()
 {
     $config = \Core::make('config');
     $site_install = $config->getLoader()->load(null, 'site_install');
     // Extract database config, and save it to database.php
     $database = $site_install['database'];
     unset($site_install['database']);
     $renderer = new Renderer($database);
     file_put_contents(DIR_CONFIG_SITE . '/database.php', $renderer->render());
     @chmod(DIR_CONFIG_SITE . '/database.php', Config::get('concrete.filesystem.permissions.file'));
     $renderer = new Renderer($site_install);
     if (!file_exists(DIR_CONFIG_SITE . '/app.php')) {
         file_put_contents(DIR_CONFIG_SITE . '/app.php', $renderer->render());
         @chmod(DIR_CONFIG_SITE . '/app.php', Config::get('concrete.filesystem.permissions.file'));
     }
     @unlink(DIR_CONFIG_SITE . '/site_install.php');
     @unlink(DIR_CONFIG_SITE . '/site_install_user.php');
     $config->clearCache();
     Core::make('cache')->flush();
 }
Example #6
0
 /**
  * @return \Concrete\Core\Error\Error
  */
 public function configure()
 {
     $error = \Core::make('helper/validation/error');
     /* @var $error \Concrete\Core\Error\Error */
     try {
         $val = Core::make('helper/validation/form');
         $val->setData($this->post());
         $val->addRequired("SITE", t("Please specify your site's name"));
         $val->addRequiredEmail("uEmail", t('Please specify a valid email address'));
         $val->addRequired("DB_DATABASE", t('You must specify a valid database name'));
         $val->addRequired("DB_SERVER", t('You must specify a valid database server'));
         $password = $_POST['uPassword'];
         $passwordConfirm = $_POST['uPasswordConfirm'];
         $uh = Core::make('helper/concrete/user');
         $uh->validNewPassword($password, $error);
         if ($password) {
             if ($password != $passwordConfirm) {
                 $error->add(t('The two passwords provided do not match.'));
             }
         }
         if (is_object($this->fileWriteErrors)) {
             $error = $this->fileWriteErrors;
         }
         $error = $this->validateDatabase($error);
         $error = $this->validateSampleContent($error);
         if ($val->test() && !$error->has()) {
             // write the config file
             $vh = Core::make('helper/validation/identifier');
             $this->fp = @fopen(DIR_CONFIG_SITE . '/site_install.php', 'w+');
             $this->fpu = @fopen(DIR_CONFIG_SITE . '/site_install_user.php', 'w+');
             if ($this->fp) {
                 $config = isset($_POST['SITE_CONFIG']) ? (array) $_POST['SITE_CONFIG'] : array();
                 $config['database'] = array('default-connection' => 'concrete', 'connections' => array('concrete' => array('driver' => 'c5_pdo_mysql', 'server' => $_POST['DB_SERVER'], 'database' => $_POST['DB_DATABASE'], 'username' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'charset' => 'utf8')));
                 $renderer = new Renderer($config);
                 fwrite($this->fp, $renderer->render());
                 fclose($this->fp);
                 chmod(DIR_CONFIG_SITE . '/site_install.php', 0700);
             } else {
                 throw new Exception(t('Unable to open config/app.php for writing.'));
             }
             if ($this->fpu) {
                 $hasher = new PasswordHash(Config::get('concrete.user.password.hash_cost_log2'), Config::get('concrete.user.password.hash_portable'));
                 $configuration = "<?php\n";
                 $configuration .= "define('INSTALL_USER_EMAIL', '" . $_POST['uEmail'] . "');\n";
                 $configuration .= "define('INSTALL_USER_PASSWORD_HASH', '" . $hasher->HashPassword($_POST['uPassword']) . "');\n";
                 $configuration .= "define('INSTALL_STARTING_POINT', '" . $this->post('SAMPLE_CONTENT') . "');\n";
                 $configuration .= "define('SITE', '" . addslashes($_POST['SITE']) . "');\n";
                 if (Localization::activeLocale() != '' && Localization::activeLocale() != 'en_US') {
                     $configuration .= "define('SITE_INSTALL_LOCALE', '" . Localization::activeLocale() . "');\n";
                 }
                 $res = fwrite($this->fpu, $configuration);
                 fclose($this->fpu);
                 chmod(DIR_CONFIG_SITE . '/site_install_user.php', 0700);
                 if (PHP_SAPI != 'cli') {
                     $this->redirect('/');
                 }
             } else {
                 throw new Exception(t('Unable to open config/site_user.php for writing.'));
             }
         } else {
             if ($error->has()) {
                 $this->set('error', $error);
             } else {
                 $error = $val->getError();
                 $this->set('error', $val->getError());
             }
         }
     } catch (Exception $ex) {
         $this->reset();
         $this->set('error', $ex);
         $error->add($ex);
     }
     return $error;
 }
Example #7
0
 /**
  * @return \Concrete\Core\Error\Error
  */
 public function configure()
 {
     $error = $this->app->make('helper/validation/error');
     /* @var $error \Concrete\Core\Error\ErrorList\ErrorList */
     try {
         $val = $this->app->make('helper/validation/form');
         /* @var \Concrete\Core\Form\Service\Validation $val */
         $val->setData($this->post());
         $val->addRequired("SITE", t("Please specify your site's name"));
         $val->addRequiredEmail("uEmail", t('Please specify a valid email address'));
         $val->addRequired("DB_DATABASE", t('You must specify a valid database name'));
         $val->addRequired("DB_SERVER", t('You must specify a valid database server'));
         $password = $_POST['uPassword'];
         $passwordConfirm = $_POST['uPasswordConfirm'];
         $this->app->make('validator/password')->isValid($password, $error);
         if ($password) {
             if ($password != $passwordConfirm) {
                 $error->add(t('The two passwords provided do not match.'));
             }
         }
         if (is_object($this->fileWriteErrors)) {
             foreach ($this->fileWriteErrors->getList() as $msg) {
                 $error->add($msg);
             }
         }
         $error = $this->validateDatabase($error);
         $error = $this->validateSampleContent($error);
         if ($this->post('canonicalUrlChecked') === '1') {
             try {
                 $url = UrlImmutable::createFromUrl($this->post('canonicalUrl'));
                 if (strcasecmp('http', $url->getScheme()) !== 0) {
                     throw new Exception('The HTTP canonical URL must have the http:// scheme');
                 }
                 $canonicalUrl = (string) $url;
             } catch (Exception $x) {
                 $error->add($x);
             }
         } else {
             $canonicalUrl = '';
         }
         if ($this->post('canonicalSSLUrlChecked') === '1') {
             $url = UrlImmutable::createFromUrl($this->post('canonicalSSLUrl'));
             if (strcasecmp('https', $url->getScheme()) !== 0) {
                 throw new Exception('The SSL canonical URL must have the https:// scheme');
             }
             $canonicalSSLUrl = (string) $url;
         } else {
             $canonicalSSLUrl = '';
         }
         if ($val->test() && !$error->has()) {
             // write the config file
             $vh = $this->app->make('helper/validation/identifier');
             $this->fp = @fopen(DIR_CONFIG_SITE . '/site_install.php', 'w+');
             $this->fpu = @fopen(DIR_CONFIG_SITE . '/site_install_user.php', 'w+');
             if ($this->fp) {
                 $config = isset($_POST['SITE_CONFIG']) ? (array) $_POST['SITE_CONFIG'] : [];
                 $config['database'] = ['default-connection' => 'concrete', 'connections' => ['concrete' => ['driver' => 'c5_pdo_mysql', 'server' => $_POST['DB_SERVER'], 'database' => $_POST['DB_DATABASE'], 'username' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'charset' => 'utf8']]];
                 $config['canonical-url'] = $canonicalUrl;
                 $config['canonical-ssl-url'] = $canonicalSSLUrl;
                 $config['session-handler'] = $_POST['sessionHandler'];
                 $renderer = new Renderer($config);
                 fwrite($this->fp, $renderer->render());
                 fclose($this->fp);
                 chmod(DIR_CONFIG_SITE . '/site_install.php', 0700);
             } else {
                 throw new Exception(t('Unable to open config/app.php for writing.'));
             }
             if ($this->fpu) {
                 $config = $this->app->make('config');
                 $hasher = new PasswordHash($config->get('concrete.user.password.hash_cost_log2'), $config->get('concrete.user.password.hash_portable'));
                 $configuration = "<?php\n";
                 $configuration .= "define('INSTALL_USER_EMAIL', " . var_export((string) $_POST['uEmail'], true) . ");\n";
                 $configuration .= "define('INSTALL_USER_PASSWORD_HASH', " . var_export((string) $hasher->HashPassword($_POST['uPassword']), true) . ");\n";
                 $configuration .= "define('INSTALL_STARTING_POINT', " . var_export((string) $this->post('SAMPLE_CONTENT'), true) . ");\n";
                 $configuration .= "define('SITE', " . var_export((string) $_POST['SITE'], true) . ");\n";
                 $locale = $this->post('siteLocaleLanguage') . '_' . $this->post('siteLocaleCountry');
                 $configuration .= "define('SITE_INSTALL_LOCALE', " . var_export($locale, true) . ");\n";
                 $configuration .= "define('APP_INSTALL_LANGUAGE', " . var_export($this->post('locale'), true) . ");\n";
                 $res = fwrite($this->fpu, $configuration);
                 fclose($this->fpu);
                 chmod(DIR_CONFIG_SITE . '/site_install_user.php', 0700);
                 if (PHP_SAPI != 'cli') {
                     $this->redirect('/');
                 }
             } else {
                 throw new Exception(t('Unable to open config/site_user.php for writing.'));
             }
         } else {
             if ($error->has()) {
                 $this->set('error', $error);
             } else {
                 $error = $val->getError();
                 $this->set('error', $val->getError());
             }
         }
     } catch (Exception $ex) {
         $this->reset();
         $this->set('error', $ex);
         $error->add($ex);
     }
     $this->setup();
     return $error;
 }
 public function finish()
 {
     $config = \Core::make('config');
     $site_install = $config->getLoader()->load(null, 'site_install');
     // Extract database config, and save it to database.php
     $database = $site_install['database'];
     unset($site_install['database']);
     $renderer = new Renderer($database);
     @unlink(DIR_CONFIG_SITE . '/database.php');
     file_put_contents(DIR_CONFIG_SITE . '/database.php', $renderer->render());
     @chmod(DIR_CONFIG_SITE . '/database.php', FILE_PERMISSIONS_MODE);
     $renderer = new Renderer($site_install);
     @unlink(DIR_CONFIG_SITE . '/app.php');
     file_put_contents(DIR_CONFIG_SITE . '/app.php', $renderer->render());
     @chmod(DIR_CONFIG_SITE . '/app.php', FILE_PERMISSIONS_MODE);
     @unlink(DIR_CONFIG_SITE . '/site_install.php');
     @unlink(DIR_CONFIG_SITE . '/site_install_user.php');
     $config->clearCache();
     Core::make('cache')->flush();
 }
 public function finish()
 {
     $config = \Core::make('config');
     $site_install = $config->getLoader()->load(null, 'site_install');
     // Extract database config, and save it to database.php
     $database = $site_install['database'];
     unset($site_install['database']);
     $renderer = new Renderer($database);
     file_put_contents(DIR_CONFIG_SITE . '/database.php', $renderer->render());
     @chmod(DIR_CONFIG_SITE . '/database.php', Config::get('concrete.filesystem.permissions.file'));
     if (isset($site_install['session-handler']) && $site_install['session-handler']) {
         $config->save('concrete.session.handler', $site_install['session-handler']);
     }
     unset($site_install['session-handler']);
     $renderer = new Renderer($site_install);
     if (!file_exists(DIR_CONFIG_SITE . '/app.php')) {
         file_put_contents(DIR_CONFIG_SITE . '/app.php', $renderer->render());
         @chmod(DIR_CONFIG_SITE . '/app.php', Config::get('concrete.filesystem.permissions.file'));
     }
     $siteConfig = \Site::getDefault()->getConfigRepository();
     if (isset($site_install['canonical-url']) && $site_install['canonical-url']) {
         $siteConfig->save('seo.canonical_url', $site_install['canonical-url']);
     }
     if (isset($site_install['canonical-ssl-url']) && $site_install['canonical-ssl-url']) {
         $siteConfig->save('seo.canonical_ssl_url', $site_install['canonical-ssl-url']);
     }
     @unlink(DIR_CONFIG_SITE . '/site_install.php');
     @unlink(DIR_CONFIG_SITE . '/site_install_user.php');
     $config->clearCache();
     Core::make('cache')->flush();
 }