<?
/*
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.
*/
/* if they bookmark this throw them out if not already validated through auth.php */
/*
This allows users with sbkupp.php to update their profile email address
The interesting thing is about this would be only one record needed to contain a user's email address.
Users can only update their own zprofile record.
Owners of hostnames can update only userids.
*/
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;
}
# must specify the notification to owners
$unote = $_REQUEST['unote'] ;
if (strtoupper($unote) != "Y" && strtoupper($unote) != "N") {
#issue error message
$_SESSION['errmsg']="perr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
# must specify the requested userid's email
$email = $_REQUEST['email'] ;
if (empty($email)) {
#issue error message
$_SESSION['errmsg']="perr";
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(" ",$email);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
# update code 0 = profile is not found. 1 = is profile found.
$uc=0;
$rfile = "archive/profile";
#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);
$fh = fopen($rfile, 'w');
$lines = explode ( "\n", $file_data );
$cnt = count($lines) - 1;
for ( $i=0; $i < $cnt; $i++ ) {
$line=$lines[$i];
list( $owner, $omail, $onote ) = explode( ':', $line );
if (strtoupper($user) == strtoupper($owner)) {
$strdata = $owner . ":" . $email . ":" . $unote . "\n";
fwrite($fh, $strdata);
$uc=1;
}
else {
$strdata = $owner . ":" . $omail . ":" . $onote . "\n";
fwrite($fh, $strdata);
}
}
#assume it must be added
if ($uc=0) {
$strdata = $user . ":" . $email . ":" . $unote . "\n";
fwrite($fh, $strdata);
}
$_SESSION['umail']=$email;
$_SESSION['unote']=$unote;
fclose($fh);
unlink($rfile."_lock");
#issue error message
$_SESSION['errmsg']="pok";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
?>