インストーラ改修(3) インストール前に権限チェック
インストーラのindex()アクションで、事前にインストール&運用に必要なディレクトリやファイルの権限チェックと表示を追加しました。
controllerで権限チェックを行い、設定不備の場合$errorにセットします。
index.ctpでは、エラーのある場合 「Click here to begin installation」の代わりにエラー内容を表示。
設定不備がある場合でも、アクションURLを手入力すれば先に進めてしまうのですが、管理画面アクションだしそこまで制限はしてません。
app/plugins/install/controllers/install_controller.php
function index() { + + // file/dir check + $error = array(); + $permissions = array( + array( + 'path' => APP.'config', + 'type' => 'dir', + ), + array( + 'path' => TMP, + 'type' => 'dir', + ), + array( + 'path' => WWW_ROOT. 'media', + 'type' => 'dir', + ), + ); + + // check file_exists + if (!file_exists(APP.'config'.DS.'database.php.install') || !is_readable(APP.'config'.DS.'datab + $error['nofile'][] = APP.'config'.DS.'database.php.install'; + } else { + $permissions[] = array( + 'path' => APP.'config'.DS.'database.php.install', + 'type' => 'file', + ); + } + + // check permission + foreach ($permissions as $k => $v) { + $allowed = array(); + if ($v['type'] == 'dir') { + $allowed = array('0777', '0707'); + } elseif ($v['type'] == 'file') { + $allowed = array('0777', '0707', '0666', '0606'); + } + + if (!in_array(substr(sprintf('%o', fileperms($v['path'])), -4), $allowed)) { + $error['permission'][] = $v['path']; + } + } + $this->set('error', $error); + $this->pageTitle = __('Installation: Welcome', true); }
app/tmp(TMP)はCakePHPに必須。
app/config と app/config/database.php.installの設定は、このプラグインには必須。
app/werboot/mediaは、私がMediaプラグイン導入してるから追加しています。
app/plugins/install/views/index.ctp
<div class="install index"> <h2><?php echo $this->pageTitle; ?></h2> +<?php if (!empty($error)): ?> + +<?php echo $html->div('message', 'ERROR') ?> +<?php if (isset($error['nofile'])): ?> +<?php __('Set below Files.'); ?> +<?php + foreach($error['nofile'] as $v) { + echo $html->div('error-message', $v); + } + ?> + <?php endif; ?> +<?php if(isset($error['permission'])): ?> +<?php __('Check Permission of them.'); ?> +<?php + foreach($error['permission'] as $v) { + echo $html->div('error-message', $v); + } + ?> +<br> +<br> +<?php echo $html->link(__('Reload', true), Router::url('/', true)); ?> +<?php endif; ?> +<?php else: ?> <p><?php echo $html->link('Click here to begin installation', array('action' => 'database')); ?></ +<?php endif; ?> </div>