| 1 |
<?php |
| 2 |
|
| 3 |
$strVersion = '0.2'; // 画面に表示するバージョン |
| 4 |
// ****************************************************** |
| 5 |
// Software name : WebSVN Administrator |
| 6 |
// |
| 7 |
// Copyright (C) INOUE Hirokazu, All Rights Reserved |
| 8 |
// http://oasis.halfmoon.jp/ |
| 9 |
// |
| 10 |
// version 0.1 (2011/01/16) |
| 11 |
// version 0.2 (2011/01/20) |
| 12 |
// |
| 13 |
// GNU GPL Free Software |
| 14 |
// |
| 15 |
// このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財 |
| 16 |
// 団によって発行された GNU 一般公衆利用許諾契約書(バージョン2か、希望によっては |
| 17 |
// それ以降のバージョンのうちどれか)の定める条件の下で再頒布または改変することが |
| 18 |
// できます。 |
| 19 |
// |
| 20 |
// このプログラムは有用であることを願って頒布されますが、*全くの無保証* です。 |
| 21 |
// 商業可能性の保証や特定の目的への適合性は、言外に示されたものも含め全く存在し |
| 22 |
// ません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。 |
| 23 |
// |
| 24 |
// あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部受け取 |
| 25 |
// ったはずです。もし受け取っていなければ、フリーソフトウェア財団まで請求してく |
| 26 |
// ださい(宛先は the Free Software Foundation, Inc., 59 Temple Place, Suite 330 |
| 27 |
// , Boston, MA 02111-1307 USA)。 |
| 28 |
// |
| 29 |
// http://www.opensource.jp/gpl/gpl.ja.html |
| 30 |
// ****************************************************** |
| 31 |
|
| 32 |
require_once('include/config.php'); // ディレクトリなどの設定 |
| 33 |
require_once('include/auth.php'); // ユーザ認証 |
| 34 |
|
| 35 |
// このスクリプトのファイル名 |
| 36 |
$strFilenameThis = htmlspecialchars(basename($_SERVER['PHP_SELF'])); |
| 37 |
|
| 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); |
| 46 |
} |
| 47 |
|
| 48 |
// HTML構文を開始し、ヘッダー部分を表示する |
| 49 |
print_html_header(); |
| 50 |
|
| 51 |
// include/config.php 内のグローバル変数が設定されているかチェック |
| 52 |
if(!check_config_file(1)){ |
| 53 |
print_html_footer(); |
| 54 |
die; |
| 55 |
} |
| 56 |
|
| 57 |
// 認証ファイルの確認結果を表示(必要な場合) |
| 58 |
if($flag_auth_file_exist == 0){ |
| 59 |
?> |
| 60 |
<p class="info">初期ユーザ名:user, パスワード:password です</p> |
| 61 |
<p><a href="<?php echo $strFilenameThis;?>">ログオン画面を表示する</a><p> |
| 62 |
</body> |
| 63 |
</html> |
| 64 |
<?php |
| 65 |
die; |
| 66 |
} |
| 67 |
elseif($flag_auth_file_exist < 0){ |
| 68 |
print("<p class=\"error\">認証用データファイルが作成できません<br />dataディレクトリに書き込み権限が無い可能性があります</p>\n"); |
| 69 |
print_html_footer(); |
| 70 |
die; |
| 71 |
} |
| 72 |
|
| 73 |
// ユーザ認証を行う |
| 74 |
if(!CheckAuth($strFilenameThis, 0)) |
| 75 |
{ |
| 76 |
print("<p>認証が行われていません。またはCookieが使えない状況です。</p>\n"); |
| 77 |
print("<a href=\"".$strFilenameThis."\">再度ログオン画面を表示する</a>\n"); |
| 78 |
|
| 79 |
print("</body>\n</html>\n"); |
| 80 |
die; |
| 81 |
} |
| 82 |
|
| 83 |
?> |
| 84 |
<div id="main_content_left"> |
| 85 |
<h2>System</h2> |
| 86 |
<p><?php echo date('Y/m/d H:i:s', time()) ; ?><br /> |
| 87 |
Subversion <?php echo get_svn_version(); ?></p> |
| 88 |
<h2>Menu</h2> |
| 89 |
<ul> |
| 90 |
<li><a href="<?php echo $strFilenameThis;?>">Home</a></li> |
| 91 |
<li><a href="<?php echo $strFilenameThis;?>?mode=backuplist">Backup Catalog</a></li> |
| 92 |
<li><a href="<?php echo $strFilenameThis; ?>?mode=chgpasswd">Change Password</a></li> |
| 93 |
<li><a href="<?php echo $strFilenameThis; ?>?mode=logout">Logout</a></li> |
| 94 |
</ul> |
| 95 |
<h2>Repositories</h2> |
| 96 |
<?php |
| 97 |
|
| 98 |
// 既存リポジトリ一覧を表示(左側ペイン) |
| 99 |
display_repositories(); |
| 100 |
|
| 101 |
?> |
| 102 |
</div> <!-- id="main_content_left" --> |
| 103 |
<div id="main_content_right"> |
| 104 |
|
| 105 |
<?php |
| 106 |
|
| 107 |
// ********************* |
| 108 |
// プログラム引数によって処理分岐 |
| 109 |
// ********************* |
| 110 |
|
| 111 |
// バックアップディレクトリの一覧 |
| 112 |
if(isset($_GET['mode']) && $_GET['mode'] === 'backuplist'){ |
| 113 |
display_backup_list(); |
| 114 |
} |
| 115 |
// 新規リポジトリ作成 |
| 116 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'makerepo' && isset($_POST['newrepo']) && strlen($_POST['newrepo'])>0){ |
| 117 |
$strRepo = trim($_POST['newrepo']); |
| 118 |
create_new_repository($strRepo); |
| 119 |
} |
| 120 |
// ログアウト |
| 121 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'logout'){ |
| 122 |
LogoffAuth(); |
| 123 |
print("<h1>Logout</h1>\n<p>ログアウトしました</p>\n"); |
| 124 |
} |
| 125 |
// ユーザ名・パスワード変更 |
| 126 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'chgpasswd'){ |
| 127 |
print("<h1>Change User and Password (ユーザ名、パスワード変更)</h1>\n"); |
| 128 |
print("<p>".ChangePassword($strFilenameThis, 'svnadmin-create')."</p>\n"); |
| 129 |
} |
| 130 |
// 既存リポジトリの情報表示(バックアップ、削除サブメニュー表示) |
| 131 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'inforepo' && isset($_GET['reponame'])){ |
| 132 |
$strRepo = $_GET['reponame']; |
| 133 |
info_repository($strRepo); |
| 134 |
} |
| 135 |
// 既存リポジトリのベリファイ |
| 136 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'verify' && isset($_GET['reponame'])){ |
| 137 |
$strRepo = $_GET['reponame']; |
| 138 |
verify_repository($strRepo); |
| 139 |
} |
| 140 |
// 既存リポジトリのバックアップ(hotcopy) |
| 141 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'hotcopy' && isset($_GET['reponame'])){ |
| 142 |
$strRepo = $_GET['reponame']; |
| 143 |
hotcopy_repository($strRepo, 0); |
| 144 |
} |
| 145 |
// 既存リポジトリのバックアップ(dump) |
| 146 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'dump' && isset($_GET['reponame'])){ |
| 147 |
$strRepo = $_GET['reponame']; |
| 148 |
dump_repository($strRepo); |
| 149 |
} |
| 150 |
// リポジトリの削除 |
| 151 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'remove' && isset($_GET['reponame'])){ |
| 152 |
$strRepo = $_GET['reponame']; |
| 153 |
remove_repository($strRepo); |
| 154 |
} |
| 155 |
// 既存リポジトリの情報表示(バックアップ、削除サブメニュー表示) |
| 156 |
elseif(isset($_GET['mode']) && $_GET['mode'] === 'viewbackupdir' && isset($_GET['dirname'])){ |
| 157 |
$strRepo = $_GET['dirname']; |
| 158 |
view_backup_dir($strRepo); |
| 159 |
} |
| 160 |
// 新規リポジトリ作成 入力画面 |
| 161 |
else{ |
| 162 |
// 引数が何もなかった場合、新規リポジトリ名の入力画面を表示 |
| 163 |
input_new_repository(); |
| 164 |
} |
| 165 |
|
| 166 |
print('</div> <!-- id="main_content_right" -->'."\n"); |
| 167 |
|
| 168 |
// HTMLのフッターを表示する(HTML構文を閉じる) |
| 169 |
print_html_footer(); |
| 170 |
|
| 171 |
exit(); |
| 172 |
|
| 173 |
// ********************* |
| 174 |
// 既存リポジトリ一覧を表示(左側ペイン) |
| 175 |
// ********************* |
| 176 |
function display_repositories() { |
| 177 |
global $strBaseDir; |
| 178 |
global $strFilenameThis; |
| 179 |
|
| 180 |
$arrDirs = array(); |
| 181 |
if ($dir = opendir($strBaseDir)) { |
| 182 |
while (($file = readdir($dir)) !== false) { |
| 183 |
if ($file != "." && $file != ".." && is_dir($strBaseDir.$file)) { |
| 184 |
array_push($arrDirs, $file); |
| 185 |
} |
| 186 |
} |
| 187 |
closedir($dir); |
| 188 |
} |
| 189 |
|
| 190 |
sort($arrDirs); |
| 191 |
|
| 192 |
print("<ul>\n"); |
| 193 |
foreach($arrDirs as $val){ |
| 194 |
print "<li class=\"repo\"><a class=\"repo\" href=\"$strFilenameThis?mode=inforepo&reponame=".htmlspecialchars($val)."\">".htmlspecialchars($val)."</a></li>\n"; |
| 195 |
} |
| 196 |
print("</ul>\n"); |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
|
| 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 |
// ********************* |
| 247 |
// 新規リポジトリ名入力画面 |
| 248 |
// ********************* |
| 249 |
function input_new_repository() { |
| 250 |
global $strFilenameThis; |
| 251 |
?> |
| 252 |
|
| 253 |
<h1>Create New Repository (リポジトリ作成)</h1> |
| 254 |
<p>svnadmin create コマンドを実行して新しいリポジトリを作成します。</p> |
| 255 |
<p> </p> |
| 256 |
<form method="post" action="./<?php echo $strFilenameThis; ?>?mode=makerepo" name="form1"> |
| 257 |
<p>作成するリポジトリ名 <input name="newrepo" type="text" size="25" /> <input type="submit" value="新規作成" /></p> |
| 258 |
<p> </p> |
| 259 |
<p style="color:gray;">リポジトリ名には半角アルファベット・数字・横線(A-Z, a-z, 0-9, -)のみ利用できます。<br /> |
| 260 |
また、既存のリポジトリ名と同じリポジトリは作成できません。</p> |
| 261 |
</form> |
| 262 |
|
| 263 |
<?php |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
// ********************* |
| 268 |
// 新規リポジトリ作成 |
| 269 |
// ********************* |
| 270 |
function create_new_repository($strRepo) { |
| 271 |
global $strSvnCmdPath; |
| 272 |
global $strBaseDir; |
| 273 |
|
| 274 |
print("<h1>Create New Repository (リポジトリ作成)</h1>\n"); |
| 275 |
print("<p class=\"info\">新しいリポジトリ『".htmlspecialchars($strRepo)."』が有効なディテクトリ名かチェック中 ...</p>\n"); |
| 276 |
|
| 277 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 278 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 279 |
print("<p class=\"error\">指定されたリポジトリ名が、命名規則から外れています。<br />20文字を越える、許容文字(A-Z,a-z,0-9,-)以外、先頭末尾に - など</p>"); |
| 280 |
return; |
| 281 |
} |
| 282 |
|
| 283 |
// すでに存在するディレクトリ名は却下 |
| 284 |
if(file_exists($strBaseDir.$strRepo)){ |
| 285 |
print("<p class=\"error\">指定されたリポジトリ名はすでに存在するディレクトリかファイル名です</p>"); |
| 286 |
return; |
| 287 |
} |
| 288 |
|
| 289 |
// 新規リポジトリ作成 |
| 290 |
print("<p class=\"info\">リポジトリ作成コマンド実行中 (svnamin create ".htmlspecialchars($strRepo).") ...</p>"); |
| 291 |
exec($strSvnCmdPath."svnadmin create ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 292 |
|
| 293 |
// 結果判定 |
| 294 |
if($nResult == 0){ print("<p class=\"ok\">コマンドが正しく実行されました</p>\n"); } |
| 295 |
else{ print("<p class=\"error\">実行エラー</p>\n"); } |
| 296 |
|
| 297 |
// コマンドのStdout出力がある場合 |
| 298 |
if(count($arrStdout)>0){ |
| 299 |
print("<pre>\n\n"); |
| 300 |
foreach($arrStdout as $str){ |
| 301 |
print($str."\n"); |
| 302 |
} |
| 303 |
print("</pre>\n"); |
| 304 |
} |
| 305 |
|
| 306 |
} |
| 307 |
|
| 308 |
// ********************* |
| 309 |
// 既存リポジトリの情報表示(バックアップ、削除サブメニュー表示) |
| 310 |
// ********************* |
| 311 |
function info_repository($strRepo) { |
| 312 |
global $strSvnCmdPath; |
| 313 |
global $strBaseDir; |
| 314 |
global $strFilenameThis; |
| 315 |
|
| 316 |
print("<h1>Repository Administration (リポジトリ管理)</h1>\n"); |
| 317 |
print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); |
| 318 |
|
| 319 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 320 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 321 |
print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); |
| 322 |
return; |
| 323 |
} |
| 324 |
|
| 325 |
// リポジトリの最終リビジョン番号を読み取る |
| 326 |
$strRevNo = ''; |
| 327 |
exec($strSvnCmdPath."svnlook youngest ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 328 |
if($nResult != 0){ |
| 329 |
print("<p class=\"error\">svnlook youngestコマンドが実行できません</p>\n"); |
| 330 |
} |
| 331 |
if(count($arrStdout) >= 1){ $strRevNo = $arrStdout[0]; } |
| 332 |
$arrStdout = array(); |
| 333 |
|
| 334 |
// リポジトリの最終変更ユーザ名を読み取る |
| 335 |
$strAuthor = ''; |
| 336 |
exec($strSvnCmdPath."svnlook author ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 337 |
if($nResult != 0){ |
| 338 |
print("<p class=\"error\">svnlook authorコマンドが実行できません</p>\n"); |
| 339 |
} |
| 340 |
if(count($arrStdout) >= 1){ $strAuthor = $arrStdout[0]; } |
| 341 |
$arrStdout = array(); |
| 342 |
|
| 343 |
// リポジトリの最終変更日時を読み取る |
| 344 |
$strDate = ''; |
| 345 |
exec($strSvnCmdPath."svnlook date ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 346 |
if($nResult != 0){ |
| 347 |
print("<p class=\"error\">svnlook dateコマンドが実行できません</p>\n"); |
| 348 |
} |
| 349 |
if(count($arrStdout) >= 1){ $strDate = $arrStdout[0]; } |
| 350 |
|
| 351 |
print("<p>直近にコミットしたユーザ : ".$strAuthor."</p>\n"); |
| 352 |
print("<p>直近のコミット日時 : ".$strDate."</p>\n"); |
| 353 |
print("<p>リビジョン no : ".$strRevNo."</p>\n"); |
| 354 |
|
| 355 |
$arrCmd = array( |
| 356 |
array('verify', 'ベリファイ'), |
| 357 |
// array('recover', 'エラー回復'), |
| 358 |
array('hotcopy', 'バックアップ(Hotcopy)'), |
| 359 |
array('dump', 'バックアップ(Dump)'), |
| 360 |
array('remove', '削除'), |
| 361 |
); |
| 362 |
|
| 363 |
foreach($arrCmd as $val){ |
| 364 |
print("<form method=\"post\" action=\"./".$strFilenameThis."?mode=".$val[0]."&reponame=".htmlspecialchars($strRepo)."\" name=\"form1\" class=\"horiz\"><input type=\"submit\" value=\"".$val[1]."\" /></form>\n"); |
| 365 |
} |
| 366 |
|
| 367 |
} |
| 368 |
|
| 369 |
// ********************* |
| 370 |
// 既存リポジトリのベリファイ |
| 371 |
// ********************* |
| 372 |
function verify_repository($strRepo) { |
| 373 |
global $strSvnCmdPath; |
| 374 |
global $strBaseDir; |
| 375 |
|
| 376 |
print("<h1>Verify Repository (ベリファイ)</h1>\n"); |
| 377 |
print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); |
| 378 |
|
| 379 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 380 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 381 |
print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); |
| 382 |
return; |
| 383 |
} |
| 384 |
|
| 385 |
// ベリファイコマンドを実行 |
| 386 |
exec($strSvnCmdPath."svnadmin verify ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 387 |
if($nResult != 0){ |
| 388 |
print("<p class=\"error\">svnadmin verifyコマンドが実行できません</p>\n"); |
| 389 |
return; |
| 390 |
} |
| 391 |
|
| 392 |
// コマンドのStdout出力がある場合 |
| 393 |
if(count($arrStdout)>0){ |
| 394 |
print("<pre>\n\n"); |
| 395 |
foreach($arrStdout as $str){ |
| 396 |
print($str."\n"); |
| 397 |
} |
| 398 |
print("</pre>\n"); |
| 399 |
print("<p class=\"info\">ベリファイが完了しました</p>\n"); |
| 400 |
} |
| 401 |
else{ |
| 402 |
print("<p class=\"info\">svnadminコマンドの出力無し。エラーの可能性あり</p>\n"); |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
// ********************* |
| 407 |
// 既存リポジトリのバックアップ(hotcopy) |
| 408 |
// ********************* |
| 409 |
// 引数 $flag_mode : 0のとき、処理のタイトルを表示する |
| 410 |
// 戻り値 0:失敗, 1:成功 |
| 411 |
function hotcopy_repository($strRepo, $flag_mode) { |
| 412 |
global $strSvnCmdPath; |
| 413 |
global $strBaseDir; |
| 414 |
global $strBackupDir; |
| 415 |
|
| 416 |
if($flag_mode == 0){ |
| 417 |
print("<h1>Backup (hotcopy) Repository (バックアップ : hotcopy)</h1>\n"); |
| 418 |
print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); |
| 419 |
} |
| 420 |
|
| 421 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 422 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 423 |
print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); |
| 424 |
return(0); |
| 425 |
} |
| 426 |
|
| 427 |
// バックアップ先ディレクトリが既存でないか検査 |
| 428 |
$strBackupBasename = $strRepo.'-'.date('Ymd-Hi', time()); |
| 429 |
if(file_exists($strBackupDir.$strBackupBasename)){ |
| 430 |
print("<p class=\"error\">バックアップ先に同じ名称のディレクトリがあります</p>\n"); |
| 431 |
return(0); |
| 432 |
} |
| 433 |
|
| 434 |
print("<p>コマンド実行中 ... (svnadmin hotcopy ".htmlspecialchars($strRepo)." ".htmlspecialchars($strBackupBasename).")</p>\n"); |
| 435 |
|
| 436 |
// バックアップコマンドを実行 |
| 437 |
exec($strSvnCmdPath."svnadmin hotcopy ".$strBaseDir.$strRepo." ".$strBackupDir.$strBackupBasename." 2>&1", $arrStdout, $nResult); |
| 438 |
if($nResult != 0){ |
| 439 |
print("<p class=\"info\">バックアップに失敗しました。単純コピーを試します</p>\n"); |
| 440 |
print("<p>コマンド実行中 ... (cp -Rv ".htmlspecialchars($strRepo)." ".htmlspecialchars($strBackupBasename).")</p>\n"); |
| 441 |
$arrStdout = array(); |
| 442 |
exec("cp -Rv ".$strBaseDir.$strRepo." ".$strBackupDir.$strBackupBasename." 2>&1", $arrStdout, $nResult); |
| 443 |
// コマンドのStdout出力がある場合 |
| 444 |
if(count($arrStdout)>0){ |
| 445 |
print("<pre>\n\n"); |
| 446 |
foreach($arrStdout as $str){ |
| 447 |
print($str."\n"); |
| 448 |
} |
| 449 |
print("</pre>\n"); |
| 450 |
} |
| 451 |
if($nResult != 0){ |
| 452 |
print("<p class=\"error\">単純コピーも出来ません。バックアップに失敗しました</p>\n"); |
| 453 |
return(0); |
| 454 |
} |
| 455 |
print("<p class=\"ok\">hotcopyは失敗しましたが、単純コピーは完了しました</p>\n"); |
| 456 |
return(1); |
| 457 |
} |
| 458 |
// コマンドのStdout出力がある場合 |
| 459 |
if(count($arrStdout)>0){ |
| 460 |
print("<pre>\n\n"); |
| 461 |
foreach($arrStdout as $str){ |
| 462 |
print($str."\n"); |
| 463 |
} |
| 464 |
print("</pre>\n"); |
| 465 |
} |
| 466 |
else{ |
| 467 |
print("<p class=\"ok\">バックアップが完了しました</p>\n"); |
| 468 |
} |
| 469 |
return(1); |
| 470 |
} |
| 471 |
|
| 472 |
// ********************* |
| 473 |
// 既存リポジトリのバックアップ(dump) |
| 474 |
// ********************* |
| 475 |
function dump_repository($strRepo) { |
| 476 |
global $strSvnCmdPath; |
| 477 |
global $strBaseDir; |
| 478 |
global $strBackupDir; |
| 479 |
|
| 480 |
print("<h1>Backup (dump) Repository (バックアップ : dump)</h1>\n"); |
| 481 |
print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); |
| 482 |
|
| 483 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 484 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 485 |
print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); |
| 486 |
return; |
| 487 |
} |
| 488 |
|
| 489 |
// バックアップ先ディレクトリが既存でないか検査 |
| 490 |
$strBackupBasename = $strRepo.'-'.date('Ymd-Hi', time()).'.txt'; |
| 491 |
if(file_exists($strBackupDir.$strBackupBasename)){ |
| 492 |
print("<p class=\"error\">バックアップ先に同じ名称のファイルがあります</p>\n"); |
| 493 |
return; |
| 494 |
} |
| 495 |
|
| 496 |
print("<p>コマンド実行中 ... (svnadmin dump ".htmlspecialchars($strRepo)." > ".htmlspecialchars($strBackupBasename).")</p>\n"); |
| 497 |
|
| 498 |
// バックアップコマンドを実行 |
| 499 |
exec($strSvnCmdPath."svnadmin dump ".$strBaseDir.$strRepo." > ".$strBackupDir.$strBackupBasename." 2>&1", $arrStdout, $nResult); |
| 500 |
if($nResult != 0){ |
| 501 |
print("<p class=\"error\">バックアップに失敗しました</p>\n"); |
| 502 |
return; |
| 503 |
} |
| 504 |
// コマンドのStdout出力がある場合 |
| 505 |
if(count($arrStdout)>0){ |
| 506 |
print("<pre>\n\n"); |
| 507 |
foreach($arrStdout as $str){ |
| 508 |
print($str."\n"); |
| 509 |
} |
| 510 |
print("</pre>\n"); |
| 511 |
} |
| 512 |
else{ |
| 513 |
print("<p class=\"ok\">バックアップが完了しました</p>\n"); |
| 514 |
} |
| 515 |
return; |
| 516 |
} |
| 517 |
|
| 518 |
// ********************* |
| 519 |
// リポジトリの削除 |
| 520 |
// ********************* |
| 521 |
function remove_repository($strRepo) { |
| 522 |
global $strSvnCmdPath; |
| 523 |
global $strBaseDir; |
| 524 |
global $strBackupDir; |
| 525 |
|
| 526 |
print("<h1>Remove Repository (リポジトリ削除)</h1>\n"); |
| 527 |
print("<p>リポジトリ名 : ".htmlspecialchars($strRepo)."</p>\n"); |
| 528 |
|
| 529 |
// リポジトリ名に不正な文字が入っていないか検査 |
| 530 |
if(!preg_match("/^[A-Za-z0-9\-]+$/", $strRepo) || $strRepo[0] == '-' || $strRepo[strlen($strRepo)-1] == '-' || strlen($strRepo) > 20 || strlen($strRepo) <= 0){ |
| 531 |
print("<p class=\"error\">不正なリポジトリ名が指定されました</p>\n"); |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
// バックアップ(hotcopy) |
| 536 |
print("<p class=\"info\">削除前に、バックアップを行います</p>\n"); |
| 537 |
if(!hotcopy_repository($strRepo, 1)){ |
| 538 |
print("<p class=\"error\">対象リポジトリがバックアップできないため、削除を中止します</p>\n"); |
| 539 |
return; |
| 540 |
} |
| 541 |
|
| 542 |
print("<p>コマンド実行中 ... (rm -rfv ".htmlspecialchars($strRepo).")</p>\n"); |
| 543 |
// 削除 |
| 544 |
exec("rm -rfv ".$strBaseDir.$strRepo." 2>&1", $arrStdout, $nResult); |
| 545 |
if($nResult != 0){ |
| 546 |
print("<p class=\"error\">削除に失敗しました</p>\n"); |
| 547 |
return; |
| 548 |
} |
| 549 |
// コマンドのStdout出力がある場合 |
| 550 |
if(count($arrStdout)>0){ |
| 551 |
print("<pre>\n\n"); |
| 552 |
print("$ rm -rfv ".htmlspecialchars($strRepo)."\n\n"); |
| 553 |
foreach($arrStdout as $str){ |
| 554 |
print($str."\n"); |
| 555 |
} |
| 556 |
print("</pre>\n"); |
| 557 |
} |
| 558 |
print("<p class=\"ok\">削除が完了しました</p>\n"); |
| 559 |
|
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
// ********************* |
| 564 |
// バックアップ一覧を表示する |
| 565 |
// ********************* |
| 566 |
function display_backup_list() { |
| 567 |
global $strBackupDir; |
| 568 |
global $strFilenameThis; |
| 569 |
|
| 570 |
print("<h1>Backup Catalog</h1>\n"); |
| 571 |
|
| 572 |
$arrDirs = array(); |
| 573 |
if ($dir = opendir($strBackupDir)) { |
| 574 |
while (($file = readdir($dir)) !== false) { |
| 575 |
if ($file != "." && $file != "..") { |
| 576 |
array_push($arrDirs, $file); |
| 577 |
} |
| 578 |
} |
| 579 |
closedir($dir); |
| 580 |
} |
| 581 |
|
| 582 |
sort($arrDirs); |
| 583 |
|
| 584 |
print("<ul>\n"); |
| 585 |
foreach($arrDirs as $val){ |
| 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 |
} |
| 592 |
} |
| 593 |
print("</ul>\n"); |
| 594 |
|
| 595 |
} |
| 596 |
|
| 597 |
|
| 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 |
// ********************* |
| 671 |
// svnコマンドのバージョン番号(文字列)を返す関数 |
| 672 |
// ********************* |
| 673 |
function get_svn_version() { |
| 674 |
|
| 675 |
global $strSvnCmdPath; |
| 676 |
global $strBaseDir; |
| 677 |
$strSvnVersion = ''; |
| 678 |
|
| 679 |
exec($strSvnCmdPath."svnlook --version 2>&1", $arrStdout, $nResult); |
| 680 |
if($nResult == 0){ |
| 681 |
if(preg_match('~([0-9]+)\.([0-9]+)\.([0-9]+)~', $arrStdout[0], $matches)) { |
| 682 |
$strSvnVersion = $matches[0]; |
| 683 |
} |
| 684 |
} |
| 685 |
return($strSvnVersion); |
| 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 |
|
| 727 |
?> |
| 728 |
|
| 729 |
|