SCMLife.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2966|回复: 2

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

[复制链接]
发表于 2017-12-1 16:38:19 | 显示全部楼层 |阅读模式
大家好,centos7 下我按网上的脚本ChangePasswd.cgi  ChangePasswd.ini  ChangePasswd.log 创建了这三个文件,但是修改密码时,报原始密码错误,明明没有输入错误的。. r7 }6 @4 e) o  F( k/ v
[root@localhost cgi-bin]# ll ChangePasswd.cgi 9 J  C4 p: S( W+ r3 o2 z% r: H# Q
-rwxrwxrwx 1 apache apache 5957 Nov 30 17:25 ChangePasswd.cgi& ?# C! h  O1 u' {
[root@localhost cgi-bin]# ll ChangePasswd.ini 7 I  Q2 P! i& k6 u& u% ~
-rwxrwxrwx 1 apache apache 566 Dec  1 15:03 ChangePasswd.ini6 Q9 K/ }+ X6 g

4 T3 G* b3 ]' O+ s+ ~+ T8 P; e
6 X6 Y& L8 o+ M& W" S/ D  S* o权限都有的,查看apache的logs也不报错,只页面提示说原始密码错误 ,不知道问题出在哪里了。请求,大家 给看看呀。。
发表于 2017-12-4 10:03:41 | 显示全部楼层
提供的信息太少,没办法回答啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-5 10:56:07 | 显示全部楼层
ChangePasswd.cgi 文件内容:
- G- E" a9 y# u! |3 ~#!/usr/bin/perl -w
# N- e0 G; M6 M& Cuse strict;
3 g* E- x/ _4 q; c( Cuse CGI;
2 V5 ]. n& ]' W  Q8 tmy $time = localtime;- F: A7 n/ n, H; V. y  P: M+ x
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};7 A; ^# R& x5 L# e
my $admin_email = $ENV{SERVER_ADMIN};
1 I2 y& g7 s. d  f8 Q' @; t4 B1 Umy $cgi = new CGI;
& e' C- }. Y1 p! x+ i: [3 u1 Mmy $pwd_not_alldiginal = "密码不能全为数字";3 }7 h$ y  j  N! _/ Q3 k+ ^* c
my $pwd_not_allchar = "密码不能全为字符";& o' g. A4 M3 m& o  ~' x
my $user_not_exists ="该用户不存在";
, S, ~( k. U: }; |9 Hmy $file_not_found ="文件不存在,请联系管理员";5 |% p! |# B" j7 r5 Q' ], B
my $authuserfile;$ q! k" L% p( O) ?
my $logfile;
$ |. G7 E' D1 U* k3 xmy $pwdminlen;5 P$ o+ _3 E3 V' y' H
my $title;
- {; l* s. A0 q2 a) c* {1 Q; l; m2 c: umy $description;  q( c  P3 `% a3 ^1 ^
my $yourname;
- N2 a( x/ j* ?& nmy $oldpwd;4 `' ]: e3 t2 B6 k+ q. o. O
my $newpwd1;
, L. N; o; n) o7 amy $newpwd2;
9 g  k& b1 \' L9 H: }* n0 m( Ymy $btn_change;8 `1 J/ M2 o1 ]' |
my $btn_reset;
( |5 t" P, k) x! ?5 nmy $changepwdok;* z: a8 `; [$ d2 g( M
my $changepwdfailed;
; o+ \0 U; V' ^4 T: t! vmy $oldpwderror;2 T5 Y$ j7 @( P$ ~- E3 B) s  b
my $passmustgreater;4 _5 M% Y! ^% Z
my $twopassnotmatched;( R' [, ?  r& R7 P& Z0 W, F
my $entername;* A* t6 Z: b: R
my $enterpwd;
" Y1 x. l6 G% {5 |my $errorpwd;
' _; ]( K2 @: _9 r& y. j' o3 Umy $back;
8 }+ g. [+ _) c* B$ u3 _ / [# W) O" c4 n! y" d$ ]
&IniInfo;
) ]1 U! I2 H( u$ W% Aif ($cgi -> param())! V/ Q- d, H. x0 Y
{#8: H( A% Y3 z& k5 I2 q7 v8 Y
my $User = $cgi->param('UserName');. m. x4 E* J1 I0 T3 l  `
my $UserPwd = $cgi->param('OldPwd');
/ z% p6 @# B- ymy $UserNewPwd = $cgi->param('NewPwd1');
! g/ K/ d) G4 b* _my $MatchNewPwd = $cgi->param('NewPwd2');
. ]7 X0 V. w- d6 [& @) \. L
* I# p' g5 u9 b& w; y& bif (!$User)
# L% l1 u5 B& I! a1 [+ v# v; j! k: V{&Writer_Log("Enter no user name");
4 U0 q1 a/ c3 q7 G3 B$ L% E&otherhtml($title,$entername,$back);}2 n6 L$ d* k9 X
elsif (!$UserPwd )
* d8 F( ~1 I4 r  A{&Writer_Log("Enter no OldPasswd");
: s7 e+ V4 ^8 ?4 j& H5 ^) ?. N&otherhtml($title,$enterpwd,$back); }
& [9 k; l& A& t  v- U5 l  Pelsif (length($UserNewPwd)<$pwdminlen)
1 Q' S$ ?1 [$ \' S$ s{&Writer_Log("Password's length must greater than".$pwdminlen);
3 l  J9 D$ k/ E" e1 \7 y&otherhtml($title,$passmustgreater.$pwdminlen,$back);}
# U3 x! d2 n. \& aelsif ($UserNewPwd =~/^\d+$/)4 L+ J, }9 W. n7 _+ J) S1 S
{&Writer_Log("New Passwd isn't all diginal");
* n1 m8 ?! ?6 n, a&otherhtml($title,$pwd_not_alldiginal,$back);}
8 W; V' o' |( Welsif ($UserNewPwd =~/^[A-Za-z]+$/)2 n; P& O$ J4 r) o5 j. K0 v1 L
{&Writer_Log("New Passwd isn't all char");
$ K; E+ w7 ?' P: z&otherhtml($title,$pwd_not_allchar,$back);}
+ e2 H2 r3 A+ X# Welsif ($UserNewPwd ne $MatchNewPwd)# |! G  T5 ~; G% c9 V/ F
{&Writer_Log("Two new passwords are not matched");( A. X7 W, l" s1 Z3 `; }. h1 E! K
&otherhtml($title,$twopassnotmatched,$back);}2 w' n, i$ W0 d1 K. {+ B
else! N+ s0 Z1 Q9 J
{if($authuserfile)
  [9 _+ d  C/ n: v, E7 h1 Y{#6
& z! }4 \( P- _8 \open UserFile, "<$authuserfile" or die "打开文件失败:$!";
& D$ O0 E# g/ N& nwhile (<UserFile>)0 N5 [) O! _1 U1 g9 r# F
{#5
1 [3 G' s7 Z! [/ R3 gmy $varstr=$_;, r+ ]6 x/ {, |' @0 I+ |9 H
if($varstr =~/($User)/)9 [" x0 i2 u) X$ J9 K; D
{#36 u8 H' `& G# M3 L2 O2 \3 I
my $eqpos =index($varstr, ":");+ {1 Z5 w7 u- P$ O; P4 R/ [) Z# `
my $UserName = substr($varstr,0,$eqpos);
  _6 f% S6 O9 ?my $cryptpwd = substr($varstr,$eqpos + 1,13);
2 G/ B* ~; Y9 q
/ g6 \1 ~+ x/ W1 pnext if($UserName ne $User);
  F: E* {4 j- Z# C
; u' k9 l) c/ t0 l. W8 gif(crypt($UserPwd,$cryptpwd) eq $cryptpwd)
& K' C# t6 x" o{#a% Y2 t. ?- f0 T, _( ~: g% k$ v5 z/ F
my $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");- h* N; w5 f, e
if ($rc == 0)
. l- R4 C0 d& H: G: B  ?{#1& y% u: Y. E4 W! j; D4 I
&Writer_Log( $User.":Change Passwd");
3 Z$ }0 m4 b, G7 X&otherhtml($title,$changepwdok,$back);+ W  k3 S! O& `  R
}#1
5 ^7 z; ?$ B: U4 Gelse5 q6 P, O% V1 t- O
{#26 u7 n8 I8 c+ Y# ^  f; w/ N
&Writer_Log( $User.":Change Passwd Failed");+ Z- X, H# _( _; f. W0 v9 w  E* o
&otherhtml($title,$changepwdfailed,$back);) k; u( |7 J1 \' h$ w0 v
}#2
' n/ d$ S; \$ kexit;
8 ~2 i2 B- B! |& |8 z3 y5 q}#a
* {2 L, r$ Y( c  F4 p% E  melse7 ?+ s9 }( C5 @9 ~) g! S. M) Y
{#b
7 w9 r) t% {$ e' c* n2 h&Writer_Log("Old Passwd is Incorrect ");
" F0 t$ I+ u+ k% _&otherhtml($title,$errorpwd,$back);
* {1 G' ]0 }! q) @* N}#b/ ?( K! ]( r( B3 N* V
exit;
* o  b. x9 P" d. n: Z}#3
# w& q0 m- w1 ?* Q0 uelse% R) f# n. v' _& y7 Q, C# v" x
{#4
3 Z0 a" t2 k- {2 Jif(eof)& t/ ^! ^7 u* Z( f
{ &Writer_Log($User.":no this user");5 _& a, p. p" E1 Z2 Q5 P; q
&otherhtml($title,$user_not_exists,$back);+ Y: w0 i7 d! b: ~: M  n
exit;
4 I! S2 N) O7 ^& G+ b3 ]* j1 \}
) K" R9 k  V4 aelse
7 w; {, x6 x5 z% x{next;}
# W+ y" ?& I$ r5 b}#4
& z$ U' X* [: q% H) q; a}#5/ [7 e5 p- \$ s& L# F. d$ M) L
close UserFile;
3 `# d& C: w! q- z1 V}#6
7 I, i# F  s/ |" V1 Yelse
. s. i6 v9 y8 C( C{#7
) |7 X4 J/ \3 E+ x& i* B  N+ d&Writer_Log($authuserfile.":no found");5 D/ _3 n" z' l0 |1 s
&otherhtml($title,$file_not_found,$back);
+ e& g* Z3 U6 L& k}#7
, ]7 z9 ~, e) E! E* U}# `8 T4 z3 g# j5 ~
}#8
* A8 S( K; p1 X1 a! _else
& Q5 S! L: G1 a& q8 _{&Index_Html;}7 A% ]9 J3 P5 w" n! [9 }
sub IniInfo{
4 c3 S. a. f* r# @2 Q) M% ]my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";( ]6 W  [6 a! }7 M# M
open CGI_INI_FILE, "<$inifile" or die "打开文件失败:$!";;' F3 ~& u1 F+ M7 l/ q
while (<CGI_INI_FILE>)
& T6 U  e; @$ c) c$ i- x& Q. y! T{& g! |% C% |7 w: q% \
my $eqpos =index($_,'=');6 _* `: |( t( ]3 L. ]8 t
my $len = length($_);% V% W, O2 m& f& X
if ($_ =~/authuserfile/)8 x, K& y! c5 W) n
{$authuserfile= substr($_, $eqpos + 1, $len - $eqpos -2);}, u, R4 _1 A! f/ @) I% J
elsif ($_ =~/logfile/)7 |8 `( j* C( L6 Y9 ?7 o0 R
{$logfile= substr($_, $eqpos + 1);}0 j- H4 ]  C+ W+ V( ^" O8 J
elsif ($_ =~/pwdminlen/)  B8 J' i, M$ w/ h' S* n
{$pwdminlen= substr($_, $eqpos + 1);}# a/ P& V% C+ B: D) W
elsif ($_ =~/title/)! i! X- y+ |+ z2 C
{$title = substr($_, $eqpos + 1);}' Y$ Q# X4 }  u3 F
elsif ($_ =~/description/)* o( r& Z- O! r# g0 B- d
{$description = substr($_, $eqpos + 1);}
; V3 y5 X. h* y6 Z9 y* Uelsif ($_ =~/yourname/)
( T% M- f  q1 z{$yourname = substr($_, $eqpos + 1);}
/ i0 B7 \. b( E+ _elsif ($_ =~/oldpwd/)
$ d! s  P8 N1 \+ O) Q{$oldpwd= substr($_, $eqpos + 1);}
, `& A' t6 J' {7 q/ b7 L2 _elsif ($_ =~/newpwd1/)0 _; o( Z+ X. I3 ~
{$newpwd1= substr($_, $eqpos + 1);}; K, z+ B) N0 F% T
elsif ($_ =~/newpwd2/)/ _: o8 B7 i' `* e3 c" I9 Y3 |  p
{$newpwd2= substr($_, $eqpos + 1);}; u# L) M, h! a. }
elsif ($_ =~/btn_change/)
4 a) n! h  d: O& ?8 @) T8 G" N8 l. Y{$btn_change = substr($_, $eqpos + 1);}( `& t, _) a3 \7 O! D. ?
elsif ($_ =~/btn_reset/)3 E. t. u5 f: H( S1 E
{$btn_reset = substr($_, $eqpos + 1);}
. i+ ~  Y. I9 p5 f( e# Aelsif ($_ =~/changepwdok/)
) Z+ u$ C% v3 U( S5 a" v: I8 L3 ^{$changepwdok = substr($_, $eqpos + 1);}& p* N6 F* o1 a! o
elsif ($_ =~/changepwdfailed/)  w4 ~/ V* Y/ j7 t: n- n
{$changepwdfailed = substr($_, $eqpos + 1);}
7 g& Q5 d& k; Y" K+ Y' Relsif ($_ =~/oldpwderror/)
; w: D$ Y* `' q3 C' Y4 c{$oldpwderror = substr($_, $eqpos + 1);}$ \/ D0 d0 S6 }2 _4 Z: N4 `
elsif ($_ =~/passmustgreater/)
4 g8 d! g& M( J6 G5 U{$passmustgreater = substr($_, $eqpos + 1);}1 ^" L5 A0 [0 E' H- F
elsif ($_ =~/twopassnotmatched/)
/ n9 O0 \. X) V  g{$twopassnotmatched = substr($_, $eqpos + 1);}
1 O# ~* N* Z$ W. O$ K1 zelsif ($_ =~/entername/)
" f5 \0 @. _( w- n0 R  a{$entername = substr($_, $eqpos + 1);}) Y+ Q" S5 [  @4 Y; A' L! p) n: {
elsif ($_ =~/enterpwd/)4 `6 s8 P! e+ J  x; u& j) w
{$enterpwd= substr($_, $eqpos + 1);}
7 o2 Y& c, a7 c# h- qelsif ($_ =~/errorpwd/)" U* j- y8 ]8 f  K$ d
{$errorpwd= substr($_, $eqpos + 1);}
- B5 s" c$ m& S$ q) V9 C) aelsif ($_ =~/back/)
6 {; K6 m# O8 W8 y4 ]) W: {: {{$back = substr($_, $eqpos + 1);}
& T7 ]% I) d9 W; _( I! A$ ~}+ r# `9 z2 ^% W/ W* J& K
close CGI_INI_FILE;. ^% [7 e& k" l9 g6 Y
}" o/ b; ?' v* V0 \- m' R/ f* T# |
sub Index_Html
8 G& `, W  p7 J{
8 _  p8 V  m/ [3 E# d/ Z! d; ^print "Content-type: text/html\n\n";
' o0 e% d0 S4 d  J# rprint <<END_OF_PAGE;
$ q, R3 I! J: I5 k<html >
. [# S: A$ V8 T2 v. i<head>
5 d% j; m7 w7 l. ?) Q$ f0 ~<title>$title</title>, O$ A" G& o" M* N3 l: ]
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />+ {" V/ A" w& D7 U) z- f& \
</head>
- P6 r" D4 k+ j' H8 C2 O<body>
3 u& H5 F! J" {/ C6 z4 h" K# z; Q/ }9 W<HR>
+ B( O5 A+ |2 t0 D3 s/ C6 p
) l3 _  _  e9 y8 G  d2 A<center><h1>$description</h1>1 ?% m' d. @# q) o7 X/ f. `- x
</center>
3 z- e$ n" z6 l0 t8 ~<form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">
& S& u: k7 N% \) T" X- L2 V( x<br>, V  n! ?, Y6 p' w5 q- W
<TABLE align="center">4 u( h$ I0 O# c2 u1 i  ~" _) M
<TR><TD class="t_text">$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>) o! U. Q( ~' F! E3 M+ W" H, _9 x
<TR><TD class="t_text">$oldpwd</TD><TD><input type="password" name="OldPwd" /></TD></TR>
" S7 Q/ Y! f1 ~3 J: T  S# _2 ^+ x<TR><TD class="t_text">$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>
0 p0 r& ?3 ]1 F: S  J4 u1 r5 l0 B<TR><TD class="t_text">$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>
& H$ p1 \! @* f  e1 h3 y* V9 s</TABLE>
- N# w3 c) r5 M( N/ o, J<br>& k$ M) E1 `( ^0 ~! l
<TABLE align="center">
1 X9 D2 L+ M, f3 H0 ^<TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>
* h1 e" y3 Z7 L4 d7 M: g</TABLE>& v! V) ]& H5 _: C. u1 c0 p
</form>' a0 a8 t# I9 P0 T* l0 H* \
<HR>; M" P5 |( [- ]9 Q7 _, G1 Z. `
<center><font color="#FF0000">注意:新密码位数必需大于$pwdminlen,且为字母与数字组合</font>
6 o$ y9 G5 p, |( u; f: \</body>
) Z( h) q/ s( A4 N</html>
# S3 s$ e  ?1 Y7 y; lEND_OF_PAGE/ I. T, a+ A+ H& F6 p, Y( ]
}
* Y2 }9 x# d/ \( z7 a' }sub otherhtml{/ D/ b+ n, L% s' i
print "Content-type: text/html\n\n";/ ]! k6 Z; b( b1 V( ?
print <<END_OF_PAGE;
* V6 j1 R, `0 m( b; P<html>5 Z: j1 e2 D& ~! E
<head>
* ~- x8 V$ ]; K  g, H& s8 q<meta http-equiv="Content-Language" content="zh-cn">5 M! \3 x* o, a% O" T8 S
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
! [( B  ]. J0 Q4 j( v" s<title>$_[0]</title>
+ _: o5 q6 a$ y+ h- P0 O# ^</head>
7 ?& b9 k/ f" o. ~( p<body>$ u* Z1 C" U. Z" u) g  l* l
<p align="center"><font size="5">$_[1]</font></p>
, H# l' d0 P' y. ]8 d  @<p align="center"><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[2]</font></a></p>, g; N& H0 E* U
<HR>) Q9 u" T1 R3 [8 s
<center>' u4 p2 B* H5 V3 ?/ W2 U
<P>如有问题请与管理员联系E-Mail: <A HREF="$admin_email.7 Z' [' l. U) A- O% U3 @
mailto:$admin_email">$admin_email</A>.</P></center>5 S( d, \! a' o! y) f' W

) W. R8 U3 q+ z+ I4 {' W* N5 b</body># J# n! u8 z& s5 u& m
  
, D6 }0 n( g+ Z1 D3 C8 g; _; ]2 L; j</html>6 C! d( W2 [  {1 b3 i% }; o3 q7 t
END_OF_PAGE6 i) P  k# e7 d4 w  u
}3 c" B$ Z4 \7 c: s" I  B/ G2 G
sub Writer_Log{( Q% S' ^( D7 w1 Z- D
if($logfile): P/ M7 e+ y# \6 k+ e0 Y! r
{
+ C; C& k: x$ I- Nmy $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[0];- V' ]! J7 w! T9 Y5 ^" [  L
open LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";
# D7 P& ^+ Y+ N# pprint LOGFILE ("$loginfo\n");0 o" x6 {0 K! x( G6 y: z  y
close LOGFILE;: N5 \; m. [  U8 `. [+ h: H# P
}5 L: {1 E+ F4 Z; a  }8 ?0 i
}
. y/ S" ?: Q# a3 Z& U
) D& M* u' r* t5 x9 g) q) v6 }ChangePasswd.ini:文件内容8 E1 q- K$ A6 e# Y; _
[path]! `" e  `/ o2 X5 w$ w
authuserfile=/data/svn/passwd
- X' d  T  r* Q" F! k! Ilogfile=/var/www/cgi-bin/ChangePasswd.log' o9 {( b1 C& _/ U: |
[setup]2 s, }1 b0 O, ^) f+ `" ]& w
pwdminlen=6
' U( s2 ?5 k: ]7 j5 ]$ S$ |. n[html]2 G6 p6 C+ z2 q0 j, P+ M* i
title=SVN用户密码自助修改; r  ?" w5 q2 I! o
description=SVN用户密码自助修改
9 |0 V! t( z/ p2 v% c2 n/ myourname=用户名:+ ]9 Y9 I8 _8 _
oldpwd=旧密码:( W$ N8 L2 Z! r5 N( G2 \8 e$ |) z
newpwd1=新密码:
! A4 ]3 |4 E6 Z" q8 r: v% h) V% ]newpwd2=确认新密码:3 ^8 L7 `" U# i+ l- }
btn_change=修 改8 S3 Y9 b3 E4 i* F: ~" Y8 J( l1 f
btn_reset=重 置$ s, E, g! a$ p4 Q* n. X
changepwdok=修改密码成功% p0 m" ~7 K! n, v+ W6 l
changepwdfailed=修改密码失败
; V: k" p7 P" x! G) ^: j2 D0 k6 hservererror=服务器错误
2 }& p* S. P- s: g, c8 ?passmustgreater=新密码位数必须大于
+ h$ R' q) t6 _% ]7 F& ytwopassnotmatched=两密码不一致
" L% {2 K& {' G/ o) s( qentername=请输入用户名, L  ~2 `& }8 B) p. N# A
enterpwd=密码未输入9 Y% v3 \( x1 T6 L" l: j' j. N$ w
errorpwd=你的密码不正确
: b8 s* ^4 G! D" H" uback=返回
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

SCMLife推荐上一条 /4 下一条

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

GMT+8, 2019-2-19 20:06 , Processed in 0.062355 second(s), 6 queries , Gzip On, MemCache On.

Powered by SCMLife X3.4 Licensed

© 2001-2017 JoyShare.

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