SCMLife.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2362|回复: 2
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
楼主
发表于 2017-12-1 16:38:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家好,centos7 下我按网上的脚本ChangePasswd.cgi  ChangePasswd.ini  ChangePasswd.log 创建了这三个文件,但是修改密码时,报原始密码错误,明明没有输入错误的。8 g3 p0 G# D* L# L1 I( n, C5 L
[root@localhost cgi-bin]# ll ChangePasswd.cgi - E+ D) r+ y; }/ n9 R
-rwxrwxrwx 1 apache apache 5957 Nov 30 17:25 ChangePasswd.cgi
: f5 h7 G% r9 M+ v( A9 |( o1 k6 c[root@localhost cgi-bin]# ll ChangePasswd.ini 7 U* L: c3 T! f! Z' f
-rwxrwxrwx 1 apache apache 566 Dec  1 15:03 ChangePasswd.ini& y0 x2 N" J+ T: x$ {: u

( r# P6 r6 b" w% x; v6 m2 g$ R7 N* y- c& H
权限都有的,查看apache的logs也不报错,只页面提示说原始密码错误 ,不知道问题出在哪里了。请求,大家 给看看呀。。
沙发
发表于 2017-12-4 10:03:41 | 只看该作者
提供的信息太少,没办法回答啊。
回复 支持 反对

使用道具 举报

板凳
 楼主| 发表于 2017-12-5 10:56:07 | 只看该作者
ChangePasswd.cgi 文件内容:
& W# U4 \: N; D#!/usr/bin/perl -w3 j: a+ f$ A  s8 }, i& M+ ^  V# ]
use strict;
/ t' j2 g' c  Z0 {4 r1 @use CGI;
4 M6 p" T* Y: X0 ]+ cmy $time = localtime;8 @$ Q+ t+ `! d! R5 [) T+ z9 @
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};3 ]7 X* ^' N- |3 f
my $admin_email = $ENV{SERVER_ADMIN};
2 [" o/ w, e# Z+ k9 R8 ?: ]my $cgi = new CGI;
8 a1 r7 m* @, j+ zmy $pwd_not_alldiginal = "密码不能全为数字";
3 `6 i. L  o. h8 K/ bmy $pwd_not_allchar = "密码不能全为字符";
# \+ h$ q( z+ O' P6 s* ]- Mmy $user_not_exists ="该用户不存在";) c$ g' A, |4 f* K  V. Q
my $file_not_found ="文件不存在,请联系管理员";
- \+ p3 t( G  O  F/ Rmy $authuserfile;1 P- b$ w* j7 D
my $logfile;
" J5 Z( v1 ~' n$ Kmy $pwdminlen;* U- w" M7 J4 L7 W: L
my $title;9 e$ C1 A" ]4 n: C
my $description;
& D% M. i& _+ g4 U% P, Umy $yourname;# r* q8 U" e0 N; y
my $oldpwd;
( ?, R* p5 y) p0 L: V; X- K8 u  B( zmy $newpwd1;
5 N0 a9 m' Z% |" T6 ]: ^6 ^( {my $newpwd2;9 U* b7 t3 \5 _3 i% [# R* A) n0 d! o
my $btn_change;, o& I- s' \, H% f. @5 t; _2 K
my $btn_reset;4 w( z4 }/ b4 e9 A' d
my $changepwdok;
- a4 F, S+ @* x0 p+ z; l! _: ~my $changepwdfailed;; ~, R$ @& w8 p! L7 _
my $oldpwderror;: x" l. C. b/ d7 B* J& w7 B
my $passmustgreater;
+ l; K2 U, u' R; Q1 l( X: M2 L, qmy $twopassnotmatched;
0 x# \) |* `6 S3 Lmy $entername;; m2 s. e+ J# Q9 ?
my $enterpwd;" A+ u) J( _( l. V8 R$ c
my $errorpwd;# K" a5 a- ~: R1 a* h
my $back;5 D7 u% @1 w2 O

& i  e3 @3 f( a4 S8 i- F9 A&IniInfo;. k8 U" F8 v8 |: C) E
if ($cgi -> param())
' `) z2 t3 f) l% v9 y{#85 V) o$ s9 f. D6 ^9 w- H( w1 W. ?, }# E
my $User = $cgi->param('UserName');4 H* u- u2 N6 f& p
my $UserPwd = $cgi->param('OldPwd');
* ^8 c$ D, u% o5 l; j3 d. Emy $UserNewPwd = $cgi->param('NewPwd1');; u, a1 N  W1 l
my $MatchNewPwd = $cgi->param('NewPwd2');$ |; J3 [+ p9 K
7 q6 r  x+ H# A
if (!$User)
4 u" M( f$ X) ~: u{&Writer_Log("Enter no user name");
' k1 C9 U, Q# B/ _&otherhtml($title,$entername,$back);}
5 D" v% T. [+ r. Nelsif (!$UserPwd )6 R* I; L1 y: F& P1 i
{&Writer_Log("Enter no OldPasswd");9 I; y' ^* n  _
&otherhtml($title,$enterpwd,$back); }7 d. x- A! |! {% a0 g3 C
elsif (length($UserNewPwd)<$pwdminlen)+ @1 V; A( _2 g9 g' S
{&Writer_Log("Password's length must greater than".$pwdminlen);
9 _6 o% a% |& K1 l7 ?8 {&otherhtml($title,$passmustgreater.$pwdminlen,$back);}
) K0 I6 I  R! H4 O2 D9 J' Gelsif ($UserNewPwd =~/^\d+$/)0 o- m6 d1 k" l, h6 A& Q) L/ M
{&Writer_Log("New Passwd isn't all diginal");* `2 J: m/ z9 X5 o
&otherhtml($title,$pwd_not_alldiginal,$back);}& `- _1 X3 n7 F* J. V' w
elsif ($UserNewPwd =~/^[A-Za-z]+$/)- P$ D% n" J  a9 Q$ {. o4 M# Q
{&Writer_Log("New Passwd isn't all char");6 X8 \7 g0 N) |% M, `, F
&otherhtml($title,$pwd_not_allchar,$back);}
  N6 B% f/ I+ U# P  C& Delsif ($UserNewPwd ne $MatchNewPwd)
+ \' V; U, m" l; A* D$ \{&Writer_Log("Two new passwords are not matched");; x0 @/ ~- E. {
&otherhtml($title,$twopassnotmatched,$back);}
6 [( ~/ ^1 I0 {' o% f3 Z: yelse
! _7 I# v- ^* b/ `{if($authuserfile)
" K2 D$ d; K+ N4 t# V2 o{#6
9 ^, e$ A0 b( }! F+ C3 |4 S/ e3 }open UserFile, "<$authuserfile" or die "打开文件失败:$!";# T3 w9 K. }$ k
while (<UserFile>)
" I3 b* I  ^6 E7 b{#5. }' l6 v  K# r8 Q! u4 t% ^
my $varstr=$_;
. c; E$ m9 R0 S6 P) jif($varstr =~/($User)/)
. t( v. t+ A  Q& T+ |; D{#3
3 ]. `, S4 o  u8 e; Emy $eqpos =index($varstr, ":");
+ S' x. x* X1 m  Q* Tmy $UserName = substr($varstr,0,$eqpos);2 e- |3 _- c* {- b7 l
my $cryptpwd = substr($varstr,$eqpos + 1,13);
8 M# j- p+ U( l$ [/ g
$ o0 q& B2 d) K7 [9 j! o/ K% ]0 ~. inext if($UserName ne $User);0 O. n0 d: ^3 m, @3 I! D& a
/ z0 P8 u3 M2 X9 D/ ]
if(crypt($UserPwd,$cryptpwd) eq $cryptpwd)2 F) S4 A' p! h. |/ y  J8 X
{#a8 a8 ^2 ^- @3 N2 O5 v" V' E
my $rc = system("/usr/bin/htpasswd -b $authuserfile $User $UserNewPwd");
; o, _0 P  r. V2 P7 {- ?1 E) i3 zif ($rc == 0)
; T( a4 o0 O3 w{#1
2 m3 n6 t1 O6 I! a" B" o5 S7 T3 h&Writer_Log( $User.":Change Passwd");- ~9 B# W" r* O$ g4 ~, W0 F
&otherhtml($title,$changepwdok,$back);
' K- P1 H7 M+ ^  A; ^}#18 h( M# V# K. X" h2 i
else8 r: M* B& o4 R7 U
{#2
2 ]$ b8 p* n! s7 S9 l5 [) b&Writer_Log( $User.":Change Passwd Failed");( A2 ~5 V9 y; @0 r% J5 [# p& \
&otherhtml($title,$changepwdfailed,$back);
' g2 B4 M$ k" G3 }5 H}#2# @) k' r4 G5 o7 G# ?
exit;
. C1 x. ~' \6 Y9 Y}#a
" t. K; w( J, D! [; Z) U2 A) }2 Pelse
7 y+ V/ E( O6 p3 @; g3 B{#b
% D8 a% q+ e: y6 @/ q7 S9 q- M# R&Writer_Log("Old Passwd is Incorrect ");
. k% t4 j: q( T! \8 z5 s4 E&otherhtml($title,$errorpwd,$back);, L/ I/ |: }8 r3 Z/ x3 b
}#b
% u7 j# `0 L# X3 A6 I" dexit;. A4 M0 P9 A* x- X+ c& q: ^
}#3; l: W, o6 Z" o3 d. h8 K/ s  `
else" [) L$ |$ f8 x/ w9 p3 x
{#4
3 ^5 ?, t) k. s) Aif(eof)1 @" N" \' a# C$ v8 ^  L/ H
{ &Writer_Log($User.":no this user");
/ s. S/ |# A+ f2 q  L/ u&otherhtml($title,$user_not_exists,$back);2 B2 P) a+ Q0 f7 \% m7 \1 i/ y, E: p
exit;! [* H- x8 E, b( p1 m/ t/ n/ r  j
}
, B! J/ `: y" F  y! N9 e% @5 `$ M+ velse
) C- x9 c+ Q3 a' e4 p{next;}) m6 |% L% O0 c2 l  T' z8 l" o
}#49 s8 b$ R7 A, t  F; n
}#5
2 w# c. ]. W. s7 E) D) T2 p+ Xclose UserFile;
* U) O. D% a6 |$ V}#6
: M, O1 x6 y  D6 w# S* velse# {; M1 d' o: C" Q
{#72 i7 C& w6 ^! J1 T
&Writer_Log($authuserfile.":no found");
# R) n- l2 a0 P, Q&otherhtml($title,$file_not_found,$back);
; D6 g" D9 y- |: h1 H! v}#7! H0 w5 @4 x7 ^/ {- z4 d
}
3 a. ~% S' L, p' h}#8! Y1 ^4 ?6 v) V4 W3 P$ u1 V, V
else
! b* H) s% |0 g$ Q% D8 a{&Index_Html;}
4 N+ V3 v- y: [+ Wsub IniInfo{% U) F& q' s( ^/ G" e5 @
my $inifile = "/var/www/cgi-bin/ChangePasswd.ini";/ c% u+ k! M3 ^+ u+ L2 i. D  U) t
open CGI_INI_FILE, "<$inifile" or die "打开文件失败:$!";;
6 e7 k5 P& d* B9 L- X! \while (<CGI_INI_FILE>)" j) _5 e6 G+ n; I
{2 A- z' s# x  B7 h
my $eqpos =index($_,'=');' o; D8 G" E. F9 X9 {* m# e
my $len = length($_);7 l1 `5 G# j7 G6 X2 _$ M
if ($_ =~/authuserfile/)0 X+ _( M2 i/ T# L7 E
{$authuserfile= substr($_, $eqpos + 1, $len - $eqpos -2);}5 ~! S' Q, E4 o  _
elsif ($_ =~/logfile/)  B; Y: F" H% y4 E: p/ d
{$logfile= substr($_, $eqpos + 1);}
. f& j# s' X' Q7 N! {4 U9 nelsif ($_ =~/pwdminlen/)6 w% n: L/ I% H  y  |- b
{$pwdminlen= substr($_, $eqpos + 1);}
! ?" n: n# A( [2 |elsif ($_ =~/title/)
2 f$ ]5 {* }) T' V{$title = substr($_, $eqpos + 1);}
1 o+ p" V- d4 Q1 o2 D9 [elsif ($_ =~/description/)1 w4 N# x, T5 j9 o' B$ N
{$description = substr($_, $eqpos + 1);}- \) x& ~3 |$ W/ S% B$ j- Y5 Q- a- i
elsif ($_ =~/yourname/)+ S, t- D- M4 _8 R" l/ b
{$yourname = substr($_, $eqpos + 1);}
; U5 a" _1 m" v: D/ Velsif ($_ =~/oldpwd/)* H- ]1 x9 E. U* f* l
{$oldpwd= substr($_, $eqpos + 1);}& Y8 Q: _0 Q) `. `% G
elsif ($_ =~/newpwd1/)
7 o+ K# H( P1 F9 z" F5 `+ j9 N- O{$newpwd1= substr($_, $eqpos + 1);}( W+ j5 L) I9 @7 U" u
elsif ($_ =~/newpwd2/)+ W* {) _+ \% f6 Z* D& i/ N3 I" K
{$newpwd2= substr($_, $eqpos + 1);}3 n/ G6 w" g. r8 u* s6 c+ t, }
elsif ($_ =~/btn_change/)
# Y4 r" I3 e$ S* c$ I; W' ]{$btn_change = substr($_, $eqpos + 1);}  g* N( r' t& G5 K
elsif ($_ =~/btn_reset/)' L; N1 ~  p! n* Q6 A$ E
{$btn_reset = substr($_, $eqpos + 1);}
$ j+ Q3 [" W1 p$ O. y3 w% `9 Qelsif ($_ =~/changepwdok/)
' W* D, _1 g; G9 r. a8 p{$changepwdok = substr($_, $eqpos + 1);}
' o, H4 N0 t5 x- V7 I& w, zelsif ($_ =~/changepwdfailed/)
3 \7 Z  L$ ^1 ^3 O{$changepwdfailed = substr($_, $eqpos + 1);}
+ n% y& ]/ G. h+ @/ {# Belsif ($_ =~/oldpwderror/)* U8 U# u: e  X2 I& K) k' k
{$oldpwderror = substr($_, $eqpos + 1);}% r. I8 M1 B& ^9 N+ ?+ y. l6 {
elsif ($_ =~/passmustgreater/)
8 B1 x0 u6 g4 V6 d( M{$passmustgreater = substr($_, $eqpos + 1);}
2 x8 q7 a& C$ ^& P, Kelsif ($_ =~/twopassnotmatched/)% v7 p8 f, ?% g1 ?. o
{$twopassnotmatched = substr($_, $eqpos + 1);}- F* O0 l! ^) h( `
elsif ($_ =~/entername/)
' |( T! l! i! r( W- t8 O0 i{$entername = substr($_, $eqpos + 1);}
  j( [; q) J1 Ielsif ($_ =~/enterpwd/)& X. y) U% }$ V4 N  B% [; w
{$enterpwd= substr($_, $eqpos + 1);}
: b/ ?) O1 V" G  g3 Jelsif ($_ =~/errorpwd/)" u9 R2 H) K8 |4 F
{$errorpwd= substr($_, $eqpos + 1);}! [: x' _: g5 z' f, g( g( F
elsif ($_ =~/back/)
3 C+ w# G2 Y% Z& f& [8 [{$back = substr($_, $eqpos + 1);}5 y. Q1 R3 I6 R8 C; h
}7 Q$ U. g0 @3 [6 {* s, ~
close CGI_INI_FILE;" H- Z- M! J4 F+ I  N/ c" R6 Q
}" U- \/ Q1 W# ^- y# g# o: Q) z
sub Index_Html
3 ]9 a/ C% i0 g% A7 O! R5 K{
- |5 R; M4 k' Y6 Z. ?+ D* z) y2 }* eprint "Content-type: text/html\n\n";
4 l; B0 y" S% P# S9 q$ Z6 kprint <<END_OF_PAGE;
+ s  M4 x" W$ C0 Z- [8 r  w<html >3 _. |  t9 X( `/ R( X% ^, |5 e
<head>! g+ Y" Q$ O1 q8 P6 y
<title>$title</title>% g$ T8 W/ T; o4 P6 T
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
4 ?. @& K9 g* N6 O</head>/ y# X1 L! l# d+ ~( M" x. B) X
<body>
& |; S- F6 M# j<HR>
8 z' X8 @  _" |* y
. n& X" B. X1 b2 Y# Z* P<center><h1>$description</h1>
- j$ W" A! f  X2 W+ \' e: T</center>6 c7 A$ @. f; e  l$ X( ]
<form method="POST" enctype="multipart/form-data" action="/cgi-bin/ChangePasswd.cgi">- e( q" }. q* n) e  [) N
<br>2 Y- _/ s  |8 v% v$ `4 @2 e
<TABLE align="center">8 }# `5 o) w. e8 V
<TR><TD class="t_text">$yourname</TD><TD><input type="text" name="UserName" /></TD></TR>
$ @5 ]/ N1 D! a6 j3 Q<TR><TD class="t_text">$oldpwd</TD><TD><input type="password" name="OldPwd" /></TD></TR>) J4 f$ M% e1 Z( i8 z
<TR><TD class="t_text">$newpwd1</TD><TD><input type="password" name="NewPwd1" /></TD></TR>; x5 y; D* s; w. V
<TR><TD class="t_text">$newpwd2</TD><TD><input type="password" name="NewPwd2" /></TD></TR>& R/ m  n2 o' ^2 E1 F
</TABLE>3 E. _1 c7 v' n) _6 B4 h
<br>% e* J) v, B- B* h% p
<TABLE align="center">
5 ~9 ^" B7 T) U2 w' g: |. m+ V<TR><TD><input type="submit" name="chgpasswd" value="$btn_change"> <input type="reset" value="$btn_reset"></TD></TR>: U7 \2 m' ~( ?7 }0 W+ m9 M6 ?$ h
</TABLE>
" @# Z; p3 [+ q) W$ V</form>
0 s2 z! d. g) I<HR>
$ e6 q' c8 s" V" q/ H& B<center><font color="#FF0000">注意:新密码位数必需大于$pwdminlen,且为字母与数字组合</font>7 J6 J- s* L3 w9 H8 a$ R6 N( f, u
</body>
* e: c8 t  g# K5 W" K- V; q& Q: w8 S% ?</html>
# l6 w+ ^- u1 ]/ I) ~END_OF_PAGE
# K& N: u$ a+ a2 G}! m, w8 E6 x- y% L
sub otherhtml{
, f, q$ h' n& N" K+ q% Mprint "Content-type: text/html\n\n";
. t9 H. \: H# A2 r' Eprint <<END_OF_PAGE;! [: E" {* W, V; b6 n# g2 ^3 \
<html>
. f* v+ z: X1 m9 g2 p1 R<head>
! B) k  k' s+ Z% m/ m5 |% w<meta http-equiv="Content-Language" content="zh-cn">
9 K9 W. w$ `- Y0 ]<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
9 I6 q; j7 R+ [5 }4 k<title>$_[0]</title>! P0 b, {9 G  ?) X
</head>: p8 p) p% d8 O# C3 \$ Z8 a
<body>
9 }3 s; n3 |1 o4 i. N% l* I<p align="center"><font size="5">$_[1]</font></p>/ }6 y' \. H0 l& V! a& D
<p align="center"><a href="/cgi-bin/ChangePasswd.cgi"><font size="4">$_[2]</font></a></p>" E& Z  j- i# V
<HR>+ Y- K5 [3 j$ J0 I8 C4 {( C
<center>
. s+ O$ ]* I3 c/ m$ q) |<P>如有问题请与管理员联系E-Mail: <A HREF="$admin_email.0 {9 ?, I# N# k' s7 t2 Z/ X3 k
mailto:$admin_email">$admin_email</A>.</P></center>9 D  _, G# H/ d% p4 M) t( Y1 l
, q9 ^# T9 }3 A# `- x
</body>  Y: f0 u6 [9 l4 B: U" a( U
  
, w  C5 J; M$ @8 i" M</html>
6 e' k9 p- Y3 BEND_OF_PAGE
  q4 m& }+ n/ K( y8 r2 d. d}
$ H4 R$ j3 {- q8 [/ ^1 t9 Esub Writer_Log{
# b  z0 j4 N" N' z" J. Q2 fif($logfile)
& U! x1 N. F1 }" e* M{
$ l1 `# A  ~# M9 t5 imy $loginfo ="[".$time."] "." [".$remote_id."] "." || ".$_[0];" h0 s' X0 Z& j! ?
open LOGFILE,">>$logfile" or die "Couldn't open LOG FILE for writing: $!";
) t8 Z" }% x, [9 s# |$ Q% iprint LOGFILE ("$loginfo\n");
! L1 h3 m" {$ H+ h7 Kclose LOGFILE;+ P( a3 {$ t$ Q: Y
}
) |# k6 k; B$ W, q}
' G* Z. O% E8 U+ a0 y% t1 G# J+ O  o) b; h
ChangePasswd.ini:文件内容. S' b) K( L4 _; v% n
[path]8 K3 e+ u) V9 V% u7 ?. B
authuserfile=/data/svn/passwd. x) X0 ~# k- q) `' l1 V& k: `
logfile=/var/www/cgi-bin/ChangePasswd.log1 A& H5 e2 P) Q2 w9 y
[setup]2 ?6 @  F2 d7 i: k
pwdminlen=61 y* u3 S2 ^  c. j4 V
[html]
6 o& D3 ?2 `4 M8 Ctitle=SVN用户密码自助修改
. k7 J% e8 \4 `) O% I+ Ndescription=SVN用户密码自助修改# m& n; K+ ]8 T, Z; u$ N
yourname=用户名:
; k# a$ y' P0 [oldpwd=旧密码:
  n. r9 J+ {5 O! g3 V  e  [8 F$ cnewpwd1=新密码:# O, j; E* d5 \9 A" y
newpwd2=确认新密码:# p9 A7 S" b7 V
btn_change=修 改; t" [, ^( W* n9 V% j+ u
btn_reset=重 置
, R  Q7 v2 v) W" v9 ~changepwdok=修改密码成功. h. F+ \7 Z7 \1 O$ ^/ m! j7 P
changepwdfailed=修改密码失败# q0 y+ y9 g$ B7 `+ h
servererror=服务器错误$ s6 \" d& G# B4 Q# h2 M  C( w
passmustgreater=新密码位数必须大于: o- @" _* t9 ?+ M2 L3 a
twopassnotmatched=两密码不一致& F0 e  F0 u% h8 \8 ^, r, ]
entername=请输入用户名; R! G  S( L5 F4 G9 V+ }
enterpwd=密码未输入
( |& r7 G- r% u- Terrorpwd=你的密码不正确) M9 [6 ]& N9 n) R8 v1 |% H
back=返回
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

SCMLife推荐上一条 /4 下一条

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

GMT+8, 2018-9-19 23:30 , Processed in 0.056932 second(s), 6 queries , Gzip On, MemCache On.

Powered by SCMLife X3.4 Licensed

© 2001-2017 JoyShare.

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