jasmine214--love

          只有當你的內心總是充滿快樂、美好的愿望和寧靜時,你才能擁有強壯的體魄和明朗、快樂或者寧靜的面容。
          posts - 731, comments - 60, trackbacks - 0, articles - 0

          linux下如何實現(xiàn)的客戶端修改svn密碼


          注意:  

                            1、ChangePasswd.ini、ChangePasswd.cgi必須放在apache的cgi-bin(根據自己電腦上的路徑來,我的是/var/www/cgi-bin)下。

                      2、以下腳本是改動網上查找腳本之后的成果。

                      3、修改密碼文件的所有者是apache,如果不是,執(zhí)行chown apache:apache passwd(密碼文件)。

                      4、如果密碼是用htpasswd -c 或-m所建,執(zhí)行htpasswd -b /etc/httpd/passwd usrname password更新。

                      /etc/httpd/passwd     //密碼路徑

                      usrname                     //用戶名

                      password                   //用戶名所對應的密碼。

                      5.需改動地方我已經用紅色標出,別的請不要隨意改動。

          一、創(chuàng)建ChangePasswd.ini文件

          創(chuàng)建一個空文件:

          a.將其命名為ChangePasswd.ini并將以下內容復制到此文件中。

          b.注意將以下紅色部分改為你自己的路徑。第一行為所建用戶和密碼文件的路徑。第二行為修改密碼的日志的路徑(該文件是自己建的)。

          [path]
          authuserfile=/etc/httpd/passwd
          logfile=/var/www/cgi-bin/ChangePasswd.log
          [setup]
          pwdminlen=6
          [html]
          title=SVN用戶密碼自助修改
          description=SVN用戶密碼自助修改
          yourname=用戶名
          oldpwd=舊密碼
          newpwd1=新密碼
          newpwd2=確認新密碼
          btn_change=修 改
          btn_reset=重 置

          changepwdok=成功修改密碼
          changepwdfailed=修改密碼失敗
          servererror=服務器錯誤
          passmustgreater=新密碼位數(shù)必須大于
          twopassnotmatched=兩密碼不一致
          entername=請輸入用戶名
          enterpwd=密碼未輸入
          errorpwd=你的密碼不正確
          back=返回

           

          二、創(chuàng)建ChangePasswd.cgi文件并設置其權限。

          創(chuàng)建一個空文件,將以下內容復制到創(chuàng)建的文件里并更名為ChangePasswd.cgi,設置其權限為755(可執(zhí)行)

          命令:chmod 755 ChangePasswd.cgi.

          #!/usr/bin/perl -w

          use strict;
          use CGI;
          my $time        = localtime;
          my $remote_id   = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
          my $admin_email = $ENV{SERVER_ADMIN};

          my $cgi = new CGI;
          my $pwd_not_alldiginal = "密碼不能全為數(shù)字";
          my $pwd_not_allchar = "密碼不能全為字符";
          my $user_not_exists ="該用戶不存在";
          my $file_not_found ="文件不存在,請聯(lián)系管理員";

          my $authuserfile;
          my $logfile;
          my $pwdminlen;
          my $title;
          my $description;
          my $yourname;
          my $oldpwd;
          my $newpwd1;
          my $newpwd2;
          my $btn_change;
          my $btn_reset;

          my $changepwdok;
          my $changepwdfailed;
          my $oldpwderror;
          my $passmustgreater;
          my $twopassnotmatched;
          my $entername;
          my $enterpwd;
          my $errorpwd;
          my $back;

          &IniInfo;

          if ($cgi -> param())
          {#8
          my $User = $cgi->param('UserName');
          my $UserPwd = $cgi->param('OldPwd');
          my $UserNewPwd = $cgi->param('NewPwd1');
          my $MatchNewPwd = $cgi->param('NewPwd2');

          if (!$User)
               {&Writer_Log("Enter no user name");
                 &otherhtml($title,$entername,$back);}
          elsif (!$UserPwd )
              {&Writer_Log("Enter no OldPasswd");
               &otherhtml($title,$enterpwd,$back); }
          elsif (length($UserNewPwd)<$pwdminlen)
              {&Writer_Log("Password's length must greater than".$pwdminlen);
               &otherhtml($title,$passmustgreater.$pwdminlen,$back);}
          elsif ($UserNewPwd =~/^\d+$/)
              {&Writer_Log("New Passwd isn't all diginal");
               &otherhtml($title,$pwd_not_alldiginal,$back);}
          elsif ($UserNewPwd =~/^[A-Za-z]+$/)
              {&Writer_Log("New Passwd isn't all char");
               &otherhtml($title,$pwd_not_allchar,$back);}
          elsif ($UserNewPwd ne $MatchNewPwd)
              {&Writer_Log("Two new passwords are not matched");
               &otherhtml($title,$twopassnotmatched,$back);}
          else
          {if($authuserfile)
          {#6
          open UserFile, "<$authuserfile" or die "打開文件失敗:$!";
          while (<UserFile>)
              {#5
                 my $varstr=$_;

                 if($varstr =~/($User)/)
              {#3
               my $eqpos =index($varstr, ":");
               my $UserName = substr($varstr,0,$eqpos);
               my $cryptpwd = substr($varstr,$eqpos + 1,13);
             
               next if($UserName ne $User);
                 
               if(crypt($UserPwd,$cryptpwd) eq $cryptpwd)
               {#a
                my $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");
                if ($rc == 0)
                   {#1
                      &Writer_Log( $User.":Change Passwd");
                      &otherhtml($title,$changepwdok,$back);
                    }#1
                 else
                    {#2
                     &Writer_Log( $User.":Change Passwd Failed");
                     &otherhtml($title,$changepwdfailed,$back);
                    }#2
                 exit;
               }#a
               else
               {#b
                &Writer_Log("Old Passwd is Incorrect ");
                &otherhtml($title,$errorpwd,$back);
               }#b
               exit;      
              }#3
                 else
              {#4
               if(eof)
               { &Writer_Log($User.":no this user");
                 &otherhtml($title,$user_not_exists,$back);
                 exit;
               }
               else
               {next;}
              }#4  
               }#5
             close UserFile;
          }#6
          else
          {#7
             &Writer_Log($authuserfile.":no found");
             &otherhtml($title,$file_not_found,$back);
          }#7
          }
          }#8
          else
          {&Index_Html;}

          sub IniInfo{
          my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";
          open CGI_INI_FILE, "<$inifile" or die "打開文件失敗:$!";;
          while (<CGI_INI_FILE>)
          {
          my $eqpos =index($_,'=');
          my $len = length($_);

          if ($_ =~/authuserfile/)
          {$authuserfile= substr($_, $eqpos + 1, $len - $eqpos -2);}
          elsif ($_ =~/logfile/)
          {$logfile= substr($_, $eqpos + 1);}
          elsif ($_ =~/pwdminlen/)
          {$pwdminlen= substr($_, $eqpos + 1);}
          elsif ($_ =~/title/)
          {$title = substr($_, $eqpos + 1);}
          elsif ($_ =~/description/)
          {$description = substr($_, $eqpos + 1);}
          elsif ($_ =~/yourname/)
          {$yourname = substr($_, $eqpos + 1);}
          elsif ($_ =~/oldpwd/)
          {$oldpwd= substr($_, $eqpos + 1);}
          elsif ($_ =~/newpwd1/)
          {$newpwd1= substr($_, $eqpos + 1);}
          elsif ($_ =~/newpwd2/)
          {$newpwd2= substr($_, $eqpos + 1);}
          elsif ($_ =~/btn_change/)
          {$btn_change = substr($_, $eqpos + 1);}
          elsif ($_ =~/btn_reset/)
          {$btn_reset = substr($_, $eqpos + 1);}
          elsif ($_ =~/changepwdok/)
          {$changepwdok = substr($_, $eqpos + 1);}
          elsif ($_ =~/changepwdfailed/)
          {$changepwdfailed = substr($_, $eqpos + 1);}
          elsif ($_ =~/oldpwderror/)
          {$oldpwderror = substr($_, $eqpos + 1);}
          elsif ($_ =~/passmustgreater/)
          {$passmustgreater = substr($_, $eqpos + 1);}
          elsif ($_ =~/twopassnotmatched/)
          {$twopassnotmatched = substr($_, $eqpos + 1);}
          elsif ($_ =~/entername/)
          {$entername = substr($_, $eqpos + 1);}
          elsif ($_ =~/enterpwd/)
          {$enterpwd= substr($_, $eqpos + 1);}
          elsif ($_ =~/errorpwd/)
          {$errorpwd= substr($_, $eqpos + 1);}
          elsif ($_ =~/back/)
          {$back = substr($_, $eqpos + 1);}
          }
          close CGI_INI_FILE;
          }

          sub Index_Html
          {
          print "Content-type: text/html\n\n";
          print <<END_OF_PAGE;
          <html >
          <head>
          <title>$title</title>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
          </head>
          <body>

          <HR>

          <center><h1>$description</h1>
          </center>
          <form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">
          <br>
          <TABLE align="center">
          <TR><TD class="t_text">$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>
          <TR><TD class="t_text">$oldpwd</TD><TD><input type="password" name="OldPwd" /></TD></TR>
          <TR><TD class="t_text">$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>
          <TR><TD class="t_text">$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>
          </TABLE>
          <br>
          <TABLE align="center">
          <TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>
          </TABLE>
          </form>
          <HR>
          <font color="#FF0000">注意:新密碼位數(shù)必需大于$pwdminlen,且為字母與數(shù)字組合</font>

          </body>
          </html>
          END_OF_PAGE
          }

          sub otherhtml{
          print "Content-type: text/html\n\n";

          print <<END_OF_PAGE;
          <html>
          <head>
          <meta http-equiv="Content-Language" content="zh-cn">
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>$_[0]</title>
          </head>

          <body>
          <p align="center"><font size="5">$_[1]</font></p>
          <p align="center"><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[2]</font></a></p>

          <HR>
          </body>

          </html>
          END_OF_PAGE
          }

          sub Writer_Log{
          if($logfile)
          {
          my $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[0];
          open LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";
          print LOGFILE ("$loginfo\n");
          close LOGFILE;
          }
          }

          三、創(chuàng)建ChangePasswd.log文件并設置其權限。

           

          進入目標位置(即你想創(chuàng)建ChangePasswd.log的位置),如: /var/www/cgi-bin(根據自己的位置定),創(chuàng)建一個名為ChangePasswd.log的文件并賦予該文件寫的權限:

          命令:chmod 666 ChangePasswd.log

          四、修改密碼

          通過http://ip:80/cgi-bin/ChangePasswd.cgi修改密碼。

           

          80對應自己設置的端口。


          原文:http://www.svnclub.com/index.php?q=node/44


          Feedback

          # re: linux下如何實現(xiàn)的客戶端修改svn密碼--待繼續(xù)研究  回復  更多評論   

          2013-01-24 08:15 by 李群霖
          為啥我用你的方法還是不行啊???
          總是報錯:The server encountered an internal error or misconfiguration and was unable to complete your request.

          主站蜘蛛池模板: 徐闻县| 湟源县| 大丰市| 油尖旺区| 澄城县| 涪陵区| 称多县| 兰考县| 沙坪坝区| 新乐市| 九江县| 聊城市| 银川市| 格尔木市| 靖远县| 新民市| 壶关县| 望都县| 宝清县| SHOW| 彰化县| 泾川县| 荣昌县| 长丰县| 乌什县| 博罗县| 中阳县| 新丰县| 龙泉市| 昌宁县| 成安县| 五指山市| 方山县| 肥城市| 丽江市| 吴堡县| 翁牛特旗| 武夷山市| 河南省| 江门市| 大渡口区|