Hatena::ブログ(Diary)

ヌル日記

2008-09-30

[][]CodeIgniterの学習 12 - FreakAuth_lightを使ってログイン認証を実現してみる - インストール記録 06:07

昨日のエントリで導入した FreakAuth_light (ログイン認証)のインストール記録をメモする。

ファイル数は多いが、まだ構築初期段階なので比較的すんなり設置できた。

後はこの仕組みをどう料理していくかだな。


インストール記録

1)ソースのダウンロード

FreakAuth_light - http://codeigniter.com/wiki/FreakAuth/ から

http://www.4webby.com/freakauth/に飛んで

http://www.4webby.com/freakauth/downloads.html から最新版を取得


2)ソースの解凍

いきなりソース全上書きはしないで一旦windows上で作業する。理由はWinMergeでさくっと比較したいから。

WinMerge - http://winmerge.org/

samba経由で開発サーバ側のディレクトリ構成を直接覗けるようにしている)

解凍したら、./installation_instructions.txtを見てインストール、以上。

なんだけど、一応続きの作業も書いておく。


あとSmartyとかは使わない予定なので、もし使っている場合にはこのままだと適合しないかも。

嫌いというわけじゃないがイラネ 。

|hoge|fuga とかでフィルタかませるのは楽だけど。それよりも、

「他のサンプルソースがそのままでは動かせないかもしれない」とか、

「templates_c ウゼー」

とかに余計な気を使いたくない。


作業:1 FreakAuthのファイルをコピーする

長いけどtreeを貼って、要点を書いておく

.
|-- FreakAuth_DB.sql (ddl文)
|-- FreakAuth_light_1.1
|   |-- public  cssjpgファイル等(ドキュメントルート/public/* に設置)
|   |   |-- admin
|   |   |   |-- css
|   |   |   |   |-- admin_console.css
|   |   |   |   `-- index.html
|   |   |   |-- images
|   |   |   |   |-- Thumbs.db
|   |   |   |   |-- background.jpg
|   |   |   |   |-- cross.png
|   |   |   |   |-- index.html
|   |   |   |   |-- login_toggle.jpg
|   |   |   |   |-- nav_bg.jpg
|   |   |   |   |-- nav_separator.jpg
|   |   |   |   |-- pencil.png
|   |   |   |   |-- transparent.gif
|   |   |   |   `-- zoom.png
|   |   |   |-- index.html
|   |   |   `-- js
|   |   |       `-- index.html
|   |   |-- frontend
|   |   |   |-- css
|   |   |   |   `-- fal_style.css
|   |   |   |-- images
|   |   |   |   |-- Thumbs.db
|   |   |   |   |-- browse_crag_bg.jpg
|   |   |   |   |-- bullet.gif
|   |   |   |   |-- footer_bg.jpg
|   |   |   |   |-- header.jpg
|   |   |   |   `-- tick.png
|   |   |   `-- js
|   |   |       `-- index.html
|   |   |-- images
|   |   |   |-- captcha
|   |   |   |   |-- base_image.jpg
|   |   |   |   `-- index.html
|   |   |   `-- index.html
|   |   |-- index.html
|   |   `-- shared
|   |       |-- css
|   |       |   `-- index.html
|   |       |-- images
|   |       |   |-- arrow.gif
|   |       |   |-- error.png
|   |       |   `-- index.html
|   |       |-- index.html
|   |       `-- js
|   |           |-- flash.js
|   |           |-- index.html
|   |           `-- jquery.js
|   |-- system
|   |   |-- application
|   |   |   |-- config
|   |   |   |   |-- autoload_demo.php (要マージ)
|   |   |   |   |-- config_demo.php (要マージ)
|   |   |   |   |-- freakauth_light.php (要変更)認証系の設定
|   |   |   |   `-- routes_demo.php (要マージ)
|   |   |   |-- controllers
|   |   |   |   |-- admin
|   |   |   |   |   |-- adminhome.php
|   |   |   |   |   |-- admins.php
|   |   |   |   |   |-- example.php
|   |   |   |   |   |-- index.html
|   |   |   |   |   `-- users.php
|   |   |   |   |-- auth.php
|   |   |   |   |-- example.php
|   |   |   |   |-- freakauth_demo.php
|   |   |   |   `-- installer.php
|   |   |   |-- helpers
|   |   |   |   |-- freakauth_light_helper.php
|   |   |   |   `-- index.html
|   |   |   |-- language
|   |   |   |   |-- english丸まるコピーしてjapaneseディレクトリを作る
|   |   |   |   |   |-- freakauth_lang.php
|   |   |   |   |   `-- index.html
|   |   |   |   `-- index.html
|   |   |   |-- libraries
|   |   |   |   |-- Db_session.php既に設置済みのDB_Session.phpを使うので不要但し、リネームとクラス名大文字小文字の修正が必要
|   |   |   |   |-- FAL_front.php
|   |   |   |   |-- FAL_validation.php
|   |   |   |   |-- Freakauth_light.php
|   |   |   |   |-- MyFALVal_demo.php
|   |   |   |   |-- MyFAL_demo.php
|   |   |   |   `-- index.html
|   |   |   |-- models
|   |   |   |   |-- FreakAuth_light
|   |   |   |   |   |-- index.html
|   |   |   |   |   `-- usertemp.php
|   |   |   |   |-- country.php
|   |   |   |   |-- usermodel.php
|   |   |   |   `-- userprofile.php
|   |   |   `-- views
|   |   |       `-- FreakAuth_light
|   |   |           |-- content
|   |   |           |   |-- activation_failed.php
|   |   |           |   |-- activation_success.php
|   |   |           |   |-- forgotten_password_reset_failed.php
|   |   |           |   |-- forgotten_password_reset_success.php
|   |   |           |   |-- forgotten_password_success.php
|   |   |           |   |-- forms
|   |   |           |   |   |-- change_password.php
|   |   |           |   |   |-- forgotten_password.php
|   |   |           |   |   |-- html_for_captcha.php
|   |   |           |   |   |-- index.html
|   |   |           |   |   |-- login.php
|   |   |           |   |   `-- register.php
|   |   |           |   |-- index.html
|   |   |           |   |-- installer.php
|   |   |           |   |-- login_anchor_guest.php
|   |   |           |   |-- login_anchor_user.php
|   |   |           |   |-- register_success.php
|   |   |           |   `-- turned_off.php
|   |   |           |-- email
|   |   |           |   |-- activation_email.php
|   |   |           |   |-- change_password_email.php
|   |   |           |   |-- forgotten_password_email.php
|   |   |           |   |-- forgotten_password_reset_email.php
|   |   |           |   `-- index.html
|   |   |           |-- index.html
|   |   |           |-- template
|   |   |           |   |-- container.php
|   |   |           |   |-- content.php
|   |   |           |   |-- denied.php
|   |   |           |   |-- examples
|   |   |           |   |   |-- conditions.php
|   |   |           |   |   |-- example.php
|   |   |           |   |   |-- examples.php
|   |   |           |   |   `-- restricted.php
|   |   |           |   |-- footer.php
|   |   |           |   |-- header.php
|   |   |           |   |-- index.html
|   |   |           |   `-- menu.php
|   |   |           `-- template_admin
|   |   |               |-- container.php
|   |   |               |-- content.php
|   |   |               |-- example
|   |   |               |   |-- example.php
|   |   |               |   `-- index.html
|   |   |               |-- footer.php
|   |   |               |-- header.php
|   |   |               |-- index.html
|   |   |               |-- menu.php
|   |   |               `-- users
|   |   |                   |-- add.php
|   |   |                   |-- detail.php
|   |   |                   |-- edit.php
|   |   |                   |-- index.html
|   |   |                   `-- list.php
|   |   `-- fonts
|   |       |-- Jester.ttf
|   |       |-- index.html
|   |       `-- texb.ttf既にあるので不要
|   `-- tmp(ドキュメントルート/tmp/ を作る。キャプチャ画像一時保存用)
|       `-- index.html
|-- License.txt
|-- changelog.txt
|-- installation_instructions.txtインストール方法
`-- upgrade_instructions.txt


ファイル設置のポイント:

1)

  • ドキュメントルート/public/*
  • ドキュメントルート/tmp/*

を必ず作って一連のファイルをコピーすること

2)

WinMergeディレクトリ比較で、足りないファイルはコピーし、

既に存在するファイルはコピーしないで既存を優先すること。

3)

application/libraries/DB_Session.php → application/libraries/Db_session.phpリネームし、

ソース内の

  • class DB_Session { → class Db_session { に
  • function DB_Session() → function Db_session() に

変更すること。

4)

いきなり上書きしないでバックアップをとって作業しましょう。

位か。



作業:2 ddl文を流して必要なテーブルを作成する

テーブルは、

FreakAuth_DB.sqlを流せば作れるのだが、

ci_sessions 既に以前のエントリで作成済みなので不要
fa_country
fa_user
fa_user_profile
fa_user_temp

を作る。fa_ のprefixは変えたければ変えられる。(config側で変更できる)



作業:3 mod_rewrite(.htaccess)を修正する

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|img|css|js|xajax_js|tmp|robots\.txt|.+\.gif$|.+\.jpg$|.+\.png$|.+\.js$|.+\.css$)

RewriteRule ^(.*)$ /index.php/$1 [L]

みたいな感じ。



作業:4 configの調整

|-- application
|   |-- config
|   |   |-- autoload_demo.php (要マージ)
|   |   |-- config_demo.php (要マージ)
|   |   |-- freakauth_light.php (要変更)
|   |   `-- routes_demo.php (要マージ)

ここは、環境によっていろいろ違うだろうから、よく考えてやること。

1)autoload_demo.php → autoload.phpとマージ

変更点抜粋

-$autoload['libraries'] = array('database','DB_Session');
+$autoload['libraries'] = array('database','Db_session', 'Freakauth_light');

-$autoload['helper'] = array();
+$autoload['helper'] = array('freakauth_light');

-$autoload['config'] = array();
+$autoload['config'] = array('freakauth_light');

ポイント:DB_Session → Db_sessionにし、 Freakauth_lightを追加した。


2) config_demo.php → config.phpとマージ

変更点抜粋

-$config['url_suffix'] = "";
+$config['url_suffix'] = ".html";

-$config['encryption_key'] = "";
+$config['encryption_key'] = "hogefuga";//暗号化のSALT、本当は適切なものにする

$config['sess_cookie_name']            = 'ci_session';//とりあえずこっちで動く後で調べる
+//$config['sess_cookie_name']          = 'FreakAuth';//マニュアルではこっち

$config['sess_encrypt_cookie'] = FALSE;//開発実験時は暗号化無し
+//$config['sess_encrypt_cookie']       = TRUE;//本稼働時にはこっち

$config['sess_use_database']   = TRUE;//以前のエントリで既にDB2_Sessionを用いて有効化済み

ポイント:コメント内の通り


3) routes_demo.phproutes.phpとマージ

変更点抜粋

$route['default_controller'] = "tasklist";//環境依存、ウチではこれなだけ
$route['scaffolding_trigger'] = "";//サンプルだとなんかあるけど、別に使わない。

+//FAL LOGIN
+$route['admin'] = "admin/adminhome";
+$route['admin/users/:num'] = "admin/users";
+$route['admin/admins/:num'] = "admin/admins";
+//FAL LOGIN end

ポイント: 管理者画面用のroute3行を追加


4) freakauth_light.php → 新規追加&設定変更

変更点抜粋

>  $config['FAL_website_name']    = "YOUR_DOMAIN.com";
<  $config['FAL_website_name']    = "自分のウェブサイト名に変更";


>  $config['FAL_user_support'] = 'you@your-email.com';
<  $config['FAL_user_support'] = 'サポート用メールアドレスに変更';

確認メール本文内等で現れる。




(08/12/12追記)

application/models/usermodel.phpの微修正

CodeIgniter1.7以降では、

<?php
//上略
  function getAdmins($fields=null, $limit=null)
  {
    $fields!=null ? $this->db->select($fields) :'';
        //$this->db->where("role='admin' OR role='superadmin'");
        $this->db->where('role','admin');
        $this->db->or_where('role','superadmin');

    ($limit != null ? $this->db->limit($limit['start'], $limit['end']) : '');

    //returns the query
    return $this->db->get($this->_table);
  }

//下略
 ?>

の様に、

$this->db->where()
を変更しないとうまく動かないので注意。




作業:5 http://開発環境/installer/に接続して、superadminのid/passを作る

http://開発環境/installer/につなぐと、↓の写真みたいなインストーラーで、

動作環境のチェックと、初期idの設定ができる。これが動かなければなんか違う。

(ファイルとか、セッションの設定とか、rewriteとか confとか)

f:id:dix3:20080930063426j:image


作業:6 application/controllersinstaller.phpを削除する

インストーラーは一回限り。リリース環境では絶対に物理削除すること。


(08/12/15追記)

一連のソース内には、テストプログラム(サンプルソース)等も入っている。

リリース時には不要なファイルをちゃんと精査して削除する必要があるこにとも注意。


こういったサンプルソースをそのまま放置すると穴になりかねない。

どんなプログラムでも、サンプルソースや不要な機能は極力ダイエットするのが重要。


(俺がsymfonyとかjoomlaとか重厚長大なものが嫌いなのはこのへん。

ファイル数や機能が多すぎると、事実上ブラックボックス化してしまう。)


余談ですが、

大多数のライトユーザーが、使いもしないxmlrpc.phpとかの機能が既存のCMS等には必ずついてくるけど、

こんな機能は速攻削除(又はhtaccess等で無効化)の対象なので、注意しましょう。

(追記終わり)

作業:7 いろいろ使って試してみる

http://www.4webby.com/freakauth/documentation/freakauth_light.html

とか参考に試す。

昨日のエントリも参照。




今日はここまで。

ずっと同じ事やってると飽きるから、

明日以降はこの詳細をやる前に別の事を試すのだ。

shinshin 2009/10/03 18:42 Question: How do you create a tree diagram? Do you use a software or online tool? If you type it, it must take ages to do it.

dix3dix3 2009/10/03 20:08 Use 'tree' command in a DOS command line or Linux shell

tree > out.txt

:)

トラックバック - http://d.hatena.ne.jp/dix3/20080930

ヌル日記の内容は一切無保証です。個人的な作業履歴なので、実用では穴や間違いがあるかもしれません。

こちらの注意書きも一応読んでくださいね