LoginSignup
5
5

More than 3 years have passed since last update.

HumHubをインストールしたら最初にやっておくべきこと

Last updated at Posted at 2018-02-12

概要

HumHubをインストールしたら、最初に行ったほうがよいセキュリティ対策など。

目次

  1. Protected、その他dotfileを公開ディレクトリより上に設置する
  2. index.phpの書き換え
  3. index-test.phpの書き換え
  4. URLのGETパラメータをキレイにする
  5. ユーザーのPasswordの文字数を制限する
  6. ユーザー名(ログインID)は半角英数字、ハイフン、アンダーバーのみ使用を許可する
  7. ログインなしでもコンテンツを閲覧できるようにする場合
  8. 本番リリースの際はDebugモードを無効にする
  9. バックアップについて

関連

Protected、その他dotfileを公開ディレクトリより上に設置する

デフォルトでは、全てのファイルが公開ディレクトリより下に設置される。

.htaccessで、protectedディレクトリ以下をブラウザから直接参照できないようにはなっているが、セキュリティ的に良くないので、protected、また以下のファイルを公開ディレクトリより上に移動させる。

  • protected
  • composer.json
  • package.json
  • Gruntfile.js
  • .codeclimate.yml
  • .editorconfig
  • .travis.yml
  • CONTRIBUTING.md
  • ruleset.xml

index.phpの書き換え

index.phpを以下に書き換えてください。

  • 変更点
    • requireされているprotectedディレクトリのパスを変更する
<?php

/**
 * @link https://www.humhub.org/
 * @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
 * @license https://www.humhub.com/licences
 */

// comment out the following two lines when deployed to production
if ($_SERVER['ENV'] == 'development') {
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
}

-require(__DIR__ . '/protected/vendor/autoload.php');
-require(__DIR__ . '/protected/vendor/yiisoft/yii2/Yii.php');
+require(__DIR__ . '/../protected/vendor/autoload.php');
+require(__DIR__ . '/../protected/vendor/yiisoft/yii2/Yii.php');

$config = yii\helpers\ArrayHelper::merge(
-    require(__DIR__ . '/protected/humhub/config/common.php'),
-    require(__DIR__ . '/protected/humhub/config/web.php'),
-    (is_readable(__DIR__ . '/protected/config/dynamic.php')) ? require(__DIR__ . '/protected/config/dynamic.php') : [],
-    require(__DIR__ . '/protected/config/common.php'),
-    require(__DIR__ . '/protected/config/web.php')
+    require(__DIR__ . '/../protected/humhub/config/common.php'),
+    require(__DIR__ . '/../protected/humhub/config/web.php'),
+    (is_readable(__DIR__ . '/../protected/config/dynamic.php')) ? require(__DIR__ . '/../protected/config/dynamic.php') : [],
+    require(__DIR__ . '/../protected/config/common.php'),
+    require(__DIR__ . '/../protected/config/web.php')
);

(new humhub\components\Application($config))->run();

index-test.phpの書き換え

index-test.phpを以下に書き換えてください。

  • 変更点
    • irequireされている、protectedディレクトリのパスを変更する
    • localhost以外からこのファイルにアクセスされた場合は、index.phpにリダイレクトさせる
<?php

/**
 * @link https://www.humhub.org/
 * @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
 * @license https://www.humhub.com/licences
 */
// NOTE: Make sure this file is not accessible when deployed to production
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
-    die('You are not allowed to access this file.');
+    header('Location: /');
}

/*defined('YII_DEBUG') or define('YII_DEBUG', true);*/
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_ENV_TEST') or define('YII_ENV_TEST', true);

-require(__DIR__ . '/protected/vendor/autoload.php');
-require(__DIR__ . '/protected/vendor/yiisoft/yii2/Yii.php');
+require(__DIR__ . '/../protected/vendor/autoload.php');
+require(__DIR__ . '/../protected/vendor/yiisoft/yii2/Yii.php');

$config = yii\helpers\ArrayHelper::merge(
    // add more configurations here
-    (is_readable(__DIR__ . '/../protected/humhub/tests/codeception/config/dynamic.php')) ? require(__DIR__ . '/../protected/humhub/tests/codeception/config/dynamic.php') : [],
-    require(__DIR__ . '/../protected/humhub/tests/codeception/config/acceptance.php')
+    (is_readable(__DIR__ . '/protected/humhub/tests/codeception/config/dynamic.php')) ? require(__DIR__ . '/protected/humhub/tests/codeception/config/dynamic.php') : [],   
+    require(__DIR__ . '/protected/humhub/tests/codeception/config/acceptance.php')
);

(new humhub\components\Application($config))->run();

protected/humhub/config/assets.phpの書き換え

 <?php

 /**
  * @link https://www.humhub.org/
  * @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
  * @license https://www.humhub.com/licences
  */

 /**
  * Configuration file for the "yii asset" console command.
  */

 // In the console environment, some path aliases may not exist. Please define these:
 Yii::setAlias('@webroot', __DIR__ . '/../../../');
 Yii::setAlias('@web', '/');

-Yii::setAlias('@webroot-static', __DIR__ . '/../../../static');
+Yii::setAlias('@webroot-static', __DIR__ . '/../../../public/static');
 Yii::setAlias('@web-static', '/static');

Gruntfile.jsの書き換え

module.exports = function (grunt) {



    var uglifyAssetcfg = {};
    uglifyAssetcfg[grunt.option('to')] = grunt.option('from');

    var cssMinAssetcfg = {};
    cssMinAssetcfg[grunt.option('to')] = [grunt.option('from')];

    grunt.log.write(grunt.option('from'));

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
         clean: ["assets/*"],
         shell: {
             buildAssets: {
-                command: "rm static/js/all-*.js ; rm static/css/all-*.css ; rm -rf static/assets/* ; cd protected ; php yii asset humhub/config/assets.php humhub/config/assets-prod
+                command: "rm public/static/js/all-*.js ; rm public/static/css/all-*.css ; rm -rf public/static/assets/* ; cd protected ; php yii asset humhub/config/assets.php humh
             },
             buildSearch: {
                 command: "cd protected ; php yii search/rebuild"

URLのGETパラメータをキレイにする

以下を参照。

ユーザーのPasswordの文字数を制限する

パスワードの文字数制限が、変更時には指定されているが、何故か新規登録時には指定されていないので、以下を追記する。

protected/humhub/modules/user/models/Password.php

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['newPassword', 'newPasswordConfirm'], 'required', 'on' => 'registration'],
            [['newPassword', 'newPasswordConfirm'], 'trim'],
+           [['newPassword', 'newPasswordConfirm'], 'string', 'min' => 6, 'max' => 255],
            [['user_id'], 'integer'],
            [['password', 'salt'], 'string'],
            [['created_at'], 'safe'],
            [['algorithm'], 'string', 'max' => 20],
            [['currentPassword'], CheckPasswordValidator::className(), 'on' => 'changePassword'],
            [['newPassword', 'newPasswordConfirm', 'currentPassword'], 'required', 'on' => 'changePassword'],
            [['newPassword', 'newPasswordConfirm'], 'string', 'min' => 6, 'max' => 255, 'on' => 'changePassword'],
            [['newPassword'], 'unequalsCurrentPassword', 'on' => 'changePassword'],
            [['newPasswordConfirm'], 'compare', 'compareAttribute' => 'newPassword', 'on' => 'changePassword'],
            [['newPasswordConfirm'], 'compare', 'compareAttribute' => 'newPassword', 'on' => 'registration'],
        ];
    }

ユーザー名(ログインID)は半角英数字、ハイフン、アンダーバーのみ使用を許可する

以下を参照。
HumHubでvalidationルールを追加する

ログインなしでもコンテンツを閲覧できるようにする場合

管理ユーザーで、Administration 管理メニューへ行く。
URL: /index.php?r=admin%2Fauthentication

左メニューのユーザー -> 設定タブ の順に進み、以下にチェックを入れると、ログインしていなくても、一部のページの閲覧が可能になります。

Allow limited access for non-authenticated users (guests)

デフォルトではチェックは入っていません。

その他の公開に関する設定もこちらで行えます。

本番リリースの際はDebugモードを無効にする

本番公開する場合は、index.phpの以下の箇所をコメントアウトし、画面にエラーログなどが表示されないようにします。

// comment out the following two lines when deployed to production
// defined('YII_DEBUG') or define('YII_DEBUG', true);
// defined('YII_ENV') or define('YII_ENV', 'dev');

参考:http://docs.humhub.org/admin-security.html

ちなみにここをコメントアウトすると

defined('YII_DEBUG') or define('YII_DEBUG', true);
をコメントアウトすると、初期設定をするinstallerが動かなくなります。

// comment out the following two lines when deployed to production
// この行だけをコメントアウトするだけで、installerが動かなくなる
defined('YII_DEBUG') or define('YII_DEBUG', true);
// この行だけをコメントアウトしても、installerは動く
defined('YII_ENV') or define('YII_ENV', 'dev');

初期設定をしていない状態で
https://sample.com/installer/index
にアクセスし「次へ」をクリックすると、以下のURIを無限に読み込もうとし、先のページへ進めなくなります。

https://sample.com/installer/index?_pjax=%23layout-content&_=1521524544905

ブラウザのinspectorのNetworkタブを見ると、その挙動を確認できます。

Screen Shot 2018-03-23 at 1.47.06.png

バックアップについて

以下は、ユーザーの行動によって、動的に中身が変わるディレクトリなので、バックアップを取ることをおすすめします。

dir desc
/protected/modules Admin管理画面でインストールしたモジュール群
/protected/config DBアカウントなどが書かれたdynamic.phpが動的に書き換わる
/uploads ユーザーがアップロードした画像など
/themes/yourtheme テーマを変更した場合に格納される

TOPページのURLを変更する

デフォルトでは、https://example.com/のようなURLでアクセスすると、https://example.com/dashboardにリダイレクトされるようになっている。
これを、以下のどちらでもでTOPページアクセスできるようにする。

protected/humhub/modules/dashboard/config.php
<?php

 return [
     'id' => 'dashboard',
     'class' => \humhub\modules\dashboard\Module::className(),
     'isCoreModule' => true,
     'events' => array(
         array('class' => \humhub\widgets\TopMenu::className(), 'event' => \humhub\widgets\TopMenu::EVENT_INIT, 'callback' => array('\humhub\modules\dashboard\Events', 'onTopMenuInit')),
     ),
     'urlManagerRules' => [
-        'dashboard' => 'dashboard/dashboard'
+        'dashboard' => 'dashboard/dashboard',
+        '/' => 'dashboard/dashboard'
     ]
 ];
?>

各メニューのトップページのリンクを、/dashboardから/に変更する。

protected/humhub/config/web.php
 <?php

 /**
  * @link https://www.humhub.org/
  * @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
  * @license https://www.humhub.com/licences
  */

 $config = [
     'id' => 'humhub',
     'bootstrap' => ['humhub\components\bootstrap\LanguageSelector'],
-    'homeUrl' => ['/dashboard/dashboard'],
+    'homeUrl' => ['/'],
     'defaultRoute' => '/home',
     'layoutPath' => '@humhub/views/layouts',
     'components' => [

参考

5
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5