您的位置:首页 > 运维架构 > Apache

svn结合apache后用户修改密码的解决方案

2011-09-28 17:03 274 查看
svn结合apache后,修改密码就得在server端,由管理员修改密码,很不方便也不安全。

现在做已了一个web界面实现用户svn密码的修改。

我用php,做了两个页面,一个是信息收集,一个是调用系统命令

前置条件:apche已集成了svn,php

1.apache添加svntools访问目录

在/etc/ini.d/http.conf

Alias /svntools "/opt/svntools/"

<Directory "/opt/svntools">

AuthType Basic

AuthName "Subversion Tools"

AuthUserFile /opt/svn/passwd

Require valid-user

</Directory>

2.在/opt/svntols目录下创建php页面
2.1 index.php页面
<html>
<head>
<title>Change your svn passwd</title>
</head>
<script type="text/javaScript">
function check(){
if(document.form.oldpwd.value.length == 0){
alert("please input your old password!");
document.form.oldpwd.focus();
return false;
}
if(document.form.oldpwd.value != document.form.pwd.value){
alert("your old pssword is not right! please input your password!");
document.form.oldpwd.focus();
return false;
}
if(document.form.newpwd.value.length == 0){
alert("please input your new password!");
document.form.newpwd.focus();
return false;
}
if(document.form.rnewpwd.value.length == 0){
alert("please repeat input your new password!");
document.form.rnewpwd.focus();
return false;
}
if(document.form.newpwd.value != document.form.rnewpwd.value){
alert("your tow password is not the same! please reset !");
document.fomr.newpwd.focus();
return false;
}
return true;
}
</script>

<body>
<h1 align="center">Change your svn password</h1>

<?php
$username = $_SERVER["PHP_AUTH_USER"];
$authed_pass = $_SERVER["PHP_AUTH_PW"];
?>

<form action="result.php" name="form" method="post">
<table width="300" cellpadding="3" cellspacing="8" align="center">
<tr><th colspan=2> Subversion Change password</th></tr>
<tr>
<td>username:</td>
<td>
<input type="text" name="a" value='<?php echo $username;?>' disabled="true"/>
<input type="hidden" name="hide" value='<?php echo $username;?>'/>
</td>
</tr>
<tr><td>oldpassword:</td>
<td>
<input type="password" name="oldpwd"/>
<input type="hidden" name="pwd" value='<?php echo $authed_pass;?>'/>
</td>
</tr>
<tr><td>newpassword:</td><td><input type="password" name="newpwd"/></td></tr>
<tr><td>repeatnewpassword:</td><td><input type="password" name="rnewpwd"/></td></tr>
<tr><td><input type="submit" value="sure" onclick="return check()"/></td><td><input type="reset" value="reset"</td></tr>
</table>
</form>
</body>
</html>

2.2 result.php页面
<html>
<head>
</head>
<body>
<h1 algin="center">RESULT</h3>
<?php
$user = $_POST["hide"];
$pwd = $_POST["newpwd"];
$command = "htpasswd -b /opt/svn/passwd $user $pwd";
exec($command,$res,$rc);
if($rc == 0){
echo "success";
echo "<br/>";
echo "please remember your username and password.";
echo "<br/>";
echo "username: $user ";
echo "<br/>";
echo "passwd: $pwd";
echo "<br/>";
}else{
echo "fails ";
}

?>
</body>
</html>

参考了以下这篇网文

http://tech.16c.cn/svnpz/20080202/58.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: