Exemple #1
0
 public function __construct(ArgumentsParser $argv)
 {
     parent::__construct($argv);
     if (!$this->arguments()->getCommand(2)) {
         $this->writeln('No domain specified, format is: springo-agent envars:set mysite.com --ENV1="first" --EXAMPLE2="another"')->exitWithError();
     }
     $this->identifier = fqdn_to_directory($this->arguments()->getCommand(2));
     $this->cli_envars = $this->readFromArgs();
     $this->local_envars = $this->readFromLocal($this->identifier);
 }
Exemple #2
0
 /**
  * Validates required arguments.
  * @return void
  */
 private function validateArguments()
 {
     foreach ($this->required_args as $requirement) {
         if (!$this->arguments()->getOption($requirement)) {
             $this->writeln(sprintf('No --%s option was specified!', $requirement))->exitWithError();
         }
     }
     $this->identifier = fqdn_to_directory($this->arguments()->getOption('domain'));
     $this->type = $this->arguments()->getOption('type');
     if (!$this->templateExists()) {
         $this->writeln('The requested scheduler template was found, aborting!')->exitWithError();
     }
 }
Exemple #3
0
 /**
  * Creates the Nginx virtualhost configuration file.
  * @param ArgumentsParser $arguments
  * @return type
  */
 protected function createVhostConfig(ArgumentsParser $arguments)
 {
     $nginx_conf = self::VHOST_AVAILABLE_DIR . DIRECTORY_SEPARATOR . $this->identifier . '.conf';
     $configuration = file_get_contents(base_path() . '/templates/nginx_vhost.template');
     $tags = ['ident' => fqdn_to_directory($this->arguments()->getOption('domain')), 'root' => $this->root, 'index' => $this->index, 'fqdns' => $this->nginxServerName($this->arguments()->getOption('domain'), $this->extractAliases($this->arguments()->getOption('aliases', '')))];
     foreach ($tags as $tag_key => $tag_value) {
         $configuration = str_replace(sprintf('{{ %s }}', $tag_key), $tag_value, $configuration);
     }
     if (!@file_put_contents($nginx_conf, $configuration)) {
         $this->writeln(SpringoAgent::TAG_ERROR . "Unable to create virtual host configuration file in {$nginx_conf}");
         return;
     }
     $symlink = self::VHOST_ENABLED_DIR . DIRECTORY_SEPARATOR . $this->identifier . '.conf';
     if (!@symlink($nginx_conf, $symlink)) {
         $this->writeln(SpringoAgent::TAG_ERROR . "Unable to create virtual host link file in {$symlink}");
         return;
     }
 }
Exemple #4
0
 /**
  * Removes HTTP redirection configuration from a specified VHOST.
  * @return void
  */
 public function removeHttpRedirection()
 {
     $this->domain = $this->arguments()->getOption('domain', false);
     $this->identifier = fqdn_to_directory($this->domain);
     if (!$this->domain) {
         $this->writeln("No domain specified, use --domain to specify the domain!")->exitWithError();
     }
     $vhost_conf = NginxHandler::VHOST_AVAILABLE_DIR . DIRECTORY_SEPARATOR . $this->identifier . '.conf';
     if (!@file_put_contents($vhost_conf, replace_between(file_get_contents($vhost_conf), '# [[HTTPS-REDIR]]', '# [[!HTTPS-REDIR]]', PHP_EOL))) {
         $this->writeln(SpringoAgent::TAG_ERROR . "Unable to update virtual host configuration file in {$vhost_conf}");
         return;
     }
     $this->writeln('Done!');
 }
Exemple #5
0
 /**
  * Add the LetsEncrypt SSL configuration in the Nginx virtualhost
  * configuraiton file.
  * @return void
  */
 private function addConfigToNginx()
 {
     $configuration = file_get_contents(base_path() . '/templates/nginx_letsencrypt.template');
     $tags = ['domain' => fqdn_to_directory($this->arguments()->getOption('domain'))];
     foreach ($tags as $tag_key => $tag_value) {
         $configuration = str_replace(sprintf('{{ %s }}', $tag_key), $tag_value, $configuration);
     }
     $vhost_config = NginxHandler::VHOST_AVAILABLE_DIR . DIRECTORY_SEPARATOR . $this->identifier . '.conf';
     file_put_contents($vhost_config, replace_between(file_get_contents($vhost_config), '# [[LESSL]]', '# [[!LESSL]]', PHP_EOL . $configuration . PHP_EOL));
     file_put_contents($vhost_config, replace_between(file_get_contents($vhost_config), '# [[SERVER-PORT]]', '# [[!SERVER-PORT]]', PHP_EOL . 'listen 443 ssl;' . PHP_EOL));
 }