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

📄 selectconf.cgi

📁 XYZ投票统计系统1.5C版
💻 CGI
字号:
#!/usr/bin/perl
###########################################################################
#CGI脚本名称:XYZ投票统计系统1.5C版,用于WWW网站建立投票调查统计系统。
#Copyright (C) 2000  Yu Ning Chen
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#############################################################################

$url='select/';                                      #设置存放记录的目录,用户自行设置
$select_cgi_url='http://zjxyz/cgi-bin/select.cgi';   #根据用户自行设置
$conf_cgi_url='http://zjxyz/cgi-bin/selectconf.cgi'; #根据用户自行设置
$adduser=1;  #是否允许添加用户,不允许就设置为0
$filelock=0; #是否需要在读写文件时对文件锁定,需要就设置为1,在windows下要设置为0,否则不能正常运行。


print "Content-type: text/html\n";
print "Pragma:no-cache\n\n";

#uncode begin
if ($ENV{'REQUEST_METHOD'} eq "POST") {          
   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;
    $A{$name} = $value;}

# # # # # 处理环境参数 # # # #
$buffer=$ENV{'QUERY_STRING'};
@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;
    $A{$name} = $value;}

if ($A{'ID'}=~/[\||<|>|\s+|\\|\/|\?|\*|\$|\n|\r|&]/){
    print "输入信息中含有非法字符<P>程序终止";
    exit0;}

#get files path of the id
 $selects="$url$A{'ID'}_select.txt";
 $selectconf="$url$A{'ID'}_selectconf.txt";
 $countrecord="$url$A{'ID'}_count.txt";

#---------- main bigin -----------
if (($ENV{'QUERY_STRING'} eq 'adduser')){
 if($adduser==0){
   print "不允许加入新用户";
   exit 0;}

  $passwd=crypt($A{'PASSWD'},'hy');
  &creact;
  &writeconf;

if( (-e $selects)&&(-e $selectconf)&&(-e $countrecord) ){
print "创建新投票组成功!以下是投票代码:";
   &readdata;
   &getcodes;}
else{
   print "创建新投票组失败,请与管理员联系";}
exit 0;}



&readdata;
print "<title>$title投票管理界面</title>";
print "<p align=center>$title投票管理界面</p>";

if ($A{'E1'} eq 'getcodes'){
   &getcodes;
   exit 0;}


if ($ENV{'QUERY_STRING'} eq 'write'){
   if ($A{'PASSWD'} ne $passwd){
       print "passwd error";
       exit 0;}
   &writeconf;
   &writeselect;
   &readdata;
   $A{'PASSWD'}=$passwd;
   print "<p align=center>修改设置成功!如果是使用一般模式请重新<a href='$conf_cgi_url?E1=getcodes&ID=$A{'ID'}'>取得投票代码</a></p>";
   &passed;
   exit 0;}

###### PASSWD #########
$A{'PASSWD'}=crypt($A{'PASSWD'},'hy');# # DES
&readdata;

if ($A{'PASSWD'} ne $passwd){
   print "passwd error";
   exit 0;}
print "<p align=center><a href='$conf_cgi_url?E1=getcodes&ID=$A{'ID'}'>取得投票代码</a></p>";

&passed;
exit 0;
#---------- main end -----------

################################################################################
############    写入 userID_select.txt  模块   sub writeselect    ##############
################################################################################

sub writeselect{  # # # 写入记录文件 userID_select.txt # # #

$k=0;

open (WRselect,">$selects");
if ($filelock){flock(WRselect,2);}

  for ($j=0;$j<$i;$j++){

   next if ($A{$form[$j]}=~/on/i);

    if($forms{$A{'T'.$k}} eq ''){
       $tem=$forms{$name[$k]};   #判断为移动,保持移动后的数据不变
       $forms{$name[$k]}=0;
    }    
   else{
       $tem=$forms{$A{'T'.$k}};  #判断为改名,保持改名后的数据不变
       $forms{$A{'T'.$k}}=0;
   }   

if($tem eq ''){
  $tem=0;}                     #判断为新增,置0

print WRselect "$form[$k],$A{'T'.$j},$tem,\n"; #####    写入 ######

#注:$forms{$name[$k]} 实际是 $forms{$name[$k]} 的票数,这个关系在是在前面建立的
    $k++;
  }#end for

# # # # 增加投票项

for ($add=1;$add<=3;$add++){
   if ($A{'add'.$add} ne ''){
      $k++;
      print WRselect "C$k,$A{'add'.$add},0,\n";}

}# end for

if($filelock){flock(WRselect,8);}
close(WRselect);

}#end writeselect sub


##############################################################################
############    写入 userID_selectconf.txt 模块  sub writeconf   #############
##############################################################################
sub writeconf{

if ($A{newpasswd1} ne ''){

    if($passwd eq crypt($A{'oldpasswd'},'hy')&&($A{newpasswd1} eq $A{newpasswd2})){
        $passwd=crypt($A{newpasswd1},'hy');}
    else{
    print "<p align=center>修改密码错误,为了保障你的数据,投票数据也没有被修改</p>";
    exit 0;} 
}
 open (WRconf,">$selectconf");
 if ($filelock){flock(WRconf,2);}

    print WRconf "$A{'TITLE'}\n";
    print WRconf "$passwd\n";   
    print WRconf "iplock=$A{'IPLOCK'}\n";
    print WRconf "sm=$A{'SM'}\n";
    print WRconf "dspmod=$A{'NEWWIN'}\n";

if($filelock){flock(WRconf,8);}
 close(WRconf);
} #end writeconf sub


#############################################################################
############      读取两个数据文件  模块    sub readdata   ##################
##############################3##############################################

sub readdata{ 
open (REconf,"$selectconf");# 读取设置文件 userID_selectconf.txt
 if ($filelock){flock(REconf,1);}
$title=<REconf>;
$passwd=<REconf>;

$iplock=<REconf>;
$sm=<REconf>;
$newwin=<REconf>;
if($filelock){flock(REconf,8);}
close(REconf);

chop($passwd);
open(RE,"$selects"); # 读取记录文件 userIDselect.txt
if($filelock){flock(RE,1);}

$i=0;
 while($re=<RE>){

  ($form[$i],$name[$i],$count[$i])= split(/,/, $re);  
     $forms{$name[$i]}=$count[$i];  
    $i++;
 }#end while
if($filelock){flock(RE,8);}
close (RE);
}#end readdata sub


#######################################################################
#############          创建新用户   模块    sub creact  ###############
#######################################################################

sub creact{
if (-e $selects){
   print "这个帐号已存在<br>";
   exit 0;}

if($A{'PASSWD'} ne $A{'CHECKPASSWD'}){
   print "确认密码出错请重新来过";
   exit 0;}

$i=10;
$k=0;

open(WRselect,">$selects");
if($filelock){flock(WRselect,2);}

for ($j=0;$j<$i;$j++){

  if ($A{'T'.$j} ne ''){
    print WRselect "C$k,$A{'T'.$j},0,\n";
    $k++;}#end if
}#end for
if($filelock){flock(WRselect,8);}
close(WRselect);

open (WRcount,">$countrecord");
if ($filelock){flock(WRcount,2);}

 print WRcount 0;
if($filelock){flock(WRcount,8);}
close(WRcount);

}#end creact sub

#######################################################################
############         进入管理界面  模块    sub passed   ###############
#######################################################################

sub passed{

##########  设定表单中有关 IP 锁定的值 ####

if ($iplock=~/yes/i){
   $iplocky='checked';
   $iplockn='';}
else{
   $iplocky='';
   $iplockn='checked';}

##########  设定表单中有关 单项或多项选择 的值 ####
if ($sm =~/mu/i){
   $smm='checked';
   $sms='';}

else{
   $smm='';
   $sms='checked';}

##########  设定表单中有关 显示投票方式 的值 ####
if ($newwin =~/new/i){
   $m1='checked';
   $m2='';}
else{
   $m1='';
   $m2='checked';}
print "<div align=center><center><table border=1 width=80% cellpadding=10 cellspacing=0><tr><td width=50% valign=top align=center>";
print "<form method='POST' action='$conf_cgi_url?write'>";
print "<p>投票项名称(标题):<br><input type='text' name=TITLE value=$title><br>";
print "<p>是否需要IP限制投票:<br>是<input type='radio' $iplocky name='IPLOCK' value='yes'>否<input type='radio' $iplockn name='IPLOCK' value='no'><br>";
print "<p>投票类型是:<br>复选<input type='radio' $smm name='SM' value='mu'>单选<input type='radio' $sms name='SM' value='si'><br>";
print "<p>显示投票结果的方式:<br>新窗口<input type='radio' $m1 name='NEWWIN' value='new'>原窗口<input type='radio' $m2 name='NEWWIN' value='old'><br>";
print "<p>更改密码<br>输入旧密码:<input type='password' name='oldpasswd' size='10'><br>";
print "输入新密码:<input type='password' name='newpasswd1' size='10'><br>";
print "确认新密码:<input type='password' name='newpasswd2' size='10'><br></td>";
print "<td width='50%' valign='top'>选择删除<br>";


for ($j=0;$j<$i;$j++){
 print "<input type='checkbox' name='$form[$j]' value='ON'>\n";
 print "<input type='text' name='T$j' size='20' value='$name[$j]'>==>$count[$j]<br>\n"; ### check

}# end for

print "增加投票项:<input type='text' name='add1' size='20'><br>";
print "增加投票项:<input type='text' name='add2' size='20'><br>";
print "增加投票项:<input type='text' name='add3' size='20'>";
print "<input type='hidden' name='ID' value=$A{'ID'}><br>\n";
print "<input type='hidden' name='PASSWD' value=$A{'PASSWD'}><br>\n";
print "</td></tr></table>";
print '<br><input type="submit" value="提交" name="B1"><input type="reset" value="复原" name="B2">';
print "</form></center></div>";
print '<div align=center>该投票系统由<a href="http://zjxyz.yeah.net" target="_blank">CGI编程设计室</a>制作,你可以在该网站免费得到本CGI程序。</div>';
}#end passed sub


