Skip to content

Commit

Permalink
sslUrl設定削除
Browse files Browse the repository at this point in the history
  • Loading branch information
seto1 committed Jul 8, 2024
1 parent d509c9a commit 8354a7f
Show file tree
Hide file tree
Showing 17 changed files with 8 additions and 133 deletions.
1 change: 0 additions & 1 deletion config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export APP_DEFAULT_TIMEZONE="Asia/Tokyo"
export INSTALL_MODE="true"
export USE_DEBUG_KIT="false"
export SITE_URL="https://localhost/"
export SSL_URL="https://localhost/"
export ADMIN_PREFIX="admin"
export BASER_CORE_PREFIX="baser"
export SQL_LOG="false"
Expand Down
4 changes: 0 additions & 4 deletions plugins/baser-core/config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@
* サイトURL
*/
'siteUrl' => env('SITE_URL', 'https://localhost/'),
/**
* SSL URL
*/
'sslUrl' => env('SSL_URL', 'https://localhost/'),
/**
* CMS URL
* CMSのURLが別ドメインの場合に設定する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function _checkReferer(): bool
}

/**
* siteUrlや、sslUrlと現在のURLが違う場合には、そちらのURLにリダイレクトを行う
* siteUrlや、cmsUrlと現在のURLが違う場合には、そちらのURLにリダイレクトを行う
* setting.php にて、cmsUrlとして、cmsUrlを定義した場合にはそちらを優先する
* @return Response|void|null
* @checked
Expand All @@ -194,8 +194,6 @@ public function redirectIfIsNotSameSite()
{
if (Configure::read('BcEnv.cmsUrl')) {
$siteUrl = Configure::read('BcEnv.cmsUrl');
} elseif ($this->getRequest()->is('https')) {
$siteUrl = Configure::read('BcEnv.sslUrl');
} else {
$siteUrl = Configure::read('BcEnv.siteUrl');
}
Expand Down
4 changes: 0 additions & 4 deletions plugins/baser-core/src/Model/Table/SiteConfigsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public function validationKeyValue(Validator $validator): Validator
->scalar('site_url')
->regex('site_url', '/^(http|https):/', __d('baser_core', 'WebサイトURLはURLの形式を入力してください。'))
->notEmptyString('site_url', __d('baser_core', 'WebサイトURLを入力してください。'));
$validator
->scalar('ssl_url')
->regex('ssl_url', '/^(http|https):/', __d('baser_core', 'WebサイトURLはURLの形式を入力してください。'))
->notEmptyString('ssl_url', __d('baser_core', 'WebサイトURLを入力してください。'));
return $validator;
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Service/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ private function checkGroup(
{
// ドメイン部分を除外
if(preg_match('/^(http(s|):\/\/[^\/]+?\/)(.*?)$/', $url, $matches)) {
if(in_array($matches[1], [Configure::read('BcEnv.siteUrl'), Configure::read('BcEnv.sslUrl')])) {
$url = str_replace([Configure::read('BcEnv.siteUrl'), Configure::read('BcEnv.sslUrl')], '', $url);
if(in_array($matches[1], [Configure::read('BcEnv.siteUrl')])) {
$url = str_replace([Configure::read('BcEnv.siteUrl')], '', $url);
if(!$url) $url = '/';
} else {
return true;
Expand Down
7 changes: 0 additions & 7 deletions plugins/baser-core/src/Service/SiteConfigsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function get(): SiteConfig
$this->entity = $this->SiteConfigs->newEntity(array_merge($this->SiteConfigs->getKeyValue(), [
'mode' => Configure::read('debug'),
'site_url' => Configure::read('BcEnv.siteUrl'),
'ssl_url' => Configure::read('BcEnv.sslUrl'),
]), ['validate' => 'keyValue']);
}
return $this->entity;
Expand Down Expand Up @@ -132,22 +131,16 @@ public function update(array $postData)
if ($siteConfig->site_url && !preg_match('/\/$/', $siteConfig->site_url)) {
$siteConfig->site_url .= '/';
}
if ($siteConfig->ssl_url && !preg_match('/\/$/', $siteConfig->ssl_url)) {
$siteConfig->ssl_url .= '/';
}

if ($this->isWritableEnv()) {
if (isset($siteConfig->mode)) $this->putEnv('DEBUG', ($siteConfig->mode)? 'true' : 'false');
if (isset($siteConfig->site_url)) $this->putEnv('SITE_URL', $siteConfig->site_url);
if (isset($siteConfig->ssl_url)) $this->putEnv('SSL_URL', $siteConfig->ssl_url);
}

$siteConfigArray = $siteConfig->toArray();
unset($siteConfigArray['mode'],
$siteConfigArray['site_url'],
$siteConfigArray['ssl_url'],
$siteConfigArray['dummy-site_url'],
$siteConfigArray['dummy-ssl_url']
);

if ($this->SiteConfigs->saveKeyValue($siteConfigArray)) {
Expand Down
14 changes: 4 additions & 10 deletions plugins/baser-core/src/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2341,32 +2341,26 @@ public function getSiteName()
/**
* WebサイトURLを出力する
*
* @param bool ssl (初期値 : false)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function siteUrl($ssl = false)
public function siteUrl()
{
echo $this->getSiteUrl($ssl);
echo $this->getSiteUrl();
}

/**
* WebサイトURLを取得する
*
* @param bool ssl (初期値 : false)
* @return string サイト基本設定のWebサイト名
* @checked
* @noTodo
*/
public function getSiteUrl($ssl = false)
public function getSiteUrl()
{
if ($ssl) {
return Configure::read('BcEnv.sslUrl');
} else {
return Configure::read('BcEnv.siteUrl');
}
return Configure::read('BcEnv.siteUrl');
}

