\n");
// page select form
printf(" \n");
printf(" \n");
printf(" | \n");
// Message Block
printf("\n");
printf(" \n");
printf(" | \n");
// Get a file into an array
$lines = @file($openfile) or send2msgblock("Error: in opening Page");
if( $lines )
{
// Loop through our array, show HTML source as HTML source
foreach ($lines as $line_num => $line)
{
$pagesource = $pagesource . htmlspecialchars($line);
}
}
if ( $_GET['action'] == "save" )
{
// save file
$pagesource = $_POST['editbox'];
$pagesource = str_replace("\r","",$_POST['editbox']); // remove '\r' that's appended
// $pagesource = str_replace("\\","",$pagesource); // remove '\r' that's appended
// Logic
// 1. Save the file in /tmp on the machine from where Wedit is running
// 2. Connect to the remote system using ftp, User and password
// 3. put the file in $DOCUMENTROOT/$PATH
// Step 2
$path = $documentroot . "/" . $filepath;
$ftp_user = $_POST['username'];
$ftp_pass = $_POST['password'];
if ($type == "http")
{
if ( !$ftp_user || !$ftp_pass )
{
send2msgblock("Error: Login and Password have to be entered to Save page on the server");
}
else
{
// Step 1
$tempfile = "/tmp/Wedit_pagesource";
$f = fopen($tempfile,"w") or send2msgblock("Error: Cannot Open file");
if ($f)
{
fwrite($f,$pagesource) or send2msgblock("Error: Cannot save file"); //place $pagesource back in file
fclose($f);
}
// set up a connection or die
@$conn_id = ftp_connect($ftp_server) or send2msgblock("Error: Cannot connect to $ftp_server");
// try to login
if ($conn_id && @ftp_login($conn_id, $ftp_user, $ftp_pass))
{
send2msgblock("Connected as $ftp_user@$ftp_server");
}
else
{
send2msgblock("Error: Cannot connect as $ftp_user");
}
// Step 3
if (@ftp_put($conn_id, $path, $tempfile, FTP_ASCII)) {
send2msgblock("successfully uploaded $file");
} else {
send2msgblock("Error: There was a problem while uploading to $file");
}
ftp_close($conn_id);
}
} // save local file
else if ($type == "local")
{
// Step 1
$f = @fopen($openfile,"w") or send2msgblock("Error: Couldn't Open file");
if ($f)
{
@fwrite($f,$pagesource,strlen($pagesource)) or send2msgblock("Error: Couldn't save file"); //place $pagesource back in file
fclose($f);
}
send2msgblock("File is saved on the server");
}
}
// Show the page source in a Text box
printf("\n |