/**************************************
Project: ** Password Manager **
Filename: index.php
***************************************/
############## CONFIGURATION ####################
# list of available .htpasswd files
#$filelist[]="/path_to_htpasswd_file/.htpasswd";
#$filelist[]="/path_to_another_htpasswd_file/.htpasswd";
# is this a part of a Siteseed distribution? (0 - no; 1 - yes)
$SITESEED=1;
# language (omit this when using Siteseed) # use: "english" / "portuguese"
$DEFAULT_LANGUAGE="english";
########## DO NOT CHANGE PAST THIS LINE #########
if(!$filelist) $filelist= Array();
if($SITESEED==1)
{
require "../config.php";
array_unshift($filelist,$pathtodm."bo/.htpasswd");
}
require "pwd_manager_strings.php";
$newuser=$_REQUEST["newuser"];
$olduser=$_REQUEST["olduser"];
$newsegredo=$_REQUEST["newsegredo"];
$confirmsegredo=$_REQUEST["confirmsegredo"];
$deleteuser=$_REQUEST["deleteuser"];
$submit1=$_REQUEST["submit1"];
$submit2=$_REQUEST["submit2"];
$create=$_REQUEST["create"];
$file=$_REQUEST["file"];
$newuser=trim($newuser);
$newsegredo=trim($newsegredo);
$confirmsegredo=trim($confirmsegredo);
if(!$file && count($filelist)>0) $file=$filelist[0];
$error_msg="";
// Create new file
if($create=="$strYes")
{
if($filehandle = fopen($file,'w')) fclose($filehandle);
else $error_msg.="$strCouldNotCreateFile
";
}
// Read the file into the array $passwords
$passwords=Array();
$file_exists=0;
if(file_exists($file))
{
$file_exists=1;
$lines = file($file);
foreach($lines as $nokey => $line)
{
$array = explode(':',$line);
$user = trim($array[0]);
$password = trim($array[1]);
if($user!="" && $password!="")$passwords[$user] = $password;
}
}
else
{
eval ("\$error_msg.= \"".$strFileDoesNotExist."\";");
$error_msg.="
$strWouldYouLikeToCreateOne";
$error_msg.="
";
$error_msg.=" ";
}
// Now you have the array $passwords with the users as keys and the (encrypted) passwords as values.
if($submit1=="$strAdd" || $submit1=="$strEdit")
{
if ($submit1=="$strAdd" && $passwords["$newuser"]!="")
{
$error_msg= "$strUserExists";
}
if( $newuser=="" || $newsegredo=="" || $confirmsegredo=="")
{
$error_msg= "$strAllFieldsMustBeFilledIn";
}
if( $newsegredo!=$confirmsegredo)
{
$error_msg= "$strPwdConfirmFailed";
}
if($error_msg=="")
{
// Add a user
// Next part to generate a random salt with letters and/or numbers
mt_srand((double)microtime()*1000000);
$chars = array_merge(range('a','z'),range('A','Z'),range(0,9));
for($i=0;$i<2;$i++)
{
$salt .= $chars[mt_rand(0,count($chars)-1)];
}
// Salt $salt created
// Now add the user
$passwords[$newuser] = crypt($newsegredo,$salt);
// Now the array $passwords contains the existing users and (encrypted) passwords from the file and the new user (and the encrypted password).
}
$submitvalue=$submit1;
if ($submit1=="$strEdit" || $error_msg!="") $usrval=$newuser;
else $usrval="";
}
if($submit2=="$strRemove" && $olduser!="")
{
unset($passwords[$olduser]);
$usrval="";
$olduser="";
$submitvalue="$strAdd";
}
if($olduser!="" && $submit1=="" && $submit2=="")
{
$usrval=$olduser;
$submitvalue="$strEdit";
}
if($submitvalue=="") $submitvalue="$strAdd";
if($file_exists==1)
if($filehandle = @fopen($file,'w'))
{
foreach($passwords as $user => $password)
{
fputs($filehandle, "$user:$password\n");
}
fclose($filehandle);
}
else
{
$error_msg="$strCouldNotWriteToFile";
}
?>