Skip to content

Commit

Permalink
Add "--enable-https" option for "add-domains" command
Browse files Browse the repository at this point in the history
  • Loading branch information
NoHate committed Mar 1, 2019
1 parent decf933 commit 6b4fbc0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ php cloud.php show-domains --save-to my-domains.csv
- --skip-existing (-s) - Если указан, то скрипт не будет пытаться добавить DNS записи для доменов которые уже добавлены в аккаунт
- --enable-proxy (-p) - Если указан, то скрипт будет включать проксирование для добавленных DNS записей
- --enable-always-online - Если указан, то скрипт не будет отключать AlwaysOnline для доменов. (по-умолчанию скрипт отключает эту настройку)
- --enable-https - Если указан, вклчюает опцию "Always use Https" (эта опция включает автоматический редирект http -> https)

Если не указан параметр `--ip`, то IP должен быть указан для КАЖДОГО домена в файле с доменами (в формате `домен|ip`).
Пример такого файла:
Expand Down
16 changes: 16 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ public function setAlwaysOnlineEnabled($zone_id, $enabled)
return $response->result;
}

/**
* @param string $zone_id
* @param string $enabled "on" or "off"
*
* @return stdClass
*/
public function setAlwaysUseHttpsEnabled($zone_id, $enabled)
{
$zone = new Zone\Settings($this->api);

$response = $zone->change_always_use_https($zone_id, $enabled);
$this->checkSuccessApiResponse($response);

return $response->result;
}

/**
* @param Domain $domain
* @param bool $proxy
Expand Down
8 changes: 8 additions & 0 deletions src/Console/AddDomainsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function configure()
$this->addOption('skip-existing', 's', InputOption::VALUE_NONE, 'Skip existing domains');
$this->addOption('enable-proxy', 'p', InputOption::VALUE_NONE, 'Enable CloudFlare proxy for DNS records');
$this->addOption('enable-always-online', null, InputOption::VALUE_NONE, 'Skip disabling Always Online');
$this->addOption('enable-https', null, InputOption::VALUE_NONE, 'Enable "Always use HTTPS" option');
}

protected function process(InputInterface $input, OutputInterface $output)
Expand All @@ -31,6 +32,7 @@ protected function process(InputInterface $input, OutputInterface $output)
$skip = (bool)$input->getOption('skip-existing');
$proxy = (bool)$input->getOption('enable-proxy');
$always_online = (bool)$input->getOption('enable-always-online');
$enable_https = (bool)$input->getOption('enable-https');

$domains = $this->app->readDomains($domains_file);

Expand Down Expand Up @@ -65,6 +67,12 @@ protected function process(InputInterface $input, OutputInterface $output)
$output->writeln("success");
}

if ($enable_https) {
$output->write("Enabling \"Always use HTTPS\" option for '{$domain->domain}' ... ");
$this->app->setAlwaysUseHttpsEnabled($domain_info['id'], "on");
$output->writeln("success");
}

$output->writeln("===============================");
} catch (Exception $e) {
$output->writeln("error. Message: " . $e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class Version
{
const VERSION = "2.0.0";
const VERSION = "2.0.1";
const USER_AGENT = "CloudFlareImport";
}

0 comments on commit 6b4fbc0

Please sign in to comment.