<?
/*
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.
*/
#
# Admin Images submittal routine.
# This allows user to create/delete form file for the standard images on the main menu.
# and the necessary html link. It is assumed the tarfile already exists and this was
# built with the BUILD VM (BVM).
#
#
/* if they bookmark this throw them out if not already validated through auth.php */
session_start();
$user=$_SESSION['user'];
if (empty($user)){
#issue error message
$_SESSION['errmsg']="autherr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
if (isset($_REQUEST['cancel'])) {
#issue error message
$_SESSION['errmsg']="cancel";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
$message = $_REQUEST['comment'];
#make sure they didn't put a white space the variable
$test=explode(" ",$message);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
$auth=false;
$filen="archive/authfile";
#lets spin until we get file lock
while (file_exists($filen."_lock")) {}
touch($filen."_lock");
$fp = fopen($filen, 'r' );
$file_data = fread( $fp, filesize( $filen ) );
fclose( $fp );
unlink($filen."_lock");
$lines = explode ( "\n", $file_data );
foreach ( $lines as $line ) {
list( $hostn, $owner, $func ) = explode( ':', $line );
if (strtoupper($hostn) == "ZBACKUP" && strtoupper($owner) == strtoupper($user)) {
$auth=true;
}
if (strtoupper($hostn) == "ZADMIN" && strtoupper($owner) == strtoupper($user)) {
$auth=true;
}
}
if (! $auth) {
#issue error message
$_SESSION['errmsg']="unauths";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
# get parmfile variables needed
include '/var/clone/bkinc.php';
#
#
$fln=$message;
$ffln=$fln . ".php";
$pfln=$wwwpath . $ffln;
if (isset($_REQUEST['add'])) {
#
# creates standard images
#
$tar = $_REQUEST['tarfile'] ;
if (empty($tar)) {
#issue error message
$_SESSION['errmsg']="error";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#make sure they didn't put a white space the variable
$test=explode(" ",$tar);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
$tarball=$tar;
$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);
$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);
$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> Standard Image Backup 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);
$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="ohost" value="' . $bvm . '">' . $nl;
fwrite($fhw, $wdata);
$wdata ='<input type="hidden" name="oip" value="' . $bvmip . '">' . $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="req" value="0">' . $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>' . $nl;
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>' . $nl;
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);
#update index.php text menu files
$iln="index.txt";
$pfln=$wwwpath . $iln;
$fhw = fopen($pfln,'a');
$filn=str_replace("_"," ",$fln);
$wdata ='<a href=' . $ffln . '>' . $filn . '</a>' . $nl;
fwrite($fhw, $wdata);
fclose($fhw);
# issue okay message
$_SESSION['errmsg']="sok";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
if (isset($_REQUEST['del'])) {
if (file_exists($pfln)) {
#
# delete the html form file .php
#
system("rm " . $pfln);
#
# lets clean out the standard image link
#
$rfile = $wwwpath . "index.txt";
#lets spin until we get file lock
while (file_exists($rfile."_lock")) {}
touch($rfile."_lock");
$fp = fopen($rfile, 'r' );
$file_data = fread( $fp, filesize( $rfile ) );
fclose( $fp );
$lines = explode ( "\n", $file_data );
$fp = fopen($rfile, 'w');
$cnt = count($lines) - 1;
for ( $i=0; $i < $cnt; $i++ ) {
$line=$lines[$i];
if (substr($line,8,strlen($fln))==substr($fln,0,strlen($fln))) {}
else {
$strdata=$line."\n";
fwrite($fp, $strdata);
}
}
fclose($fp);
unlink($rfile."_lock");
#issue ok message
$_SESSION['errmsg']="sdel";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
} else {
#issue error message
$_SESSION['errmsg']="snok";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
}
}
?>