[go: up one dir, main page]

Menu

[r2]: / cpy / bkuph  Maximize  Restore  History

Download this file

215 lines (210 with data), 7.6 kB

#!/usr/bin/php5
<? 
/*
VMLMAT: VM Linux Management and Archival Tool.
Copyright (c) 2007, Ronnie Michael, BMC Software Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the BMC Software Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ 
# This routine builds the restore html form file 
# This routine is designed to look for a special Build Machine Name (BVM)
# and place in www root directory for standard builds, all others go to the correct user directory 
#
#
#
# get parmfile variables needed
include 'bkinc.php';
#
#
#
$rfile = "reqfile.txt";
$prfile="/mnt/request/" . $rfile;
$fh = fopen($prfile, 'r'); 
$rdata = fgets($fh); 
fclose($fh);
$strgs = explode(" ", $rdata);
/* array starts at offset zero */
$fln=$strgs[11];
$ffln=$fln . ".php";
$tarball=$strgs[6];
$usr=$strgs[8];
$host=$strgs[4];
$hip=$strgs[5];
if (strtoupper($host) == $bvm) {
$pfln=$wwwpath . $ffln;
}
else {
$pfln=$wwwpath . $usr . "/" . $ffln;
}
$fhw = fopen($pfln,'w');
$nl = "\n";
$wdata ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<html><head><title>' . $fln . ' - Restore Your System</title>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<link rel="stylesheet" type="text/css" href="/templates/astyle.css" title="standard"/>' . $nl;
fwrite($fhw, $wdata);
$wdata ='</head><body>' . $nl;
fwrite($fhw, $wdata);
if (strtoupper($host) == $bvm) {
$wdata ='<div id="banner"><a name="top"></a><h1><a href="index.php">' . $fln . '</a></h1><h2> Linux Management System </h2>' . $nl;
} 
else {
$wdata ='<div id="banner"><a name="top"></a><h1><a href="../index.php">' . $fln . '</a></h1><h2> Linux Management System </h2>' . $nl;
}
fwrite($fhw, $wdata);
$wdata ='</div>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<div id="commentcontent">' . $nl;
fwrite($fhw, $wdata);
if (strtoupper($host) == $bvm) {
$wdata ='<p> next entry: <a href="index.php" target="_self">Return</a>' . $nl;
}
else {
$wdata ='<p> next entry: <a href="../index.php" target="_self">Return</a>' . $nl;
}
fwrite($fhw, $wdata);
$today = date("F j, Y, g:i a");
$wdata ='<h1><span class="date">' . $today . '</span>Backup/Restore System</h1>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<p>Fill out below to begin restore <br />' . $nl;
fwrite($fhw, $wdata);
$wdata ='<br />' . $nl;
fwrite($fhw, $wdata);
$wdata ='<br />' . $nl;
fwrite($fhw, $wdata);
$wdata ='<br />' . $nl;
fwrite($fhw, $wdata);
$wdata ='<br />' . $nl;
fwrite($fhw, $wdata);
$wdata ='</p>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<p><p>Must Fill out the info below</p><a name="comm"></a></p>' . $nl;
fwrite($fhw, $wdata);
if (strtoupper($host) == $bvm) {
$wdata ='<p><a name="#comments"></a><a name="#bottom"></a><form method="post" action="submit.php" name="form" >' . $nl;
}
else {
$wdata ='<p><a name="#comments"></a><a name="#bottom"></a><form method="post" action="../submit.php" name="form" >' . $nl ;
}
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="req" value="0">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="ohost" value="' . $host . '">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="oip" value="' . $hip . '">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="tarfile" size="40" value="' . $tarball . '">' . $nl;      
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="userid" value="dummy">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="comment" value="comment">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="url" value=self.location>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<table border=0 cellspacing=0 cellpadding=0 width="640">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<tr>';
fwrite($fhw, $wdata);
$wdata ='      <td>Email:</td>' . $nl;
fwrite($fhw, $wdata);
$wdata ='<?' . $nl;
fwrite($fhw, $wdata);
$wdata ='session_start();' . $nl;
fwrite($fhw, $wdata);
$wdata ='$umail=$_SESSION["umail"];' . $nl;
fwrite($fhw, $wdata);
$wdata ='print "<td><input name=email type=text value=" . $umail . " size=40></td></tr><tr>";' . $nl;
fwrite($fhw, $wdata);
$wdata ='?>' . $nl;
fwrite($fhw, $wdata);
$wdata ='      <td>Hostname:</td>' . $nl;
fwrite($fhw, $wdata);
$wdata ='      <td><input name="hostname" type="text" size="40"></td></tr><tr>' . $nl;
fwrite($fhw, $wdata);
$wdata ='      <td>Bring up? (Y=yes, N=no):</td>' . $nl;
fwrite($fhw, $wdata);
$wdata ='      <td><input name="upc" type="text" size="1" value="Y"></td></tr><tr>' . $nl;
fwrite($fhw, $wdata);
$wdata ='	<td>Gzip Tarball:</td>' . $nl;
fwrite($fhw, $wdata);
$wdata ='      <td>' . $tarball . '</td></tr><tr>' . $nl;      
fwrite($fhw, $wdata);
$wdata ='</table>';  
fwrite($fhw, $wdata);
$wdata ='<input type="submit" name="start" value="Start" style="border: 1px inset black;">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="submit" name="cancel" value="Cancel" style="border: 1px inset black;">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<br><br>' . $nl;
fwrite($fhw, $wdata);
$wdata ='</form></p>' . $nl;
fwrite($fhw, $wdata);
$wdata ='</div>' . $nl;
fwrite($fhw, $wdata);
$wdata ='</body>' . $nl;
fwrite($fhw, $wdata);
$wdata ='</html>' . $nl;
fwrite($fhw, $wdata);
fclose($fhw);
#
chmod($pfln,0777);
#
#update index.php text menu files with the links if a BVM
#
if (strtoupper($host) == $bvm) {
$iln="index.txt";
$pfln=$wwwpath . $iln;
#lets spin until we get file lock
while (file_exists($pfln."_lock")) {}
touch($pfln."_lock");
# Lets add to the end (append)
$fhw = fopen($pfln,'a');
#
# remove the underscores from the link name
$filn=str_replace("_"," ",$fln);
$wdata ="<a href=$ffln>$filn</a>\n";
fwrite($fhw, $wdata);
fclose($fhw);
# It is not necessary to sort this file since index.php 
# will do this anyway before displaying
# but what the heck.
#
# lets re-read the file 
$fp = fopen($pfln, 'r' ); 
$file_data = fread( $fp, filesize( $rfile ) ); 
fclose( $fp ); 
$lines = explode ( "\n", $file_data );
#
# and lets sort these links in order
#
array_multisort($lines); 
#
# and lets rewrite the file in the 
# correct alphabetic-numeric order
#
$fp = fopen($rfile, 'w'); 
$cnt = count($lines) - 1;
for ( $i=0; $i < $cnt; $i++ ) { 
$line=$lines[$i];
$strdata=$line."\n";
fwrite($fp, $strdata);
}
fclose($fp);
unlink($pfln."_lock");
}
?>