由于在linux系统Apache+svn服务器,用户需要自定义密码怎么办呢?
1.创建脚本目录
mkdir -p /var/www/svn/svntools
2.创建apache配置文件
touch /etc/httpd/conf.d/alias.conf
3.输入以下内容:
Alias /svntools "/var/www/svn/svntools"
<Directory "/var/www/svn/svntools"> Require valid-user AuthType Basic AuthName "svn tools" AuthUserFile "/var/www/svn/passwd"</Directory>
4.创建修改密码的php脚本,当然不一定是php脚本,js脚本也可轻易做到等等
- <?php
- $username = $_SERVER["PHP_AUTH_USER"]; //获取当前用户名
- $authed_pass = $_SERVER["PHP_AUTH_PW"]; //获取当前用户密码
- $input_oldpass = (isset($_REQUEST["oldpass"]) ? $_REQUEST["oldpass"] : ""); //输入的原密码
- $newpass = (isset($_REQUEST["newpass"]) ? $_REQUEST["newpass"] : ""); //输入的新密码
- $repeatpass = (isset($_REQUEST["repeatpass"]) ? $_REQUEST["repeatpass"] : ""); //输入的重复密码
- $action = (isset($_REQUEST["action"]) ? $_REQUEST["action"] : ""); //以hide方式提交到服务器的action
- if($action!="modify"){
- $action = "view";
- }
- else if($authed_pass!=$input_oldpass){
- $action = "oldpasswrong";
- }
- else if(empty($newpass)){
- $action = "passempty";
- }
- else if($newpass!=$repeatpass){
- $action = "passnotsame";
- }
- else{
- $action = "modify";
- }
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>SVN密码修改</title>
- </head>
- <body>
- <?php
- //action=view 显示普通的输入信息
- if ($action == "view"){
- ?>
- <style type="text/css">
- <!--
- table {
- border: 1px solid #CCCCCC;
- background-color: #f9f9f9;
- text-align: center;
- vertical-align: middle;
- font-size: 9pt;
- line-height: 15px;
- }
- th {
- font-weight: bold;
- line-height: 20px;
- border-top-width: 1px;
- border-right-width: 1px;
- border-bottom-width: 1px;
- border-left-width: 1px;
- border-bottom-style: solid;
- color: #333333;
- background-color: f6f6f6;
- }
- input{
- height: 18px;
- }
- .button {
- height: 20px;
- }
- -->
- </style>
- <br><br><br>
- <form method="post">
- <input type="hidden" name="action" value="modify"/>
- <table width="220" cellpadding="3" cellspacing="8" align="center">
- <tr>
- <th colspan=2>SVN密码修改</th>
- </tr>
- <tr>
- <td>用户名:</td>
- <td align="left"> <?=$username?></td>
- </tr>
- <tr>
- <td>原密码:</td>
- <td><input type=password size=12 name=oldpass></td>
- </tr>
- <tr>
- <td>用户密码:</td>
- <td><input type=password size=12 name=newpass></td>
- </tr>
- <tr>
- <td>确认密码:</td>
- <td><input type=password size=12 name=repeatpass></td>
- </tr>
- <tr>
- <td colspan=2>
- <input οnclick="return loginIn(this.form)" class="button" type=submit value="修 改">
- <input name="reset" type=reset class="button" value="取 消">
- </td>
- </tr>
- </table>
- </form>
- <?
- }
- else if($action == "oldpasswrong"){
- $msg="原密码错误!";
- }
- else if($action == "passempty"){
- $msg="请输入新密码!";
- }
- else if($action == "passnotsame"){
- $msg="两次输入密码不一致,请重新输入!";
- }
- else{
- $passwdfile="/var/www/svn/project/conf/passwd";
- $command='"htpasswd" -b '.$passwdfile." ".$username." ".$newpass;
- system($command, $result);
- if($result==0){
- $msg="用户[".$username."]密码修改成功,请用新密码登陆.";
- }
- else{
- $msg="用户[".$username."]密码修改失败,请和管理员联系!";
- }
- }
- if (isset($msg)){
- ?>
- <script language="javaScript">
- <!--
- alert("<?=$msg?>");
- window.location.href="<?=$_SERVER["PHP_SELF"]?>"
- //-->
- </script>
- <?
- }
- ?>
- </body>
- </html>
可能出现问题
(1).php文件放置位置 ? /var/www/svn/svntools/svnpass.php
(2).访问路径?http://ip:port/svntools/svnpass.php
(3).apache端口冲突?修改/etc/httpd/conf/httpd.conf中的端口号
(4).php文件乱码问题?查看php文件格式是否为utf8
(5).修改passwd权限问题? chown root:root passwd chmod 777 * -R chmod -R passwd 777 chmod 777 passwd -R
(6). 如查看apache日志中有如下错误[Wed Jun 13 09:34:34.462360 2018] [core:notice] [pid 22132] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
sudo: unable to open audit system: Permission deniedsudo: pam_open_session: System errorsudo: policy plugin failed session initializationsudo: unable to open audit system: Permission denied?
解决方法1:setenforce 0 :用于关闭selinux防火墙,但重启后失效。
[root@localhost ~]# setenforce 0
[root@localhost ~]# /usr/sbin/sestatus 1、关闭firewall防火墙,保证apache能够访问正常。2、没有关闭selinux,时出现了如上错误。
解决方法2: 永久关闭修改selinux的配置文件,重启后生效。打开 selinux 配置文件[root@localhost ~]# vim /etc/selinux/config修改 selinux 配置文件将SELINUX=enforcing改为SELINUX=disabled,保存后退出# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=enforcing# SELINUXTYPE= can take one of three two values:# targeted - Targeted processes are protected,# minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection.SELINUXTYPE=targeted此时获取当前selinux防火墙的安全策略仍为Enforcing,配置文件并未生效。[root@localhost ~]# getenforceEnforcing重启[root@localhost ~]# reboot验证[root@localhost ~]# /usr/sbin/sestatusSELinux status: disabled[root@localhost ~]# getenforceDisabled
(7)如果出现用户权限不足?
首先 查看你的apache用户或者nginx php-fpm用户可以使用 ps -ef | grep httpd 命令来查看 其他同理经查我的apache用户为apache用户然后 visudo 或者 vim /etc/sudoers 找到## Allow root to run any commands anywhereroot ALL=(ALL) ALL这一行 在下边追加-
- apache ALL=(root) NOPASSWD:ALL