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

📄 public.cgi

📁 这个是分屏聊天室源码。需要分屏的聊天室请参考
💻 CGI
字号:
###############################################
#过滤掉输入中的 html 数据
###############################################
sub filterhtml {
local($return)=$_[0];
$return =~ s/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
   $return =~ s/<([^>]|\n)*>//g;
   $return =~ s/\\//g;
   }
return $return; }
####################################
#设置值的格式
####################################
sub setvaluetoform {
if ($FORM{$_[0]}) { $FORM{$_[0]}="$FORM{$_[0]}§$_[1]"; }
else {  $FORM{$_[0]}=$_[1]; } }
#########
#取出变量
sub get_var {
local($return)="";
$return="$FORM{$_[0]}" if ($FORM{$_[0]});
$return=~ s/$_[1]//g;
return $return; }
#########################################
# 读数据
#########################################
sub get_form {
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach (@querys) {
  ($name,$value) = split(/=/, $_);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value = &filterhtml($value) if (!(($name eq "says")||($name eq "sysmess")));
  &setvaluetoform($name, $value); }

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value = &filterhtml($value) if (!(($name eq "says")||($name eq "sysmess")));
  &setvaluetoform($name, $value);  }
}
#########
#读文件函数
sub readtxtfile {
open(READTXTFILE,"$filehead$_[0]");
flock(READTXTFILE,2) if ($unixsys == 1);
	@readtxtdata=<READTXTFILE>;
flock(READTXTFILE,8) if ($unixsys == 1);
close(READTXTFILE);
return @readtxtdata; }
sub readtxtfile2 {
local($textfile)=$_[0];
open(READTXTFILE,"<$textfile");
flock(READTXTFILE,2) if ($unixsys == 1);
	$readltxtfile=<READTXTFILE>;
flock(READTXTFILE,8) if ($unixsys == 1);
close(READTXTFILE) ;
return $readltxtfile; }
#########
#读用户文件函数
sub readuserfile {
open(READTXTFILE,"$userhead$_[0]$userext");
$readtxtdata=<READTXTFILE>;
close(READTXTFILE);
return $readtxtdata; }
#########
#读名单文件函数
sub readlinefile {
open(READTXTFILE,"$linehead$_[0]");
$readtxtdata=<READTXTFILE>;
close(READTXTFILE);
return $readtxtdata; }
#############
# 检查变量为空的情况
sub checkempty {
local($chkval)=$_[0];
$chkval =~ s/ |<br>|\n//g;
&error($_[1]) if ($chkval eq ""); }
##########
#错误输出文件
sub error { &sysprompt("错误: $_[0]"); }
#########################
#成功输出文件
sub success { &sysprompt("成功: $_[0]");}
#####################################
#数据赋值,并进行数据合法性检查
sub set_var {
$job              =&get_var('job'            ,'\n|‖');
$usersex          =&get_var('usersex'        ,'\n|‖');
$towhoway         =&get_var('towhoway'       ,'\n|‖');
$towho            =&get_var('towho'          ,'\n|‖');
$says             =&get_var('says'           ,"$bd_wd");
$addwordcolor     =&get_var('addwordcolor'   ,'\n|‖');
$addsays          =&get_var('addsays'        ,'\n|‖');
$addsign          =&get_var('addsign'        ,'\n|‖');
$changelogouturl  =&get_var('changelogouturl'  ,'\n|‖');
$userpassword     =&get_var('userpassword','\n|"|<|>|\&|;| |\?|‖');
$usersex = "Boy" if ($usersex ne "Girl");
$username = &get_var('username' ,'\n|"|<|>|\&|;| |\?|‖|\?|\_|\*|\%|\@|\!|\~|\^|\#|\{|\}|\[|\]|\.|');
$username=~ s/$bd_wd//g;

$userip=$ENV{'REMOTE_ADDR'};
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time+(3600*$time_hour)+($time_min*60));
$monn=$monn+1;
$yearn = $yearn + 1900;
if ($monn<10)  {$monn="0$monn";}
if ($dayn<10)  {$dayn="0$dayn";}
if ($hourn<10) {$hourn="0$hourn";}
if ($minn<10)  {$minn="0$minn";}
if ($secn<10)  {$secn="0$secn";}
$daten="$yearn/$monn/$dayn";
$timen="$hourn\:$minn\:$secn";
$dnsecn = $secn;
$secn=time;
$userinfo="&username=$username";
$userinfo="$userinfo&usersex=$usersex" if ($usersex ne ""); 
if (($userpassword ne "")&&($job eq "login")) {
	$tempassword = crypt($userpassword,"DN");
	$userinfo="$userinfo&userpassword=$tempassword"; }
