Файл: id2759/PHP Version/fileman/common.lib.php
Строк: 508
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | Aquonics File Manager |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 Aquonics Scripting |
// +----------------------------------------------------------------------+
// | You may not remove the copyright or redistribute the script in any |
// | form. This program is Freeware, please read the license at |
// | http://www.aquonics.com/license.php |
// | |
// | Visit www.aquonics.com for more top scripts, free and custom. |
// +----------------------------------------------------------------------+
// | Authors: Stephen Ball <stephen@aquonics.com> |
// +----------------------------------------------------------------------+
//
// $Id$
// Prints out the header used on all pages
function html_header($title)
{
global $new_dir, $username;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?=$title;?></title>
<style type="text/css">
<!--
A:visited, A:link {
color: #000000;
text-decoration: underline;
background-color: transparent;
}
A:active, A:hover {
color: #000000;
text-decoration: underline;
background-color: transparent;
}
input, textarea, select, option {
font-family: Verdana, Geneva, Arial, Helvetica, Sans-Serif;
font-size: 10px;
border: 1px solid #000000;
}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function open_window(url) {
var NEW_WIN = null;
NEW_WIN = window.open("", "SourceViewer", "toolbar=no,width=600,height=400,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
NEW_WIN.document.location.href = url;
}
function NewFileName() {
var fileName = window.upload.filename.value.toLowerCase();
window.upload.newname.value = fileName.substring(fileName.lastIndexOf("\") + 1, fileName.length);
}
function chmod(name, folder) {
var chmodval = window.prompt("Change CHMOD for '" + name + "' to: ", "")
if (chmodval == null) {
return;
}
if (isNaN(chmodval) || (chmodval == "") || (chmodval.length > 3) || !isChmod(chmodval)) {
window.alert("Please enter the permissions in octal and in only three digits. EG 755.")
}
else {
window.location.href = "<?=$PHP_SELF;?>?op=chmod&chmod=" + chmodval + "&file=" + escape(name) + "&dir=" + escape(folder)
}
}
function rename(name, folder) {
var inValid = /[\/:*?"<>|]/;
var newname = window.prompt("Rename '" + name + "' to: ", "")
if (newname == null) {
return;
}
if (inValid.test(newname) == true) {
window.alert("The new name cannot contain any of the following characters: \/:*?"<>|");
return;
}
else {
window.location.href = "<?=$PHP_SELF;?>?op=rename&new=" + newname + "&file=" + escape(name) + "&dir=" + escape(folder)
}
}
function delFile(name, folder) {
if (window.confirm("Are you sure you want to delete the file named '" + name + "' ?")) {
window.location.href = "<?=$PHP_SELF;?>?op=del&file=" + escape(name) + "&dir=" + escape(folder)
}
}
function delDir(name, folder) {
if (window.confirm("Are you sure you want to delete the directory named '" + name + "' ?")) {
window.location.href = "<?=$PHP_SELF;?>?op=deldir&rmdir=" + escape(name) + "&dir=" + escape(folder)
}
}
function isValid(fields) {
var text = fields;
var inValid = /[\/:*?"<>|]/;
if (inValid.test(text) == true) {
window.alert("The filename cannot contain any of the following characters: \/:*?"<>|");
return false;
}
return true;
}
function mkdir(folder) {
var newdir = window.prompt("Please enter the name of the new directory.", "<?=$new_dir;?>")
var inValid = /[\/:*?"<>|]/;
if (newdir == null) {
return;
}
else if (newdir == "") {
window.alert("The new directory must have a name");
return;
}
else if (inValid.test(newdir) == true) {
window.alert("The directory name cannot contain any of the following characters: \/:*?"<>|");
return;
}
else {
window.location.href = "<?=$PHP_SELF;?>?op=mkdir&dir=" + escape(folder) + "&newdir=" + escape(newdir)
}
}
function isChmod(Val) {
if (!Val) {
return false;
}
for (i=0; i<Val.length; i++) {
if (Val.charAt(i) < "0") {
return false;
}
if (Val.charAt(i) > "7") {
return false;
}
}
return true;
}
function checkdetails() {
var Valid = /[a-zd_]/i;
var name = window.user.newusername.value;
var pass = window.user.newpassword.value;
var selected = window.user.newlevel.selectedIndex;
var level = window.user.newlevel.options[selected].value;
if (name == "" || name < 3 || Valid.test(name) == false) {
window.user.newusername.focus();
window.alert("Please enter a different username.rnrnNote: A name must be at least 3 characters and may only contain Alphanumerical characters and the underscore '_' character.");
return false;
}
else if (pass == "" || pass < 6 || Valid.test(pass) == false) {
window.user.newpassword.focus();
window.alert("Please enter a different password.rnrnNote: A password must be at least 5 characters and may only contain Alphanumerical characters and the underscore '_' character.");
return false;
}
else if (level == 1) {
var confirm = window.confirm("Are you sure you wish to give '" + name + "' Admin Access?");
if(!confirm) {
window.user.newlevel.focus();
return false;
}
}
return true;
}
function deluser() {
var selected = window.remove.user.selectedIndex;
var level = window.remove.user.options[selected].value;
var name = window.remove.user.options[selected].text;
if (name == "<?=$username;?>") {
var ok = window.confirm("Are you sure you want to remove yourself from the access list?rnrnYou will be logged out, and will have to log in with another account.")
if(!ok) {
return false;
}
else {
return true;
}
}
else if (window.confirm("Are you sure you want to remove " + name + " from the access list?")) {
return true;
}
return false;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF">
<!-- Using overLIB (c) Erik Bosrup -->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script language="JavaScript" src="overlib.js" type="text/javascript"></script>
<!-- http://www.bosrup.com -->
<div align="center">
<table border="0" width="85%" bgcolor="#000000" cellpadding="4" cellspacing="1">
<?php
}
// Prints out the footer used on all pages
function html_footer($starttime)
{
?>
<br />
<!-- Copyright and admin stats -->
<table border="0" width="85%" bgcolor="#FFFFFF" cellpadding="4" cellspacing="1">
<tr>
<td align="center" valign="top" colspan="2"><a href="http://validator.w3.org/check/referer"><img src="images/validxhtml.gif" alt="Valid XHTML 1.0!" height="31" width="88" border="0" /></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="images/validcss.gif" alt="Valid CSS!" height="31" width="88" border="0" /></a></td>
</tr>
<tr>
<td align="center" valign="top" colspan="2"><font face="Verdana, Geneva, Arial, Helvetica, Sans-Serif" size="1" color="#000000">This page took <?php echo endtime($starttime); ?> seconds to produce.<br /><br />Powered by <a href="http://www.aquonics.com">Aquonics File Manager</a> Version 1.5<br />©2001 <a href="mailto:stephen@aquonics.com">Stephen Ball</a> of <a href="http://www.aquonics.com" target="_blank">Aquonics Scripting</a></font></td>
</tr>
</table>
</div>
</body>
</html>
<?
}
// Finds out the startime time
function starttime()
{
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
return $starttime;
}
// Finds out the end time
function endtime($starttime)
{
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
$totaltime = round($totaltime, 3);
return $totaltime;
}
// Validates that the user is
// allowed access
function validate_user($user, $pass)
{
global $script_dir;
$usercheck = file($script_dir . "userlist.cgi");
$valid = 0;
while(list(,$value) = each ($usercheck)) {
list($username, $password, $level) = split("[|]", $value);
if (($username == $user) && ($password == $pass)) {
return 1;
}
}
if ($valid == 0) {
return 0;
}
}
// Returns the users access level
function user_level($user, $pass)
{
global $script_dir;
$usercheck = file($script_dir . "userlist.cgi");
while(list(,$value) = each ($usercheck)) {
list($username, $password, $level) = split("[|]", $value);
if (($username == $user) && ($password == $pass)) {
return $level;
}
}
}
// Formats the file size into
// a readable value
function formatsize($filesize)
{
if ($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . " Gigabytes";
}
else if ($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . " Megabytes";
}
else if ($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . " Kilobytes";
}
else {
$filesize = $filesize . " Bytes";
}
return $filesize;
}
// Gets the icon for the
// current file
function get_icon($extension = "")
{
global $iconarray;
reset($iconarray);
if ($extension == "") {
return "unknown.gif";
}
while(list($key, $value) = each($iconarray)) {
$iconlist = explode(" ", $value);
foreach($iconlist as $icon) {
if ($icon == $extension) {
return $key;
}
}
}
return "unknown.gif";
}
// Returns the current
// CHMOD value
function chmod_value($file)
{
$mode = fileperms($file);
$mode &= 0x1ff; # Remove the bits we don't need
$chmod = sprintf("%o", $mode);
return $chmod;
}
// Returns the message linked
// to the msgnum variable
function getmsg($msgnum)
{
$msg[1] = "The root directory does not exist.";
$msg[2] = "The specified directory does not exist, using root directory instead.";
$msg[3] = "There was an error changing the CHMOD value.";
$msg[4] = "The CHMOD value have been modified.";
$msg[5] = "There was an error saving the file.";
$msg[6] = "The file could not be deleted.";
$msg[7] = "The file has been deleted.";
$msg[8] = "The specified directory already exists.";
$msg[9] = "The new directory could not be created.";
$msg[10] = "The new directory has been created.";
$msg[11] = "The specified directory does not exist.";
$msg[12] = "The specified directory could not be removed.";
$msg[13] = "The directory has been removed.";
$msg[14] = "The new file name already exists.";
$msg[15] = "The specified file does not exist.";
$msg[16] = "The specified file could not be renamed.";
$msg[17] = "The file has successfully been renamed.";
$msg[18] = "The new file already exists.";
$msg[19] = "The file could not be uploaded.";
$msg[20] = "The file has successfully been uploaded.";
$msg[21] = "The user already exists.";
$msg[22] = "The new user has been created successfully.";
$msg[23] = "There was an error creating the new user.";
$msg[24] = "The selected user does not exist.";
$msg[25] = "The user has been deleted.";
$msg[26] = "There was an error removing the user.";
$msg[27] = "The users settings have been modified.";
$msg[28] = "There was an error editing the users settings.";
$msg[29] = "You do not have the required access rights.";
$msg[30] = "The webmaster has choosen to prevent access to this directory.";
$msg[31] = "You used an illegal path";
if (empty($msg[$msgnum])) {
$msg[$msgnum] = "There was an unknown error.";
}
return $msg[$msgnum];
}
// Prints out the error/success message
function msg($num)
{
echo" <tr>rn";
echo" <td align="left" bgcolor="#F5F5F5" valign="middle"><font size="1" face="Verdana, Geneva, Arial, Helvetica, Sans-Serif" color="#000000">" . getmsg($num) . "</font></td>rn";
echo" </tr>rn";
echo"</table>rn";
echo"<br />rn";
echo"<table border="0" width="85%" bgcolor="#000000" cellpadding="4" cellspacing="1">rn";
}
// Returns the file extension
function getext($file)
{
$temparray = explode(".", $file);
$ext = $temparray[count($temparray) - 1];
$ext = strtolower($ext);
return $ext;
}
// A small function to encode the url
// a fix the safe mode/rawurlencode bug
function encoded($url)
{
$url = rawurlencode($url);
$url = str_replace("%00", "%2F", $url);
return $url;
}
// Trim more than one backslashes
function trimslash($path)
{
$path = ereg_replace("/{2,}", "/", $path);
return $path;
}
// Cleans the path so it doesn't contain ../ etc or a drive letter
function cleanpath($path) {
$path = ereg_replace(".[.]+", "", $path);
$path = ereg_replace("^[/]+", "", $path);
return $path;
}
?>