Osfm
Osfm
Osfm
php
/****************************************************************/
/*
*/
/* osfm Static
*/
/* ---------*/
/*
*/
/* This script will perform basic functions on files
*/
/* Functions include, List, Open, View, Edit, Create, Upload, */
/* Rename and Move.
*/
/*
*/
/* This version has had its SQL striped out of it.
*/
/*
*/
/*
*/
/* Written by Devin Smith, July 1st 2003
*/
/* http://www.osfilemanager.com
*/
/* http://www.arzy.net
*/
/*
*/
/****************************************************************/
/****************************************************************/
/* Config Section
*/
/*
*/
/* $adminfile - THIS filename.
*/
/* $sitetitle - The title at the top of all pages.
*/
/* $filefolder - The main folder to be browsing.
*/
/* $user - The username required to login.
*/
/* $pass - The password required to login.
*/
/* $tbcolor1 - Color1 of TD on home.
*/
/* $tbcolor2 - Color2 of TD on home.
*/
/* $tbcolor3 - Top of home list.
*/
/* $bgcolor1 - Main color of page.
*/
/* $bgcolor2 - Color of page border.
*/
/* $bgcolor3 - Color of textarea abd button borders.
*/
/* $txtcolor1 - Color of Normal text and hovered links.
*/
/* $txtcolor2 - Color of links.
*/
/****************************************************************/
$adminfile = $SCRIPT_NAME;
$tbcolor1c = "#bacaee";
$tbcolor2c = "#daeaff";
$tbcolor3c = "#7080dd";
$bgcolor1c = "#ffffff";
$bgcolor2c = "#a6a6a6";
$bgcolor3c = "#003399";
$txtcolor1c = "#000000";
$txtcolor2c = "#003399";
$filefolder = "/home/";
$sitetitle = 'OSFM Static';
$user = 'admin';
$pass = 'passesed';
if
if
if
if
if
if
if
(!$tbcolor1) $tbcolor1 =
(!$tbcolor2) $tbcolor2 =
(!$tbcolor3) $tbcolor3 =
(!$bgcolor1) $bgcolor1 =
(!$bgcolor2) $bgcolor2 =
(!$bgcolor3) $bgcolor3 =
(!$txtcolor1) $txtcolor1
$tbcolor1c;
$tbcolor2c;
$tbcolor3c;
$bgcolor1c;
$bgcolor2c;
$bgcolor3c;
= $txtcolor1c;
/****************************************************************/
/* function maintop()
*/
/*
*/
/* Controls the style and look of the site.
*/
/* Recieves $title and displayes it in the title and top.
*/
/****************************************************************/
function maintop($title,$showtop = true) {
global $sitetitle, $lastsess, $login, $viewing, $iftop, $bgcolor1, $bgcolor2,
$bgcolor3, $txtcolor1, $txtcolor2, $user, $pass, $password, $debug, $issuper;
echo "<html>\n<head>\n"
."<title>$sitetitle :: $title</title>\n"
."</head>\n"
."<body bgcolor=\"#ffffff\">\n"
."<style>\n"
."td { font-size : 80%;font-family : tahoma;color: $txtcolor1;font-weight:
700;}\n"
."A:visited {color: \"$txtcolor2\";font-weight: bold;text-decoration: unde
rline;}\n"
."A:hover {color: \"$txtcolor1\";font-weight: bold;text-decoration: underl
ine;}\n"
."A:link {color: \"$txtcolor2\";font-weight: bold;text-decoration: underli
ne;}\n"
."A:active {color: \"$bgcolor2\";font-weight: bold;text-decoration: underl
ine;}\n"
if ($er) {
echo "<font class=error>**ERROR: Incorrect login information.**<
/font><br><br>\n";
}
echo "<form action=\"".$adminfile."?op=".$op."\" method=\"post\">\n"
."<table><tr>\n"
."<td><font size=\"2\">Username: </font>"
."<td><input type=\"text\" name=\"user\" size=\"18\" border=\"0\" class=
\"text\" value=\"$user\">\n"
."<tr><td><font size=\"2\">Password: </font>\n"
."<td><input type=\"password\" name=\"pass\" size=\"18\" border=\"0\" cl
ass=\"text\" value=\"$pass\">\n"
."<tr><td colspan=\"2\"><input type=\"submit\" name=\"submitButtonName\"
value=\"Login\" border=\"0\" class=\"button\">\n"
."</table>\n"
."</form>\n";
mainbottom();
}
/****************************************************************/
/* function home()
*/
/*
*/
/* Main function that displays contents of folders.
*/
/****************************************************************/
function home() {
global $folder, $tbcolor1, $tbcolor2, $tbcolor3, $filefolder, $HTTP_HOST;
maintop("Home");
echo "<font face=\"tahoma\" size=\"2\"><b>\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=100%>\n";
$content1 = "";
$content2 = "";
$count = "0";
$style = opendir($folder);
$a=1;
$b=1;
if ($folder) {
if (ereg("/home/",$folder)) {
$folderx = ereg_replace("$filefolder", "", $folder);
$folderx = "http://".$HTTP_HOST."/".$folderx;
} else {
$folderx = $folder;
}
}
while($stylesheet = readdir($style)) {
if (strlen($stylesheet)>40) {
$sstylesheet = substr($stylesheet,0,40)."...";
} else {
$sstylesheet = $stylesheet;
}
if ($stylesheet[0] != "." && $stylesheet[0] != ".." ) {
if (is_dir($folder.$stylesheet) && is_readable($folder.$stylesheet)) {
$content1[$a] ="<td>".$sstylesheet."</td>\n"
."<td> "
bgcolor=\"$tbcolor3\" width=100%>"
width=300>Filename\n"
width=65>Size\n"
align=\"center\" width=44>Open\n"
align=\"center\" width=58>Rename\n"
align=\"center\" width=57>Delete\n"
align=\"center\" width=40>Move\n"
align=\"center\" width=44>View\n"
height=\"2\"><td height=\"2\" colspan=\"3\">\n";
/****************************************************************/
/* function edit()
*/
/*
*/
/* First step in edit.
*/
/* Reads the file from disk and displays it to be edited.
*/
/* Recieves $upfile from up() as the uploaded file.
*/
/****************************************************************/
function edit($fename) {
global $folder, $origTime;
if (!$fename == "") {
maintop("Edit");
echo $folder.$fename;
$origTime = filemtime($folder.$fename);
echo "<form action=\"".$adminfile."?op=save\" method=\"post\">\n"
."<textarea cols=\"73\" rows=\"40\" name=\"ncontent\">\n";
$handle = fopen ($folder.$fename, "r");
$contents = "";
while ($x<1) {
$data = @fread ($handle, filesize ($folder.$fename));
if (strlen($data) == 0) {
break;
}
$contents .= $data;
}
fclose ($handle);
$replace1
$replace2
$replace3
$replace4
$replacea
$replaceb
$contents
=
=
=
=
=
=
=
"</text";
"area>";
"< / text";
"area>";
$replace1.$replace2;
$replace3.$replace4;
ereg_replace ($replacea,$replaceb,$contents);
echo $contents;
echo "</textarea>\n"
."<br><br>\n"
."<input type=\"hidden\"
."<input type=\"hidden\"
."<input type=\"hidden\"
."<input type=\"submit\"
."</form>\n";
mainbottom();
} else {
home();
}
name=\"origTime\" value=\"".$origTime."\">\n"
name=\"folder\" value=\"".$folder."\">\n"
name=\"fename\" value=\"".$fename."\">\n"
value=\"Edit\" class=\"button\">\n"
}
/****************************************************************/
/* function save()
*/
/*
*/
/* Second step in edit.
*/
=
=
=
=
=
=
=
"</text";
"area>";
"< / text";
"area>";
$replace1.$replace2;
$replace3.$replace4;
ereg_replace ($replaceb,$replacea,$ncontent);
$ydata = stripslashes($ncontent);
if(fwrite($fp, $ydata)) {
echo "The file <a href=\"".$adminfile."?op=viewframe&file=".$fename."&fold
er=".$folder."\">".$folder.$fename."</a> was succesfully edited\n";
touch($loc, $_REQUEST['origTime']);
$origTime = date('m-d-Y h:i:s', filemtime($loc));
echo $origTime;
$fp = null;
} else {
echo "There was a problem editing this file\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function cr()
*/
/*
*/
/* First step in create.
*/
/* Promts the user to a filename and file/directory switch.
*/
/****************************************************************/
function cr() {
global $folder, $content, $filefolder;
maintop("Create");
if (!$content == "") { echo "<br><br>Please enter a filename.\n"; }
echo "<form action=\"".$adminfile."?op=create\" method=\"post\">\n"
."Filename: <br><input type=\"text\" size=\"20\" name=\"nfname\" class=\"t
ext\"><br><br>\n"
."Destination:<br><select name=ndir size=1>\n"
."<option value=\"".$filefolder."\">".$filefolder."</option>";
listdir($filefolder);
echo $content
."</select><br><br>";
echo "File <input type=\"radio\" size=\"20\" name=\"isfolder\" value=\"0\" che
cked><br>\n"
echo "</table><br>\n"
."<input type=\"hidden\" name=\"rename\" value=\"".$file."\">\n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."New Name:<br><input class=\"text\" type=\"text\" size=\"20\" name=\"nr
ename\">\n"
."<input type=\"Submit\" value=\"Rename\" class=\"button\">\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function renam()
*/
/*
*/
/* Second step in rename.
*/
/* Rename the specified file.
*/
/* Recieves $rename from ren() as the old filename.
*/
/* Recieves $nrename from ren() as the new filename.
*/
/****************************************************************/
function renam($rename, $nrename, $folder) {
global $folder;
if (!$rename == "") {
maintop("Rename");
$loc1 = "$folder".$rename;
$loc2 = "$folder".$nrename;
if(rename($loc1,$loc2)) {
echo "The file ".$folder.$rename." has been changed to <a href=\"".$adminf
ile."?op=viewframe&file=".$nrename."&folder=$folder\">".$folder.$nrename."</a>\n
";
} else {
echo "There was a problem renaming this file\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function listdir()
*/
/*
*/
/* Recursivly lists directories and sub-directories.
*/
/* Recieves $dir as the directory to scan through.
*/
/****************************************************************/
function listdir($dir, $level_count = 0) {
global $content;
if (!@($thisdir = opendir($dir))) { return; }
while ($item = readdir($thisdir) ) {
if (is_dir("$dir/$item") && (substr("$item", 0, 1) != '.')) {
listdir("$dir/$item", $level_count + 1);
}
}
if ($level_count > 0) {
$dir = ereg_replace("[/][/]", "/", $dir);
$content .= "<option value=\"".$dir."/\">".$dir."/</option>";
}
}
/****************************************************************/
/* function mov()
*/
/*
*/
/* First step in move.
*/
/* Prompts the user for destination path.
*/
/* Recieves $file and sends to move().
*/
/****************************************************************/
function mov($file) {
global $folder, $content, $filefolder;
if (!$file == "") {
maintop("Move");
echo "<form action=\"".$adminfile."?op=move\" method=\"post\">\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."Move ".$folder.$file." to:\n"
."<select name=ndir size=1>\n"
."<option value=\"".$filefolder."\">".$filefolder."</option>";
listdir($filefolder);
echo $content
."</select>"
."</table><br><input type=\"hidden\" name=\"file\" value=\"".$file."\">\
n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."<input type=\"Submit\" value=\"Move\" class=\"button\">\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function move()
*/
/*
*/
/* Second step in move.
*/
/* Moves the oldfile to the new one.
*/
/* Recieves $file and $ndir and creates $file.$ndir
*/
/****************************************************************/
function move($file, $ndir, $folder) {
global $folder;
if (!$file == "") {
maintop("Move");
if (rename($folder.$file, $ndir.$file)) {
echo $folder.$file." has been succesfully moved to ".$ndir.$file;
} else {
echo "There was an error moving ".$folder.$file;
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function viewframe()
*/
/*
*/
break;
case "edit":
edit($_REQUEST['fename']);
break;
case "save":
save($_REQUEST['ncontent'], $_REQUEST['fename']);
break;
case "cr":
cr();
break;
case "create":
create($_REQUEST['nfname'], $_REQUEST['isfolder'], $_REQUEST['ndir']);
break;
case "ren":
ren($_REQUEST['file']);
break;
case "rename":
renam($_REQUEST['rename'], $_REQUEST['nrename'], $folder);
break;
case "mov":
mov($_REQUEST['file']);
break;
case "move":
move($_REQUEST['file'], $_REQUEST['ndir'], $folder);
break;
case "viewframe":
viewframe($_REQUEST['file']);
break;
case "viewtop":
viewtop($_REQUEST['file']);
break;
case "printerror":
printerror($error);
break;
case "logout":
logout();
break;
default:
home();
break;
}
?>