多语言展示
当前在线:832今日阅读:167今日分享:16

SVN自助修改密码ChangePasswd重新整理

对于未做ldap集成的SVN,我们会遇到一个问题,配置SVN的密码时,配的简单吧安全性太低,配的复杂吧,用的人还不一定自己记得住,而且你还要为每个人去想个密码,最好就是给个初始的,然后让使用者自己去修改。网上找了几篇资料,照着试了一遍,不能用起来,花了一点时间排除了一些问题,重新整理一份可用的配置手册。
工具/原料

LINUX服务器一台

SVN安装并集成httpd
1

使用yum安装方式,完成svn以及http的安装(当然你也可以自己下载包编译安装,这里yum安装比较方便)yum -y install mod_dav_svnyum -y install httpd

2

建一个目录,作为svn的存储目录#cd /#mkdir test#cd test#svnadmin create svn对svn目录进行授权(不授权的话在访问版本库创建目录时可能会报错)#chmod 777 -R svn确保防火墙已经关闭,或者将以下端口全部打开/sbin/iptables -I INPUT -p tcp --dport 3690 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 389 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 636 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 873 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 8443 -j ACCEPT打开 /test/svn/conf下的authz文件,添加一个测试账号,比如:[/]ywyuan=rw* =

3

清空passwd的文件内容(清空,直接是空白)然后#cd /test/svn/conf,执行#htpasswd -c /test/svn/conf/passwd ywyuan接着输入两次密码完成配置这里如果要再加一个账号的话执行的是htpasswd -m而不是-c,否则会将原来的覆盖掉

自助密码修改的配置
1

进入/var/www/cgi-bin目录创建一个空文件,命名为ChangePasswd.ini,并粘贴以下内容:[path]authuserfile=/test/svn/conf/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=新密码位数必须大于twopassnotmatched=两次密码输入必须相同entername=请输入你的用户名enterpwd=请输入你的密码errorpwd=你的密码不正确back=返 回

2

创建一个空文件,将命名为ChangePasswd.cgi,粘贴以下内容,并授权为755命令:chmod 755 ChangePasswd.cgi #!/usr/bin/perl -wuse 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 = "PASSWD CAN'T BE ALL NUMBERS";my $pwd_not_allchar = "PASSWD CAN'T BE ALL LETTERS";my $user_not_exists ="USER DOES NOT EXIST";my $file_not_found ="FILE DOES NOT EXIST,PLEASE CONTACT THE MANAGER"; 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()){#8my $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){#6open UserFile, "<$authuserfile" or die "open file failed:$!";while ()    {#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;}#6else{#7   &Writer_Log($authuserfile.":no found");   &otherhtml($title,$file_not_found,$back);}#7}}#8else{&Index_Html;} sub IniInfo{my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";open CGI_INI_FILE, "<$inifile" or die "open file failed:$!";;while (){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 <$title 


 

$description


$yourname
$oldpwd
$newpwd1
$newpwd2


WARNING:YOUR NEWPASSWD MUST MORE THAN $pwdminlen CHARACTERS,ADN BOTH CONTAIN NUMBERS AND LETTERS END_OF_PAGE} sub otherhtml{print "Content-type: text/html\n\n"; print <$_[0] 

$_[1]

$_[2]

 
 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;}}

3

创建ChangePasswd.log,并赋予写的权限chmod 666 ChangePasswd.log

关闭selinux
1

#setenforce 0注意这一步很关键,否则当你点击修改时,直接会报图中错误,网上搜到有人提了这个问题,都没答案,最后关闭了selinux后可以了

2

service httpd restart打开浏览器,访问http://IP/cgi-bin/ChangePasswd.cgi尝试修改测试的账号密码

推荐信息