dumpファイルのダウンロード、認証の内部処理、ヘッダ・フッタ書き出しを関数化
@@ -8,6 +8,7 @@ | ||
8 | 8 | // |
9 | 9 | // version 1.0 (2010/02/21) |
10 | 10 | // version 1.1 (2011/01/16) |
11 | +// version 1.2 (2011/01/22) | |
11 | 12 | // |
12 | 13 | // GNU GPL Free Software |
13 | 14 | // |
@@ -39,9 +40,9 @@ | ||
39 | 40 | // |
40 | 41 | // 認証状態はセッションに格納される(認証ログオフは、LogoffAuth 関数) |
41 | 42 | // |
42 | -// 認証されている場合 TRUE を返す | |
43 | -// 認証されていない場合 FALSE を返す | |
44 | -function CheckAuth($strReloadPage, $strLogPage) | |
43 | +// 認証されている場合 1 を返す | |
44 | +// 認証されていない場合 0 を返す | |
45 | +function CheckAuth($strReloadPage, $flag_check_only) | |
45 | 46 | { |
46 | 47 | if(!isset($_SESSION)){ session_start(); } |
47 | 48 | $strAuthUser = ''; // 認証されたユーザ名 |
@@ -49,9 +50,12 @@ | ||
49 | 50 | if (isset($_SESSION['svnadmin-user'])) |
50 | 51 | { |
51 | 52 | // 既にログオンしてている場合 |
52 | - $strAuthUser = $_SESSION['svnadmin-user']; | |
53 | - return($strAuthUser); | |
53 | + return(1); // 認証成功 | |
54 | 54 | } |
55 | + elseif(isset($flag_check_only) && $flag_check_only == 1){ | |
56 | + // ログオンしていない場合で、結果のみ返す場合 | |
57 | + return(0); | |
58 | + } | |
55 | 59 | elseif(!isset($_POST['user']) || !isset($_POST['password'])){ |
56 | 60 | // 新規入力画面を表示する |
57 | 61 |
@@ -64,7 +68,7 @@ | ||
64 | 68 | print("\t</table>\n"); |
65 | 69 | print("</form>\n"); |
66 | 70 | |
67 | - return($strAuthUser); | |
71 | + return(0); // 認証失敗 | |
68 | 72 | } |
69 | 73 | else { |
70 | 74 | // DBを参照して、認証チェックを行う |
@@ -72,12 +76,12 @@ | ||
72 | 76 | if($strAuthUser != '') { |
73 | 77 | // 認証OK |
74 | 78 | $_SESSION['svnadmin-user'] = $strAuthUser; |
75 | - return($strAuthUser); | |
79 | + return(1); // 認証成功 | |
76 | 80 | } |
77 | 81 | } |
78 | 82 | |
79 | 83 | // 認証失敗 |
80 | - return($strAuthUser); | |
84 | + return(0); | |
81 | 85 | |
82 | 86 | } |
83 | 87 |
@@ -155,7 +159,7 @@ | ||
155 | 159 | return(-1); // 認証ファイルが作成できない |
156 | 160 | } |
157 | 161 | |
158 | - return(0); | |
162 | + return(0); // 認証ファイルを新規作成した | |
159 | 163 | } |
160 | 164 | |
161 | 165 | // ユーザ名、パスワードをチェック |
@@ -2,8 +2,9 @@ | ||
2 | 2 | session.use_cookies = On |
3 | 3 | session.save_path = "/tmp" |
4 | 4 | |
5 | -; output buffer (for cookie write) | |
6 | -output_buffering = 4096 | |
5 | +; session_start() warning surpress, and cookie support | |
6 | +; uncomment 'output_buffering' line | |
7 | +output_buffering = 4096 | |
7 | 8 | |
8 | 9 | ; error on screen |
9 | 10 | display_errors="0" |
@@ -1,5 +1,3 @@ | ||
1 | -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> | |
3 | 1 | <?php |
4 | 2 | |
5 | 3 | $strVersion = '0.2'; // 画面に表示するバージョン |
@@ -31,27 +29,6 @@ | ||
31 | 29 | // http://www.opensource.jp/gpl/gpl.ja.html |
32 | 30 | // ****************************************************** |
33 | 31 | |
34 | -?> | |
35 | -<head> | |
36 | - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
37 | - <meta http-equiv="Content-Language" content="ja" /> | |
38 | - <link rel="stylesheet" href="style.css" type="text/css" /> | |
39 | - | |
40 | - <title> </title> | |
41 | - | |
42 | - <script type="text/javascript" src="../utf.js"></script> | |
43 | - <script type="text/javascript" src="../md5.js"></script> | |
44 | - <script type="text/javascript" src="../authpage_form_md5.js"></script> | |
45 | - | |
46 | -</head> | |
47 | -<body> | |
48 | - | |
49 | -<div style="height:100px; width:100%; padding:0px; margin:0px;"> | |
50 | -<p><img src="./logo-svn.png" width="109" height="93" alt="Subversion" style="vertical-align:middle;" /><span style="margin:0px 20px; font-size:30px; font-weight:lighter;">WebSVN-Admin</span><span style="margin:0px 0px; font-size:25px; font-weight:lighter; color:lightgray;">Subversion Administration</span></p> | |
51 | -</div> | |
52 | - | |
53 | -<?php | |
54 | - | |
55 | 32 | require_once('include/config.php'); // ディレクトリなどの設定 |
56 | 33 | require_once('include/auth.php'); // ユーザ認証 |
57 | 34 |
@@ -58,21 +35,27 @@ | ||
58 | 35 | // このスクリプトのファイル名 |
59 | 36 | $strFilenameThis = htmlspecialchars(basename($_SERVER['PHP_SELF'])); |
60 | 37 | |
61 | -// config.php で設定が行われているか確認する | |
62 | -if(!isset($strSvnCmdPath) || !isset($strBaseDir) || !isset($strBackupDir)){ | |
63 | - print("<p class=\"error\">include/config.php の初期設定が行われていません</p>\n"); | |
64 | - print("</body>\n</html>\n"); | |
65 | - die; | |
38 | +// 認証ファイルの確認 | |
39 | +// auth.datの存在確認 1:OK, 0:Create, -1:Create Error | |
40 | +$flag_auth_file_exist = CheckAuthDataFile(); | |
41 | + | |
42 | +// ファイルのダウンロード(ヘッダを表示する前に行い、終了する) | |
43 | +if(isset($_GET['mode']) && $_GET['mode'] === 'download' && isset($_GET['dumptext'])){ | |
44 | + $strRepo = $_GET['dumptext']; | |
45 | + download_dump_text($strRepo); | |
66 | 46 | } |
67 | 47 | |
68 | -// execコマンドに渡す変数の汚染除去(エスケープ) | |
69 | -$strSvnCmdPath = escapeshellcmd($strSvnCmdPath); | |
70 | -$strBaseDir = escapeshellcmd($strBaseDir); | |
71 | -$strBackupDir = escapeshellcmd($strBackupDir); | |
48 | +// HTML構文を開始し、ヘッダー部分を表示する | |
49 | +print_html_header(); | |
72 | 50 | |
51 | +// include/config.php 内のグローバル変数が設定されているかチェック | |
52 | +if(!check_config_file(1)){ | |
53 | + print_html_footer(); | |
54 | + die; | |
55 | +} | |
73 | 56 | |
74 | -$nResult = CheckAuthDataFile(); | |
75 | -if($nResult == 0){ | |
57 | +// 認証ファイルの確認結果を表示(必要な場合) | |
58 | +if($flag_auth_file_exist == 0){ | |
76 | 59 | ?> |
77 | 60 | <p class="info">初期ユーザ名:user, パスワード:password です</p> |
78 | 61 | <p><a href="<?php echo $strFilenameThis;?>">ログオン画面を表示する</a><p> |
@@ -81,16 +64,14 @@ | ||
81 | 64 | <?php |
82 | 65 | die; |
83 | 66 | } |
84 | -elseif($nResult < 0){ | |
67 | +elseif($flag_auth_file_exist < 0){ | |
85 | 68 | print("<p class=\"error\">認証用データファイルが作成できません<br />dataディレクトリに書き込み権限が無い可能性があります</p>\n"); |
86 | - print("</body>\n</html>\n"); | |
69 | + print_html_footer(); | |
87 | 70 | die; |
88 | 71 | } |
89 | 72 | |
90 | 73 | // ユーザ認証を行う |
91 | -$strReturn = CheckAuth($strFilenameThis, 'svnadmin-create'); | |
92 | - | |
93 | -if(!$strReturn) | |
74 | +if(!CheckAuth($strFilenameThis, 0)) | |
94 | 75 | { |
95 | 76 | print("<p>認証が行われていません。またはCookieが使えない状況です。</p>\n"); |
96 | 77 | print("<a href=\"".$strFilenameThis."\">再度ログオン画面を表示する</a>\n"); |
@@ -171,6 +152,11 @@ | ||
171 | 152 | $strRepo = $_GET['reponame']; |
172 | 153 | remove_repository($strRepo); |
173 | 154 | } |
155 | +// 既存リポジトリの情報表示(バックアップ、削除サブメニュー表示) | |
156 | +elseif(isset($_GET['mode']) && $_GET['mode'] === 'viewbackupdir' && isset($_GET['dirname'])){ | |
157 | + $strRepo = $_GET['dirname']; | |
158 | + view_backup_dir($strRepo); | |
159 | +} | |
174 | 160 | // 新規リポジトリ作成 入力画面 |
175 | 161 | else{ |
176 | 162 | // 引数が何もなかった場合、新規リポジトリ名の入力画面を表示 |
@@ -177,17 +163,10 @@ | ||
177 | 163 | input_new_repository(); |
178 | 164 | } |
179 | 165 | |
180 | -?> | |
181 | -</div> <!-- id="main_content_right" --> | |
182 | -<p> </p> | |
183 | -<div class="clear"></div> | |
184 | -<div id="footer"> | |
185 | -<p><a href="http://sourceforge.jp/projects/websvn-admin/">WebSVN-Admin</a> version <?php echo $strVersion; ?> GNU GPL free software</p> | |
186 | -</div> <!-- id="footer" --> | |
166 | +print('</div> <!-- id="main_content_right" -->'."\n"); | |
187 | 167 | |
188 | -</body> | |
189 | -</html> | |
190 | -<?php | |
168 | +// HTMLのフッターを表示する(HTML構文を閉じる) | |
169 | +print_html_footer(); | |
191 | 170 | |
192 | 171 | exit(); |
193 | 172 |
@@ -220,6 +199,51 @@ | ||
220 | 199 | |
221 | 200 | |
222 | 201 | // ********************* |
202 | +// HTML構文を開始し、ヘッダー部分を表示する | |
203 | +// ********************* | |
204 | +function print_html_header() { | |
205 | +?> | |
206 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
207 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> | |
208 | +<head> | |
209 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
210 | + <meta http-equiv="Content-Language" content="ja" /> | |
211 | + <link rel="stylesheet" href="style.css" type="text/css" /> | |
212 | + | |
213 | + <title> </title> | |
214 | + | |
215 | + <script type="text/javascript" src="../utf.js"></script> | |
216 | + <script type="text/javascript" src="../md5.js"></script> | |
217 | + <script type="text/javascript" src="../authpage_form_md5.js"></script> | |
218 | + | |
219 | +</head> | |
220 | +<body> | |
221 | + | |
222 | +<div style="height:100px; width:100%; padding:0px; margin:0px;"> | |
223 | +<p><img src="./logo-svn.png" width="109" height="93" alt="Subversion" style="vertical-align:middle;" /><span style="margin:0px 20px; font-size:30px; font-weight:lighter;">WebSVN-Admin</span><span style="margin:0px 0px; font-size:25px; font-weight:lighter; color:lightgray;">Subversion Administration</span></p> | |
224 | +</div> | |
225 | +<?php | |
226 | +} | |
227 | + | |
228 | +// ********************* | |
229 | +// フッター部分を表示した後、HTML構文を閉じる | |
230 | +// ********************* | |
231 | +function print_html_footer() { | |
232 | + global $strVersion; | |
233 | +?> | |
234 | +<p> </p> | |
235 | +<div class="clear"></div> | |
236 | +<div id="footer"> | |
237 | +<p><a href="http://sourceforge.jp/projects/websvn-admin/">WebSVN-Admin</a> version <?php echo $strVersion; ?> GNU GPL free software</p> | |
238 | +</div> <!-- id="footer" --> | |
239 | + | |
240 | +</body> | |
241 | +</html> | |
242 | +<?php | |
243 | +} | |
244 | + | |
245 | + | |
246 | +// ********************* | |
223 | 247 | // 新規リポジトリ名入力画面 |
224 | 248 | // ********************* |
225 | 249 | function input_new_repository() { |
@@ -541,6 +565,7 @@ | ||
541 | 565 | // ********************* |
542 | 566 | function display_backup_list() { |
543 | 567 | global $strBackupDir; |
568 | + global $strFilenameThis; | |
544 | 569 | |
545 | 570 | print("<h1>Backup Catalog</h1>\n"); |
546 | 571 |
@@ -558,7 +583,12 @@ | ||
558 | 583 | |
559 | 584 | print("<ul>\n"); |
560 | 585 | foreach($arrDirs as $val){ |
561 | - print "<li>".htmlspecialchars($val)."</li>\n"; | |
586 | + if(is_dir($strBackupDir.$val)){ | |
587 | + print "<li><a href=\"".$strFilenameThis."?mode=viewbackupdir&dirname=".htmlspecialchars($val)."\">".htmlspecialchars($val)."</a></li>\n"; | |
588 | + } | |
589 | + else{ | |
590 | + print "<li><a href=\"".$strFilenameThis."?mode=download&dumptext=".htmlspecialchars($val)."\">".htmlspecialchars($val)."</a></li>\n"; | |
591 | + } | |
562 | 592 | } |
563 | 593 | print("</ul>\n"); |
564 | 594 |
@@ -566,6 +596,78 @@ | ||
566 | 596 | |
567 | 597 | |
568 | 598 | // ********************* |
599 | +// バックアップ一覧を表示する(ディレクトリの場合) | |
600 | +// ********************* | |
601 | +function view_backup_dir($strRepo) { | |
602 | + global $strBackupDir; | |
603 | + | |
604 | + print("<h1>View Backup Repository (hotcopy dir)</h1>\n"); | |
605 | + print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); | |
606 | + | |
607 | + // リポジトリ名に不正な文字が入っていないか検査 | |
608 | + if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 40 || strlen($strRepo) <= 0){ | |
609 | + print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); | |
610 | + return; | |
611 | + } | |
612 | + | |
613 | + print("<p>コマンド実行中 ... (ls -laR ".htmlspecialchars($strRepo).")</p>\n"); | |
614 | + // ファイル一覧 | |
615 | + exec("ls -laR ".$strBackupDir.$strRepo." 2>&1", $arrStdout, $nResult); | |
616 | + if($nResult != 0){ | |
617 | + print("<p class=\"error\">一覧取得に失敗しました</p>\n"); | |
618 | + return; | |
619 | + } | |
620 | + // コマンドのStdout出力がある場合 | |
621 | + if(count($arrStdout)>0){ | |
622 | + print("<pre>\n\n"); | |
623 | + print("$ ls -laR ".htmlspecialchars($strRepo)."\n\n"); | |
624 | + foreach($arrStdout as $str){ | |
625 | + print($str."\n"); | |
626 | + } | |
627 | + print("</pre>\n"); | |
628 | + } | |
629 | + | |
630 | +} | |
631 | + | |
632 | + | |
633 | +// ********************* | |
634 | +// dump(バックアップ)ファイルをダウンロードする | |
635 | +// ********************* | |
636 | +function download_dump_text($strRepo) { | |
637 | + global $strFilenameThis; | |
638 | + global $strBackupDir; | |
639 | + | |
640 | + // 認証確認 | |
641 | + if(!CheckAuth($strFilenameThis, 1)){ | |
642 | + die("Error : not logged on\n"); | |
643 | + } | |
644 | + | |
645 | + // include/config.php 内のグローバル変数が設定されているかチェック | |
646 | + if(!check_config_file(0)){ | |
647 | + die("Error : config value\n"); | |
648 | + } | |
649 | + | |
650 | + // リポジトリ名に不正な文字が入っていないか検査 | |
651 | + if(!preg_match("/^[A-Za-z0-9\-\.]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 40 || strlen($strRepo) <= 0){ | |
652 | + die("Error : unsupported filename\n"); | |
653 | + } | |
654 | + | |
655 | + $strFilename = $strBackupDir.$strRepo; | |
656 | + if(!is_file($strFilename)){ | |
657 | + die("file '$strFilename' not exist\n"); | |
658 | + } | |
659 | + | |
660 | + $file_length = filesize($strFilename); | |
661 | + header("Content-Disposition: attachment; filename=$strFilename"); | |
662 | + header("Content-Length:$file_length"); | |
663 | + header("Content-Type: application/octet-stream"); | |
664 | + readfile ($strFilename); | |
665 | + | |
666 | + exit(); | |
667 | +} | |
668 | + | |
669 | + | |
670 | +// ********************* | |
569 | 671 | // svnコマンドのバージョン番号(文字列)を返す関数 |
570 | 672 | // ********************* |
571 | 673 | function get_svn_version() { |
@@ -582,6 +684,46 @@ | ||
582 | 684 | } |
583 | 685 | return($strSvnVersion); |
584 | 686 | } |
687 | + | |
688 | + | |
689 | +// ********************* | |
690 | +// config.php が正しく設定されているかチェック | |
691 | +// ********************* | |
692 | +function check_config_file($flag_in_html) { | |
693 | + global $strSvnCmdPath; | |
694 | + global $strBaseDir; | |
695 | + global $strBackupDir; | |
696 | + | |
697 | + $flag_ok = 1; // 正しくセットされていれば 1, 設定が足りなければ 0 | |
698 | + | |
699 | + if(!isset($flag_in_html)){ $flag_in_html = 0; } | |
700 | + | |
701 | + // config.php で設定が行われているか確認する | |
702 | + $arrVarName = array( | |
703 | + array($strSvnCmdPath, '$strSvnCmdPath'), | |
704 | + array($strBaseDir, '$strBaseDir'), | |
705 | + array($strBackupDir, '$strBackupDir'), | |
706 | + ); | |
707 | + | |
708 | + foreach($arrVarName as $val){ | |
709 | + if(!isset($val[0])){ | |
710 | + if($flag_in_html){ print("<p class=\"error\">include/config.php に ".$val[1]." が設定されていません</p>\n");} | |
711 | + else{print("Error : include/config.php - ".$val[1]." not exist\n");} | |
712 | + $flag_ok = 0; | |
713 | + } | |
714 | + } | |
715 | + | |
716 | + if(!$flag_ok){ return(0); } | |
717 | + | |
718 | + // execコマンドに渡す変数の汚染除去(エスケープ) | |
719 | + $strSvnCmdPath = escapeshellcmd($strSvnCmdPath); | |
720 | + $strBaseDir = escapeshellcmd($strBaseDir); | |
721 | + $strBackupDir = escapeshellcmd($strBackupDir); | |
722 | + | |
723 | + return(1); | |
724 | +} | |
725 | + | |
726 | + | |
585 | 727 | ?> |
586 | 728 | |
587 | 729 |