OSDN Git Service

PHP Notice対応
[trpgtools-onweb/AjaxChat.git] / setup.php
1 <?php
2 /*
3  Ajax Chat for TRPG ver.2.6.2
4  (c)2007-2009 Cake All Rights Reserved.
5  Mail : cake_67@users.sourceforge.jp
6  Home : http://trpgtools-onweb.sourceforge.jp/
7  */
8 /*****************
9  *  かんたんセットアップ
10  *****************/
11 // 設定ファイルの読み込み
12 require_once './trpgchat-ini-2.php';
13 require_once './lib/trpgchat.php';
14 require_once './lib/setup.php';
15
16 if (file_exists('./trpgchat-ini.php')) {
17     error('セットアップ済みです。再度セットアップする際は、index.phpと同じディレクトリにあるtrpgchat-ini.phpを削除してください', false, false, true);
18 }
19
20 // 受信データの成形
21 $request = request();
22 $mode = $request['mode'];
23 $prev_dir = $request['previous_chat_dir'];
24
25 /* セットアップ開始 */
26 print html_header_setup();
27 ?>
28 </head>
29 <body>
30 <?php
31 // 入り口
32 if (!$mode) {
33     print '<p>Ajax Chat for TRPGのセットアップを始めます。<br>以下から選択してください。</p>';
34     print '<form action="./setup.php" method="'.METHOD.'">';
35     print '<table border="1">'."\n";
36     print '<tr><td>';
37     print input_area('radio', 'mode', 'install', '', '', 'checked'). ":新規インストール<br>\n";
38     print input_area('radio', 'mode', 'verup', ''). ":バージョンアップ<br>\n";
39     print " * バージョンアップは<font color=\"red\"><b>ver.2.0以降のみ</b></font>対応。<br>\n";
40     print "</td></tr>\n";
41     print '<tr><td style="text-align:center;">';
42     print input_area('submit', 'submit', '次へ');
43     print "</td></tr>\n";
44     print "</table>\n";
45     print '<p align="center"> </p>';
46     print "</form>";
47
48 // 新規インストール
49 } elseif ($mode == 'install') {
50     print "<h2>重要な設定</h2>\n";
51     print "<h3>セキュリティに関わるので、<font color=\"red\">必ず変更してください。</font></h3>\n";
52     print '<form action="./setup.php" method="'.METHOD.'">';
53     print input_area('hidden', 'mode', 'install_do'). "\n";
54     print '<table border="1">'."\n";
55     print output_table("管理者用パスワード");
56     print input_area('text', 'masterpass', 'password', '10');
57     print "<br> * 必ず変更してください。\n";
58     print output_table("パスワードの暗号化キー");
59     print input_area('text', 'admin_hash', 'ajaxchat', '10');
60     print "<br> * 4文字以上入力してください";
61     print output_table("クッキー名");
62     print input_area('text', 'cookie', 'AjaxChat', 20);
63     print "<br> * 空にするとクッキーを使用できません";
64     print '<tr><td colspan="2">';
65     print '簡易設定のみでOKの場合、「次へ」を押してください。<p align="center"> <br>';
66     print input_area('submit', 'submit', '次へ');
67     print "</p></td></tr>\n";
68     print "</table>\n";
69
70     print " <p><br>詳細な設定を行なう場合は以下を設定して「次へ」を押してください。<br> </p> <br> <hr> <br>";
71
72     easy_setup_config_ext1("i");
73
74     print "<h2>ファイルの設定</h2>\n";
75     print '<table border="1">'."\n";
76     print output_table("重要な設定ファイル");
77     print input_area('text', 'imp', './config-data-important.php');
78     print output_table("タグの設定ファイル");
79     print input_area('text', 'tag', './config-data-tag.php');
80     print output_table("TRPG関連の設定ファイル");
81     print input_area('text', 'trpg', './config-data-trpg.php');
82     print output_table("カード関連の設定ファイル");
83     print input_area('text', 'card', './config-data-card.php');
84     print output_table("全体の配色設定ファイル");
85     print input_area('text', 'bc', './config-data-base-color.php');
86     print output_table("チャット画面の配色設定ファイル");
87     print input_area('text', 'mc', './config-data-main-color.php');
88     print output_table("全般設定ファイル");
89     print input_area('text', 'main', './config-data-main.php');
90     print output_table("アイコン設定ファイル");
91     print input_area('text', 'icon', './config-data-icon.php');
92     print output_table("携帯設定ファイル");
93     print input_area('text', 'mobile', './config-data-mobile.php');
94     print output_table("最新ログファイル");
95     print input_area('text', 'rlog', './trpgchat.log');
96     print output_table("直近の過去ログファイル");
97     print input_area('text', 'plog', './trpgchat_past.log');
98     print output_table("HTML化過去ログ保管ディレクトリ");
99     print input_area('text', 'pdir', './past/');
100     print output_table("管理用過去ログ保管ディレクトリ");
101     print input_area('text', 'mpdir', './master_past/');
102     print output_table("参加メンバーログファイル");
103     print input_area('text', 'mem', './member.log');
104     print output_table("システムログファイル");
105     print input_area('text', 'syslog', './system.log');
106     print output_table("ロックファイル");
107     print input_area('text', 'l1', './lock.txt');
108     print input_area('text', 'l2', './lock2.txt');
109     print input_area('text', 'l3', './lock3.txt');
110     print output_table("カード設定ディレクトリ");
111     print input_area('text', 'cdir', './lib/card/');
112     print output_table("現在のカード状態ファイル");
113     print input_area('text', 'nd', './deckset.json');
114     print input_area('text', 'nds', './deck_status.json');
115     print "\n";
116
117     print "</td></tr>\n";
118     print '<tr><td style="text-align:center;" colspan="2">';
119     print input_area('submit', 'submit', '次へ');
120     print '<p align="center"> </p>';
121     print "</td></tr>\n";
122     print '</table>';
123     print "</form>";
124
125 // バージョンアップ
126 } elseif ($mode == 'verup') {
127     print "<h2>重要な設定</h2>\n";
128     print '<form action="./setup.php" method="GET">';
129     print input_area('hidden', 'mode', 'verup_do'). "\n";
130
131     print '<table border="1">'."\n";
132     print output_table("前バージョンのディレクトリ");
133     print input_area('text', 'previous_chat_dir', '../trpgchat/', '30');
134     print "<br> * 設定を引き継ぎたいチャットの設置場所(パス)を指定してください。<br>\n";
135     print output_table("管理者用パスワード");
136     print input_area('text', 'masterpass', 'password', '10');
137     print "<br> * 設定を引き継ぎたいチャットで用いているパスワードを入力してください。\n";
138     print output_table("直近の過去ログをコピーする");
139     print input_area('radio', 'clog', '1', '', '', 'checked')." : はい<br>\n";
140     print input_area('radio', 'clog', '0', '', '')." : いいえ";
141     print output_table("過去ログは手動で設定する");
142     print input_area('radio', 'mlog', '1', '', '')." : はい<br>\n";
143     print input_area('radio', 'mlog', '0', '', '', 'checked')." : いいえ";
144     print '<tr><td colspan="2">';
145     print '簡易設定のみでOKの場合、「次へ」を押してください。<p align="center"> <br>';
146     print input_area('submit', 'submit', '次へ');
147     print "</p></td></tr>\n";
148     print "</table>\n";
149
150     print " <p><br>詳細な設定を行なう場合は以下を設定して「次へ」を押してください。<br> </p> <br> <hr> <br>";
151
152     easy_setup_config_ext1("v");
153
154     print "</form>";
155
156 // セットアップ
157 } elseif ($mode == 'install_do' || $mode == 'verup_do') {
158     if (!$request['masterpass']) {
159         error("管理者用パスワードを入力してください", true);
160     }
161     if ($mode == 'install_do' && !$request['admin_hash']) {
162         error("暗号化キーを入力してください", true);
163     }
164
165     // デモモード
166     if (DEMO_SETUP) {
167         setup_end($request);
168     }
169     // ファイル名・ディレクトリ名チェック
170     foreach ($request as $k => $v) {
171         if ($k != 'submit' && $k != '777' && $k != '666' && $k != 'htaccess' && $k != 'clog' && $k != 'mlog' && $k != 'obf' && $k != 'ht_domain') check_name2($v);
172         if ($request['htaccess'] == "1" && $k == 'ht_domain') {
173             check_name2(preg_replace('/^(http\:\/\/)|(https\:\/\/)/', '', $v), "チャットのドメインを入力してください。");
174         }
175     }
176
177     // trpgchat-ini.phpの出力と読み込み
178     // バージョンアップの場合
179     if ($mode == 'verup_do') {
180         // 前バージョンの設定
181         if (!is_readable($prev_dir)) error("指定のディレクトリ $prev_dir にアクセスできません", true);
182
183         $prev_ini = $prev_dir.'/trpgchat-ini.php';
184         if (!file_exists($prev_ini)) error($prev_ini."にアクセスできません", true);
185
186         if (!defined('CONFIG_MOBILE')) {
187             define('CONFIG_MOBILE', './config-data-mobile.php');
188         }
189         if (!defined('CONFIG_CARD')) {
190             define('CONFIG_CARD', './config-data-card.php');
191         }
192         if (!defined('LOCK3')) {
193             define('LOCK3', './lock3.txt');
194         }
195         if (!defined('CARD_DIR')) {
196             define('CARD_DIR', './lib/card/');
197         }
198         if (!defined('NOW_DECK')) {
199             define('NOW_DECK', './deckset.json');
200         }
201         if (!defined('NOW_DECK_STATUS')) {
202             define('NOW_DECK_STATUS', './deck_status.json');
203         }
204
205         require_once $prev_ini;
206         $data = array(
207             'masterpass' => MASTERPASS,
208             'admin_hash' => ADMIN_HASH_KEY,
209             'cookie' => COOKIE,
210             'imp' => CONFIG_IMPORTANT,
211             'tag' => CONFIG_TAG,
212             'trpg' => CONFIG_TRPG,
213             'card' => CONFIG_CARD,
214             'bc' => CONFIG_BASE_COLOR,
215             'mc' => CONFIG_MAIN_COLOR,
216             'main' => CONFIG_MAIN,
217             'icon' => CONFIG_ICON,
218             'mobile' => CONFIG_MOBILE,
219             'rlog' => RECENT_LOG,
220             'plog' => PAST_LOG,
221             'pdir' => PAST_DIR,
222             'mpdir' => MASTER_PAST_DIR,
223             'mem' => NOW_MEMBER,
224             'syslog' => SYSTEM_LOG,
225             'l1' => LOCK,
226             'l2' => LOCK2,
227             'l3' => LOCK3,
228             'cdir' => CARD_DIR,
229             'nd' => NOW_DECK,
230             'nds' => NOW_DECK_STATUS,
231         );
232
233         if ($data['masterpass'] != $request['masterpass']) error("パスワードが合致しません", true);
234
235         if ($request['obf']) $data['obf'] = '1';
236
237         set_ini($data);
238     } elseif ($mode == 'install_do') {
239         set_ini($request);
240         require_once './trpgchat-ini.php';
241     }
242
243     // configファイルの設定
244     $GLOBALS['AJAX_CHAT_TRPG']['CONFIGFILES_NAME'] = array(
245         CONFIG_IMPORTANT,
246         CONFIG_TAG,
247         CONFIG_TRPG,
248         CONFIG_CARD,
249         CONFIG_BASE_COLOR,
250         CONFIG_MAIN_COLOR,
251         CONFIG_MAIN,
252         CONFIG_ICON,
253         CONFIG_MOBILE,
254     );
255
256     foreach($GLOBALS['AJAX_CHAT_TRPG']['CONFIGFILES_NAME'] as $k => $v) {
257         if (($mode == 'install_do' && copy(SETUP_ORIGFILE_DIR.$GLOBALS['AJAX_CHAT_TRPG']['ORIG_CONFIGFILES_NAME'][$k], $v))
258             || ($mode == 'verup_do' && setup_config($prev_dir, $k, $v))) {
259             set_permission_666($v, $request['666']);
260         } else {
261             unlink('./trpgchat-ini.php');
262             error($v."の設定に失敗しました", true);
263         }
264     }
265
266     if ($data) $request = array_merge($request, $data);
267
268     // ログファイルの設定
269     if (!($request['mode'] == 'verup_do' && $request['mlog']) && !set_logs($request)) {
270         unlink('./trpgchat-ini.php');
271         error("過去ログ関連の設定に失敗しました", true);
272     }
273
274     // .htaccessの設定
275     if ($request['htaccess'] && $request['ht_domain']) {
276         $contents = output_file_string(SETUP_DIR.'.htaccess');
277         write_string_to_file('./.htaccess', sprintf($contents, quotemeta($request['ht_domain'])));
278     }
279
280     // setup.phpを削除してメッセージを表示
281     setup_end($request);
282
283 } else {
284     error('パラメータが不正です。');
285 }
286
287 // フッター
288 print html_footer();
289 exit;
290 ?>