由於在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 onclick="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 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這一行 在下邊追加
- apache ALL=(root) NOPASSWD:ALL