source: branches/feature-module-update/data/downloads/module/security/security.php @ 15078

Revision 15078, 5.4 KB checked in by nanasess, 17 years ago (diff)

r15064 から svn cp
とりあえず暫定コミット.

  • UTF-8 に変更
  • slib.php, glib.php のクラス化
  • LC_Page の抽象化(一部)
Line 
1<?php
2/**
3 *
4 * @copyright   2000-2006 LOCKON CO.,LTD. All Rights Reserved.
5 * @version CVS: $Id: ebis_tag.php,v 1.0 2006/10/26 04:02:40 naka Exp $
6 * @link        http://www.lockon.co.jp/
7 *
8 */
9 
10//ページ管理クラス
11class LC_Page {
12    //コンストラクタ
13    function LC_Page() {
14        //メインテンプレートの指定
15        $this->tpl_mainpage = MODULE_PATH . 'security/security.tpl';
16        $this->tpl_subtitle = 'セキュリティチェック';
17    }
18}
19
20$objPage = new LC_Page();
21$objView = new SC_AdminView();
22
23switch($_POST['mode']) {
24case 'edit':
25    $inst_inc = DATA_PATH . 'install.php';
26    // install.phpの隠蔽
27    $hidden_inc = MODULE_PATH . 'security/install_inc.php';
28    if(sfIsNormalInstallInc()) {
29        if(copy($inst_inc, $hidden_inc)) {
30            if(file_exists($hidden_inc)) {
31                $require = "<?php\n".
32                           "    require_once('$hidden_inc');\n".
33                           "?>";
34                if($fp = fopen($inst_inc,"w")) {
35                    fwrite($fp, $require);
36                    fclose($fp);
37                }
38            }
39        }
40    }
41    break;
42default:
43    break;
44}
45
46$arrList[] = sfCheckOpenData();
47$arrList[] = sfCheckInstall();
48$arrList[] = sfCheckIDPass('admin', 'password');
49$arrList[] = sfCheckInstallInc();
50
51$objPage->arrList = $arrList;
52
53$objView->assignobj($objPage);                  //変数をテンプレートにアサインする
54$objView->display($objPage->tpl_mainpage);      //テンプレートの出力
55//-------------------------------------------------------------------------------------------------------
56// 設定ファイル(data)のパスが公開パスでないか確認する
57function sfCheckOpenData() {
58    // ドキュメントルートのパスを推測する。
59    $doc_root = ereg_replace(URL_DIR . "$","/",HTML_PATH);
60    $data_path = realpath(DATA_PATH);
61   
62    // dataのパスがドキュメントルート以下にあるか判定
63    if(ereg("^".$doc_root, $data_path)) {
64        $arrResult['result'] = "×";
65        $arrResult['detail'] = "設定ファイルが、公開されている可能性があります。<br>";
66        $arrResult['detail'].= "/data/ディレクトリは、非公開のパスに設置して下さい。";
67    } else {
68        $arrResult['result'] = "○";
69        $arrResult['detail'] = "設定ファイルは、公開パス配下に存在しません。";       
70    }
71   
72    $arrResult['title'] = "設定ファイルの保存パス";
73    return $arrResult;
74}
75
76// インストールファイルが存在するか確認する
77function sfCheckInstall() {
78    // インストールファイルの存在チェック
79    $inst_path = HTML_PATH . "install/index.php";
80   
81    if(file_exists($inst_path)) {
82        $arrResult['result'] = "×";
83        $arrResult['detail'] = "/install/index.phpは、インストール完了後にファイルを削除してください。";           
84    } else {
85        $arrResult['result'] = "○";
86        $arrResult['detail'] = "/install/index.phpは、見つかりませんでした。";   
87    }
88   
89    $arrResult['title'] = "インストールファイルのチェック";
90    return $arrResult;
91}
92
93// 管理者ユーザのID/パスワードチェック
94function sfCheckIDPass($user, $password) {
95    $objQuery = new SC_Query();
96    $sql = "SELECT password FROM dtb_member WHERE login_id = ? AND del_flg = 0";
97    // DBから暗号化パスワードを取得する。
98    $arrRet = $objQuery->getAll($sql, array($user));
99    // ユーザ入力パスワードの判定
100    $ret = sha1($password . ":" . AUTH_MAGIC);
101   
102    if($ret == $arrRet[0]['password']) {
103        $arrResult['result'] = "×";
104        $arrResult['detail'] = "非常に推測のしやすい管理者IDとなっています。個人情報漏洩の危険性があります。";       
105    } else {
106        if(count($arrRet) > 0) {
107            $arrResult['result'] = "△";
108            $arrResult['detail'] = "管理者名に「admin」を利用しないようにして下さい。";               
109        } else {
110            $arrResult['result'] = "○";
111            $arrResult['detail'] = "独自のID、パスワードが設定されているようです。";               
112        }
113    }
114   
115    $arrResult['title'] = "ID/パスワードのチェック";
116    return $arrResult;
117}
118
119
120// install.phpのファイルをチェックする
121function sfCheckInstallInc() {
122    // install.phpが隠蔽後のものか判定する
123    if(sfIsNormalInstallInc()) {
124        $arrResult['result'] = "×";
125        $arrResult['detail'] = "install.phpを簡単に表示できなくすることができます。内容を隠蔽しますか?";
126        $arrResult['detail'].= "<input type='submit' value='隠蔽する'>";       
127    } else {
128        $arrResult['result'] = "○";
129        $arrResult['detail'] = "install.phpの隠蔽対策がとられています。";                       
130    }
131    $arrResult['title'] = "install.phpの可読性チェック";
132    return $arrResult;
133}
134
135// install.phpが隠蔽後のものか判定する
136function sfIsNormalInstallInc() {
137    // install.phpのパスを取得する
138    $inst_inc = DATA_PATH . 'install.php';
139    if(file_exists($inst_inc)) {
140        if($fp = fopen($inst_inc, "r")) {
141            $data = fread($fp, filesize($inst_inc));
142            fclose($fp);
143        }
144        if(ereg("DB_PASSWORD", $data)) {
145            return true;
146        }
147    }
148    return false;
149}
150
151?>
Note: See TracBrowser for help on using the repository browser.