Hey all first post here looks like a nice place...
I too do a good bit of work for clients and run around with laptop.
Fortunately most of the time, I work from home though. However all the websites I make I put in the following script.
Its completely unsafe and I just made it in the past year in a 30 minute coding session.
I made it so that I could do BASIC editing on files in a pinch because most large clients do not let you ssh in or ftp in to the website if they are smart that is.
However, it does work if you are sure to do the following:
!!! Put this in a safe place with a weird url!!!
and
!!! use a .htaccess password protector. !!!
chmod the files in the webspace so that apache can write there.
Please feel to add to this script whatever you want.
Definately please fee free to send back improvements.
Lastly, doubly feel free to accept this script as is with absolutely no warranty on anything...
I would give a demo however this is an extremely powerful script in the hands of a potential misfit hacker. So you just have to try it out on a test / dev area first if you desire...
Code:
<?php
if( ! isset( $_GET['file'] ) )
{
$_GET['file'] = ".";
}
if( $_GET['delete'] == 1 )
{
if( is_file( $_GET['file'] ) )
{
unlink( $_GET['file'] );
$_GET['file'] = dirname( $_GET['file'] );
$_GET['delete'] = 0;
}
}
if( $_GET['delete'] == 1 )
{
if( is_dir( $_GET['file'] ) )
{
rmdir( $_GET['file'] );
$_GET['file'] = dirname( $_GET['file'] );
$_GET['delete'] = 0;
}
}
if( isset( $_FILES['thefile'] ) ) {
$uploaddir = $_POST['path']."/";
$uploadfile = $uploaddir . $_FILES['thefile']['name'];
if (move_uploaded_file($_FILES['thefile']['tmp_name'], $uploadfile)) {
chmod("$uploadfile", 0766);
}else{ echo "ERROR"; exit; }
$_GET['file'] = $_POST['path'];
}
if( is_file( $_GET['file'] ) )
{
$edit_file = 1;
}
if( is_dir( $_GET['file'] ) )
{
$show_directory = 1;
}
if( $_GET['create'] == 1 )
{
touch( $_POST['path']."/".$_POST['file'] );
$_GET['file'] = $_POST['path'];
}
if( $_GET['createdir'] == 1 )
{
mkdir( $_POST['path']."/".$_POST['file'] );
$_GET['file'] = $_POST['path'];
}
#get file contents function
if (!function_exists('file_get_contents'))
{
function file_get_contents($filename, $use_include_path = 0)
{
$file = @fopen($filename, 'rb', $use_include_path);
if ($file)
{
if ($fsize = @filesize($filename))
{
$data = fread($file, $fsize);
}
else
{
while (!feof($file))
{
$data .= fread($file, 1024);
}
}
fclose($file);
}
return $data;
}
}
#file_put_contents
if (!function_exists('file_put_contents')) {
define('FILE_APPEND', 1);
function file_put_contents($filename, $content, $flags = 0) {
if (!($file = fopen($filename, ($flags & FILE_APPEND) ? 'a' : 'w')))
return false;
$n = fwrite($file, $content);
fclose($file);
`chmod 766 $filename`;
#, 0766);
return $n ? $n : false;
}
}
if( $_POST['submitter'] == 'Save and View' )
{
file_put_contents($_GET['file'],stripslashes($_POST['file_source']),"w");
$_GET['file'] = dirname( $_GET['file'] );
$show_directory = 1;
$edit_file = 0;
#header("Location: ".$_GET['file']);
}
?>
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function HandleKeyDown(obj) {
var tabKeyCode = 9;
if (event.keyCode == tabKeyCode && event.srcElement == obj) {
obj.selection = document.selection.createRange();
obj.selection.text = String.fromCharCode(tabKeyCode);
event.returnValue = false;
}
}
</script>
<title>reditor</title>
</head>
<!-- show a directory -->
<?php if( $show_directory ) { ?>
<p>DIRECTORY: <?= $_GET['file'] ?></p>
<table>
<?php
if ($handle = opendir( $_GET['file'] )) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$dir = "";
$delete = "x";
if( is_dir( $file ) )
{
$dir = "/";
}
?>
<tr>
<td><a href = "?file=<?= $_GET['file'] ?>/<?=$file?>"><?= $file ?><?= $dir ?></a></td>
<td><a href = "?file=<?= $_GET['file'] ?>/<?=$file?>&delete=1"><?= $delete ?></a></td>
</tr>
<?php }
}
closedir($handle);
}
?>
</table>
<form action = "?create=1" method = "POST">
<input type = "text" name = "file" >
<input type = "hidden" name = "path" value = "<?= $_GET['file'] ?>">
<input type = "submit" value = "Create New File">
</form>
<form action = "?createdir=1" method = "POST">
<input type = "text" name = "file" >
<input type = "hidden" name = "path" value = "<?= $_GET['file'] ?>">
<input type = "submit" value = "Create New Dir">
</form>
<form enctype="multipart/form-data" action = "?upload=1" method = "POST">
<input type = "file" name = "thefile" >
<input type = "hidden" name = "path" value = "<?= $_GET['file'] ?>">
<input type = "submit" value = "Upload File">
</form>
<?php } ?>
<!-- edit a file -->
<?php if( $edit_file ) { ?>
<?php $file_src = file_get_contents( $_GET['file'] ); ?>
<body>
<h2>Editing <?= $_GET['file'] ?></h2>
<form name="sited" enctype="multipart/form-data" METHOD="POST" ACTION="">
<textarea name="file_source" wrap="OFF" style="height:580px; width:840px "ONKEYDOWN="HandleKeyDown(this);"><?php echo $file_src; ?></textarea>
<br />
<input type="submit" name="submitter" value="Save and View">
</form>
<?php } ?>
</html>