OSDN Git Service

trpgchat ver2.6.1
[trpgtools-onweb/AjaxChat.git] / lib / setup.php
1 <?php
2 /*
3  Ajax Chat for TRPG ver.2.6.1
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  *  PHPライブラリ:かんたんセットアップ用
11  *****************/
12
13 // 設定ファイル名一覧
14 $GLOBALS['AJAX_CHAT_TRPG']['ORIG_CONFIGFILES_NAME'] = array(
15     'config-data-important.php',
16     'config-data-tag.php',
17     'config-data-trpg.php',
18     'config-data-card.php',
19     'config-data-base-color.php',
20     'config-data-main-color.php',
21     'config-data-main.php',
22     'config-data-icon.php',
23     'config-data-mobile.php',
24 );
25 define('SETUP_DIR', './setup/');
26 define('SETUP_ORIGFILE_DIR', SETUP_DIR.'orig/');
27
28
29 // ヘッター
30 function html_header_setup($title='Ajax Chat for TRPG かんたんセットアップ') {
31     $header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
32     $header .= '<html>'."\n";
33     $header .= '<head>'."\n";
34     $header .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
35     $header .= '<meta http-equiv="Content-Script-Type" content="text/javascript" />'."\n";
36     $header .= '<meta http-equiv="Content-Style-Type" content="text/css" />'."\n";
37     $header .= '<meta http-equiv="Pragma" content="no-cache">'."\n";
38     $header .= '<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">'."\n";
39     $header .= '<meta http-equiv="Expires" content="Thu, 01 Feb 1960 00:00:00 GMT">'."\n";
40     $header .= '<link rel="stylesheet" type="text/css" href="./css/trpgchat.css">'."\n";
41     $header .= '<link rel="stylesheet" type="text/css" href="./css/setup.css">'."\n";
42     $header .= '<script type="text/javascript" src="./lib/js/jquery.js"></script>'."\n";
43     $header .= '<title>'.$title.'</title>'."\n";
44
45     return $header;
46 }
47
48 // 設定テーブル
49 function output_table($title) {
50     return "</td></tr>\n<tr><td>$title</td><td>\n";
51 }
52
53 // ファイルを読み込んで文字列として出力
54 function output_file_string($file) {
55     if (!is_readable($file)) {
56         error('セットアップ失敗しました。ディレクトリの読み込み権限を確認してください', false, true, true);
57     }
58     $fp = file($file);
59     return implode($fp, "");
60 }
61
62 // 文字列内容を書き込んだファイルを生成
63 function write_string_to_file($file, $string) {
64 //    if (!is_writable($file)) error('セットアップ失敗しました。ディレクトリの書き込み権限を確認してください', false, true, true);
65     $fp = fopen($file, "x");
66     if (!fwrite($fp, $string)) return false;
67     fclose($fp);
68     return $contents;
69 }
70
71 // trpgchat-ini.phpの出力
72 function set_ini($data) {
73     if (!is_readable(SETUP_DIR.'trpgchat-ini.php')) {
74         error(SETUP_DIR."ディレクトリ内にtrpgchat-ini.phpがありません", true);
75     }
76
77     $contents = output_file_string(SETUP_DIR.'trpgchat-ini.php');
78
79     if (!$contents) {
80         error(SETUP_DIR."trpgchat-ini.phpの読み込みに失敗しました", true);
81     }
82     $output = sprintf($contents,
83                 $data['masterpass'],
84                 $data['admin_hash'],
85                 $data['cookie'],
86                 $data['obf'],
87                 $data['imp'],
88                 $data['tag'],
89                 $data['trpg'],
90                 $data['card'],
91                 $data['bc'],
92                 $data['mc'],
93                 $data['main'],
94                 $data['icon'],
95                 $data['mobile'],
96                 $data['rlog'],
97                 $data['plog'],
98                 $data['pdir'],
99                 $data['mpdir'],
100                 $data['mem'],
101                 $data['l1'],
102                 $data['l2'],
103                 $data['l3'],
104                 $data['cdir'],
105                 $data['nd'],
106                 $data['nds']
107             );
108     if (!$output) error('trpgchat-ini.phpの内容設定に失敗しました。', false, true, true);
109
110     write_string_to_file('./trpgchat-ini.php', $output);
111     if (!file_exists("./trpgchat-ini.php")) error('セットアップに失敗しました。ディレクトリの書き込み権限を確認してください', false, true, true);
112     return true;
113 }
114
115 // 設定ファイルの出力
116 function setup_config($prev_dir, $key, $file) {
117     // 前バージョンの設定読み込み
118     $pcl = read_config_one($prev_dir.$file);
119     $prev_config_set = array();
120     foreach ($pcl as $v1) {
121         $v1 = rtrim($v1);
122         if ($v1) {
123             $prev_config = explode("<>", $v1);
124             if ($prev_config[2]) {
125                 if ($prev_config[2] == 'TAGS') {
126                     $prev_config_set["$prev_config[2]"] = $prev_config[6]."<>".$prev_config[7]."<>".$prev_config[8]."<>".$prev_config[9]."<>".$prev_config[10]."<>".$prev_config[11];
127                 } else {
128                     $prev_config_set["$prev_config[2]"] = $prev_config[6];
129                 }
130             }
131         }
132     }
133
134     // 新バージョンの設定ファイルを配列に
135     $lines = file(SETUP_ORIGFILE_DIR.$GLOBALS['AJAX_CHAT_TRPG']['ORIG_CONFIGFILES_NAME'][$key]);
136     if (!$lines) error("新バージョンの設定ファイルが読み込めません", true);
137
138     if (file_exists($file)) unlink($file);
139     $fp = @fopen($file, "x") or error("設定ファイルを作成できません。", true);
140     foreach ($lines as $v) {
141         $temp = explode("<>", $v);
142         // 前バージョンの設定があればセット
143         if ($temp[2]) {
144             if (isset($prev_config_set[$temp[2]])) {
145                 if ($temp[2] == 'TAGS') {
146                     array_pop($temp);
147                     array_pop($temp);
148                     array_pop($temp);
149                     array_pop($temp);
150                     array_pop($temp);
151                 }
152                 $temp[6] = $prev_config_set[$temp[2]]."\n";
153             }
154         }
155         $line = implode($temp, "<>");
156         fwrite($fp, $line);
157     }
158     @fclose($fp);
159
160     return file_exists($file);
161 }
162
163 // ログファイルの出力
164 function set_logs($data) {
165
166     // ロックファイル
167     touch($data['l1']);
168     set_permission_666($data['l1'], $data['666']);
169     touch($data['l2']);
170     set_permission_666($data['l2'], $data['666']);
171     touch($data['l3']);
172     set_permission_666($data['l3'], $data['666']);
173
174     // 在室メンバー
175     touch($data['mem']);
176     set_permission_666($data['mem'], $data['666']);
177
178     // 過去ログ
179     if (!$data['mlog']) {
180         act_log($data['rlog'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
181         act_log($data['plog'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
182         act_log($data['nd'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
183         act_log($data['nds'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
184         act_mkdir($data);
185     }
186
187     if (is_writable($data['rlog']) && is_writable($data['plog']) && is_writable($data['pdir']) && is_writable($data['mpdir']) && is_writable($data['l1']) && is_writable($data['l2']) && is_writable($data['l3'])) {
188         return true;
189     } else {
190         return false;
191     }
192 }
193
194 /* 指定ディレクトリ内の内容を全てコピー */
195 function copy_all_contents4dir($dir, $copy_to, $permission =false) {
196     $d = copy_all_files4dir($dir, $copy_to);
197     // ディレクトリ内コピーは1階層のみ
198     if ($d) {
199         foreach ($d as $v) {
200             if ($msg = mk_pastlog_dir('', $copy_to.$v, $data['777'])) {
201                 unlink('./trpgchat-ini.php');
202                 error($copy_to.$v."の設定に失敗しました", true);
203             }
204             copy_all_files4dir($dir.$v."/", $copy_to.$v."/");
205         }
206     }
207 }
208 /* 指定ディレクトリ内のファイルを全てコピー */
209 function copy_all_files4dir($dir, $copy_to) {
210     $contents = get_dir_contents_list($dir);
211     if ($contents['files']) {
212         foreach ($contents['files'] as $v) {
213             copy($dir.$v, $copy_to.$v);
214         }
215     }
216     return $contents['dirs'];
217 }
218
219 // 直近の過去ログファイルの作成
220 function act_log($file, $permission, $mode, $prev_dir = '', $copy = '', $obf = '') {
221     if ($mode == 'install_do' || !$copy) {
222         touch($file);
223     } elseif ($mode == 'verup_do' && $prev_dir) {
224         if (!$obf) {
225             if (!copy($prev_dir.$file, $file)) {
226                 touch($file);
227             }
228         } else {
229             touch($file);
230         }
231     } else {
232         unlink('./trpgchat-ini.php');
233         error("設定が不正です");
234     }
235
236     set_permission_666($file, $permission);
237
238     if (!is_writable($file)) {
239         unlink('./trpgchat-ini.php');
240         error($file."の設定に失敗しました", true);
241     }
242 }
243
244 // 過去ログディレクトリの作成
245 function act_mkdir($data) {
246     act_mkdir_indi($data, $data['pdir']);
247     act_mkdir_indi($data, $data['mpdir']);
248 }
249 function act_mkdir_indi($data, $dir) {
250     if (!file_exists($dir)) {
251         if ($msg = mk_pastlog_dir('', $dir, $data['777'])) {
252             unlink('./trpgchat-ini.php');
253             error($dir."の設定に失敗しました", true);
254         }
255     }
256
257     // アップデートの場合、前の過去ログディレクトリ全コピー
258     if ($data['mode']== 'verup_do') {
259         copy_all_contents4dir($data['previous_chat_dir'].$dir, $dir, $data['777']);
260     }
261
262     return file_exists($dir);
263 }
264
265
266 // セットアップ完了画面表示
267 function setup_end($data){
268     if (!DEMO_SETUP) {
269         unlink('./setup.php');
270     // デモ用
271     } else {
272         $msg = '*現在デモモードのため、セットアップ開始画面に戻ります';
273     }
274     print <<< DOC
275 <style type="text/css">
276 <!--
277 * {
278         margin: 5px;
279 }
280 -->
281 </style>
282 </head>
283 <body>
284 <p class="msg">セットアップが完了しました<br>
285 <br>
286 その他の細かい設定は、管理画面から変更してください。<br>
287 <br>
288 以下のボタンで、チャット画面を表示します<br>
289 $msg
290 <br>
291 </p>
292
293 <center>
294 <form action="./index.php">
295 <input type="submit" value="チャット画面を表示">
296 </FORM>
297 </center>
298
299 DOC;
300 exit;
301 }
302
303 // セットアップとバージョンアップで共通の設定表示
304 function easy_setup_config_basic() {
305 }
306 function easy_setup_config_ext1($mode) {
307     print "<h2>ファイル・ディレクトリのパーミッション設定</h2>\n";
308     print "<h3>お使いのサーバでパーミッションの制限がある場合、変更してください</h3>\n";
309     print '<table border="1">'."\n";
310     print output_table("読み書き可");
311     print input_area('radio', '666', '0', '', '', 'checked')." : 666<br>\n";
312     print input_area('radio', '666', '1', '', '')." : 606";
313     print output_table("読み書き実行可");
314     print input_area('radio', '777', '0', '', '', 'checked')." : 777<br>\n";
315     print input_area('radio', '777', '1', '', '')." : 707";
316     print "</td></tr>\n";
317     print '<tr><td style="text-align:center;" colspan="2">';
318     print input_area('submit', 'submit', '次へ');
319     print '<p align="center"> </p>';
320     print "</td></tr>\n";
321     print '</table>';
322
323     print ' <br> ';
324
325     print "<h2>ログ隠し設定</h2>\n";
326     print "<h3>ログファイルを外部から見えずらくする設定です。<br>見えずらくすると、一般的に『重く』なります。</h3>\n";
327     print '<table border="1">'."\n";
328     print output_table("ログの直接表示を禁止する");
329     print input_area('radio', 'htaccess', '1', '', '')." : する<br>\n";
330     print input_area('radio', 'htaccess', '0', '', '', 'checked')." : しない<br>";
331     print "直近の過去ログファイルの直接表示を禁止します。<br>.htaccessを用いるため、環境によっては誤作動する場合があります。<br>解除したい場合は、index.phpと同じディレクトリにある.htaccessファイルを削除してください";
332     print output_table("チャットのドメイン");
333     print input_area('test', 'ht_domain', 'http://')."\n";
334     print "<br>チャットを設置するサイトのドメインを入力してください。<br>ログの直接表示禁止には必須の設定です。<br><b> [例]</b><br>チャットのURL <strong>http://sample.site.ne.jp/username/trpgchat/index.php</strong><br>ドメイン <strong>http://sample.site.ne.jp/username/</strong>";
335     print output_table("直近の過去ログを難読化する");
336     print input_area('radio', 'obf', '1', '', '')." : する<br>\n";
337     print input_area('radio', 'obf', '0', '', '', 'checked')." : しない<br>";
338     print <<<HD
339 直近の過去ログファイルを、普通には読めないように変換して保管します。<br>
340 <strong>・暗号化ではありません。</strong><br>
341 ・この機能を用いると、負荷が多少高くなります。また、トラブルが起こった時にログの復元がしずらくなります。<br>
342 ・難読化している場合、今後のバージョンアップ時にHTML化していない過去ログは、引き継げない場合があります。ご了承ください。<br>
343 HD;
344     if($mode == 'v') print "・また、この設定を選ぶと、<strong>直近の過去ログを引き継ぎません</strong><br>";
345     print "</td></tr>\n";
346     print '<tr><td style="text-align:center;" colspan="2">';
347     print input_area('submit', 'submit', '次へ');
348     print '<p align="center"> </p>';
349     print "</td></tr>\n";
350     print '</table>';
351
352     print ' <br> ';
353
354 }
355
356 ?>