SCMLife.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2619|回复: 2

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

[复制链接]
发表于 2017-12-1 16:38:19 | 显示全部楼层 |阅读模式
大家好,centos7 下我按网上的脚本ChangePasswd.cgi  ChangePasswd.ini  ChangePasswd.log 创建了这三个文件,但是修改密码时,报原始密码错误,明明没有输入错误的。
" e5 C+ o# K: c[root@localhost cgi-bin]# ll ChangePasswd.cgi
' d6 D* U+ w4 g6 ?: n+ U/ X( ?-rwxrwxrwx 1 apache apache 5957 Nov 30 17:25 ChangePasswd.cgi" i- h, K. q: b) K2 C4 w
[root@localhost cgi-bin]# ll ChangePasswd.ini , }  L2 i5 \* s0 Q' G6 w( L- f
-rwxrwxrwx 1 apache apache 566 Dec  1 15:03 ChangePasswd.ini: l% ^) O7 l9 E# Z. s4 ~
0 F- E" f" Y* x9 u- o
9 }4 J& h6 J; r- K1 ]: b
权限都有的,查看apache的logs也不报错,只页面提示说原始密码错误 ,不知道问题出在哪里了。请求,大家 给看看呀。。
发表于 2017-12-4 10:03:41 | 显示全部楼层
提供的信息太少,没办法回答啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-5 10:56:07 | 显示全部楼层
ChangePasswd.cgi 文件内容:
, w- ]7 a( b& x* F0 d#!/usr/bin/perl -w+ z% n) L/ O  s4 E* f
use strict;
& v' Q& \8 O& ^" x# j- y" h' fuse CGI;
7 H# n# O; L3 N4 ~my $time = localtime;% l/ J. g+ f! F" i( }7 \" t- _" p
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
" b+ l9 E4 r: o+ f" Rmy $admin_email = $ENV{SERVER_ADMIN};
! x" m$ C0 f5 R2 \my $cgi = new CGI;
6 l5 v! u" x& ]% }  Ymy $pwd_not_alldiginal = "密码不能全为数字";
' v5 v! i2 _& f# T: Omy $pwd_not_allchar = "密码不能全为字符";+ a# @, V$ V, k0 o# P, g" Y' e8 x
my $user_not_exists ="该用户不存在";2 o; T( h/ ?. |2 u" }1 C5 |$ R# D
my $file_not_found ="文件不存在,请联系管理员";
+ p; H; c% _3 w# Smy $authuserfile;4 L3 H1 S* g' @4 D6 v
my $logfile;8 s+ y6 A4 F0 P/ ^6 ~% M; P
my $pwdminlen;, j: `( V% Q( k0 [5 @7 S
my $title;9 U+ h3 e, ^0 C2 L: H6 k  D
my $description;
  u2 f5 u/ X  U! v9 v- V! tmy $yourname;
5 Q- S) Z% a" v* }6 Kmy $oldpwd;
! _2 ~6 ]: B5 Qmy $newpwd1;
8 L9 O5 U# G( }* d; J$ emy $newpwd2;
4 M9 l& n2 w* o/ ~  B  |my $btn_change;
; O  e, Z% l  _: `; o( omy $btn_reset;2 F' m) [7 O  a! u; R9 Y
my $changepwdok;
8 I: W* C' h; V" g5 A1 i* C& wmy $changepwdfailed;% c! W8 B- c  q1 ]
my $oldpwderror;9 i1 C! g  F7 x: a: R
my $passmustgreater;$ V. A; Q; A5 @% s
my $twopassnotmatched;
; X1 l4 m! N7 S0 s! B* I+ I5 b1 N9 Rmy $entername;2 F+ r2 T+ c6 f5 }7 L
my $enterpwd;3 i; h/ L' t& n! \
my $errorpwd;
; X) a1 r9 r( I4 X  I' H2 i7 X6 m1 [my $back;
; s! j# a+ T& Y' I" r
& x: d/ b% A" ]  T) K&IniInfo;
5 ]( x5 Z" w: I) D8 [* Aif ($cgi -> param())7 u( i7 b, g3 v0 k/ m* F
{#8
7 J% }9 O" S7 V1 s! |my $User = $cgi->param('UserName');
$ C1 ]! H$ U. n1 amy $UserPwd = $cgi->param('OldPwd');- H. S  k0 {# W* h* w9 a0 f* F" f0 g8 L
my $UserNewPwd = $cgi->param('NewPwd1');
3 p3 X! F8 s: w$ N+ Cmy $MatchNewPwd = $cgi->param('NewPwd2');+ O, v. m) r5 Y

/ a! Z6 b$ o0 ^8 Qif (!$User)  b9 o+ A' o6 f* J
{&Writer_Log("Enter no user name");
" z* z$ m4 u/ A6 i" d: M- i+ J: r9 }&otherhtml($title,$entername,$back);}
' ~  `1 L. P4 {elsif (!$UserPwd )
# }! F9 c( i& u{&Writer_Log("Enter no OldPasswd");2 K5 O* S9 }# a9 y
&otherhtml($title,$enterpwd,$back); }
& b, b4 L( v2 s3 q4 Eelsif (length($UserNewPwd)<$pwdminlen), S$ A& g9 T7 v6 t: u7 o* y' P- W7 w
{&Writer_Log("Password's length must greater than".$pwdminlen);
* f  g$ u) I9 G&otherhtml($title,$passmustgreater.$pwdminlen,$back);}
2 N' B, q* w& h0 @! x2 W1 O8 }4 }( lelsif ($UserNewPwd =~/^\d+$/)1 _. m) @, O" k" N, F8 S+ g
{&Writer_Log("New Passwd isn't all diginal");) x0 y$ v  b5 }4 Z. ^
&otherhtml($title,$pwd_not_alldiginal,$back);}
+ h& a" |: ]9 |- O- F  [8 eelsif ($UserNewPwd =~/^[A-Za-z]+$/)6 Q# O( P/ e( ~4 e8 e9 P: l9 u
{&Writer_Log("New Passwd isn't all char");
9 u; \( |6 e$ A! E! X&otherhtml($title,$pwd_not_allchar,$back);}
% y, N' d3 J6 ~elsif ($UserNewPwd ne $MatchNewPwd)' h8 j' s: W2 G
{&Writer_Log("Two new passwords are not matched");
4 f. |+ v5 G# u# r0 ]) a&otherhtml($title,$twopassnotmatched,$back);}( N. M) W0 n4 M% f* M" s! i
else
* i. w% ]7 V7 z3 x  u) [+ X{if($authuserfile)) @0 l8 H8 ^- O/ \
{#6
& Z5 n! L, \. X4 P: uopen UserFile, "<$authuserfile" or die "打开文件失败:$!";
3 j/ ~3 S' Y, m' V2 ], F1 k" kwhile (<UserFile>)
* \! i2 v* E2 V: U% \$ |2 m{#5
: K' A6 w( \  A4 Q; q. [my $varstr=$_;1 q$ \9 b( ?2 u& Y/ V+ S
if($varstr =~/($User)/)3 t4 r" j4 q- h. ]6 T
{#3
9 W8 Y0 Q! N$ I" amy $eqpos =index($varstr, ":");
: \3 k* i- W% Q3 E8 F% Lmy $UserName = substr($varstr,0,$eqpos);
$ l& n* t6 M* T7 ~0 P; |) q) I) ymy $cryptpwd = substr($varstr,$eqpos + 1,13);  U4 |. s3 q2 U2 E0 e3 F. _9 V2 g
% O3 X$ Z* P" {
next if($UserName ne $User);
% o0 i: b) Z( ~. n; K4 E $ X' {( h( l* v+ x: W' I# {' P
if(crypt($UserPwd,$cryptpwd) eq $cryptpwd)
* L! N+ n& n) T- Y  V/ V. P# n9 N' \{#a
7 B: K7 Q5 Q& v2 Z/ M% A  Kmy $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");4 l/ z) T: T( _" B4 p
if ($rc == 0)
- R% Z" n; Z! j' M. D{#1
8 W6 I8 @6 ^; e& k4 t. [! n&Writer_Log( $User.":Change Passwd");, n% f- H" a; C3 m3 ?
&otherhtml($title,$changepwdok,$back);
) `: v# Q1 A: c. k* A5 T1 O5 X}#1
; A6 b* W' e# u, D+ eelse
" j5 O- P8 q' A7 q. b. @  \{#2
# r7 c/ h1 N0 r7 m&Writer_Log( $User.":Change Passwd Failed");, o8 e, r7 c: A# s
&otherhtml($title,$changepwdfailed,$back);3 u0 G+ p! s. P* J* f- }
}#2- w+ s9 k% t" ]& R+ t% A+ {+ y, _9 A5 d
exit;' z" l* {* v$ S# Z4 {% a# A9 a
}#a
9 q8 w  L' M" selse
" B! E# r& L9 q6 {: g; V3 c# B6 n{#b
- F! J& u( g, |1 X! L- \&Writer_Log("Old Passwd is Incorrect ");* e" R  A, ], v* B. c
&otherhtml($title,$errorpwd,$back);* g# z6 L% V* @9 b$ c
}#b+ |) U. b" Q& R# n( [
exit;( P  [/ j0 K* p; }( q
}#3! Q) d* \6 ?8 u4 y
else
8 I5 r9 C9 O% o$ Q0 D; z{#4
  a& m7 a8 B3 {3 e% tif(eof). L* A! V# h( p4 q7 _) t
{ &Writer_Log($User.":no this user");
" M$ x, v, z, L- _' J2 n( f2 |( ?5 }&otherhtml($title,$user_not_exists,$back);
/ ]* m0 P5 X+ S( i& Jexit;
# ~. L- }) `; [1 l" x* v3 h}
3 N% u0 ]; H5 `2 A( M, c( \else, k4 Q, Q0 n) {1 x2 {
{next;}
: c& l) r& x: w}#4
4 v1 t# a8 P+ p( [& T$ n( U1 w}#5' X: B1 z- g/ s6 i
close UserFile;
. t* D' z4 E/ n. f9 R1 b' v}#6
1 ~  Z3 v$ `8 w' felse
! l2 X$ @) g" R% G# D' ]{#75 a0 s, W. G! y* I! y5 k; @
&Writer_Log($authuserfile.":no found");, w. _% t4 e2 P$ B/ \& x8 g
&otherhtml($title,$file_not_found,$back);
& Q! K  I" `! m. B. x0 J. W% }}#7
( P1 J! k3 b7 L" d) T}
1 y: O1 z& `/ \  P6 n/ _" V# l, c}#8
* K0 w$ g5 N& G) ?else2 z) z" {/ X* H2 X" D" m
{&Index_Html;}
, g" j6 _7 X$ F7 Usub IniInfo{% v% i- @4 J0 `6 Z: j) k9 l
my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";
& K; S  Z7 s3 X8 g6 K8 s' E# r( zopen CGI_INI_FILE, "<$inifile" or die "打开文件失败:$!";;) e" {7 M# \5 B4 b7 {3 [  _9 r
while (<CGI_INI_FILE>)- `  X$ z' S6 G$ `6 [; V- A1 T
{9 {! Q; c# f' l/ ~# J
my $eqpos =index($_,'=');
$ E4 z: B7 W7 f7 b. w7 {my $len = length($_);
. P' a2 O/ r; T6 O6 Mif ($_ =~/authuserfile/)
1 t/ h, W) u( _{$authuserfile= substr($_, $eqpos + 1, $len - $eqpos -2);}9 y' S# h) Z! d
elsif ($_ =~/logfile/)7 n/ p! S/ q+ v& u- H
{$logfile= substr($_, $eqpos + 1);}
7 G! b9 p% d: U9 B! W+ z1 Z: Ielsif ($_ =~/pwdminlen/)
5 G2 o3 F' u  G' O( \; o{$pwdminlen= substr($_, $eqpos + 1);}
: T  r. m: U0 i$ Y8 Jelsif ($_ =~/title/)
$ h& k# S0 b/ u! k{$title = substr($_, $eqpos + 1);}( i, P' |  ]! V- y, t3 _* _( x8 J
elsif ($_ =~/description/)
4 }1 S9 h- D. b{$description = substr($_, $eqpos + 1);}
. f4 I5 V: @& telsif ($_ =~/yourname/)& K) F+ {4 L: M* B* Q
{$yourname = substr($_, $eqpos + 1);}; g/ O. u2 `5 K! t* R
elsif ($_ =~/oldpwd/)- R3 E3 h. g- \3 f
{$oldpwd= substr($_, $eqpos + 1);}
3 E; w0 `8 P3 l/ s& helsif ($_ =~/newpwd1/)
7 y9 Z, [0 }  ]1 f3 q' m& ^{$newpwd1= substr($_, $eqpos + 1);}  s0 j4 z  _; U4 Y0 P5 U
elsif ($_ =~/newpwd2/)( Y6 C* J/ X/ D2 X/ l
{$newpwd2= substr($_, $eqpos + 1);}
# r, Y* b- k( m+ t* jelsif ($_ =~/btn_change/)
% x3 @/ ?; q! t{$btn_change = substr($_, $eqpos + 1);}
0 i" P. g* t5 o+ }! m1 M8 n" q0 Celsif ($_ =~/btn_reset/)
% ^" @: s" ]( I( G{$btn_reset = substr($_, $eqpos + 1);}% Z5 N7 v$ N6 U4 Q7 ^
elsif ($_ =~/changepwdok/)
' ]0 R0 [: O3 r+ d4 A9 Q& J. C5 n{$changepwdok = substr($_, $eqpos + 1);}
! g. l. x2 ^" H4 h' u# aelsif ($_ =~/changepwdfailed/)
6 U* |! @6 `: _. [- X) e2 I- q{$changepwdfailed = substr($_, $eqpos + 1);}, ]* B, p! V# q3 c4 |! i8 K
elsif ($_ =~/oldpwderror/)
) ?. F/ u' y3 Z, V5 h5 J8 c{$oldpwderror = substr($_, $eqpos + 1);}- L* X2 L3 k: q3 k5 A
elsif ($_ =~/passmustgreater/)% G3 c2 G. @7 t/ {" v
{$passmustgreater = substr($_, $eqpos + 1);}6 C8 e" G+ ]# H
elsif ($_ =~/twopassnotmatched/)
! A: F3 l% G/ y{$twopassnotmatched = substr($_, $eqpos + 1);}
7 n9 J0 E+ H2 x3 \elsif ($_ =~/entername/)
1 X8 a% Q; M# e& _3 w. D& G9 f$ S' {{$entername = substr($_, $eqpos + 1);}( y3 I1 W6 C8 l+ K* o0 D. m
elsif ($_ =~/enterpwd/)* p& f& |4 B5 n  Y) K
{$enterpwd= substr($_, $eqpos + 1);}; @# Z6 j( P- n- ~$ F
elsif ($_ =~/errorpwd/). |) l) q$ f( Z1 j& ~0 S
{$errorpwd= substr($_, $eqpos + 1);}: L" h* j! U: B
elsif ($_ =~/back/), v* G8 Y* X8 l3 ~; f7 E( I0 A
{$back = substr($_, $eqpos + 1);}
% J# J7 p, @$ Z}
. R+ W% R5 w$ ?0 n4 rclose CGI_INI_FILE;
% q! Q$ r# n% f}/ d" z* M6 l: ~+ {" Y8 K
sub Index_Html1 ^1 k: S4 L  k% F; T1 E8 X3 I
{- {* v; z3 L- A
print "Content-type: text/html\n\n";
" r, |+ ^4 s7 I1 Y' [+ ^4 ^print <<END_OF_PAGE;
0 S2 d6 F) V' @4 m  c. _<html >- C" ^; a5 B; ~! o
<head>
) k' O$ T1 h1 K8 M7 t5 z3 d; H) j<title>$title</title>
) k* O3 ^) Y. X. A: o+ k<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
$ n, J1 ^+ m2 [. D</head>8 K% `( J: Q% i: Z  x
<body>
2 a3 ~( g1 R+ F) {3 {0 x- c5 L7 P<HR>
9 x5 B7 X; K& k1 n3 y* a- i: Z5 ~3 R
+ K; P; ?/ A$ Q: W$ K% N4 ?<center><h1>$description</h1>
) G; a0 r  d- p4 c4 z. Z% ?</center>  L! o  d7 l% `5 Y, C
<form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">
. L( c, x- l; c; K( F+ `<br>3 S% H6 _, H1 N# }) R4 y4 F. l
<TABLE align="center">
# q* e& Q" }" V% M1 y% U( z<TR><TD class="t_text">$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>! R* ?$ r$ A# s* d
<TR><TD class="t_text">$oldpwd</TD><TD><input type="password" name="OldPwd" /></TD></TR>
" T$ Z, B/ k1 G! Q% R" A2 @; R$ g<TR><TD class="t_text">$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>
4 C- o" V* b9 t, W$ L- V. v3 n+ A<TR><TD class="t_text">$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>
* z/ }; P- `+ X, S8 ~( L  M# u</TABLE>  {7 j0 b4 T1 k5 `1 w- v" U
<br>
2 ~0 \. X3 Z* a<TABLE align="center">% T% |' k# ?) D6 K
<TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>& Y0 C$ ]$ [2 o/ ]0 a
</TABLE>
' |2 L, E) e8 f) Y</form>0 u% m  @7 ]8 _- T
<HR>
! i  `; d' l# m) \- v<center><font color="#FF0000">注意:新密码位数必需大于$pwdminlen,且为字母与数字组合</font>/ m  E1 d7 k9 f
</body>
( g9 h" y0 S5 t3 z</html>- w0 F/ R4 i: ^) }$ q& @  e" m
END_OF_PAGE/ g9 H9 z0 E$ k5 }
}: ^( q) I2 L  Y7 j/ t$ P: v# M' N
sub otherhtml{
# M7 q) R0 G5 s+ V6 xprint "Content-type: text/html\n\n";
7 h0 Y3 m/ y1 R% Z7 R9 c2 R+ Rprint <<END_OF_PAGE;+ G! d5 K( g7 _( g  o. G
<html>
' U9 m9 X5 V: t% n. k; C. K) V! k4 m* k<head>5 I7 a7 d2 `& \. C
<meta http-equiv="Content-Language" content="zh-cn">  F0 n: C+ w6 N+ ?
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">5 s( @& i; ~; Y
<title>$_[0]</title>; F" l7 A2 N& g
</head>' F# Y! O4 @% P1 ]
<body>
- l2 K3 B: j, K<p align="center"><font size="5">$_[1]</font></p>% s7 `8 P* ^5 A' h- d$ `; m
<p align="center"><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[2]</font></a></p>
9 k1 E$ b, ~0 z: D. f<HR>
5 G- e8 h( e6 G* Y& ^) @9 `* x# A<center>
( z. C3 `( z9 b<P>如有问题请与管理员联系E-Mail: <A HREF="$admin_email." w; h0 [3 Q' ^* y/ ~8 X1 N
mailto:$admin_email">$admin_email</A>.</P></center>6 e5 V: A: r: z& I1 c' N

) Z' G( i- |8 Y1 h</body>- R& [* j+ j& a. v0 A$ Q! q2 |+ C4 f' }& T
  # ]  O3 W! x1 m) v
</html>
2 n0 q/ A8 z/ N0 C: f; ^END_OF_PAGE
) t9 j7 L. N" ]' V}- v, i% p  E2 d4 z) ?( z( ]
sub Writer_Log{
3 p* C/ ~- q. g: iif($logfile)
! B( G$ x! B8 T6 y' t% a4 ^6 w{
: P4 @4 ~* e9 hmy $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[0];3 w2 X$ R: i* Q, y
open LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";1 O& c& I, \, s) y. k
print LOGFILE ("$loginfo\n");! G" o+ `. U8 V% c; i3 q% x% E
close LOGFILE;
" W  b4 K4 i: Y# b2 O% V3 ^& d" r}) _" Q& ~8 R- l
}
% L' x3 |) `. r/ t+ H6 U) T; L6 [/ P6 G( ?- Z1 @8 A6 {
ChangePasswd.ini:文件内容; z# P2 \; h( L/ j% }/ z" M8 v9 V
[path]
5 ]& i: K" g" y4 j0 {$ aauthuserfile=/data/svn/passwd
( n% j" ?+ s8 b& N# a5 Glogfile=/var/www/cgi-bin/ChangePasswd.log
0 z( F5 |) h1 {& e9 J( D/ V" h8 J9 R. {! X[setup]
5 Y& q+ T# @6 ]5 g' Hpwdminlen=67 B; \4 q7 @5 w1 r# o9 J8 [9 p
[html]
' R1 ~6 I) C+ c8 l* Stitle=SVN用户密码自助修改0 J, _  w) m& I- e  R. h) ~5 M
description=SVN用户密码自助修改* z, V( t5 {0 q7 O( X
yourname=用户名:# y+ u! {* y% B- `
oldpwd=旧密码:3 L( u; A( B# Z1 O$ k
newpwd1=新密码:
$ F; ?# ~7 x) V. U% X2 @2 u1 a; Hnewpwd2=确认新密码:
6 }7 }0 ^7 w2 wbtn_change=修 改6 F* ?& c. W1 P9 l
btn_reset=重 置
1 D2 Z: _0 p0 l/ x7 d" Zchangepwdok=修改密码成功  ~- ^+ m6 {0 \
changepwdfailed=修改密码失败. b3 J/ ~/ m* s9 M( V' x  v5 y
servererror=服务器错误7 C* u" J* t4 T1 b
passmustgreater=新密码位数必须大于, \: P2 `; z( u3 r0 r" b% P' B
twopassnotmatched=两密码不一致
. }7 R: K1 B3 {/ rentername=请输入用户名. F" w& F  s& ~  ^. V. t
enterpwd=密码未输入  [5 F+ g0 V+ {% T/ y) `
errorpwd=你的密码不正确; \6 i; g4 l/ X
back=返回
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

SCMLife推荐上一条 /4 下一条

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

GMT+8, 2018-12-11 22:49 , Processed in 0.063726 second(s), 6 queries , Gzip On, MemCache On.

Powered by SCMLife X3.4 Licensed

© 2001-2017 JoyShare.

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