インストーラ改修(5) core.phpの書換え:Security.salt

CandyCaneベースのインストーラで、core.phpの設定(Security.salt)をランダムハッシュで行なう改修です。

この機能追加は、概ねCroogo ver.1.3の仕様ベースです。


controllerのコア処理

 まず、app/configに core.phpが書込み可能で存在する事が必須条件なので、インストーラ開始時にチェックします。


app/plugins/install/controllers/install_controller.php

@@ -80,6 +80,14 @@ class InstallController extends InstallAppController {
	// check file_exists
(中略)
+       if (!file_exists(APP.'config'.DS.'core.php') || !is_readable(APP.'config'.DS.'core.php')) {
+               $error['nofile'][] = APP.'config'.DS.'core.php';
+       } else {
+               $permissions[] = array(
+                       'path' => APP.'config'.DS.'core.php',
+                       'type' => 'file',
+               );
+       }

        // check permission
        foreach ($permissions as $k => $v) {
@@ -176,6 +184,19 @@ class InstallController extends InstallAppController {
     function finish() {
         $this->pageTitle = __('Installation completed successfully', true);

+               // set new salt and seed value
+               $File =& new File(CONFIGS . 'core.php');
+               if (!class_exists('Security')) {
+                   require LIBS . 'security.php';
+               }
+               $salt = Security::generateAuthKey();
+               $seed = mt_rand() . mt_rand();
+               $contents = $File->read();
+               $contents = preg_replace('/(?<=Configure::write\(\'Security.salt\', \')([^\' ]+)(?=\'\)
+//             $contents = preg_replace('/(?<=Configure::write\(\'Security.cipherSeed\', \')(\d+)(?=\'
+               if (!$File->write($contents)) {
+                       $this->Session->setFlash(__('Could not set Security.salt of "app/config/core.ph
+               }

"Security.cipherSeed" という設定は、ver1.2.5時点で見当たらないので、とりあえずコメントアウトしました。


以上で、core.phpのsalt設定はランダムハッシュ生成されるようになります。


あとは、完了画面(finish)で、パーミッション設定の変更を促す一文を追加。

--- a/app/plugins/install/views/install/finish.ctp
+++ b/app/plugins/install/views/install/finish.ctp
@@ -2,13 +2,17 @@
     <h2><?php echo $this->pageTitle; ?></h2>

     <p>
-        <?php __('Change the permission of <strong>app/config to 755</strong>, and <strong>app/config/
+        <?php __('CHANGE the PERMISSION of <strong>app/config</strong> to 755, <strong>app/config/data
     </p>

     <p>
         <?php __('Delete the installation directory <strong>/app/plugins/install</strong>.') ?>
     </p>

+    <p>
+        <?php __('If you want to <strong>change the ORIGINAL SETTINGS</strong> of CakePHP for example
+    </p>
+
     <br />