/**
Expand Down
4 changes: 0 additions & 4 deletions plugins/baser-core/src/View/Helper/BcSmartphoneHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,12 @@ public function afterLayout($layoutFile)
// 内部リンクの自動変換
if ($site->auto_link) {
$siteUrl = Configure::read('BcEnv.siteUrl');
$sslUrl = Configure::read('BcEnv.sslUrl');
$currentAlias = $request->getAttribute('currentSite')->alias;
$base = '/' . $request->getAttribute('base');
$regBaseUrls = [
preg_quote($base, '/'),
preg_quote(preg_replace('/\/$/', '', $siteUrl) . $base, '/'),
];
if ($sslUrl) {
$regBaseUrls[] = preg_quote(preg_replace('/\/$/', '', $sslUrl) . $base, '/');
}
$regBaseUrl = implode('|', $regBaseUrls);

// 一旦プレフィックスを除外
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function testValidationKeyValueRegular()
'name' => 'hoge',
'email' => '[email protected]',
'site_url' => 'https://localhost/',
'ssl_url' => 'https://localhost/',
]);
$this->assertEmpty($errors);
}
Expand All @@ -116,18 +115,14 @@ public function testvalidationKeyValueURL()
{
$validator = $this->SiteConfigs->getValidator('keyValue');
$errors = $validator->validate([
'ssl_url' => 'hoge',
'site_url' => 'hoge',
]);
$this->assertEquals('WebサイトURLはURLの形式を入力してください。', current($errors['ssl_url']));
$this->assertEquals('WebサイトURLはURLの形式を入力してください。', current($errors['site_url']));

$validator = $this->SiteConfigs->getValidator('keyValue');
$errors = $validator->validate([
'ssl_url' => '/hoge',
'site_url' => '/hoge',
]);
$this->assertEquals('WebサイトURLはURLの形式を入力してください。', current($errors['ssl_url']));
$this->assertEquals('WebサイトURLはURLの形式を入力してください。', current($errors['site_url']));
}

Expand Down
1 change: 0 additions & 1 deletion plugins/baser-core/tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function testBootStrap(): void
export INSTALL_MODE="false"
export SITE_URL="https://localhost/"
export SSL_URL="https://localhost/"
export ADMIN_PREFIX="admin"
export BASER_CORE_PREFIX="baser"
export SQL_LOG="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public function testGet()
$result = $this->SiteConfigs->get();
$this->assertArrayHasKey('mode', $result);
$this->assertArrayHasKey('site_url', $result);
$this->assertArrayHasKey('ssl_url', $result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,8 @@ public function testGetLink($title, $url, $option, $expected)
if (!empty($option['forceTitle'])) {
$this->loginAdmin($this->getRequest('/baser/admin'), 2);
}
if (!empty($option['ssl'])) {
Configure::write('BcEnv.sslUrl', 'https://localhost/');
}
$result = $this->BcBaser->getLink($title, $url, $option);
$this->assertEquals($expected, $result);
Configure::write('BcEnv.sslUrl', '');
}

public static function getLinkDataProvider()
Expand All @@ -344,9 +340,6 @@ public static function getLinkDataProvider()
['<b>title</b>', 'https://example.com/<b>link</b>', ['escapeTitle' => false], '<a href="https://example.com/&lt;b&gt;link&lt;/b&gt;"><b>title</b></a>'], // エスケープ
['固定ページ管理', ['prefix' => 'Admin', 'controller' => 'pages', 'action' => 'index'], [], '<a href="/baser/admin/baser-core/pages/index">固定ページ管理</a>'], // プレフィックス
['システム設定', ['Admin' => true, 'controller' => 'site_configs', 'action' => 'index'], ['forceTitle' => true], '<span>システム設定</span>'], // 強制タイトル
['会社案内', '/about', ['ssl' => true], '<a href="https://localhost/about">会社案内</a>'], // SSL
['テーマファイル管理', ['controller' => 'themes', 'action' => 'manage', 'jsa'], ['ssl' => true], '<a href="https://localhost/baser-core/themes/manage/jsa">テーマファイル管理</a>'], // SSL
['画像', '/img/test.jpg', ['ssl' => true], '<a href="https://localhost/img/test.jpg">画像</a>'], // SSL
];
}

Expand Down Expand Up @@ -1816,12 +1809,7 @@ public function testGetSiteName()
public function testGetSiteUrl()
{
Configure::write('BcEnv.siteUrl', 'https://basercms.net/');
Configure::write('BcEnv.sslUrl', 'https://basercms.net/');

// http
$this->assertEquals('https://basercms.net/', $this->BcBaser->getSiteUrl());
//https
$this->assertEquals('https://basercms.net/', $this->BcBaser->getSiteUrl(true));
}

/**
Expand Down
12 changes: 1 addition & 11 deletions plugins/bc-admin-third/templates/Admin/SiteConfigs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,11 @@
<input type="password" name="dummy-site_url" style="display: none">
<?php $this->BcAdminForm->unlockFields('dummy-site_url') ?>
<?php echo $this->BcAdminForm->control('site_url', ['type' => 'text', 'size' => 35, 'maxlength' => 255, 'data-margin' => 'bottom', 'disabled' => !$isWritableEnv]) ?>
<br>
<input type="password" name="dummy-ssl_url" style="display: none">
<?php $this->BcAdminForm->unlockFields('dummy-ssl_url') ?>
<?php echo $this->BcAdminForm->control('ssl_url', [
'type' => 'text',
'size' => 35,
'maxlength' => 255,
'disabled' => !$isWritableEnv]
) ?> <small>[SSL]</small>
<i class="bca-icon--question-circle bca-help"></i>
<div class="bca-helptext">
<?php echo __d('baser_core', 'baserCMSを設置しているURLを指定します。管理画面等でSSL通信を利用する場合は、SSL通信で利用するURLも指定します。') ?>
<?php echo __d('baser_core', 'baserCMSを設置しているURLを指定します。') ?>
</div>
<?php echo $this->BcAdminForm->error('site_url') ?>
<?php echo $this->BcAdminForm->error('ssl_url') ?>
</td>
</tr>

Expand Down
1 change: 0 additions & 1 deletion plugins/bc-installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public function install(Arguments $args, ConsoleIo $io, array $dbConfig)
$service->buildPermissions();
$siteConfigsService = $this->getService(SiteConfigsServiceInterface::class);
$siteConfigsService->putEnv('SITE_URL', $siteUrl);
$siteConfigsService->putEnv('SSL_URL', $siteUrl);
if ($dbConfig['datasource'] === 'postgres') {
$service->BcDatabase->updateSequence();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public function initDb(ServerRequest $request): void
// SITE_URL更新
$siteConfigsService = $this->getService(SiteConfigsServiceInterface::class);
$siteConfigsService->putEnv('SITE_URL', BcUtil::siteUrl());
$siteConfigsService->putEnv('SSL_URL', BcUtil::siteUrl());

// シーケンスを更新する
$dbConfig = ConnectionManager::getConfig('default');
Expand Down
26 changes: 0 additions & 26 deletions plugins/bc-mail/src/Model/Table/MailContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,9 @@ public function validationDefault(Validator $validator): Validator
'message' => __d('baser_core', 'BCC用送信先メールアドレスのEメールの形式が不正です。')
]]);

// ssl_on
$validator
->add('ssl_on', [
'checkSslUrl' => [
'rule' => 'checkSslUrl',
'provider' => 'table',
'message' => __d('baser_core', 'SSL通信を利用するには、システム設定で、事前にSSL通信用のWebサイトURLを指定してください。')
]]);

return $validator;
}

/**
* SSL用のURLが設定されているかチェックする
*
* @param array $check チェック対象文字列
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function checkSslUrl($value)
{
if ($value && !Configure::read('BcEnv.sslUrl')) {
return false;
}
return true;
}

/**
* 英数チェック
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,6 @@ public function testInputTypeErrors()
$this->assertEquals('リダイレクトURLはURLの形式を入力してください。', current($errors['redirect_url']));
}

public function testSSLTrue()
{
Configure::write('BcEnv.sslUrl', 'on');
$validator = $this->MailContent->getValidator('default');
$errors = $validator->validate([
'ssl_on' => ['on'],
]);
$this->assertCount(0, $errors);
}

public function testSSLFalse()
{
Configure::write('BcEnv.sslUrl', '');
$validator = $this->MailContent->getValidator('default');
$errors = $validator->validate([
'ssl_on' => ['on'],
]);

$this->assertEquals('SSL通信を利用するには、システム設定で、事前にSSL通信用のWebサイトURLを指定してください。', current($errors['ssl_on']));
}

public function testURLErrors()
{
//エラーテスト
Expand Down Expand Up @@ -199,25 +178,6 @@ public function testURLErrors()
$this->assertCount(0, $errors);
}

/**
* SSL用のURLが設定されているかチェックする
* @dataProvider checkSslUrlProvider
*/
public function testCheckSslUrl($expected, $sslUrl, $value)
{
Configure::write('BcEnv.sslUrl', $sslUrl);
$this->assertEquals($expected, $this->MailContent->checkSslUrl($value));
}

public static function checkSslUrlProvider()
{
return [
[true, true, 'https://example.com/'],
[false, false, 'https://example.com/'],
[true, false, null],
];
}

/**
* 英数チェック
* @dataProvider alphaNumericDataProvider
Expand Down

0 comments on commit 8354a7f

Please sign in to comment.