Important alert: (current site time 7/15/2013 10:24:41 AM EDT)
 

VB icon

Adminastrative Web Developement

Email
Submitted on: 5/27/2003 8:50:25 PM
By: Taylor K.  
Level: Intermediate
User Rating: By 3 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 12555
(About the author)
 
     A general web developement tool. It can edit/view/organize any files you have premission to view. Take care of your server from anywhere in the wold. A must have for any admin.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Adminastrative Web Developement
// Description:A general web developement tool. It can edit/view/organize any files you have premission to view. Take care of your server from anywhere in the wold. A must have for any admin.
// By: Taylor K.
//
// Inputs:GUI BABY!!!
//
// Returns:GUI based file/folder lookup
//
// Assumes:All files/folders you are planing to edit are properly chmoded and chowned.
//
// Side Effects:None Known, E-mail s7master@hotmail.com
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1020&lngWId=8//for details.//**************************************

<?php
 // Change
$pathvarB="/tools/";// directory of files.php
$passwordabc="password";//login password
$userabc="user";//Change it if you want
$fileabc="/usr/local/apache2/htdocs2"; //change this to your web servers root (where index.php is)
$backup="/valuble/data/dir/ /valuable/file";//what to backup, seperated by a space for multiple entries
$backup_location="/backup/"; // Location to backup to, make sure to have a / at the end
 //dont change from here on down
$self=$_SERVER['SCRIPT_FILENAME'];
$dateA=date("ymdHi");
$valid=0;
$header="Welcome";
$file=$_POST['file'];
if($_GET['file']){
 $file=$_GET['file'];
 $header=$file;
}
if($file=="")
 $file=$fileabc;
elseif($file=="self")
 $file=$self;
$file=trim($file);
$filea=$file;
if((strlen($file)-1 == strrpos($file, '/')) && $file != '/')
 $file=substr($file, 0, strlen($file)-1);
if($_GET["prefix"])
 $file=$_GET["prefix"]."/".$file;
if($_COOKIE['files_pass']==$passwordabc){
 if($GET["action"]!="logoff")
 setcookie("files_pass", $_COOKIE['files_pass'], time()+3600, $pathvarB);
 $valid=1;
}elseif($_POST['pass']==$passwordabc){
 $valid=1;
 setcookie("files_pass", $_POST['pass'], time()+3600, $pathvarB);
 $header="Logged In";
}elseif($_COOKIE['files_pass'] || $_POST['pass']){
 $valid=0;
 $header="Failed to Log On";
}
switch($_GET['action']){
 case 'logoff': setcookie("files_pass", 0, time()-3600);
 $valid=0;
 break;
 case 'edit': $disfile=stripslashes($_POST['edit']);
 $fp=fopen($file, "w");
 fwrite($fp, $disfile);
 fclose($fp);
 break;
 case 'New': if(strpos($filea, '/') && !file_exists($file))
 mkdir($file, 0755);
 elseif(!file_exists($file)){
 $fp=fopen($file, "w");
 fwrite($fp, "New file created!");
 fclose($fp);
 chmod($file, 0755);
 }
 break;
 case 'chmod': $farray=explode(' : ', $_POST['fvar']);
 for($c=0;$farray{$c} && $_POST['carray']{$c};$c++){
 if($farray{$c}=='./')
 chmod($file, octdec($_POST['carray']{$c}));
 elseif($farray{$c}=='../'){
 if(substr_count($file, '/')>1)
$dd=substr($file, 0, strrpos($file, '/'));
 else
$dd="/";
 chmod($dd, octdec($_POST['carray']{$c}));
 }else
 chmod($file.'/'.$farray{$c}, octdec($_POST['carray']{$c}));
 }
 break;
 case 'rename': $farray=explode(' : ', $_POST['fvar']);
 for($c=0;$farray{$c} && $_POST['rarray']{$c};$c++){
 rename($file."/".$farray{$c}, $file."/".$_POST["rarray"]{$c});
 }
 break;
 case 'upload': move_uploaded_file($_FILES['upload']['tmp_name'], $file.'/'.$_FILES['upload']['name']);
 break;
 case 'backup': exec("tar -cf ".$backup_location."backup".$dateA.".tar $backup");
}
switch($_POST["action"]){
 case 'Delete': for($c=0; $_POST["farray"]{$c} && $_POST["farray"]{$c} != './' && $_POST["farray"]{$c} != '../'; $c++){
 if(!is_dir($file.'/'.$_POST["farray"]{$c}))
 unlink($file.'/'.$_POST["farray"]{$c});
 else
 rmdir($file.'/'.$_POST["farray"]{$c});
 }
 break;
}
?>
<html>
 <head>
 <title>File Manager - <?php echo $header ?></title>
 <style>
 a{ text-decoration: none }
 a:hover{ text-decoration: underline }
 </style>
 </head>
 <body alink=red vlink=blue link=blue>
 <?php
 if($valid==0){
 ?>
 
 <table align=center border=0 width=450 cellpadding=0 cellspacing=0>
 <tr>
 <td><b>Login</b>
 </td>
 </tr>
 <tr>
 <td>
 <form method="post" action="files.php">
 User: <font style="font-size: 90%"><tt><?php echo $userabc; ?></tt></font><br>
 Password: <input type=password name="pass"><br>
 <input type=submit value="Login">
 </form>
 </td>
 </tr>
 </table>
 <?php
 }elseif($valid==1){
 ?>
 <table width=85% align=center cellpadding=0 cellspacing=0 border=0>
 <tr>
 <td align=right>
 <a href="files.php?action=logoff">Log Off</a>
 </td>
 </tr>
 <tr>
 <td>
 <form method=get>Location: <input type=text size=80 name="file" <?php echo "value=\"$file\">" ?> <input type=submit value="Go"></form>
 </td>
 </tr>
 <tr>
 <td>
 <hr width=100%>
 <?php 
if(is_file($file)){
$disfile=ereg_replace("<", "&lt;", ereg_replace(">", "&gt;", ereg_replace("&", "&amp;", implode("", file($file)))));
echo "<form method=post action='files.php?file=$file&action=edit'><h2 align=center>$file</h2><textarea cols=100 rows=30 wrap='off' name=edit>$disfile</textarea><p><input type=submit value='Change'> <input type=reset value='Undo All'></form>";
}elseif($_POST["action"]=="Chmod"){
echo "<h2 align=center>Chmod</h2><form method=post action='files.php?file=$file&action=chmod'><table cellpadding=0 cellspacing=0 border=0 width=50%><tr><td width=50%><b>Name</b></td><td width=50%><b>Chomd</b></td></tr>";
$fvar="";
for($c=0; $_POST['farray']{$c}; $c++){
$fvar=$fvar.$_POST['farray']{$c}.' : ';
echo "<tr><td>".$_POST['farray']{$c}."</td><td><input type=text name=carray[] value='".substr(sprintf("%o",fileperms($file.'/'.$_POST['farray']{$c})),-3)."'></td></tr>";
}
echo "</table><input type=hidden name=fvar value='$fvar'><input type=submit value='Chmod'> <input type=reset></form>";
}elseif($_POST["action"]=="Rename"){
echo "<h2 align=center>Rename</h2><form method=post action='files.php?file=$file&action=rename'>";
$fvar="";
for($c=0; $_POST['farray']{$c}; $c++){
$fvar=$fvar.$_POST['farray']{$c}.' : ';
echo "<input type=text name=rarray[] value='".$_POST['farray']{$c}."'><br>";
}
echo "<input type=hidden name=fvar value='$fvar'><input type=submit value='Rename'> <input type=reset></form>";
}elseif(is_dir($file)){
echo "<b>$file Listing:</b><form method=post action='files.php?file=$file'>\n";
if($dir=@opendir($file)){
echo "<p><table cellpadding=0 cellspacing=1 border=1 width=100%><tr bgcolor='#666666'><td width=3%>&nbsp;</td><td width=28%><b>Filename:</b></td><td width=3%>&nbsp;</td><td width=20%><b>File Size:</b></td><td width=3%>&nbsp;</td><td width=15%><b>Permissions/ID:</b></td><td width=3%>&nbsp;</td><td width=25%><b>Last Modified:</b></td></tr>";
if($file=='/')
$file="";
while(false!==($a=readdir($dir))){
$size=filesize($file.'/'.$a).' Bytes';
$perms=substr(sprintf("%o",fileperms($file.'/'.$a)),-3).'/'.fileowner($file.'/'.$a);
$date=date("F d Y g:i A", filemtime($file.'/'.$a));
if($a=='.'){
 if($file=="")
 echo "<tr><td bgcolor='#999999'><input type=checkbox name=farray[] value='./'></td><td><a href='files.php?file=/'>./</a></td><td bgcolor='#999999'>&nbsp;</td><td>$size</td><td bgcolor='#999999'>&nbsp;</td><td>$perms</td><td bgcolor='#999999'>&nbsp;</td><td>$date</td></tr>\n";
 else
 echo "<tr><td bgcolor='#999999'><input type=checkbox name=farray[] value='./'></td><td><a href='files.php?file=$file'>./</a></td><td bgcolor='#999999'>&nbsp;</td><td>$size</td><td bgcolor='#999999'>&nbsp;</td><td>$perms</td><td bgcolor='#999999'>&nbsp;</td><td>$date</td></tr>\n";
}elseif($a=='..'){
 if(substr_count($file, '/')>1)
 $dd=substr($file, 0, strrpos($file, '/'));
 else
 $dd="/";
 echo "<tr><td bgcolor='#999999'><input type=checkbox name=farray[] value='../'></td><td><a href='files.php?file=$dd'>../</a></td><td bgcolor='#999999'>&nbsp;</td><td>$size</td><td bgcolor='#999999'>&nbsp;</td><td>$perms</td><td bgcolor='#999999'>&nbsp;</td><td>$date</td></tr>\n";
}elseif(is_dir("$file/$a"))
 echo "<tr><td bgcolor='#999999'><input type=checkbox name=farray[] value='$a'></td><td><a href='files.php?file=$file/$a'>$a/</a></td><td bgcolor='#999999'>&nbsp;</td><td>$size</td><td bgcolor='#999999'>&nbsp;</td><td>$perms</td><td bgcolor='#999999'>&nbsp;</td><td>$date</td></tr>\n";
else
 echo "<tr><td bgcolor='#999999'><input type=checkbox name=farray[] value='$a'></td><td><a href='files.php?file=$file/$a'>$a</a></td><td bgcolor='#999999'>&nbsp;</td><td>$size</td><td bgcolor='#999999'>&nbsp;</td><td>$perms</td><td bgcolor='#999999'>&nbsp;</td><td>$date</td></tr>\n";
}
?>
 </table>
 <hr width=100%><br>
 <table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<td width=33% alinn=left>
<input type=submit name=action value='Delete'> <input type=submit name=action value='Chmod'> <input type=submit name=action value='Rename'></form>
</td>
<td width=33% align=center>
<form method=get action='files.php'><input type=submit value='New'> <input type=hidden name=action value='New'><input type=hidden name=prefix value=<?php echo "'$file'>"; ?><input type=text name=file></form>
</td>
<td width=34% align=right>
<form enctype='multipart/form-data' method=post action='files.php?file=<?php echo $file; ?>&action=upload'><input type="hidden" name="MAX_FILE_SIZE" value="100000000"><b>Upload: </b><input type=file name=upload> <input type=submit value='Go'></form>
</td>
</tr>
 </table><p>
 <center><a href="files.php?action=backup&file=<?php echo $file; ?>">Quick Backup</a></center>
<?php
}else
echo "Failed!";
}else{
echo "<b>$file - Please enter a valid file or folder</b>";
}
 ?>
 </td>
 </tr>
 </table>
 <?php
 }
 ?>
 </body>
</html>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
1/5/2004 1:12:37 PM

hallo
(If this comment was disrespectful, please report it.)

 
8/9/2004 5:14:17 AM

very good code
(If this comment was disrespectful, please report it.)

 
9/1/2005 12:44:50 PMian

thanx for your share..
i luv it...
(If this comment was disrespectful, please report it.)

 
1/14/2006 5:17:07 AMLawrence Cherone

files.php is missing.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.