⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addaccount.cgi

📁 最新的仙镜传说服务器C语言源码
💻 CGI
字号:
#!/usr/bin/perl

#=========================================================================
# addaccount.cgi  ver.1.00  by 層挶棖
#	ladmin傪儔僢僾偟偨丄傾僇僂儞僩傪嶌惉偡傞CGI丅
#	ladmin ver.1.04偱偺摦嶌傪妋擣丅
#
# ** 愝掕曽朄 **
#
# - 壓偺$ladmin曄悢偵ladmin傊偺僷僗傪愝掕偡傞偙偲丅
# - 僒乕僶乕僾儘僌儔儉傗僽儔僂僓偵傛偭偰偼 $cgiuri 偵偙偺僼傽僀儖傊偺
#   姰慡側URI傪僙僢僩偟側偗傟偽側傜側偄応崌傕偁傞丅
# - perl偵僷僗偑捠偭偰偄側偄応崌偼 $perl 傪perl傊偺惓偟偄僷僗偵偡傞偙偲丅
# - 懠偼晛捠偺CGI偲摨偠丅乮幚峴尃傗cgi-bin僼僅儖僟側偳乯
#
# ** 偦偺懠 **
#   addaccount.cgi 傪僽儔僂僓偱奐偔偲僒儞僾儖HTML乮偦偺傑傑巊偊傑偡乯偑
#   奐偒傑偡丅傑偨丄偙偺cgi偼僽儔僂僓偐傜憲傜傟傞Accept-Language偑
#   ja偱巒傑偭偰偄傟偽儊僢僙乕僕偺堦晹傪擔杮岅偵曄姺偟傑偡丅
#   (IE側傜僀儞僞乕僱僢僩僆僾僔儑儞偺尵岅愝掕偱堦斣忋偵擔杮岅傪抲偔)
#	偦傟埲奜偺応崌偼塸岅偺傑傑弌椡偟傑偡丅
#-------------------------------------------------------------------------

my($ladmin)	= "../ladmin";			# ladmin偺僷僗(偍偦傜偔曄峏偑昁梫)

my($cgiuri)	= "./addaccount.cgi";	# 偙偺僼傽僀儖偺URI
my($perl)	= "perl";				# perl偺僐儅儞僪柤



#--------------------------- 愝掕偙偙傑偱 --------------------------------






use strict;
use CGI;

my($cgi)= new CGI;
my(%langconv)=(
	'Athena login-server administration tool.*' => '',
	'logged on.*' => '',
);

# ----- 擔杮岅娐嫬側傜曄姺僥乕僽儖傪僙僢僩 -----
if($ENV{'HTTP_ACCEPT_LANGUAGE'}=~/^ja/){
	my(%tmp)=(
		'Account \[(.+)\] is successfully created.*'
			=> '傾僇僂儞僩 "$1" 傪嶌惉偟傑偟偨.',
		'Account \[(.+)\] creation failed\. same account exists.*'
			=> '傾僇僂儞僩 "$1" 偼婛偵懚嵼偟傑偡.',
		'Illeagal charactor found in UserID.*'
			=> 'ID偺拞偵晄惓側暥帤偑偁傝傑偡.',
		'Illeagal charactor found in Password.*'
			=> 'Password偺拞偵晄惓側暥帤偑偁傝傑偡.',
		'input UserID 4-24 bytes.'
			=> 'ID偼敿妏4乣24暥帤偱擖椡偟偰偔偩偝偄.',
		'input Password 4-24 bytes.'
			=> 'Password偼敿妏4乣24暥帤偱擖椡偟偰偔偩偝偄.',
		'Illeagal gender.*'
			=> '惈暿偑偍偐偟偄偱偡.',
		'Cant connect to login server.*'
			=> '儘僌僀儞僒乕僶乕偵愙懕偱偒傑偣傫.',
		'login error.*'
			=> '儘僌僀儞僒乕僶乕傊偺娗棟幰尃尷儘僌僀儞偵幐攕偟傑偟偨',
		"Can't execute ladmin.*"
			=> 'ladmin偺幚峴偵幐攕偟傑偟偨',
		'UserID "(.+)" is already used.*'
			=> 'ID "$1" 偼婛偵巊梡偝傟偰偄傑偡.',
		'You can use UserID \"(.+)\".*'
			=> 'ID "$1" 偼巊梡壜擻偱偡.',
		
		'account making'	=>'傾僇僂儞僩嶌惉',
		'\>UserID'			=>'>俬俢',
		'\>Password'		=>'>僷僗儚乕僪',
		'\>Gender'			=>'>惈暿',
		'\>Male'			=>'>抝惈',
		'\>Female'			=>'>彈惈',
		'\"Make Account\"'	=>'"傾僇僂儞僩嶌惉"',
		'\"Check UserID\"'	=>'"ID偺僠僃僢僋"',
	);
	map { $langconv{$_}=$tmp{$_}; } keys (%tmp);
}