else {$userinfo="$userinfo&userpassword=$userpassword";}
&send_html; #输出html头
}
###########################################
#利用名单文件进行密码检查
###########################################
sub check_password {
	$linefile = "$linehead$username";
	$sflag	= 0;
	if (not -e $linefile ) {
		if (($_[0] eq "show")||($job eq "online")||($job eq "says")) { 
			&dn_sprompt("top.location ='$cgiurl$login?$userinfo&changelogouturl=$logouturl&job=logout';");	}
		else { &error("$username, 您已经脱机,请重新登录") ; }
	}
	$temline = &readtxtfile2($linefile,$lockfilename);
	&readlinedata($temline);
	$userlevel = 0;
	$smalladmin  = 0;
	$find_id     = 0;
	if (($username eq $chkusername) && ($userpassword eq $chkuser_password)) {
		$userlevel = $chkuserlevel;	$smalladmin = $chkuser_samll; $chkpass = $chkuser_pass;
		$chksecn = time();
		$chktimen = $timen;
		$find_id = 1 if ($username eq $superuser);
		$dnlastno = $chkdnlastno;
		$sflag = $chksflag;
		if ($_[0] eq "show") {
			&getsysnum;
			$chkdnlastno = $lastno; }
		&writelinedata; 
	}
	else { $chkpass = 0;}

	#错误登录
	if ( $chkpass == 0 ){ 
		if (($_[0] eq "show")||($job eq "online")||($job eq "says")) { 
			&dn_sprompt("top.location ='$cgiurl$login?$userinfo&changelogouturl=$logouturl&job=logout';");}
		else { &error("$username 密码错误,请重新登录") ; }
	}
	# 赋权限
	$allow_html=1 if ($userlevel>=$level_html);
}
########################################################################
#取用户信息号码
sub getusernum { 
	&getsysnum if ($lastno eq "");
	$linefile = "$linehead$username";
	&dn_sprompt("top.location ='$cgiurl$login?$userinfo&changelogouturl=$logouturl&job=logout';") unless(-e $linefile);
	$temline = &readtxtfile2($linefile,$lockfilename);
	&readlinedata($temline);
	$dnlastno = $chkdnlastno;
	$chkdnlastno = $lastno; 
	&writelinedata;  }
########################################################################
#取系统信息序列号
sub getsysnum {
	$numberfile = "$filehead$numfile";
	&dn_prompt("$numberfile系统序列号文件不存在") unless(-e $numberfile);
	$lastno = &readtxtfile2($numberfile,$lockfilename);
	$lastno = 1000000 if (($lastno eq "")||($lastno < 1000000 )); }
########################################################################
#写系统信息序列号
sub putsysnum {
	$numberfile = "$filehead$numfile";
	&dn_prompt("$numberfile系统序列号文件不存在") unless(-e $numberfile);
	$lastno ++ ;
	$lastno = 1000000 if (($lastno eq "")||($lastno < 1000000 ));
	open(NUMDATA,">$numberfile") || &dn_prompt("序列号无法写入 $numberfile!");
	flock(NUMDATA,2) if ($unixsys == 1);
	print NUMDATA  "$lastno"; 
	flock(NUMDATA,8) if ($unixsys == 1);
	close(NUMDATA); }
