(if you need a jsp or perl front end page, you can write one yourself)
Here's the shell script to change password for svn:
#!/bin/sh
#changepass.sh , function: change password for svn
#usage: changepass.sh username oldpass newpass newpassretype
if [ ! "$#" = 4 ]
then
echo "Usage:`basename $0` username oldpass newpass newpassretype"
exit 1
fi
passfile="/home/svn/passwd"
username=
oldpass=
newpass1=
newpass2=
username=$1
oldpass=$2
newpass1=$3
newpass2=$4
if [ ! $newpass1 = $newpass2 ]
then
#echo "password does not match!";
echo "password does not match!"
exit 2
fi
export NEWPASS=$newpass1
export USERNAME=$username
i=`sed /^"$username"[" ""\t"]*=[" ""\t"]*$oldpass\$/p $passfile -n|wc -l`
if [ $i = 1 ]
then
awk '{ if(index($0,ENVIRON["USERNAME"])==1) {print ENVIRON["USERNAME"] " = " ENVIRON["NEWPASS"] }else {print $0} }' $passfile > /home/svn/newpass
rm /home/svn/newpass 2>&1 1> /dev/null
cp /home/svn/newpass $passfile
echo 'password changed!'
elif [ `sed /"$username"/p $passfile -n |wc -l` > 0 ]
then
echo ' username and password does not match'
else
echo 'could not find username'
fi
here's the php front end changepass.php , it is for php 5, if you use php 4, maybe you need use $HTTP_POST_VARS instead $_POST ( just guess, i haven't test it):
if(strlen($_POST["pwd1"]) >0 ){
if($_POST["pwd1"]!=$_POST["pwd2"]){
print("Passwords do not match, try again.
\n");
}else{
$LoginName = $_POST["loginname"];
$OldPassword = $_POST["oldpwd"];
$NewPass1 = $_POST["pwd1"];
$NewPass2 = $_POST["pwd2"];
$retval='';
#echo $LoginName;
#echo $OldPassword;
// user apache or nobody(who runs httpd daemon) needs the permission of passwd file and temp file
$command = "/mnt/apache/changepass.sh ".$LoginName." ".$OldPassword." ".$NewPass1." ".$NewPass2 ;
#$command = "/bin/cat /mnt/apache/changepass.sh "." 2>&1";
$command = $command." 2>&1";
#system("/bin/echo abc",$retval);
system($command, $retval);
echo "
" ;echo $retval;echo '
';
if($retval!=0){
print("
Error while setting password:
\n");
}
}
}
else{
;#echo "parameters not set!";
}
?>
Login Name: | |
Old Password: | |
New Password: | |
Repeat Password: |
the php page and shell scripts should works ok, but the php page shows nothing after click "submit" in fedora, however in slackware it is ok.
After debug step by step, found that shell script error message would not be ouput on the web page, so i add this line: $command = $command." 2>&1";
And finally found that SELinux would block some function on the web server. I disabled SELinux in the firewall settings, and it works.
No comments:
Post a Comment