# ----- 捛壛 -----
if( $cgi->param("addaccount") ){
	my($userid)= $cgi->param("userid");
	my($passwd)= $cgi->param("passwd");
	my($gender)= lc(substr($cgi->param("gender"),0,1));
	if(length($userid)<4 || length($userid)>24){
		HttpError("input UserID 4-24 bytes.");
	}
	if(length($passwd)<4 || length($passwd)>24){
		HttpError("input Password 4-24 bytes.");
	}
	if($userid=~/[^0-9A-Za-z\@\_\-\']/){
		HttpError("Illeagal charactor found in UserID.");
	}
	if($passwd=~/[\x00-\x1f\x80-\xff\']/){
		HttpError("Illeagal charactor found in Password.");
	}
	if($gender!~/[mf]/){
		HttpError("Gender error.");
	}
	open PIPE,"$perl $ladmin --add $userid $gender $passwd |"
		or HttpError("Can't execute ladmin.");
	my(@msg)=<PIPE>;
	close PIPE;
	HttpMsg(@msg);
}
# ----- 懚嵼僠僃僢僋 -----
elsif( $cgi->param("check") ){
	my($userid)= $cgi->param("userid");
	if(length($userid)<4 || length($userid)>24){
		HttpError("input UserID 4-24 bytes.");
	}
	if($userid=~/[^0-9A-Za-z\@\_\-\']/){
		HttpError("Illeagal charactor found in UserID.");
	}
	open PIPE,"$perl $ladmin --search --regex \\b$userid\\b |"
		or HttpError("Can't execute ladmin.");
	my(@msg)=<PIPE>;
	close PIPE;
	if(scalar(@msg)==6 && (split /[\s\0]+/,substr($msg[4],11,24))[0] eq $userid){
		HttpMsg("NG : UserID \"$userid\" is already used.");
	}elsif(scalar(@msg)==5){
		HttpMsg("OK : You can use UserID \"$userid\"");
	}
	HttpError("ladmin error ?\n---output---\n",@msg);
}

# ----- 僼僅乕儉 -----
else{
	print LangConv( <<"EOM" );
Content-type: text/html\n
<html>
 <head>
  <title>Athena account making cgi</title>
 </head>
 <body>
  <h1>Athena account making cgi</h1>
  <form action="$cgiuri" method="post">
   <table border=2>
    <tr>
     <th>UserID</th>
     <td><input name="userid" size=24 maxlength=24></td>
    </tr>
    <tr>
     <th>Password</th>
     <td><input name="passwd" size=24 maxlength=24 type="password"></td>
    </tr>
    <tr>
     <th>Gender</th>
     <td>
      <input type="radio" name="gender" value="male">Male
      <input type="radio" name="gender" value="female">Female
     </td>
    </tr>
    <tr>
     <td colspan=2>
      <input type="submit" name="addaccount" value="Make Account">
      <input type="submit" name="check" value="Check UserID">
     </td>
    </tr>
   </table>
  </form>
 </body>
</html>
EOM
	exit;
}

sub LangConv {
	my(@lst)= @_;
	my($a,$b,@out)=();
	foreach $a(@lst){
		foreach $b(keys %langconv){
			$a=~s/$b/$langconv{$b}/g;
			my($rep1)=$1;
			$a=~s/\$1/$rep1/g;
		}
		push @out,$a;
	}
	return @out;
}

sub HttpMsg {
	my($msg)=join("", LangConv(@_));
	$msg=~s/\n/<br>\n/g;
	print LangConv("Content-type: text/html\n\n"),$msg;
	exit;
}

sub HttpError {
	my($msg)=join("", LangConv(@_));
	$msg=~s/\n/<br>\n/g;
	print LangConv("Content-type: text/html\n\n"),$msg;
	exit;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -