OSDN Git Service

PHP Notice対応
[trpgtools-onweb/AjaxChat.git] / lib / 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  *  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['syslog'],
102                 $data['l1'],
103                 $data['l2'],
104                 $data['l3'],
105                 $data['cdir'],
106                 $data['nd'],
107                 $data['nds']
108             );
109     if (!$output) error('trpgchat-ini.phpの内容設定に失敗しました。', false, true, true);
110
111     write_string_to_file('./trpgchat-ini.php', $output);
112     if (!file_exists("./trpgchat-ini.php")) error('セットアップに失敗しました。ディレクトリの書き込み権限を確認してください', false, true, true);
113     return true;
114 }
115
116 // 設定ファイルの出力
117 function setup_config($prev_dir, $key, $file) {
118     // 前バージョンの設定読み込み
119     $pcl = read_config_one($prev_dir.$file);
120     $prev_config_set = array();
121     foreach ($pcl as $v1) {
122         $v1 = rtrim($v1);
123         if ($v1) {
124             $prev_config = explode("<>", $v1);
125             if ($prev_config[2]) {
126                 if ($prev_config[2] == 'TAGS') {
127                     $prev_config_set["$prev_config[2]"] = $prev_config[6]."<>".$prev_config[7]."<>".$prev_config[8]."<>".$prev_config[9]."<>".$prev_config[10]."<>".$prev_config[11];
128                 } else {
129                     $prev_config_set["$prev_config[2]"] = $prev_config[6];
130                 }
131             }
132         }
133     }
134
135     // 新バージョンの設定ファイルを配列に
136     $lines = file(SETUP_ORIGFILE_DIR.$GLOBALS['AJAX_CHAT_TRPG']['ORIG_CONFIGFILES_NAME'][$key]);
137     if (!$lines) error("新バージョンの設定ファイルが読み込めません", true);
138
139     if (file_exists($file)) unlink($file);
140     $fp = @fopen($file, "x") or error("設定ファイルを作成できません。", true);
141     foreach ($lines as $v) {
142         $temp = explode("<>", $v);
143         // 前バージョンの設定があればセット
144         if ($temp[2]) {
145             if (isset($prev_config_set[$temp[2]])) {
146                 if ($temp[2] == 'TAGS') {
147                     array_pop($temp);
148                     array_pop($temp);
149                     array_pop($temp);
150                     array_pop($temp);
151                     array_pop($temp);
152                 }
153                 $temp[6] = $prev_config_set[$temp[2]]."\n";
154             }
155         }
156         $line = implode($temp, "<>");
157         fwrite($fp, $line);
158     }
159     @fclose($fp);
160
161     return file_exists($file);
162 }
163
164 // ログファイルの出力
165 function set_logs($data) {
166
167     // ロックファイル
168     touch($data['l1']);
169     set_permission_666($data['l1'], $data['666']);
170     touch($data['l2']);
171     set_permission_666($data['l2'], $data['666']);
172     touch($data['l3']);
173     set_permission_666($data['l3'], $data['666']);
174
175     // 在室メンバー
176     touch($data['mem']);
177     set_permission_666($data['mem'], $data['666']);
178
179     // 過去ログ
180     if (!$data['mlog']) {
181         act_log($data['rlog'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
182         act_log($data['plog'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
183         act_log($data['nd'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
184         act_log($data['nds'], $data['666'], $data['mode'], $data['previous_chat_dir'], $data['clog'], $data['obf']);
185         act_mkdir($data);
186     }
187
188     // システムログ
189     if (!$data['mlog']) {
190         touch($data['syslog']);
191         set_permission_666($data['syslog'], $data['666']);
192     }
193
194     if (is_writable($data['rlog']) && is_writable($data['plog']) && is_writable($data['pdir']) && is_writable($data['mpdir']) && is_writable($data['mem']) && is_writable($data['syslog']) && is_writable($data['l1']) && is_writable($data['l2']) && is_writable($data['l3'])) {
195         return true;
196     } else {
197         return false;
198     }
199 }
200
201 /* 指定ディレクトリ内の内容を全てコピー */
202 function copy_all_contents4dir($dir, $copy_to, $permission =false) {
203     $d = copy_all_files4dir($dir, $copy_to);
204     // ディレクトリ内コピーは1階層のみ
205     if ($d) {
206         foreach ($d as $v) {
207             if ($msg = mk_pastlog_dir('', $copy_to.$v, $data['777'])) {
208                 unlink('./trpgchat-ini.php');
209                 error($copy_to.$v."の設定に失敗しました", true);
210             }
211             copy_all_files4dir($dir.$v."/", $copy_to.$v."/");
212         }
213     }
214 }
215 /* 指定ディレクトリ内のファイルを全てコピー */
216 function copy_all_files4dir($dir, $copy_to) {
217     $contents = get_dir_contents_list($dir);
218     if ($contents['files']) {
219         foreach ($contents['files'] as $v) {
220             copy($dir.$v, $copy_to.$v);
221         }
222     }
223     return $contents['dirs'];
224 }
225
226 // 直近の過去ログファイルの作成
227 function act_log($file, $permission, $mode, $prev_dir = '', $copy = '', $obf = '') {
228     if ($mode == 'install_do' || !$copy) {
229         touch($file);
230     } elseif ($mode == 'verup_do' && $prev_dir) {
231         if (!$obf) {
232             if (!copy($prev_dir.$file, $file)) {
233                 touch($file);
234             }
235         } else {
236             touch($file);
237         }
238     } else {
239         unlink('./trpgchat-ini.php');
240         error("設定が不正です");
241     }
242
243     set_permission_666($file, $permission);
244
245     if (!is_writable($file)) {
246         unlink('./trpgchat-ini.php');
247         error($file."の設定に失敗しました", true);
248     }
249 }
250
251 // 過去ログディレクトリの作成
252 function act_mkdir($data) {
253     act_mkdir_indi($data, $data['pdir']);
254     act_mkdir_indi($data, $data['mpdir']);
255 }
256 function act_mkdir_indi($data, $dir) {
257     if (!file_exists($dir)) {
258         if ($msg = mk_pastlog_dir('', $dir, $data['777'])) {
259             unlink('./trpgchat-ini.php');
260             error($dir."の設定に失敗しました", true);
261         }
262     }
263
264     // アップデートの場合、前の過去ログディレクトリ全コピー
265     if ($data['mode']== 'verup_do') {
266         copy_all_contents4dir($data['previous_chat_dir'].$dir, $dir, $data['777']);
267     }
268
269     return file_exists($dir);
270 }
271
272
273 // セットアップ完了画面表示
274 function setup_end($data){
275     if (!DEMO_SETUP) {
276         unlink('./setup.php');
277     // デモ用
278     } else {
279         $msg = '*現在デモモードのため、セットアップ開始画面に戻ります';
280     }
281     print <<< DOC
282 <style type="text/css">
283 <!--
284 * {
285         margin: 5px;
286 }
287 -->
288 </style>
289 </head>
290 <body>
291 <p class="msg">セットアップが完了しました<br>
292 <br>
293 その他の細かい設定は、管理画面から変更してください。<br>
294 <br>
295 以下のボタンで、チャット画面を表示します<br>
296 $msg
297 <br>
298 </p>
299
300 <center>
301 <form action="./index.php">
302 <input type="submit" value="チャット画面を表示">
303 </FORM>
304 </center>
305
306 DOC;
307 exit;
308 }
309
310 // セットアップとバージョンアップで共通の設定表示
311 function easy_setup_config_basic() {
312 }
313 function easy_setup_config_ext1($mode) {
314     print "<h2>ファイル・ディレクトリのパーミッション設定</h2>\n";
315     print "<h3>お使いのサーバでパーミッションの制限がある場合、変更してください</h3>\n";
316     print '<table border="1">'."\n";
317     print output_table("読み書き可");
318     print input_area('radio', '666', '0', '', '', 'checked')." : 666<br>\n";
319     print input_area('radio', '666', '1', '', '')." : 606";
320     print output_table("読み書き実行可");
321     print input_area('radio', '777', '0', '', '', 'checked')." : 777<br>\n";
322     print input_area('radio', '777', '1', '', '')." : 707";
323     print "</td></tr>\n";
324     print '<tr><td style="text-align:center;" colspan="2">';
325     print input_area('submit', 'submit', '次へ');
326     print '<p align="center"> </p>';
327     print "</td></tr>\n";
328     print '</table>';
329
330     print ' <br> ';
331
332     print "<h2>ログ隠し設定</h2>\n";
333     print "<h3>ログファイルを外部から見えずらくする設定です。<br>見えずらくすると、一般的に『重く』なります。</h3>\n";
334     print '<table border="1">'."\n";
335     print output_table("ログの直接表示を禁止する");
336     print input_area('radio', 'htaccess', '1', '', '')." : する<br>\n";
337     print input_area('radio', 'htaccess', '0', '', '', 'checked')." : しない<br>";
338     print "直近の過去ログファイルの直接表示を禁止します。<br>.htaccessを用いるため、環境によっては誤作動する場合があります。<br>解除したい場合は、index.phpと同じディレクトリにある.htaccessファイルを削除してください";
339     print output_table("チャットのドメイン");
340     print input_area('test', 'ht_domain', 'http://')."\n";
341     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>";
342     print output_table("直近の過去ログを難読化する");
343     print input_area('radio', 'obf', '1', '', '')." : する<br>\n";
344     print input_area('radio', 'obf', '0', '', '', 'checked')." : しない<br>";
345     print <<<HD
346 直近の過去ログファイルを、普通には読めないように変換して保管します。<br>
347 <strong>・暗号化ではありません。</strong><br>
348 ・この機能を用いると、負荷が多少高くなります。また、トラブルが起こった時にログの復元がしずらくなります。<br>
349 ・難読化している場合、今後のバージョンアップ時にHTML化していない過去ログは、引き継げない場合があります。ご了承ください。<br>
350 HD;
351     if($mode == 'v') print "・また、この設定を選ぶと、<strong>直近の過去ログを引き継ぎません</strong><br>";
352     print "</td></tr>\n";
353     print '<tr><td style="text-align:center;" colspan="2">';
354     print input_area('submit', 'submit', '次へ');
355     print '<p align="center"> </p>';
356     print "</td></tr>\n";
357     print '</table>';
358
359     print ' <br> ';
360
361 }
362
363 ?>