sub lockfile { }
sub unlockfile { }
#########################################################################
# 加密函数,只是针对那些不懂perl语言的网虫。欢迎提供更好的加密解密函数
#########################################################################
sub passcode {
local($ls_temp1)=$_[0];
local($ls_temp2)="";
while (length($ls_temp1) > 0) {
	$ls_temp1  = reverse($ls_temp1);
	$ls_temp2 .= pack("C",(unpack("C",$ls_temp1) - length($ls_temp1) * 2));
	$ls_temp1 = substr($ls_temp1,1,length($ls_temp1));
}
return $ls_temp2;
}
#############################
#输出html页头
sub send_html {  print "Content-type: text/html;CHARSET=gb2312\n\n"; }
sub getlinedata {
@linetem=();
$linedir=$linehead;
chop $linedir;
opendir (MEMBERDIR, "$linedir"); 
    @linelist = readdir(MEMBERDIR);
closedir (MEMBERDIR);
foreach $tline (@linelist) {
	if (($tline ne "\.")&&($tline ne "\.\.")) {
		$linefile = "$linehead$tline";
		if (-e "$linefile") { $linedata=&readlinefile($tline); push (@linetem,$linedata); }
	}
}
return @linetem; }
#########################################################################
# 取用户数据
sub readuserdata { 
	($mark,$chkusername,$chkuserpass,$chkuserlevel,$chksadmin,$chkuserexperi,$chkuseremail,$chkuserphoto,$chkcomment,$chkusersdate,$chkuseredate,$chkuserin,$chkuserout,$chkusersec)=split(/‖/,$_[0]);
}
#########################################################################
# 写用户数据
sub writeuserdata { 
open(USERDATA,">$userfile") || &error("无法创建$userfile用户文件!");
flock(USERDATA,2) if ($unixsys == 1);
print USERDATA  "userdata‖$chkusername‖$chkuserpass‖$chkuserlevel‖$chksadmin‖$chkuserexperi‖$chkuseremail‖$chkuserphoto‖$chkcomment‖$chkusersdate‖$chkuseredate‖$chkuserin‖$chkuserout‖$chkusersec‖\n"; 
flock(USERDATA,8) if ($unixsys == 1);
close(USERDATA);
}
#########################################################################
# 取名单数据
sub readlinedata { ($mark,$chkuserip,$chkusername,$chkuserlevel,$chkusersex,$chkuser_password,$chkuser_samll,$chkuser_pass,$chktimen,$chksecn,$chkdnlastno,$chkfilterlist,$chkstat,$chksflag)=split(/‖/,$_[0]); }
# 写名单数据
sub writelinedata { 
open(LINEDATA,">$linefile") || &error("无法创建 $chkusername 的在线名单文件!");
flock(LINEDATA,2) if ($unixsys == 1);
print LINEDATA  "online‖$chkuserip‖$chkusername‖$chkuserlevel‖$chkusersex‖$chkuser_password‖$chkuser_samll‖$chkuser_pass‖$chktimen‖$chksecn‖$chkdnlastno‖$chkfilterlist‖$chkstat‖$chksflag‖\n"; 
flock(LINEDATA,8) if ($unixsys == 1);
close(LINEDATA);
}
#写文件的函数
sub writetxtfile {
	local($textfile)=$_[0];
	local($textdata)=$_[1];
	$tfileexist = 1;
	if (not (-e $textfile)) { 
		 open(TEXTDATA, ">$textfile")|| die "不能建立$textfile文件"; 
		 $tfileexist = 0; }
	 else {  open(TEXTDATA, ">>$textfile")|| die "不能修改$textfile文件 ";  }
	 flock(TEXTDATA,2) if ($unixsys == 1);
	 print TEXTDATA "$textdata\n";
	 flock(TEXTDATA,8) if ($unixsys == 1);
	 close(TEXTDATA);
	 chmod(0666,"$textfile") if ($tfileexist == 0);
}
#信息窗口的提示函数
sub  dn_prompt {
print "<html><head><META HTTP-EQUIV=REFRESH CONTENT='$reloadx;URL=$cgiurl$chat?job=look$userinfo'></head><body>\n";
$promt_mess = $_[0];
$promt_mess =~ s/\"/\'/g;
if ($promt_mess ne "") {
$promt_mess = "<font color=$sysmesscolor>[系统信息]:</font><font color=$sysmesscolor>" . $promt_mess."</font>";
print "<script Language='JavaScript'>\n";
if ($sflag == 0) { print "parent.message.document.writeln(\"$promt_mess<br>\");\n"; }
else { print "parent.smessage.document.writeln(\"$promt_mess<br>\");\n"; }
print " </script>\n";
}
print "</body></html>\n";
exit;
}
#信息窗口javascript信息输出函数
sub  dn_sprompt {
print "<html><head><META HTTP-EQUIV=REFRESH CONTENT='$reloadx;URL=$cgiurl$chat?job=look$userinfo'></head><body>\n";
if ($_[0] ne "") {
	print "<script Language='JavaScript'>\n";
	if ($sflag == 0) {
		print "parent.message.document.writeln(\"<script>$_[0]\");";
		print "parent.message.document.writeln(\"</\"+\"script>\");"; }
	else {
		print "parent.smessage.document.writeln(\"<script>$_[0]\");";
		print "parent.smessage.document.writeln(\"</\"+\"script>\");"; }
	print " </script>\n"; }
print "</body></html>\n";
exit; }
#输出系统提示信息的函数,在单独的窗口内
sub sysprompt {
print <<_dnchat;
<html><head><title>$roomtitle提示信息</title>
<body bgcolor=$bg_color text=$text_color link="#FF00FF">
<br><br><div align="center">
<table width="300" border="1" bordercolorlight="#CCFFFF" bordercolordark="#000000"
bordercolor="#33CCFF" align="center" bgcolor="#99CCFF" >
  <tr><td  bgcolor="#D6D5CD" height="20"><p align="right"><font color="#000000"><SPAN style="FONT-SIZE: 14px">$roomtitle</span></font></td></tr>
  <tr><td  bgcolor="#FDF0EA" height="14"><p align="center"><font color="#0000FF"><SPAN style="FONT-SIZE: 16px">提&nbsp;示&nbsp;信&nbsp;息</span></font></td></tr>
   <tr><td bgcolor="#EFEDEF" height="16"><br><center><SPAN style="FONT-SIZE: 14px">$_[0]</span><br><br><br></center></td></tr>
  <tr><td  bgcolor="#D6D5CD"  height="20"><p align="center">
  <INPUT language=javascript onclick="javascript:window.close()" style="BACKGROUND-COLOR: DDDDFF; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: 000000; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt" type=submit value="关闭窗口">
</td> </tr></table></form>
</span><br><br><SPAN style="FONT-SIZE: 12px">技术支持&nbsp;<a href="http://deen.126.com" target="_blank"><ACRONYM TITLE='提供最酷的聊天程序,去看看了'>聊天同盟</ACRONYM></a></span>
</div></body></html>
_dnchat
exit 0; }

⌨️ 快捷键说明

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