coniglio

由于在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脚本也可轻易做到等等

  1. <?php  
  2. $username = $_SERVER["PHP_AUTH_USER"]; //获取当前用户名  
  3. $authed_pass = $_SERVER["PHP_AUTH_PW"]; //获取当前用户密码  
  4. $input_oldpass = (isset($_REQUEST["oldpass"]) ? $_REQUEST["oldpass"] : ""); //输入的原密码  
  5. $newpass = (isset($_REQUEST["newpass"]) ? $_REQUEST["newpass"] : ""); //输入的新密码  
  6. $repeatpass = (isset($_REQUEST["repeatpass"]) ? $_REQUEST["repeatpass"] : ""); //输入的重复密码  
  7. $action = (isset($_REQUEST["action"]) ? $_REQUEST["action"] : ""); //以hide方式提交到服务器的action  
  8. if($action!="modify"){  
  9. $action = "view";  
  10. }  
  11. else if($authed_pass!=$input_oldpass){  
  12. $action = "oldpasswrong";  
  13. }  
  14. else if(empty($newpass)){  
  15. $action = "passempty";  
  16. }  
  17. else if($newpass!=$repeatpass){  
  18. $action = "passnotsame";  
  19. }  
  20. else{  
  21. $action = "modify";  
  22. }  
  23. ?>  
  24. <html>  
  25. <head>  
  26. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  27. <title>SVN密码修改</title>  
  28. </head>  
  29. <body>  
  30. <?php  
  31. //action=view 显示普通的输入信息  
  32. if ($action == "view"){  
  33. ?>  
  34. <style type="text/css">  
  35. <!--  
  36. table {  
  37. border: 1px solid #CCCCCC;  
  38. background-color: #f9f9f9;  
  39. text-align: center;  
  40. vertical-align: middle;  
  41. font-size: 9pt;  
  42. line-height: 15px;  
  43. }  
  44. th {  
  45. font-weight: bold;  
  46. line-height: 20px;  
  47. border-top-width: 1px;  
  48. border-right-width: 1px;  
  49. border-bottom-width: 1px;  
  50. border-left-width: 1px;  
  51. border-bottom-style: solid;  
  52. color: #333333;  
  53. background-color: f6f6f6;  
  54. }  
  55. input{  
  56. height: 18px;  
  57. }  
  58. .button {  
  59. height: 20px;  
  60. }  
  61. -->  
  62. </style>  
  63. <br><br><br>  
  64. <form method="post">  
  65. <input type="hidden" name="action" value="modify"/>  
  66. <table width="220" cellpadding="3" cellspacing="8" align="center">  
  67. <tr>  
  68. <th colspan=2>SVN密码修改</th>  
  69. </tr>  
  70. <tr>  
  71. <td>用户名:</td>  
  72. <td align="left"> <?=$username?></td>  
  73. </tr>  
  74. <tr>  
  75. <td>原密码:</td>  
  76. <td><input type=password size=12 name=oldpass></td>  
  77. </tr>  
  78. <tr>  
  79. <td>用户密码:</td>  
  80. <td><input type=password size=12 name=newpass></td>  
  81. </tr>  
  82. <tr>  
  83. <td>确认密码:</td>  
  84. <td><input type=password size=12 name=repeatpass></td>  
  85. </tr>  
  86. <tr>  
  87. <td colspan=2>  
  88. <input onclick="return loginIn(this.form)" class="button" type=submit value="修 改">  
  89. <input name="reset" type=reset class="button" value="取 消">  
  90. </td>  
  91. </tr>  
  92. </table>  
  93. </form>  
  94. <?  
  95. }  
  96. else if($action == "oldpasswrong"){  
  97. $msg="原密码错误!";  
  98. }  
  99. else if($action == "passempty"){  
  100. $msg="请输入新密码!";  
  101. }  
  102. else if($action == "passnotsame"){  
  103. $msg="两次输入密码不一致,请重新输入!";  
  104. }  
  105. else{  
  106. $passwdfile="/var/www/svn/project/conf/passwd";  
  107. $command='"htpasswd" -b '.$passwdfile." ".$username." ".$newpass;  
  108. system($command, $result);  
  109. if($result==0){  
  110. $msg="用户[".$username."]密码修改成功,请用新密码登陆.";  
  111. }  
  112. else{  
  113. $msg="用户[".$username."]密码修改失败,请和管理员联系!";  
  114. }  
  115. }  
  116. if (isset($msg)){  
  117. ?>  
  118. <script language="javaScript">  
  119. <!--  
  120. alert("<?=$msg?>");  
  121. window.location.href="<?=$_SERVER["PHP_SELF"]?>"  
  122. //-->  
  123. </script>  
  124. <?  
  125. }  
  126. ?>  
  127. </body>  
  128. </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 denied
sudo: pam_open_session: System error
sudo: policy plugin failed session initialization

sudo: 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 ~]# getenforce
Enforcing
重启
[root@localhost ~]# reboot
验证
[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 disabled
[root@localhost ~]# getenforce

Disabled

(7)如果出现用户权限不足?
首先 查看你的apache用户或者nginx php-fpm用户
可以使用 ps -ef  | grep httpd 命令来查看  其他同理
经查我的apache用户为apache用户
然后 visudo   或者 vim /etc/sudoers 找到
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL这一行 在下边追加

[plain] view plain copy
    1. apache ALL=(root)  NOPASSWD:ALL   

相关文章: