SCMLife.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 492|回复: 2

[求助] linux下使用CGI脚本更改svn密码报错

[复制链接]
发表于 2017-12-1 16:38:19 | 显示全部楼层 |阅读模式
大家好,centos7 下我按网上的脚本ChangePasswd.cgi  ChangePasswd.ini  ChangePasswd.log 创建了这三个文件,但是修改密码时,报原始密码错误,明明没有输入错误的。: U/ ?$ p4 a' ?# n8 j
[root@localhost cgi-bin]# ll ChangePasswd.cgi
7 s! ~7 F# Z$ M' p! r- A. |. k-rwxrwxrwx 1 apache apache 5957 Nov 30 17:25 ChangePasswd.cgi
0 {. a! D" A- W: {' H7 K+ ?+ Y2 z[root@localhost cgi-bin]# ll ChangePasswd.ini % I0 B7 X% o  L1 n4 b0 r" b
-rwxrwxrwx 1 apache apache 566 Dec  1 15:03 ChangePasswd.ini2 u. ^/ m) D% C  B

% b1 D0 T$ J' C1 I6 t8 n8 \: t3 Z0 D' Q. y
权限都有的,查看apache的logs也不报错,只页面提示说原始密码错误 ,不知道问题出在哪里了。请求,大家 给看看呀。。
发表于 2017-12-4 10:03:41 | 显示全部楼层
提供的信息太少,没办法回答啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-5 10:56:07 | 显示全部楼层
ChangePasswd.cgi 文件内容:
( L7 @$ l$ v8 z. v9 V2 x* ?#!/usr/bin/perl -w" `3 f! G& s8 q; Q
use strict;
$ W' ~  I# C1 H! q4 xuse CGI;& ~1 X3 T! r+ ?) Z1 C6 I1 R$ O
my $time = localtime;" }8 ^3 D( S8 m5 O3 }  o7 f
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};$ R& J$ o/ r) A7 s$ y5 |
my $admin_email = $ENV{SERVER_ADMIN};
. M- N+ f( s5 p. a( n# nmy $cgi = new CGI;
2 B- E% k4 p8 D, Z- ^my $pwd_not_alldiginal = "密码不能全为数字";
: o" |& V( @' k8 Pmy $pwd_not_allchar = "密码不能全为字符";1 J8 _. B& I9 C/ w
my $user_not_exists ="该用户不存在";  @6 s( F" L. g. L/ C, O
my $file_not_found ="文件不存在,请联系管理员";
; P6 ], R8 W# X/ ]$ Pmy $authuserfile;
6 T& k3 h2 n# fmy $logfile;
0 s: y7 {! B# Q9 Q, @, Y; Rmy $pwdminlen;" S- S, Y4 T5 F/ G
my $title;
  F# }2 G0 r( |, Lmy $description;
4 g- y$ R+ n) D6 f6 |& ^. ]1 Ymy $yourname;# o* K  A4 Y: E
my $oldpwd;
0 P, E( R: j) e+ n# b3 ?my $newpwd1;
/ p! N$ z9 i5 \) Z/ Jmy $newpwd2;3 o' R. K! k/ s( m% \3 Z1 m# F( g
my $btn_change;6 R$ X8 l8 e6 |6 A$ `5 e
my $btn_reset;: m: _& Q( Q8 M- @3 u
my $changepwdok;
$ H6 l& I$ z+ _7 ^8 jmy $changepwdfailed;
& x, k7 b* f- i- H1 H; C4 P! Wmy $oldpwderror;, G8 l3 {) E5 X* [6 s0 j% h
my $passmustgreater;
, m- z0 i$ ?6 Z! S" pmy $twopassnotmatched;0 U7 g' C' B7 Q" `
my $entername;
: O8 D* G; i/ m  P! Hmy $enterpwd;
+ s" X% H8 x$ K6 A$ Amy $errorpwd;2 y: w* g3 ?* K( a' i
my $back;2 H7 a. J; q2 D2 ]; l4 g- B  e) |

" V- Y4 q: O; K& y2 R* J&IniInfo;
3 E& O( F! t3 e- T7 ~0 _+ Lif ($cgi -> param())
4 M; ]8 B' v* T! K; G7 T{#8
6 g  p0 u- t) I% B; T: _8 Qmy $User = $cgi->param('UserName');
; z7 V: k) Y( f' Emy $UserPwd = $cgi->param('OldPwd');
4 U0 W) F- ~* V) \  dmy $UserNewPwd = $cgi->param('NewPwd1');
; {. P; }9 N# Y1 W7 S$ I" y0 v  vmy $MatchNewPwd = $cgi->param('NewPwd2');
- K) w8 s3 _. v* P/ T* S6 _ ; H2 Z. r) O5 S
if (!$User)& }+ q) L2 H2 k% b% E: t: T% z
{&Writer_Log("Enter no user name");+ a9 E; s/ k+ f
&otherhtml($title,$entername,$back);}) K6 o" ]$ B; I
elsif (!$UserPwd )
3 Y1 ~9 J3 c7 v. d% T6 H{&Writer_Log("Enter no OldPasswd");" ~9 o) L9 ~& D; l9 M
&otherhtml($title,$enterpwd,$back); }
5 I  n; U: x4 {& H' R" E; Jelsif (length($UserNewPwd)<$pwdminlen): h- c+ e( R" ?) L0 C; T, w7 F
{&Writer_Log("Password's length must greater than".$pwdminlen);
7 I% c& m1 C4 S( G+ _&otherhtml($title,$passmustgreater.$pwdminlen,$back);}' U7 p* o0 o3 {
elsif ($UserNewPwd =~/^\d+$/)  ]2 Y( g7 {9 y, S5 f  p8 V2 u$ P
{&Writer_Log("New Passwd isn't all diginal");* D0 K$ [, A) o+ L  u/ C
&otherhtml($title,$pwd_not_alldiginal,$back);}
5 c, F5 o" M4 D; Delsif ($UserNewPwd =~/^[A-Za-z]+$/)6 m+ f; f* h* |' w
{&Writer_Log("New Passwd isn't all char");
* z+ ?, g' X2 M" n3 c&otherhtml($title,$pwd_not_allchar,$back);}
* ~7 P! s) j- Eelsif ($UserNewPwd ne $MatchNewPwd)
/ \+ T' h3 D. {9 z6 D{&Writer_Log("Two new passwords are not matched");: F. U' `1 ]' J
&otherhtml($title,$twopassnotmatched,$back);}9 h* L% Q( A. _9 X, u4 R
else
5 b) [6 [: q; g% D{if($authuserfile)
* F% U0 K" l% v5 I! _{#6
7 Z0 A  A/ r( g% Lopen UserFile, "<$authuserfile" or die "打开文件失败:$!";  K3 o5 K; a  X( l. b3 I
while (<UserFile>)) w1 V" J2 \/ ?  {5 l& z& [
{#5
& v/ u* K3 m4 a" J+ Omy $varstr=$_;
* {* M. r, o3 j3 b, |! Dif($varstr =~/($User)/)
" ~$ M9 j3 e* b{#3
5 o( a9 i8 C5 q: F" Rmy $eqpos =index($varstr, ":");
7 I1 v  ~% `- Nmy $UserName = substr($varstr,0,$eqpos);
1 z( g+ b3 z4 e& z0 m( f" s) zmy $cryptpwd = substr($varstr,$eqpos + 1,13);& B' u0 U. {, v0 @& w5 Z. h
7 h8 \$ ^! {. Q0 D" d
next if($UserName ne $User);
" p7 s! F' O" A3 U
$ n  a! [3 t# ^" ]1 Uif(crypt($UserPwd,$cryptpwd) eq $cryptpwd): T4 J/ L  w& H2 `1 ~
{#a
3 F# }; m) p8 G* omy $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");' h% E; y0 `# k
if ($rc == 0)& H& i& O3 C) T) R
{#1( D9 `+ n" G# u( @/ v# m
&Writer_Log( $User.":Change Passwd");- F- j, e0 V% F/ z
&otherhtml($title,$changepwdok,$back);
9 O/ a" F5 a% z9 {% s  i) ~}#1
0 e  u2 _+ p$ D. B4 P; g5 O  _else. A" \  X2 f2 W+ }, I* ^
{#2
* p$ Y+ }1 G! X+ i$ P: x9 w&Writer_Log( $User.":Change Passwd Failed");
& W( {6 v  D1 s' u: Y2 ?( y8 {" c&otherhtml($title,$changepwdfailed,$back);8 ]/ h. W& r& @% ~: k
}#2
; `0 ~0 B$ X9 ^" K. P9 n* Y) `exit;
* s. c/ ^2 r' v. @$ O}#a
7 D5 {2 g2 d+ e: M3 E) Eelse. u1 {  y$ }: J- h% K8 R7 i4 g
{#b
3 d7 I3 i$ `2 Y. s&Writer_Log("Old Passwd is Incorrect ");$ A1 L/ Z% W2 V0 b5 K- \
&otherhtml($title,$errorpwd,$back);+ t( Z- k" y" l
}#b- F. e6 Q! O1 k: a& t. y! x
exit;: ^0 }( I/ Z' u
}#3
# t; Y, i3 R, p2 r. j. x9 Yelse4 X* L. ^3 e0 o6 X
{#49 H# U4 m" |4 I& Z) i# Y1 J4 w, E
if(eof)
  q% g, d) y( y5 w, c+ l" _4 ]6 B$ K5 O{ &Writer_Log($User.":no this user");4 g: y6 L! N; }0 }) e; h
&otherhtml($title,$user_not_exists,$back);
. [- x/ G! U/ Q% G8 wexit;
( @* v( ^& z. e, y: w}
# J: u+ d. E4 ^" Felse
) h4 {" j7 {8 X/ x: C: |{next;}
5 q* ~; T1 Z" w2 `; H( B; [$ }}#4! h- E) V0 V3 v% Y0 z$ {
}#5# \; s" e5 c* x' k, u
close UserFile;
, y% z' \6 i6 i# l& |( \  f}#6
1 j- p" Q& J- q: p1 s: telse
0 T5 b0 @  ^) C4 M{#7
& o0 k% Y/ R) U3 q3 J) \* N1 }&Writer_Log($authuserfile.":no found");
- \( y; C& u# r# N# U$ w* _5 f&otherhtml($title,$file_not_found,$back);
9 }2 f7 O5 T* ^9 r, ^' n! D8 [' {}#7! ]% g$ H( J( S; @5 I
}1 B4 X$ \4 f! d" G
}#8
6 H+ G, [( W# O9 h/ L4 Felse
- R6 c  o+ @$ ~" l2 x( O9 `9 W{&Index_Html;}& y" m- R9 Z9 v: h" ?
sub IniInfo{6 a* K* S$ d2 ^" L0 x
my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";
( ~! ^2 s9 x9 y; h$ C4 S. ?% fopen CGI_INI_FILE, "<$inifile" or die "打开文件失败:$!";;
! Q- e; J- p6 fwhile (<CGI_INI_FILE>)
5 v, S: p8 @( j{
# x. l4 e( S$ P8 l9 y/ T  hmy $eqpos =index($_,'=');* {) {2 n$ _3 B
my $len = length($_);+ V: c4 n- H' o( ^; Q' c& W3 f9 {# G
if ($_ =~/authuserfile/). s. L9 e4 ]* n/ c- e3 `
{$authuserfile= substr($_, $eqpos + 1, $len - $eqpos -2);}/ e# b$ `& D; \9 E2 _$ f. F
elsif ($_ =~/logfile/)
" ?* k4 {6 U" j, T. Z4 i4 m* _) t{$logfile= substr($_, $eqpos + 1);}
0 O  |4 c3 t+ h; H: H" Zelsif ($_ =~/pwdminlen/)! q& U$ i1 q  a( M0 \3 `# g
{$pwdminlen= substr($_, $eqpos + 1);}6 m6 _  Z2 f+ c& P6 \" X
elsif ($_ =~/title/)+ n% w& y2 f" g8 ?/ d5 E6 G
{$title = substr($_, $eqpos + 1);}$ z: H: {; p5 `: [* I; X  T5 \5 p
elsif ($_ =~/description/)0 Z* A& p$ }" l) `6 J( S
{$description = substr($_, $eqpos + 1);}
$ Z: U$ K! d. Nelsif ($_ =~/yourname/); E* O: A( b" k7 }
{$yourname = substr($_, $eqpos + 1);}' E: B) k5 i: Z& {% U* l; S
elsif ($_ =~/oldpwd/)
' n4 Z6 q" V3 z0 A4 ^% h, o{$oldpwd= substr($_, $eqpos + 1);}8 m* J" ^2 ^: r) @* B- T' B" N' s
elsif ($_ =~/newpwd1/)
# ^3 }7 E4 M) f& J{$newpwd1= substr($_, $eqpos + 1);}7 e3 w% k- P! G: o5 t2 }
elsif ($_ =~/newpwd2/)
9 Y6 X+ t" u! g/ ]{$newpwd2= substr($_, $eqpos + 1);}* h( I9 c9 e8 \0 j" B
elsif ($_ =~/btn_change/)
' T+ z+ S; {/ c  a' U1 n{$btn_change = substr($_, $eqpos + 1);}4 Q; o8 r; y! N; m# \3 j
elsif ($_ =~/btn_reset/); c. c9 o. ~, _& i" I/ v
{$btn_reset = substr($_, $eqpos + 1);}
  K( B; }3 i; k+ a) t8 W7 yelsif ($_ =~/changepwdok/)
4 N! d) t1 _/ \& n{$changepwdok = substr($_, $eqpos + 1);}
  t2 F- @% W5 S' S( B" b, eelsif ($_ =~/changepwdfailed/)# E/ Z* g, g6 r
{$changepwdfailed = substr($_, $eqpos + 1);}& F+ M" t- o8 c! Z' K/ b- V
elsif ($_ =~/oldpwderror/)- B. a) H- w! O& \5 d/ ~7 w
{$oldpwderror = substr($_, $eqpos + 1);}5 E( w# P. W- U" t" x
elsif ($_ =~/passmustgreater/)5 D9 P4 g9 v3 U' g
{$passmustgreater = substr($_, $eqpos + 1);}$ f3 v. ]- O8 C$ q6 `: i; Z
elsif ($_ =~/twopassnotmatched/)
$ g8 [$ V! `5 ^5 t{$twopassnotmatched = substr($_, $eqpos + 1);}
, K/ h& v' v: _+ O; b% W7 g4 selsif ($_ =~/entername/)
- Z7 t' `7 `1 q0 w2 b{$entername = substr($_, $eqpos + 1);}6 X8 }- q3 \: q0 c* Z! Z; ?/ g  h
elsif ($_ =~/enterpwd/)) S5 ^; m6 X. X% o
{$enterpwd= substr($_, $eqpos + 1);}
4 S" \* v2 A# f. v& b, {elsif ($_ =~/errorpwd/)
8 ^( ?# X% O9 V9 Y0 }# }: I{$errorpwd= substr($_, $eqpos + 1);}
, t$ D; f( D) t4 d" celsif ($_ =~/back/)
* ]1 C; b8 B$ y9 V8 |) @/ F{$back = substr($_, $eqpos + 1);}
* }5 w5 a: u- ~6 v7 t) E7 L}4 r+ q9 B5 L9 y2 ~
close CGI_INI_FILE;
* c; w5 X8 C' Q) z) f: m2 l( z}! F" i% ?2 k  b; I) T  A
sub Index_Html
' a* n4 ~' j) x5 p1 k# P1 }" q" |{
; {5 X- W. T& Z9 o( ?! Q3 Vprint "Content-type: text/html\n\n";& h( U  F  W  ?0 d3 {, o: z0 ]
print <<END_OF_PAGE;! M9 x. E% ]+ Q  R
<html >
5 W& C4 Y# b, V" D) D<head>
6 \# }* K/ G& b# N! A( w<title>$title</title>
5 P/ J  ?+ ^1 k$ X( N<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
( }$ k; {  r5 [</head>; H  I5 c# D) h+ x
<body>6 H! `. W7 w1 |6 h8 c7 J2 `( l+ |
<HR>
* w1 F& ?7 y3 L* S9 V ! k2 M, i$ Y, y
<center><h1>$description</h1>* ~5 \4 K7 l/ f; p8 U2 g, _
</center>
8 e, h( N/ {2 k$ b8 a' ]<form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">6 |& P" y# P. b' S% I
<br>
2 |# V! A$ I3 P; `2 a<TABLE align="center">5 q, x9 `4 V0 y) z
<TR><TD class="t_text">$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>5 C* z3 W" }2 [. f* ~' T
<TR><TD class="t_text">$oldpwd</TD><TD><input type="password" name="OldPwd" /></TD></TR>
( }" a, _9 p/ e. S% K<TR><TD class="t_text">$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>" ^9 A+ c* k$ e5 c
<TR><TD class="t_text">$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>
- F- I% R8 ?% U; u5 w9 Q! `( y</TABLE>
, c  U6 |% y9 P/ u0 x<br>
7 N5 S6 L3 i3 m* E( `1 k; Y<TABLE align="center">
3 ]- ?) ]1 L% s5 M" m( ^<TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>
0 b+ l! r7 c; Z, F</TABLE>/ M2 z6 b1 K7 W3 j7 Z' g* r$ {, a6 x
</form>
% {" \" y2 _5 b<HR>
2 r1 d7 ^6 u$ O0 A& t<center><font color="#FF0000">注意:新密码位数必需大于$pwdminlen,且为字母与数字组合</font>. [6 Y& I& e7 K& }- z2 g
</body>: b( U7 p$ U6 K% y1 G6 f. d8 W$ c
</html>! J# T" T: g7 l, g; n- Y2 O/ S
END_OF_PAGE. E$ q$ j+ s4 o- ]( H0 B
}
! d/ b3 G0 Z" ?5 Wsub otherhtml{
# c% S% I* z2 N  Y  w# j+ M! f9 Lprint "Content-type: text/html\n\n";
* `. c7 N! y8 U8 K' D2 o* Jprint <<END_OF_PAGE;
8 R/ ?" C( Z7 y3 o, W<html>
( B/ }% r- q# \8 F4 ^<head>
& N/ N& o+ [0 j, f' d<meta http-equiv="Content-Language" content="zh-cn">% `$ j* T7 P. }# r- q- i
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">% h; G/ Z' ^# I1 S' A1 T4 k
<title>$_[0]</title>
, A8 p0 d. w* v5 K+ S</head>% j* y% `2 E: O$ X) p$ K" o
<body>
( ]' v0 H9 v* H; ?2 m, T* O- F<p align="center"><font size="5">$_[1]</font></p>
: g9 b. |) {, H0 O<p align="center"><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[2]</font></a></p>
, N' s* @1 z9 m5 W# U<HR>
% U0 a/ C: \0 a' U7 d<center>+ j3 v) Q3 \/ Q3 ?( A* B3 V- [
<P>如有问题请与管理员联系E-Mail: <A HREF="$admin_email.& C8 {) K+ m. H) [! `: f2 v; k: t4 X
mailto:$admin_email">$admin_email</A>.</P></center>7 `0 e$ M( f2 p
: s9 X% R, a2 O9 [2 y# W8 Z
</body>
$ L; |( j5 Y, d# s; S! w- u% m  0 x# C$ L& U3 D- \% V) ^% Y  Z* A
</html>$ m# G4 C+ z/ ^7 A, l2 `; o
END_OF_PAGE
: f5 y; `; @6 i$ Y5 v}5 g! B: p+ s7 g
sub Writer_Log{9 P: x2 X* v3 O$ g  E  A) A
if($logfile)+ O" k4 D5 i& V; B. K
{
% R/ o  |: Y1 }; {, ^my $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[0];
2 C  ?7 C8 ?5 M7 _2 }5 oopen LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";! |$ N& a& v5 q( y7 E& A4 v
print LOGFILE ("$loginfo\n");: o  I' x( q0 z* |
close LOGFILE;
* ~; {3 Z! U9 V. g% I2 s& J}
8 D& v$ e9 d& g3 T. u}
, z- P- ]5 ~# X8 k0 {+ c( k" n3 Z
: K0 W. m/ a( s9 ]) j' }! DChangePasswd.ini:文件内容
6 r+ {1 P3 T% [- `) X5 ~7 u[path]+ X* }4 _  r6 b6 y# ]1 v
authuserfile=/data/svn/passwd
% p) \( ?9 H3 k) Elogfile=/var/www/cgi-bin/ChangePasswd.log  a4 k. R# }( H" b7 Q9 q
[setup]& Y; K7 {& f( D) |
pwdminlen=6$ q6 e0 S! _6 L/ m9 @
[html]
" O7 [) _4 f) c# {1 I2 O. ?: {title=SVN用户密码自助修改' K2 P* X4 [" x3 ^4 l% c$ y
description=SVN用户密码自助修改
% i( ~9 ]# K5 x% u: Gyourname=用户名:
( X) L( C- b4 l) V  B% l% Ioldpwd=旧密码:0 _. |+ _0 P& _6 u% ~
newpwd1=新密码:; ^) x# j4 f! e8 Z) E9 y
newpwd2=确认新密码:
9 m8 N/ w! i( H$ r4 D+ P0 Z' Sbtn_change=修 改6 O& ~  Q, X& d% W6 z( ?6 l
btn_reset=重 置
: J' j" j, R& o0 a( f5 J2 h# uchangepwdok=修改密码成功' d7 @5 C" a. X* T8 A. H
changepwdfailed=修改密码失败
, W  ]6 F6 U& v6 a4 O  o; ~servererror=服务器错误- j% l$ e/ P) `: K( b5 W9 F3 G
passmustgreater=新密码位数必须大于& K$ s- C8 o' r: G
twopassnotmatched=两密码不一致5 n0 d* q/ t- X& P* e6 O$ b+ f
entername=请输入用户名
' F4 `% Y0 J; |6 d% H8 ienterpwd=密码未输入
  p9 r3 ~. h) ]errorpwd=你的密码不正确
7 ]6 Z: g  F; v  l# Y4 Jback=返回
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|无图版|SCMLife.com ( 京ICP备06056490号-1 )

GMT+8, 2018-1-18 09:07 , Processed in 0.062961 second(s), 6 queries , Gzip On, MemCache On.

Powered by SCMLife X3.4 Licensed

© 2001-2017 JoyShare.

快速回复 返回顶部 返回列表