在Linux上实现SVN用户密码自助修改
1.首先本文是在一篇百度经验的基础上修改而成,将网址记录上,以示尊重。
https://jingyan.baidu.com/article/48b37f8dd4bbb31a646488c2.html
2.设计思想
SVN的用户密码都保存在一个密码文件中,SVN管理员通过调用htpasswd命令来实现用户密码的新增,修改。
自助用户修改的设计思想就是把这个密码文件修改方法公共给用户们使用; 具体的说,就是一个CGI网页来封装htpasswd修改用户命令,用户在网页上输入新用户密码后,CGI调用htpasswd命令来修改用户。
至于为什么要用CGI,哈哈,因为简单啊,Perl在Linux上原生就有,不用安装。
如果你熟PHP,那你就用PHP来封装,如果你熟JAVA那你就JAVA封装,原理都一样
最关键的那个命令:
/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd
$authuserfile 密码文件所在路径,必须是绝对路径
$User 用户名
$UserNewPwd 用户新密码
2.安装Perl的CGI库
yum install perl-CGI
3.创建Cig配置文件
cd /var/www/cgi-bin
vi ChangePasswd.ini
[path]
authuserfile=/data/svn/conf/http_passwd
logfile=/var/www/cgi-bin/ChangePasswd.log
[setup]
pwdminlen=6
[html]
title=SVN Password Modification
description=SVN Password Modification
yourname=User Name
oldpwd=Old Password
newpwd1=New Password
newpwd2=Confirm New Password
btn_change=Modification
btn_reset=Reset changepwdok=Password reset complete
changepwdfailed=Password modification failed
servererror=Server error, please contact the administrator
passmustgreater=The new password digit must be greater than 6 digits
twopassnotmatched=Two password entries must be the same
entername=Please enter your username
enterpwd=Please enter your password
errorpwd=Your password is incorrect
back=Back
4.创建CGI文件
注:我隐去了原有密码校验
cd /var/www/cgi-bin
vi 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 = "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())
{#
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);}
else
{if($authuserfile)
{#
open UserFile, "<$authuserfile" or die "open file failed.$!";
while (<UserFile>)
{#
my $varstr=$_;
if($varstr =~/($User)/)
{#
my $eqpos =index($varstr, ":");
my $UserName = substr($varstr,,$eqpos);
my $cryptpwd = substr($varstr,$eqpos + ,);
next if($UserName ne $User);
#if(crypt($UserPwd,$cryptpwd) eq $cryptpwd)
if()
{#a
my $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");
if ($rc == )
{#
&Writer_Log( $User.".Change Passwd");
&otherhtml($title,$changepwdok,$back);
}#
else
{#
&Writer_Log( $User.".Change Passwd Failed");
&otherhtml($title,$changepwdfailed,$back);
}#
exit;
}#a
else
{#b
&Writer_Log("Old Passwd is Incorrect ");
&otherhtml($title,$errorpwd,$back);
}#b
exit;
}#
else
{#
if(eof)
{ &Writer_Log($User.".no this user");
&otherhtml($title,$user_not_exists,$back);
exit;
}
else
{next;}
}#4
}#
close UserFile;
}#
else
{#
&Writer_Log($authuserfile.".no found");
&otherhtml($title,$file_not_found,$back);
}#
}
}#
else
{&Index_Html;}
sub IniInfo{
my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";
open CGI_INI_FILE, "<$inifile" or die "open file failed.$!";;
while (<CGI_INI_FILE>)
{
my $eqpos =index($_,'=');
my $len = length($_);
if ($_ =~/authuserfile/)
{$authuserfile= substr($_, $eqpos + , $len - $eqpos -);}
elsif ($_ =~/logfile/)
{$logfile= substr($_, $eqpos + );}
elsif ($_ =~/pwdminlen/)
{$pwdminlen= substr($_, $eqpos + );}
elsif ($_ =~/title/)
{$title = substr($_, $eqpos + );}
elsif ($_ =~/description/)
{$description = substr($_, $eqpos + );}
elsif ($_ =~/yourname/)
{$yourname = substr($_, $eqpos + );}
#elsif ($_ =~/oldpwd/)
#{$oldpwd= substr($_, $eqpos + 1);}
elsif ($_ =~/newpwd1/)
{$newpwd1= substr($_, $eqpos + );}
elsif ($_ =~/newpwd2/)
{$newpwd2= substr($_, $eqpos + );}
elsif ($_ =~/btn_change/)
{$btn_change = substr($_, $eqpos + );}
elsif ($_ =~/btn_reset/)
{$btn_reset = substr($_, $eqpos + );}
elsif ($_ =~/changepwdok/)
{$changepwdok = substr($_, $eqpos + );}
elsif ($_ =~/changepwdfailed/)
{$changepwdfailed = substr($_, $eqpos + );}
elsif ($_ =~/oldpwderror/)
{$oldpwderror = substr($_, $eqpos + );}
elsif ($_ =~/passmustgreater/)
{$passmustgreater = substr($_, $eqpos + );}
elsif ($_ =~/twopassnotmatched/)
{$twopassnotmatched = substr($_, $eqpos + );}
elsif ($_ =~/entername/)
{$entername = substr($_, $eqpos + );}
elsif ($_ =~/enterpwd/)
{$enterpwd= substr($_, $eqpos + );}
elsif ($_ =~/errorpwd/)
{$errorpwd= substr($_, $eqpos + );}
elsif ($_ =~/back/)
{$back = substr($_, $eqpos + );}
}
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=utf-8" />
</head>
<body>
<HR>
<center><h1>$description</h1>
</center>
<form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">
<br>
<TABLE>
<TR><TD>$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>
<TR><TD>$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>
<TR><TD>$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>
</TABLE>
<br>
<TABLE>
<TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>
</TABLE>
</form>
<HR>
<font color="#FF0000; charset=utf-8">WARNING:YOUR NEWPASSWD MUST MORE THAN $pwdminlen CHARACTERS.</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=utf-8">
<title>$_[]</title>
</head>
<body>
<p><font size="5">$_[]</font></p>
<p><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[]</font></a></p>
<HR>
</body>
</html>
END_OF_PAGE
}
sub Writer_Log{
if($logfile)
{
my $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[];
open LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";
print LOGFILE ("$loginfo\n");
close LOGFILE;
}
}
5.设置文件权限和建立日志文件
cd /var/www/cgi-bin
touch ChangePasswd.log
chmod 755 ChangePasswd.cgi
chmod 666 ChangePasswd.log
6.重启Httpd服务
service httpd restart
7.验证功能
http://<SVN服务器IP>/cgi-bin/ChangePasswd.cgi
8.问题解决
服务器防火墙要关闭
服务器SeLinux服务要关闭
enjoy :)
在Linux上实现SVN用户密码自助修改的更多相关文章
- Linux系统下超级用户密码的修改
1)重启系统:在虚拟机刚启动界面,不停地按上下键,停止系统的自动引导(界面底部有提示) 2) 按 e 进入编辑模式 3) 编辑内容如下:完成后按Ctrl+x (具体编辑内容为下图:删除倒数第三行 ...
- 通过web修改svn用户密码
使用方法: 将文件changePasswd.cgi和changePasswd.ini 放到apche安装目录下的cgi-bin下(cgi-bin的目录可以通过/etc/httpd/conf/httpd ...
- Linux上部署SVN
Linux上部署SVN author:headsen chen 2017-10-16 16:45:04 前提:通过yum来安装,必须是centos6.5的桌面版的.否则会出现某些的安装包不全而导致 ...
- 很实用的linux 上的svn安装和svnserver 的重启
虽然在windows上搭建SVN很简单,但是效能却不高,这当然是和linux相比了.然而在linux上搭建SVN却非常繁琐,所以今天这篇文章就来一步一步教您如何在Centos上搭建SVN 安装 #yu ...
- (转载)如何借助KeePassX在Linux上管理多个密码
转自:http://netsecurity.51cto.com/art/201311/417764.htm 如今,基于密码的身份验证在网上非常普遍,结果你恐怕数不清自己到底在使用多少个密码.实际上,据 ...
- Linux系统重置root用户密码
Linux系统重置root用户密码 作者:Eric 微信:loveoracle11g 查看系统版本是不是RHEL7 [root@zhouwanchun ~]# cat /etc/redhat-rele ...
- CentOS Linux搭建独立SVN Server全套流程(修改svn仓库地址、服务启动等)
CentOS Linux搭建独立SVN Server全套流程(修改svn仓库地址.服务启动等) 原 一事能狂便少年 发布于 2016/12/27 11:16 字数 1113 阅读 1.3K 收藏 0 ...
- Linux上搭建SVN服务
环境:centos7 一.搭建svn服务 1. 安装svn yum -y install subversion 2. 创建一个目录作为svn服务的地址(svn://192.168.0.2:3690 访 ...
- 在Linux上安装SVN服务
1.安装SVNyum install subversion 2.查看版本svnserve --version3.创建目录mkdir -p /web/svndata3.创建repo测试库svnadmin ...
随机推荐
- HDU - 2604 Queuing(递推式+矩阵快速幂)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 详述MSSQL服务在渗透测试中的利用(上篇)
前言: 致力于复现最实用的漏洞利用过程. 本文将带领大家学习以下内容: 学习使用`xp_cmdshell`扩展存储过程 学习调用`wscript.shell` 学习MSSQL写文件 学习沙盘模式提权 ...
- mongoose 基础api 图表整理
一.背景 今天看 mongoose 的基础 API,参考了下面的链接做了图表以供查阅. 参考资料: http://www.cnblogs.com/xiaohuochai/p/7215067.html ...
- odoo 开发基础 -- postgresql重新启动、状态查看
场景描述: 当遇到数据库不能正常访问的时候,我们首先想到的是,查看相关的告警日志,一般先查看系统的日志,然后查看数据库的日志,Linux平台下,postgresql的日志文件存放目录在如下路径: te ...
- 【原创】关于程序卸载的一个Bug
今天解决了一个问题,程序安装目录下的某个文件不能被卸载,干净环境下不能重现,某些计算机可以重现. 解决: 这个问题里有两个文件不能被卸载 1.由程序生成的文件,如日志,即不是通过安装包安装的文件在卸载 ...
- (转)学会数据库读写分离、分表分库——用Mycat,这一篇就够了!
原文:https://www.cnblogs.com/joylee/p/7513038.html 系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理 ...
- Java内存模型(JSR133)问与答
What is a memory model, anyway? In multiprocessor systems, processors generally have one or more lay ...
- Android开发艺术探索学习笔记(四)
第四章 View的工作原理 4.1初识ViewRoot和DecorView ViewRoot是连接WindowManager和DecorView的纽带,View的三大流程均是通过ViewRoot来完成 ...
- 执行bin/hdfs haadmin -transitionToActive nn1时出现,Automatic failover is enabled for NameNode at bigdata-pro02.kfk.com/192.168.80.152:8020 Refusing to manually manage HA state的解决办法(图文详解)
不多说,直接上干货! 首先, 那么,你也许,第一感觉,是想到的是 全网最详细的Hadoop HA集群启动后,两个namenode都是standby的解决办法(图文详解) 这里,nn1,不多赘述了.很简 ...
- logstash-2-插件配置
配置语法: Logstash必须有一个 input 和一个 output 1, 处理输入的input 1), 从文件录入 logstash使用一个名为 filewatch的 ruby gem库来监听 ...