#######################################################################
############      取得投票代码    模块   sub getcodes    ##############
#######################################################################

sub getcodes{

if ($sm=~/mu/i){
    $type='checkbox';
    $sw1='name';
    $sw2='value=ON';}
 else{
    $type='radio';
    $sw1='value';
    $sw2='name=RR';}

print "<div align='center'><center><table border='1' width='80%'><tr><td width='100%' align=center>";
print "<p>这是简单模式的代码:<br>";
print "<p><form><textarea rows=3 name=code1 cols=70 wrap=physical><script language=JavaScript1.1 src='$select_cgi_url?B3=easymode&ID=$A{'ID'}'></script></textarea></p>";
print "这是一般模式的代码,你可以自由编辑表单的位置令其美观些,<br>但不要修改其值及相关的脚本代码<br>";
print "<textarea rows=16 name=S1 cols=70 wrap=physical>";
print "<form method=POST action name=$A{'ID'} ID=$A{'ID'}>"; #plug poin
print "<p>$title</p>";
for ($j=0;$j<$i;$j++){
print "<input type=$type $sw1=$form[$j] $sw2>$name[$j]<br>";}#plug poin
print "<p><input type=button value=投票 name=B1  onclick='$A{'ID'}_atshow();'>";
print "<input type='button' value=结果 name=B2 onclick='$A{'ID'}_show();'></p>";
print "<p><script language=JavaScript1.1 src=$select_cgi_url?B3=B3&amp;ID=$A{'ID'}></script>";#plug poin
print "<script language='JavaScript'>";

if ($newwin!~/old/){
    print "var $A{'ID'}_new_win=1;";}
else {
print "var $A{'ID'}_new_win=0;";}
print "var $A{'ID'}=null;";
print "$A{'ID'}_len=document.$A{'ID'}.length-2;$A{'ID'}_Flag=1;";#plug poin
print "function $A{'ID'}_atshow(){if($A{'ID'}_Flag==0){";
print "alert('谢谢!你已经投过一次票了,请下次再来!');return 0;}";
print "a='$select_cgi_url?ID=$A{'ID'}&B1=B1&';$A{'ID'}_k=0;";
print "for(j=0;j<$A{'ID'}_len;j++){if(document.$A{'ID'}.elements[j].checked==true){";#plug poin

###########
if ($type eq 'checkbox'){
  print "tem=document.$A{'ID'}.elements[j].name;$A{'ID'}_k=1;}";
  print "else tem='F';a+=document.$A{'ID'}.elements[j].name+'='+tem+'&';}";}
else {
  print "tem=document.$A{'ID'}.elements[j].value;$A{'ID'}_k=1;}";
  print "else tem='F';a+=document.$A{'ID'}.elements[j].value+'='+tem+'&';}";}
#############
print "if($A{'ID'}_k==0){$A{'ID'}_Flag=1;alert('对不起,你还没有选择你的投票项!');return 0;}$A{'ID'}_Flag=0;";
print "if ($A{'ID'}_new_win==1){$A{'ID'}=window.open(a,'$A{'ID'}','width=350,height=400,resizable=1,scrollbars=yes');}";
print "else{this.location.href = a;}}";
print "function $A{'ID'}_show(){";
print "a='$select_cgi_url?B2=B2&ID=$A{'ID'}';";
print "if ($A{'ID'}_new_win==1){$A{'ID'}=window.open(a,'$A{'ID'}','width=350,height=400,resizable=1,scrollbars=yes');}";
print "else{this.location.href = a;}}";
print "</script></form>";
print "</textarea></form><br><br></p>";
print "</td></tr></table></center></div>";
print '<div align=center><br>该投票系统由<a href="http://zjxyz.yeah.net" target="_blank">CGI编程设计室</a>制作,你可以在该网站免费得到本CGI程序。</div>';
}#end sub getcodes

⌨️ 快捷键说明

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