用戶svn密碼自定義


由於在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   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM