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! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. 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!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |