前陣兒公司內部配置好了subverion來做版代碼管理,為了便於個人修改密碼,所以網上找了很多關於自助修改密碼的資料,結果發現很多都是針對windows版的,即使有針對linux版的,但還是有一些問題,不能直接拿來用,說明文字也比少。
下面是我自己用的配置文件,99%來源於網絡,只有很少一點點是我根據自己的實際情況修改的。希望對大家有用。
需要倆個文件:
svnpass.ini
svnpass.cgi
svnpass.ini中的內容如下:
[path]
authuserfile=/opt/svn/svnuser
logfile=/opt/svn/changepwd.log
[setup]
pwdminlen=2
[html]
title=SVN用戶密碼自助修改
description=SVN用戶密碼自助修改
yourname=用戶名
oldpwd=舊密碼
newpwd1=新密碼
newpwd2=確認新密碼
btn_change=修 改
btn_reset=重 置
changepwdok=成功修改密碼
changepwdfailed=修改密碼失敗
servererror=服務器錯誤
passmustgreater=新密碼位數必須大於
twopassnotmatched=兩密碼不一致
entername=請輸入用戶名
enterpwd=密碼未輸入
errorpwd=你的密碼不正確
back=返回
說明:
關鍵是紅顏色是三行內容:
authuserfile=/opt/svn/svnuser :subversion用戶與密碼文件存放位置
logfile=/opt/svn/changepwd.log :修改密碼的日志文件存放位置
pwdminlen=2 :密碼的最小長度
以上三項,根據實際情況修改即可。
其他內容保持不變即可。
svnpass.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 = "密碼不能全為數字";
my $pwd_not_allchar = "密碼不能全為字符";
my $user_not_exists ="該用戶不存在";
my $file_not_found ="文件不存在,請聯系管理員";
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("htpasswd -b $authuserfile $User $UserNewPwd");