This is a early version of a filesystem editor we wrote for our developers kit. It allows you do view a directory, create files, erase files, edit files, create directories, remove directories, and upload files from your browser directly into the directory.
By : bleach
<? session_register("GlimpseDir");
if(!$GlimpseDir) $GlimpseDir="/";
/* This software was written 2000 by Derek Young at GSData Design */
/* Please Use some type of auth system for this file, if it got in the
wrong hands, you could be seriously messed with. You can put it in
a protected directory via .htaccess, or use your own auth system in
php, either way, be carefull, I take no responsibility for any
damages that this file causes. */
/* Set this directory to the physical location on your filesystem for
the document root. */
$basedir="/usr/httpd/html/glimpse";
function reloadnow() {
global $PHP_SELF;
global $addons;
header("Status: 302 Moved");
header("Location: $PHP_SELF".$addons);
exit(); }
if($cancel) $action="";
if($action=="root") $GlimpseDir="/";
if($action=="chdr") $GlimpseDir=$file."/";
if($action=="dele" && $confirm==1) { unlink($basedir.$file); $action="";}
if($action=="move" && $confirm && $newfile) {
rename($basedir.$file,$basedir.$newfile); $action=""; }
if($action=="rmdr") rmdir($basedir.$file);
if($action=="edit" && $confirm && $file) {
$fp=fopen($basedir.$file,"w");
fputs($fp,stripslashes($code));
fclose($fp);
$addons="?action=edit&file=".rawurlencode($file);
reloadnow(); }
if($upload) { copy($userfile,$basedir.$GlimpseDir.$userfile_name);
reloadnow(); }
if($touch) { touch($basedir.$GlimpseDir.$touchfile); reloadnow(); }
if($mkdir) { mkdir($basedir.$GlimpseDir.$mkdirfile,0700); reloadnow(); }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3c.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>Filesystem Browser-Current Directory="<?=$GlimpseDir;?>"</TITLE>
</HEAD>
<BODY> <?
if ($action=="dele") {
echo "Are you sure you want to delete $file ?<BR>";
echo "<A HREF=\"$PHP_SELF?action=dele&file=" . rawurlencode($file) . "&confirm=1\">YES</A><BR>";
echo "<A HREF=\"$PHP_SELF\">NO</A><BR>";
echo "</BODY></HTML>";
exit(); }
if ($action=="move") {
echo "Current Filename is: ".$file . "<BR>\n";
echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\">Newfile Name<BR>\n";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Change\">\n";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
echo "</FORM></BODY></HTML>";
exit(); }
if ($action=="edit") {
echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
echo "Current Filename is: ".$file ." ";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"edit\">\n";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Save\">\n";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Exit\"><BR>\n";
$fp=fopen($basedir.$file,"r");
$contents=fread($fp,filesize($basedir.$file));
echo "<TEXTAREA NAME=\"code\" rows=\"20\" cols=\"80\">\n";
echo htmlspecialchars($contents);
echo "</TEXTAREA><BR>\n";
echo "</FORM></BODY></HTML>";
exit(); }
?>
<A HREF="<?=$PHP_SELF;?>?action=root">Back to root</A><BR>
<TABLE BORDER="1">
<TR><TD>Filename</TD><TD>Type</TD><TD>Size</TD><TD>Action</TD></TR>
<? $handle=opendir($basedir . $GlimpseDir);
while($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$filename=$basedir.$GlimpseDir.$file;
$fileurl=rawurlencode($GlimpseDir.$file);
echo "<TR>";
echo "<TD>" . htmlspecialchars($file) . "</TD>\n";
echo "<TD>" . filetype($filename) . "</TD>\n";
echo "<TD>" . filesize($filename) . "</TD>\n";
echo "<TD>";
if(filetype($filename)=="file") {
echo "<A HREF=\"$GlimpseDir$file\">View</A> ";
echo "<A HREF=\"$PHP_SELF?action=edit&file=$fileurl\">Edit</A> ";
echo "<A HREF=\"$PHP_SELF?action=dele&file=$fileurl\">Dele</A> ";
echo "<A HREF=\"$PHP_SELF?action=move&file=$fileurl\">Move</A> ";
} if(filetype($filename)=="dir") {
echo "<A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\">ChDr</A> ";
echo "<A HREF=\"$PHP_SELF?action=rmdr&file=$fileurl\">RmDr</A> ";
}
echo "</TD>";
echo "</TR>\n";
}
}
closedir($handle);
?>
</TABLE>
<BR>
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?=$PHP_SELF;?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="SUBMIT" NAME="upload" VALUE="Upload"><BR>
<INPUT TYPE="TEXT" NAME="touchfile">
<INPUT TYPE="SUBMIT" NAME="touch" VALUE="Touch"><BR>
<INPUT TYPE="TEXT" NAME="mkdirfile">
<INPUT TYPE="SUBMIT" NAME="mkdir" VALUE="Mkdir"><BR>
</FORM>
</BODY>
</HTML>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |