#####################################################
#  LEO SuperCool BBS / LeoBBS X / 雷傲極酷超級論壇  #
#####################################################
# 基於山鷹(糊)、花無缺製作的 LB5000 XP 2.30 免費版  #
#   新版程式製作 & 版權所有: 雷傲科技 (C)(R)2004    #
#####################################################
#      主頁地址： http://www.LeoBBS.com/            #
#      論壇地址： http://bbs.LeoBBS.com/            #
#####################################################

$versionnumber = "<b>L<font color=#F26522>eo</font>B<font color=#00AEEF>BS</font></b> X Build050706";
$ENV{'REMOTE_ADDR'} = $ENV{'HTTP_X_FORWARDED_FOR'} if (($ENV{'REMOTE_ADDR'} eq "127.0.0.1")&&($ENV{'HTTP_X_FORWARDED_FOR'} ne "")&&($ENV{'HTTP_X_FORWARDED_FOR'} ne "unknow"));
$skin = "leobbs" if ($skin eq "");

($memdir,$msgdir,$usrdir) = split (/\|/, getdir());

sub dofilter {
    my $infiltermessage=shift;
    
    if (open (FILE, "${lbdir}data/wordfilter.cgi")) {
	$wordfilter = <FILE>;
	close (FILE);
	chomp $wordfilter;
	$wordfilter=~ s/(\.|\*|\(|\)|\||\\|\/|\?|\+|\[|\])//ig;
	$wordfilter=~ s/\t/\|/ig;
	$wordfilter=~ s/\|\|/\|/ig;
	$wordfilter=~ s/^\|//ig;
	$wordfilter=~ s/\|$//ig;
    }
    else { $wordfilter = "";}

    my $tempinfilter = $infiltermessage;
    if ($wordfilter) { $tempinfilter =~ s/$wordfilter/ *** /isg; }
    if ($tempinfilter ne $infiltermessage) { &error("有問題&你所寫的內容中也許\包含了$div_one些本論壇不准許\發佈的言論，請仔細檢查後，重新發佈，謝謝！"); }
    $tempinfilter =~ s/\&nbsp\;//ig;
    $tempinfilter =~ s/\<.+?\>//ig;
    $tempinfilter =~ s/\[.+?\]//g;
    $tempinfilter =~ s/ |　|\.|\*|\(|\)|\||\\|\/|\?|\+|\[|\]//g;
    my $tempinfilter1 = $tempinfilter;
    if ($wordfilter) { $tempinfilter1 =~ s/$wordfilter/ *** /isg; }
    if ($tempinfilter1 ne $tempinfilter) { &error("有問題&你所寫的內容中也許\包含了$div_one些本論壇不准許\發佈的言論，請仔細檢查後，重新發佈，謝謝！！"); }

    if (open (FILE, "${lbdir}data/badwords.cgi")) {
	$badwords = <FILE>;
	close (FILE);
	$badwords=~ s/[\a\f\n\e\0\r\t]//ig;
	$badwords=~ s/(\.|\*|\(|\)|\||\\|\/|\?|\+|\[|\])//ig;
    }
    else { $badwords = "";}

    if ($badwords) {
        study($infiltermessage);
	my @pairs = split(/\&/,$badwords);
	foreach (@pairs) {
	    my ($bad, $good) = split(/=/,$_);
	    chomp $good;
	    $infiltermessage =~ s/$bad/$good/isg;
        }
    }
    return $infiltermessage;
}

sub checksearchbot {
   return 1 if ($allowsearch ne "yes");
   my $useragent = $ENV{'HTTP_USER_AGENT'};
   my @allowsearchs = split(/\s+/, $allowsearch);
   foreach my $eachsearch ("Googlebot","baiduspider","lycos","yahooseeker","MSNBOT","InfoSeek")
   {
       return 0 if ($useragent =~ /$eachsearch/i);
   }
   return 1;
}

sub ipbanned {
    $inmembername = $query->cookie("amembernamecookie") if ($inmembername eq "");
    $inmembername =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
    $infilemembername = $inmembername;
    $infilemembername =~ s/ /_/g;
    $infilemembername =~ tr/A-Z/a-z/;

    $ipaddress     = $ENV{"REMOTE_ADDR"};
    $trueipaddress = $ENV{"HTTP_CLIENT_IP"};
    $trueipaddress = $ENV{"HTTP_X_FORWARDED_FOR"} if ($trueipaddress eq "" || $trueipaddress eq "unknown" || $trueipaddress =~ m/^192\.168\./ || $trueipaddress =~ m/^10\./);
    $trueipaddress = $ipaddress if ($trueipaddress eq "" || $trueipaddress eq "unknown" || $trueipaddress =~ m/^192\.168\./ || $trueipaddress =~ m/^10\./);
    $infilemembername = $trueipaddress if (($inmembername eq "")||($inmembername eq "訪客"));
    if ((-e "${lbdir}cache/id/$infilemembername.cgi")&&((-M "${lbdir}cache/id/$infilemembername.cgi") *86400 < 600)) {
    	#直接通過
    }
    else { require "doipbanned.pl"; }
}

sub title {
  if ($showskin ne "off") {
    eval{ require "${lbdir}data/skinselect.pl"; };
    if ($@) { 
    	require "${lbdir}dorepireskin.pl";
	print header();
	print "<script language='javascript'>javascript:this.location.reload()</script>";
        print "網頁已經更新，程式自動重新整理，如果沒有自動重新整理，請手動重新整理$div_one次！！<BR><BR><meta http-equiv='refresh' content='3;'>";
	exit;
    }
  } else { $userskins=""; $skinselect=""; }

    &doonoff;
    $newmail = "<p>";
    if ($inmembername eq "" || $inmembername eq "訪客") {
	$inmembername = "訪客";
	$loggedinas = qq~<b>訪客</b>： <a href=loginout.cgi?forum=$inforum title=從這裡開始進入論壇>登入論壇</a> <img src=$imagesurl/images/fg.gif width=1> <a href=register.cgi?forum=$inforum title=註冊了$div_then能發表文章哦！><B><font color=$fonthighlight>按這裡註冊</font></B></a> <img src=$imagesurl/images/fg.gif width=1> <a href=profile.cgi?action=lostpassword title=好慘啊，忘記密碼登入不了 style=cursor:help>忘記密碼</a> <img src=$imagesurl/images/fg.gif width=1> <a href=whosonline.cgi title=看看有誰在線……>在線名單</a> <img src=$imagesurl/images/fg.gif width=1> <a href="search.cgi?forum=$inforum" title=按關鍵字、$div_edit者來搜尋>尋找文章</a> $skinselect<img src=$imagesurl/images/fg.gif width=1> <span style=cursor:hand onClick=javascript:openScript('help.cgi',500,400) title=常見問題的解鎖答>說明文件</span>&nbsp;~;
	if (($regaccess eq "on" && &checksearchbot)&&($thisprog ne "loginout.cgi")&&($thisprog ne "register.cgi")&&($thisprog ne "profile.cgi")&&($thisprog ne "viewavatars.cgi")) {
	    print header(-cookie=>[$namecookie, $passcookie] , -expires=>"$EXP_MODE" , -cache=>"$CACHE_MODES");
	    print "<script language='javascript'>document.location = 'loginout.cgi?forum=$inforum'</script>";
	    exit;
	}
	if(($regpuonoff eq "ontop")&&($thisprog eq "leobbs.cgi")||($regpuonoff eq "oneach")&&($thisprog ne "loginout.cgi")&&($thisprog ne "register.cgi")) {
	    if ($boardlogo =~ /\.swf$/i) {$forumgraphic1 = qq~<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=$imagesurl/myimages/$boardlogo quality=high width=$boardlogow height=$boardlogoh pluginspage="http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application\/x-shockwave-flash"><\/embed>~}
            else {$forumgraphic1 = qq~<img src=$imagesurl/myimages/$boardlogo border=0>~};		
            $popupmsg = qq~請先註冊以避免此視窗出現~ if(!$popupmsg);
            $popupmsg = &HTML("$popupmsg");
	    $loggedinas .=qq~<script src="$imagesurl/images/lbpopup.js"></script><div id="lbplocation" style="position: absolute;visibility: hidden;height: 1;width: 1;top: 100;left: 50"><table width=520 height=320 bgcolor=$titleborder style="border: 1 outset $miscbackone"><tr><td><table width=490 height=290 bgcolor=$menubackground align=center style="border: 1 inset $miscbacktwo"><tr><td align=center valign=middle><a href=leobbs.cgi>$forumgraphic1</a><br>$popupmsg<br><br><b><a href=register.cgi title=按這裡進行註冊><U>註　冊</U></a>　　<a href=loginout.cgi?forum=$inforum title=從這裡開始進入論壇><U>登　入</U></a></b><p>(此視窗將於 5 秒後自動關閉)</td></tr></table></td></tr></table></div>~;
	}
    }
    else {
       if (($thisprog eq "leobbs.cgi")||($thisprog eq "forums.cgi")||($thisprog eq "topic.cgi")) {
	 $memberfilename = $inmembername;
	 $memberfilename =~ s/ /\_/g;
	 $memberfilename =~ tr/A-Z/a-z/;

  	 if ((-e "${lbdir}cache/mymsg/$memberfilename.pl")&&((-M "${lbdir}cache/mymsg/$memberfilename.pl") < (-M "${lbdir}$msgdir/in/${memberfilename}_msg.cgi"))) {
    	    eval{ require "${lbdir}cache/mymsg/$memberfilename.pl";};
    	    if ($@) { unlink ("${lbdir}cache/mymsg/$memberfilename.pl"); $totalmessages = 0;$unread = 0; }
  	 } else {
  	     require "domymsg.pl";
	 }
      }
      $loggedinas = qq~$inmembername：<a href=loginout.cgi?forum=$inforum>重新登入</a> <img src=$imagesurl/images/fg.gif width=1> <span style=cursor:hand onMouseover="showmenu(event,linkset[1])" onMouseout="delayhidemenu()">控制版面</span> <img src=$imagesurl/images/fg.gif width=1> <a href=search.cgi?forum=$inforum title=按關鍵字、$div_edit者來搜尋論壇內的文章>尋找文章</a> <img src=$imagesurl/images/fg.gif width=1> <a href=whosonline.cgi title=看看有誰在線……>在線名單</a> <img src=$imagesurl/images/fg.gif width=1> <span style=cursor:hand onMouseover="showmenu(event,linkset[0])" onMouseout="delayhidemenu()">論壇設施</span> $skinselect<img src=$imagesurl/images/fg.gif width=1> <span style=cursor:hand onClick="javascript:openScript('help.cgi',500,400)" title=常見問題的解鎖答>說明文件</span> <img src=$imagesurl/images/fg.gif width=1> <a href=loginout.cgi?action=logout title=在公眾的地方上網記得要按登出身份哦><font color=$fonthighlight>登出身份</font></a>&nbsp;~;
    }

    if ($useadscript ne 0) {
        $adscript = &HTML("$adscript");
        $adscript =~ s/\$imagesurl/$imagesurl/isg;
	$adscript =~ s/\[br\]/\n/isg;
    }
    else { $adscript =""; }

    if ($thisprog eq "leobbs.cgi" && $adscriptmain ne "") {
        $adscriptmain = &HTML("$adscriptmain");
        $adscriptmain =~ s/\$imagesurl/$imagesurl/isg;
	$adscriptmain =~ s/\[br\]/\n/isg;
	$adscript = $adscriptmain;
    }

    if ($inforum eq "") {
        if ($boardlogo ne "") {
            if ($boardlogo =~ /\.swf$/i) {$forumgraphicoutput = qq~<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=$imagesurl/myimages/$boardlogo quality=high width=$boardlogow height=$boardlogoh pluginspage="http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application\/x-shockwave-flash"><\/embed>~}
                else {$forumgraphicoutput = qq~<img src=$imagesurl/myimages/$boardlogo>~};
        }
    } else {
	if ($forumgraphic) {
	    ($fgwidth,$fgheight) = split(/\|/,$fgwidth);
	    if ($forumgraphic =~ /\.swf$/i) {$forumgraphicoutput = qq~<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=$imagesurl/myimages/$forumgraphic quality=high width=$fgwidth height=$fgheight pluginspage="http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application\/x-shockwave-flash"><\/embed>~}
	        else {$forumgraphicoutput = qq~<a href=forums.cgi?forum=$inforum><img src=$imagesurl/myimages/$forumgraphic border=0 height=60></a>~};
	} else {
	    if ($boardlogo =~ /\.swf$/i) {$forumgraphicoutput = qq~<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=$imagesurl/myimages/$boardlogo quality=high width=$boardlogow height=$boardlogoh pluginspage="http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application\/x-shockwave-flash"><\/embed>~}
	        else {$forumgraphicoutput = qq~<a href=forums.cgi?forum=$inforum><img src=$imagesurl/myimages/$boardlogo border=0 height=60></a>~};
	}
    }

    if (-e "${lbdir}data/skincache.pl") {
        eval{ require "${lbdir}data/skincache.pl";};
        if ($@) {  unlink ("${lbdir}data/skincache.pl"); }
    }
    $loggedinas .= qq~<img src=$imagesurl/images/fg.gif width=1> <a href=admin.cgi target=_blank>管理中心</a>&nbsp;~ if (($membercode eq "ad")||($membercode eq "smo"));

    if ($navadd ne "") {
    	$navadd=&HTML($navadd);
    	$loggedinas .= qq~<img src=$imagesurl/images/fg.gif width=1> $navadd&nbsp;~;
    }

    if ($thisprog eq "leobbs.cgi") {
    	$headmark = "$headmark1$headmark";
    	$footmark = "$footmark1$footmark";
    }
        

    if ($headmark ne "") { $headmark=&HTML($headmark); $headmark =~ s/\n/<BR>/isg; $headmark =~ s/\$imagesurl/$imagesurl/isg; $headmark =~ s/\[br\]/\n/isg; }
    if ($footmark ne "") { $footmark=&HTML($footmark); $footmark =~ s/\n/<BR>/isg; $footmark =~ s/\$imagesurl/$imagesurl/isg; $footmark =~ s/\[br\]/\n/isg;}

    if ($menubackpic ne "") { $menubackpic = "background=$imagesurl/images/$skin/$menubackpic"; }

    $output = qq~
<style>
.menuskin{position:absolute;background-color:$menubackground;border:1px solid $titleborder;line-height:20px;z-index:100;visibility:hidden;}
#mouseoverstyle{BACKGROUND-COLOR: #C9D5E7; margin:1px;}
#mouseoverstyle a{color:white;}
.menuitems{margin:1px;padding:1px;word-break:keep-all;}
</style>
<script>
linkset[1]='<div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("messanger.cgi?action=new",600,400) title=傳送悄悄話短訊給站內的朋友>發短訊給朋友</span>&nbsp;</div><div class=menuitems>&nbsp;<a href=profile.cgi?action=modify title=編輯修改您的個人資料><font color=$menufontcolor>修改我的資料</font></a>&nbsp;</div><div class=menuitems>&nbsp;<a href=fav.cgi?action=show&member=$inmembername title=對您收藏的文章進行管理><font color=$menufontcolor>管理我的收藏</font></a>&nbsp;</div><div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("friendlist.cgi",420,320) title=查看、新增、刪除你的通訊錄>管理通訊錄</span>&nbsp;</div><div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("blocklist.cgi",420,320) title=查看、新增、刪除你的黑名單>管理黑名單表</span>&nbsp;</div><div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("recopr.cgi?action=new",420,320) title=顯示論壇最新的文章名單>論壇最新文章</span>&nbsp;</div><div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("recopr.cgi?action=post",420,320) title=我發表的、而且已經被別人回覆過的主題名單>被回覆的主題</span>&nbsp;</div><div class=menuitems>&nbsp;<span style=cursor:hand onClick=javascript:openScript("recopr.cgi?action=reply",420,320) title=我發表回覆過的主題名單>我參與的主題</span>&nbsp;</div><div class=menuitems>&nbsp;<a href=delmycache.cgi title=清除我的快取，確保個人所有資料都是最新的><font color=$menufontcolor>更新我的快取</font></a>&nbsp;</div>'
</script>
$pluginadd$headmark$userskins~;
    if (($usesuperannounce eq "1")&&($thisprog eq "leobbs.cgi" || $thisprog eq "forums.cgi" || $thisprog eq "topic.cgi")) {
    	require "superannounce.pl";
        $sann = qq~<span style=cursor:hand onClick=displayfadeinbox();><img src=$imagesurl/images/sann.gif height=16></span>　~;
    }

  eval{ require "${lbdir}data/myskin/${skin}.pl";};
  if ($@) { require "${lbdir}data/myskin/title.pl";}   # 調入頁首 skin ，如果不存在或者錯$div_wrong，預設 title.pl 。

    if ($firstout eq "yemei") {
        $output .= $yemei if ($usetopm ne "no");
        $output .= $daohang;
    } else {
        $output .= $daohang;
        $output .= $yemei if ($usetopm ne "no");
    }

    $output .= qq~<base onmouseover="window.status='$statusbar';return true">~ if ($statusbar ne "");

    if ($forumlastvisit) {
	my $fulldate  = &fulldatetime($forumlastvisit+$timedifferencevalue*3600+$timezone*3600);
	$lastvisitdata = qq~ 最近瀏覽論壇時間： $fulldate~;
    }
    else { $lastvisitdata = qq~ $forumname歡迎您的到來 ~; }
    $uservisitdata = qq~<a href=forums.cgi?forum=$inforum&action=resetposts title="$lastvisitdata">標記論壇所有內容為已讀取</a>&nbsp;~;
}

sub mischeader {
  local($misctype) = @_;

  if (-e "${lbdir}cache/forumstitle$inforum.pl") {
        eval{ require "${lbdir}cache/forumstitle$inforum.pl";};
        if ($@) { unlink ("${lbdir}cache/forumstitle$inforum.pl"); require "domischeader.pl"; }
  } else {
      require "domischeader.pl";
  }
  &title;
  if ($inforum eq "") { $titleoutput =~ s/\ →\ \<a href=forums.cgi\?forum=\>\<\/a\>//isg; $titleoutput =~ s/\>\>\>\ //isg; }
  $titleoutput =~ s/misctypehtc/$misctype/isg;
  $output .= qq~$titleoutput~;
}

sub getoneforum {
    local $inforum = shift;
    return if ($inforum eq "");
    if (-e "${lbdir}cache/forumsone$inforum.pl") {
        eval{ require "${lbdir}cache/forumsone$inforum.pl";};
        if ($@) { unlink ("${lbdir}cache/forumsone$inforum.pl"); require "dogetoneforum.pl"; }
        ($forumid, $category, $categoryplace, $forumname, $forumdescription, $no, $htmlstate, $idmbcodestate, $privateforum, $startnewthreads, $lastposter, $lastposttime, $threads, $posts, $forumgraphic, $miscad2, $misc, $forumpass, $hiddenforum, $indexforum, $teamlogo, $teamurl, $fgwidth, $fgheight, $miscad4, $todayforumpost, $miscad5) = split(/\t/, $forums);
        unlink("${lbdir}cache/forumsone$inforum.pl") if ((-M "${lbdir}cache/forumsone$inforum.pl") *86400 > 600);
    } else {
    	require "dogetoneforum.pl";
    }
    $forummodnamestemp = ",$forummoderator,";
    my $tempinmembername = ",$inmembername,";
    $inmembmod = $forummodnamestemp =~ /\Q$tempinmembername\E/i || (($membercode eq "cmo" || $membercode eq "mo" || $membercode eq "amo") && ($forummodnamestemp =~ /,全體版主,/ || $forummodnamestemp =~ /,全體版主,/)) ? "yes" : "no";
    return;
}

sub moderator {
    local $inforum = shift;
    return if ($inforum eq "");
    if (-e "${lbdir}cache/forums$inforum.pl") {
        eval{ require "${lbdir}cache/forums$inforum.pl";};
        if ($@) { unlink ("${lbdir}cache/forums$inforum.pl"); require "domoderator.pl"; }
        ($forumid, $category, $categoryplace, $forumname, $forumdescription, $forummoderator, $htmlstate, $idmbcodestate, $privateforum, $startnewthreads, $lastposter, $lastposttime, $threads, $posts, $forumgraphic, $miscad2, $misc, $forumpass, $hiddenforum, $indexforum, $teamlogo, $teamurl, $fgwidth, $fgheight, $miscad4, $todayforumpost, $miscad5) = split(/\t/, $thisforums);

        if ($forummodnamestemp =~ /\Q\,$inmembername\,\E/i || (($membercode eq "cmo" || $membercode eq "mo" || $membercode eq "amo") && ($forummodnamestemp =~ /,全體版主,/ || $forummodnamestemp =~ /,全體版主,/))) { $inmembmod = "yes"; } else { $inmembmod = "no"; }
        unlink("${lbdir}cache/forums$inforum.pl") if ((-M "${lbdir}cache/forums$inforum.pl") *86400 > 600);
    } else {
    	require "domoderator.pl";
    }
    eval{ require "${lbdir}boarddata/forumposts$inforum.pl";} if ($thisprog eq "forums.cgi");
    return;
}

sub checkmemfile {
    my ($nametocheck, $namenumber) = @_;
    if (-e "${lbdir}$memdir/$nametocheck.cgi") {
        my @fileinfo = stat("${lbdir}$memdir/$nametocheck.cgi");
        my $filelength = $fileinfo[7];
    	if ($filelength <=50) { unlink("${lbdir}$memdir/$nametocheck.cgi"); }
    	else {
    	    if ($loadcopymo ne 1) { eval('use File::Copy;'); $loadcopymo = 1; }
    	    copy("${lbdir}$memdir/$nametocheck.cgi","${lbdir}$memdir/$namenumber/$nametocheck.cgi");
    	    unlink("${lbdir}$memdir/$nametocheck.cgi");
    	}
    }

    my @fileinfo = stat("${lbdir}$memdir/$namenumber/$nametocheck.cgi");
    my $filelength = $fileinfo[7];
    if ((!(-e "${lbdir}$memdir/$namenumber/$nametocheck.cgi"))||($filelength <=50)) {
    	if (-e "${lbdir}$memdir/old/$nametocheck.cgi") {
    	    if ($loadcopymo ne 1) { eval('use File::Copy;'); $loadcopymo = 1; }
    	    copy("${lbdir}$memdir/old/$nametocheck.cgi","${lbdir}$memdir/$namenumber/$nametocheck.cgi");
    	}
    }
}

sub getnamenumber {
    my $nametocheck = shift;
#    my $namenumber = int((ord(substr($nametocheck,0,1))+ord(substr($nametocheck,1,1)))/2);
    my $namenumber = ((ord(substr($nametocheck,0,1))&0x3c)<<3)|((ord(substr($nametocheck,1,1))&0x7c)>>2);
    mkdir ("${lbdir}$memdir/$namenumber", 0777) if (!(-e "${lbdir}$memdir/$namenumber"));
    chmod(0777,"${lbdir}$memdir/$namenumber");
    return $namenumber;
}

sub getmember {
    my ($nametocheck, $readtype) = @_;
    $nametocheck =~ s/ /\_/g;
    $nametocheck =~ tr/A-Z/a-z/;
    $nametocheck =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
    my $namenumber = &getnamenumber($nametocheck);
    &checkmemfile($nametocheck,$namenumber);
    $userregistered = "";
    undef $filedata;
    my $filetoopen = "${lbdir}$memdir/$namenumber/$nametocheck.cgi";

    if ($readtype eq "check") {
	if ((-e $filetoopen)&&($nametocheck !~ /^訪客/)&&($nametocheck ne "")) {
	    return 1;
	} else {
	    return 0;
	}
    }

    if ((-e $filetoopen)&&($nametocheck !~ /^訪客/)&&($nametocheck ne "")) {
	&winlock($filetoopen) if (($OS_USED eq "Nt") && ($readtype ne "no"));
        open(FILE3,"$filetoopen");
        flock(FILE3, 1) if (($OS_USED eq "Unix") && ($readtype ne "no"));
        my $filedata = <FILE3>;
        close(FILE3);
	&winunlock($filetoopen) if (($OS_USED eq "Nt") && ($readtype ne "no"));
	chomp($filedata);
	($membername, $password, $membertitle, $membercode, $numberofposts, $emailaddress, $showemail, $ipaddress, $homepage, $oicqnumber, $icqnumber ,$location ,$interests, $joineddate, $lastpostdate, $signature, $timedifference, $privateforums, $useravatar, $userflag, $userxz, $usersx, $personalavatar, $personalwidth, $personalheight, $rating, $lastgone, $visitno, $useradd04, $useradd02, $mymoney, $postdel, $sex, $education, $marry, $work, $born, $chatlevel, $chattime, $jhmp, $jhcount,$ebankdata,$onlinetime,$userquestion,$awards,$jifen,$userface,$soccerdata,$useradd5) = split(/\t/,$filedata);
	$showemail = "no" if ($dispmememail eq "no");
	$membername =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
	$password =~ s/[\a\f\n\e\0\r\t\|\@\;\#\{\}\$]//isg;
	if (($password !~ /^lEO/)&&($password ne "")) {
	    eval {$password = md5_hex($password);};
	    if ($@) {eval('use Digest::MD5 qw(md5_hex);$password = md5_hex($password);');}
	    unless ($@) {$password = "lEO$password";}
	}
	$membercode ||= "me";
	$jhcount = "0" if ($jhcount <= 0);
	$jhcount ||= "0";
	$visitno ||= "0";
	$onlinetime = "3000" if ($onlinetime < 0);
	($signatureorigin, $signaturehtml) = split(/aShDFSiod/,$signature); 
	$signatureorigin =~ s/<br>/\n/g; 
	$timedifferencevalue = $timedifference;
	($numberofposts, $numberofreplys) = split(/\|/,$numberofposts);
	$numberofposts ||= "0";
	$numberofreplys ||= "0";
	$jifen = $numberofposts * 2 + $numberofreplys - $postdel * 5 if ($jifen eq "");
        chomp $privateforums;
        if ($privateforums) {
	    my @private = split(/&/,$privateforums);
	    foreach (@private) {
		chomp $_;
		($access, $value) = split(/=/,$_);
		$allowedentry{$access} = $value;
	    }
	}
	return 1;
    }
    else { $userregistered = "no"; $membercode =""; return 0;}
}

sub uplogintime {
        my($nametocheck,$visit) = @_;
	my $nametochecktemp = $nametocheck;
	$nametocheck =~ s/ /\_/g;
	$nametocheck =~ tr/A-Z/a-z/;
        $nametocheck =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
	my $namenumber = &getnamenumber($nametocheck);
	&checkmemfile($nametocheck,$namenumber);
        my $filetoopen = "${lbdir}$memdir/$namenumber/$nametocheck.cgi";
	if (-e $filetoopen) {
	    &winlock($filetoopen) if ($OS_USED eq "Nt");
	    open(FILE6,"+<$filetoopen");
	    flock (FILE6, 2) if ($OS_USED eq "Unix");
            my $filedata = <FILE6>;
	    chomp($filedata);
	    (my $membername, my $password, my $membertitle, my $membercode, my $numberofposts, my $emailaddress, my $showemail, my $ipaddress, my $homepage, my $oicqnumber, my $icqnumber ,my $location ,my $interests, my $joineddate, my $lastpostdate, my $signature, my $timedifference, my $privateforums, my $useravatar, my $userflag,my  $userxz, my $usersx, my $personalavatar, my $personalwidth, my $personalheight, my $rating, my $lastgone, my $visitno,my  $useradd04,my  $useradd02, my $mymoney, my $postdel, my $sex, my $education, my $marry, my $work, my $born, my $chatlevel,my  $chattime, my $jhmp,my $jhcount,my $ebankdata,my $onlinetime,my $userquestion,my $awards,my $jifen,my $userface, my $soccerdata, my $useradd5) = split(/\t/,$filedata);

	    $nowtimetemp = time;
    	    if ($visit eq "T") { $visitno++ if (($nowtimetemp - $lastgone) > 300); } else { $onlinetime = 0 if ($onlinetime =~ /[^0-9]/); $onlinetime = $onlinetime + $savedtime-$savedcometime if (($nowtimetemp - $lastgone) > 150); unlink ("${lbdir}cache/id/$nametocheck.cgi"); unlink ("${lbdir}cache/myinfo/$nametocheck.pl"); unlink ("${lbdir}cache/online/$nametocheck.cgi"); }
	    if (($membername ne "")&&($password ne "")) {
	      $lastgone = $nowtimetemp;
	      seek(FILE6,0,0);
	      print FILE6 "$membername\t$password\t$membertitle\t$membercode\t$numberofposts\t$emailaddress\t$showemail\t$ipaddress\t$homepage\t$oicqnumber\t$icqnumber\t$location\t$interests\t$joineddate\t$lastpostdate\t$signature\t$timedifference\t$privateforums\t$useravatar\t$userflag\t$userxz\t$usersx\t$personalavatar\t$personalwidth\t$personalheight\t$rating\t$lastgone\t$visitno\t$useradd04\t$useradd02\t$mymoney\t$postdel\t$sex\t$education\t$marry\t$work\t$born\t$chatlevel\t$chattime\t$jhmp\t$jhcount\t$ebankdata\t$onlinetime\t$userquestion\t$awards\t$jifen\t$userface\t$soccerdata\t$useradd5\t\n";
	      close(FILE6);
	      my ($post1, $post2) = split(/\|/,$numberofposts);
	      $post1 ||= "0";
	      $post2 ||= "0";
	      $jifen = $post1 * 2 + $post2 - $postdel * 5 if ($jifen eq "");
	      if (((-M "${lbdir}$memdir/old/$nametocheck.cgi") > 0.5)||(!(-e "${lbdir}$memdir/old/$nametocheck.cgi"))) {
	      	  open(FILE6,">${lbdir}$memdir/old/$nametocheck.cgi");
	          print FILE6 "$membername\t$password\t$membertitle\t$membercode\t$numberofposts\t$emailaddress\t$showemail\t$ipaddress\t$homepage\t$oicqnumber\t$icqnumber\t$location\t$interests\t$joineddate\t$lastpostdate\t$signature\t$timedifference\t$privateforums\t$useravatar\t$userflag\t$userxz\t$usersx\t$personalavatar\t$personalwidth\t$personalheight\t$rating\t$lastgone\t$visitno\t$useradd04\t$useradd02\t$mymoney\t$postdel\t$sex\t$education\t$marry\t$work\t$born\t$chatlevel\t$chattime\t$jhmp\t$jhcount\t$ebankdata\t$onlinetime\t$userquestion\t$awards\t$jifen\t$userface\t$soccerdata\t$useradd5\t\n";
	          close(FILE6);
		  unlink ("${lbdir}cache/meminfo/$nametocheck.pl");
		  unlink ("${lbdir}cache/myinfo/$nametocheck.pl");
	      }
	    } else {
                close(FILE6);
	    }
	    &winunlock($filetoopen) if ($OS_USED eq "Nt");
	}
}

sub numerically { $a <=> $b }
sub alphabetically { lc($a) cmp lc($b) }
sub whosonline {
	my $instruct = shift;
	(my $tempusername, my $where, my $method, my $where2) = split(/\t/, $instruct);
	my $ipaddress  = $ENV{'REMOTE_ADDR'};
	$trueipaddress = $ENV{'HTTP_X_FORWARDED_FOR'};
	$trueipaddress = $ipaddress if ($trueipaddress eq "" || $trueipaddress eq "unknown" || $trueipaddress =~ m/^192\.168\./ || $trueipaddress =~ m/^10\./);
	my $trueipaddress1 = $ENV{'HTTP_CLIENT_IP'};
	$trueipaddress = $trueipaddress1 if ($trueipaddress1 ne "" && $trueipaddress1 ne "unknown" && $trueipaddress1 !~ m/^192\.168\./ && $trueipaddress1 !~ m/^10\./);
	my $ipall      = "$ipaddress=$trueipaddress";
	my $tempusername1=$tempusername;
	$tempusername = "訪客($ipaddress)" if ($tempusername eq "訪客");
	$totleonlineall = 0;
	$guests  = 0;
	$members = 0;
	$onlineuserlist       = "\_";
	$onlineuserlisthidden = "\_";
	undef @onlinedata;
	undef @onlinedata1;
	$currenttime = time;
	$membergone = 15 if (($membergone < 5)||($membergone > 180));
	my $userexpire = $currenttime - $membergone * 60;
	$memberprinted = "no";
	$screenmode=8 if ($screenmode eq "");
	my $firstcome = 'yes';
	
     my $filetoopen = "$lbdir" . "data/onlinedata.cgi";
     my @fileinfo = stat("$filetoopen");
     my $filelength1 = $fileinfo[7];
        @fileinfo = stat("$filetoopen.cgi");
     my $filelength2 = $fileinfo[7];
     if ((($filelength1 <60)&&($filelength2 > 60))||(($filelength2-$filelength1>1200)&&($filelength2<3000))||(($filelength2 > $filelength1*1.2)&&($filelength2>=3000)&&($filelength2<80000))||(($filelength2 > $filelength1*1.5)&&($filelength2>=80000))) {
	if (open(FILE5,"$filetoopen.cgi")) {
  	  sysread(FILE5, $onlinedata1,(stat(FILE5))[7]);
	  close(FILE5);
	  $onlinedata1 =~ s/\r//isg;
	}
     }
     else {
        &winlock($filetoopen) if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
        if (open(FILE5,"$filetoopen")) {
	  flock (FILE5, 1) if ($OS_USED eq "Unix");
  	  sysread(FILE5, $onlinedata1,(stat(FILE5))[7]);
	  close(FILE5);
	  $onlinedata1 =~ s/\r//isg;
	}
        &winunlock($filetoopen) if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
        unlink ("${lbdir}data/onlinedata.cgi.cgi") if ((-M "${lbdir}data/onlinedata.cgi.cgi") *86400 > 100);
     }

        @onlinedata1=split(/\n/,$onlinedata1);
        $onlinedatanumber=@onlinedata1;
	my @onlinefr = ();
	my $onlineprompt = $query->cookie('onlineprompt') if (defined($query));
        foreach my $line (@onlinedata1) {
                chomp $line;
                local ($savedusername, $savedcometime, $savedtime, $savedwhere, $savedipaddress, $saveosinfo, $savebrowseinfo, $savedwhere2, $fromwhere, $savemembercode, $savehidden, $savesex) = split(/\t/, $line);
 		my ($lookfor, $no) = split(/\(/,$savedusername);
                next if (((length($savedusername)>12)&&($lookfor ne "訪客"))||($lookfor eq ""));
                $fromwhere = "不明" if (length($fromwhere) > 40);
                $saveosinfo = "不明" if (length($saveosinfo) > 15);
                $savebrowseinfo = "不明" if (length($savebrowseinfo) > 28);
		$lookfor =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?\[\]]/ /isg;
		$savedwhere =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?\[\]]/ /isg;
		$savedwhere2 =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?\[\]]/ /isg;
		$fromwhere =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?\[\]]/ /isg;

                $savedusername =~ s/\_/ /g;
                $tempusername =~ s/\_/ /g;

		if ($userexpire <= $savedtime) {
		    if ($savedusername !~ /^訪客/) { if ($savehidden ne 1) { $onlineuserlist = "$onlineuserlist$savedusername\_"; } else { $onlineuserlisthidden = "$onlineuserlisthidden$savedusername\_"; } }
                    if ((lc($savedusername) eq lc($tempusername))||(($savedusername eq "訪客($ipaddress)")&&($ipall eq $savedipaddress)&&($tempusername =~ /^訪客/ || ($where eq "論壇登入" && $where2 eq "登入論壇" && $action eq "login")))) {
                         if ((($currenttime - $savedtime) <= $banfreshtime - 1)&&(($currenttime - $savedtime) >= 0)&&($savedwhere eq $where)&&($savedwhere2 eq $where2)&&(($thisprog eq "post.cgi")||($thisprog eq "leobbs.cgi")||($thisprog eq "forums.cgi")||($thisprog eq "topic.cgi")||($thisprog eq "printpage.cgi")||($thisprog eq "whosonline.cgi"))) {
                             print header(-charset=>big5 , -expires=>"$EXP_MODE" , -cache=>"$CACHE_MODES");
                             print "<BR>伺服器忙，請 $banfreshtime 秒後按重新整理鍵$div_run續。<BR><BR>出錯原因：你重新整理網頁過快，或者你打開了過多視窗來瀏覽本網站。";
                             exit;
                         }
                         $savedcometime = $currenttime if (lc($savedusername) ne lc($tempusername));
                         if ($memberprinted eq "no") {
                             $savehidden = $hidden if ($hidden ne "");
                             $tempdata = "$tempusername\t$savedcometime\t$currenttime\t$where\t$ipall\t$saveosinfo\t$savebrowseinfo\t$where2\t$fromwhere\t$membercode\t$savehidden\t$sex\t" ;
			     $osinfo=$saveosinfo;
	   		     $browseinfo=$savebrowseinfo;
                             $tempdata =~ s/[\a\f\n\e\0\r]//isg;
                             $fromwhere1 = $fromwhere;
                             push(@onlinedata,$tempdata);
                             $memberprinted = "yes";
			     $firstcome = 'no' if (lc($savedusername) eq lc($tempusername));
                             $onlinetimeadd = $currenttime - $savedcometime;
                         }
                    }
                    else {
                         $line =~ s/[\a\f\n\e\0\r]//isg;
                         push(@onlinedata,$line);
			 if ($tempusername !~ /^訪客/ && $friendonlinepop ne 'no') {
			     $savedusernametemp = $savedusername;
			     $savedusernametemp =~ s/\\\|\(\)\[\]\*\+\?//isg;
			     if ($onlineprompt =~ /,$savedusername,/i) {
				push(@onlinefr, $savedusername);
				$onlineprompt =~ s/,$savedusername,/,/isg;
			     }
			 }
                    }
                }
                else {
                	&uplogintime("$savedusername","") if ($savedusername !~ /^訪客/);
                }
        }

	if ($tempusername !~ /^訪客/ && $friendonlinepop ne 'no')
	{
		if ($firstcome ne 'yes')
		{
			if (@onlinefr)
			{
				my $onlinefriend = join('　　', @onlinefr);
				$onlinepopup = "你下面這些好友剛剛上線了！<p>$onlinefriend";
				require 'onlinepop.pl';
			}
			$onlineprompt = uri_escape($onlineprompt);
			$output .= qq~<script>var exp = new Date(); exp.setTime(exp.getTime() + ($membergone*60*1000)); document.cookie="onlineprompt=$onlineprompt; expires=" + exp.toGMTString();</script>~;
		}
		else
		{
			my $temptempuser = $tempusername;
			$temptempuser =~ s/ /\_/g;
			$temptempuser =~ tr/A-Z/a-z/;
			$temptempuser =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\|\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
			if (open(FRD, "${lbdir}memfriend/$temptempuser.cgi"))
			{
				sysread(FRD, my $friendlist, (stat(FRD))[7]);
				close(FRD);
				$friendlist =~ s/\r//isg;
				my @friendlist = split($/, $friendlist);
				my @noonlinefr = ();
				my @onlinefr = ();
				foreach my $friend (@friendlist)
				{
					$friend =~ s/^＊＃！＆＊//;
					$friend =~ s/[\r\n]*$//;
					next if ($friend eq '');
					if (grep(/^$friend\t/i, @onlinedata) > 0)
					{
						push(@onlinefr, $friend);
					}
					else
					{
						push(@noonlinefr, $friend);
					}
				}
				if (@onlinefr)
				{
					my $onlinefriend = join('　　', @onlinefr);
					$onlinepopup = "你下面這些好友正在線上！<p>$onlinefriend";
					require 'onlinepop.pl';
				}
				if (@noonlinefr)
				{
					my $onlineprompt = join(',', @noonlinefr);
					$onlineprompt = uri_escape($onlineprompt);
					$output .= qq~<script>var exp = new Date(); exp.setTime(exp.getTime() + ($membergone*60*1000)); document.cookie="onlineprompt=,$onlineprompt,; expires=" + exp.toGMTString();</script>~;
				}
			}
		}
	}

        if ($memberprinted eq "no") {
	   if (($onlinedatanumber >= $arrowonlinemax)&&($arrowonlinemax > 0)&&($membercode ne "ad")&&($membercode ne "smo")&&($membercode ne "cmo")&&($membercode ne "mo")&&($membercode ne "amo")) {
       	      print header(-charset=>big5 , -expires=>"$EXP_MODE" , -cache=>"$CACHE_MODES");
              print "<BR>伺服器忙，已經超出論壇准許\的最大在線人數。<BR><BR>目前論壇在線 $onlinedatanumber 人，最大准許\同時在線 $arrowonlinemax 人。";
              exit;
           }
	   use testinfo qw(ipwhere osinfo browseinfo);
	   eval { $osinfo=&osinfo(); };
    	   if ($@) { $osinfo="Unknow"; }
	   eval { $browseinfo=&browseinfo(); };
    	   if ($@) { $browseinfo="Unknow"; }
           my $fromwhere = &ipwhere("$trueipaddress");
           my $tempdata = "$tempusername\t$currenttime\t$currenttime\t$where\t$ipall\t$osinfo\t$browseinfo\t$where2\t$fromwhere\t$membercode\t$hidden\t$sex\t" ;
           $fromwhere1 = $fromwhere;
           &uplogintime("$tempusername","T") if ($tempusername !~ /^訪客/);
           $tempdata =~ s/[\a\f\n\e\0\r]//isg;
           push(@onlinedata,$tempdata);
        }

        my $filetoopen = "$lbdir" . "data/onlinedata.cgi";
        $filetoopens = &lockfilename($filetoopen);
  	if (!(-e "$filetoopens.lck")) {
            $onlinedata = join("\n",@onlinedata);
	    &winlock($filetoopen) if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
            if (open(FILE4,">$filetoopen")) {
              flock(FILE4, 2) if ($OS_USED eq "Unix");
              print FILE4 "$onlinedata";
              close(FILE4);
            }
            &winunlock($filetoopen) if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
            my $nowsize = length($onlinedata);
	    unlink ("${lbdir}data/onlinedata.cgi.cgi") if ((-M "${lbdir}data/onlinedata.cgi.cgi") *86400 >= 60);
            if ((!(-e "${lbdir}data/onlinedata.cgi.cgi"))&&($nowsize > 2000)) {
             if (open(FILE4,">${filetoopen}.cgi")) {
              print FILE4 "$onlinedata";
              close(FILE4);
             }
            }
        }
	else {
    	    unlink ("$filetoopens.lck") if ((-M "$filetoopens.lck") *86400 > 60);
	}

my $filetoopens = "${lbdir}data/counter.cgi";
$filetoopens = &lockfilename($filetoopens);
if ((!(-e "$filetoopens.lck"))||($thisprog eq "leobbs.cgi")||($thisprog eq "index.cgi")) {
    &winlock("${lbdir}data/counter.cgi") if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
    if (-e "${lbdir}data/counter.cgi") {
    	open(FILE,"+<${lbdir}data/counter.cgi");
        $count = <FILE>;
        $onlinemax = @onlinedata;
        ($count1,$count2,$onlinemax1,$onlinemaxtime1) = split(/\t/, $count);
        $onlinemaxtime1 = $currenttime if ($onlinemaxtime1 eq "");
        $count1=0 if ($count1 eq "");
        $count2=0 if ($count2 eq "");
        $count2++;
        $count1++ if ($memberprinted eq "no");
        if ($onlinemax < $onlinemax1) {
	    $onlinemax = $onlinemax1; $onlinemaxtime = $onlinemaxtime1;
        } else { $onlinemaxtime = $currenttime; }

        seek(FILE,0,0);
        print FILE "$count1\t$count2\t$onlinemax\t$onlinemaxtime\t";
        close(FILE);
    } else {
        $onlinemax = @onlinedata;
        $onlinemaxtime = $currenttime;
        $count1 = $count2 = 1;
    	open(FILE,">${lbdir}data/counter.cgi");
        print FILE "1\t1\t$onlinemax\t$onlinemaxtime\t";
        close(FILE);
    }
    &winunlock("${lbdir}data/counter.cgi") if ($OS_USED eq "Nt" || $OS_USED eq "Unix");
}

        if ($method ne "none") {
	    $memberoutput = qq~<script>
function OLO(img, name, name1, place, action, time, time1, os, browser, ip, where, xa, xb) {document.write("<td width=12 align=center><img src=$imagesurl/images/" + img + " border=0 align=absmiddle alt='發送$div_one個短訊給 " + name + "' onClick=\\"javascript:openScript('messanger.cgi?action=new&touser=" + name1 + "', 600, 400)\\" style='cursor: hand'></td><td width=108><span onClick=\\"javascript:O9('" + name1 + "')\\" nowarp title=\\"目前位置：" + place + "\\n目前動$div_edit：" + action + "\\n來訪時間：" + time + "\\n活動時間：" + time1 + "\\n$div_edit$div_yip系統：" + os + "\\n瀏 覽 器：" + browser + "\\nIP地址：" + ip + "\\n估計來自：" + where + "\\" style='cursor: hand'>" + xa + name + xb + "</span></td>");}
function OHO(time, time1, ip, where, xa, xb) {document.write("<td width=12 align=center><img src=$imagesurl/images/$onlineguest align=absmiddle alt='請勿打擾！'></td><td width=108><a href=# nowarp title=\\"來訪時間：" + time + "\\n活動時間：" + time1 + "\\nIP地址：" + ip + "\\n估計來自：" + where + "\\">" + xa + "隱身會員" + xb + "</a></td>");}
~;
	    $memberoutput1 = qq~<script>
function OGO(place, action, time, time1, os, browser, ip, where, xa, xb) {document.write("<td width=12 align=center><img src=$imagesurl/images/$onlineguest border=0 align=absmiddle alt='快註冊呀！'></td><td width=108><a href=# nowarp title=\\"目前位置：" + place + "\\n目前動$div_edit：" + action + "\\n來訪時間：" + time + "\\n活動時間：" + time1 + "\\n$div_edit$div_yip系統：" + os + "\\n瀏 覽 器：" + browser + "\\nIP地址：" + ip + "\\n估計來自：" + where + "\\">" + xa + "訪客" + xb + "</a></td>");}
~;

            foreach my $line (@onlinedata) {
                chomp $line;
		$line =~ s/＊＃！＆＊//;
                my ($savedusername, $savedcometime, $savedtime, $savedwhere, $postipaddresstemp, $saveosinfo, $savebrowseinfo, $savedwhere2, $fromwhere, $memcod, $hiddened, $savesex) = split(/\t/, $line);

 		my ($lookfor, $no) = split(/\(/,$savedusername);
    	    	next if ($lookfor =~ m/[\(\)\*]/ || $lookfor eq "");

		       if ($memcod eq "ad")  {$mspic=$onlineadmin;}
		    elsif ($memcod eq "smo") {$mspic=$onlinesmod;}
		    elsif ($memcod eq "cmo") {$mspic=$onlinecmod;}
		    elsif ($memcod eq "mo")  {$mspic=$onlinemod;}
		    elsif ($memcod eq "amo") {$mspic=$onlineamod;}
		    elsif ($memcod =~ /^rz/) {$mspic = $memcod eq "rz1" && $defrz1 ne "" && $defrzonline1 ne "" ? $defrzonline1 : $memcod eq "rz2" && $defrz2 ne "" && $defrzonline2 ne "" ? $defrzonline2 : $memcod eq "rz3" && $defrz3 ne "" && $defrzonline3 ne "" ? $defrzonline3 : $memcod eq "rz4" && $defrz4 ne "" && $defrzonline4 ne "" ? $defrzonline4 : $memcod eq "rz5" && $defrz5 ne "" && $defrzonline5 ne "" ? $defrzonline5 : $onlinerz;}
		    else  {$mspic=$onlinemember;}

		($savedipaddress,$truepostipaddress) = split(/\=/,$postipaddresstemp);
		$totleonlineall++;

		$fromwhere = "已設定保密" unless (($pvtip eq "on")||($membercode eq "ad")||(($membercode eq 'smo')&&($smocanseeip eq "no")));

			if ($membercode eq "smo") {
				$savedipaddress = "已設定保密" unless ($pvtip eq "on" || $smocanseeip eq "no");
			}
			elsif ($membercode eq "cmo" || $membercode eq "mo") {
				if ($pvtip eq "on") {
					my ($ip1, $ip2, $ip3, $ip4) = split(/\./, $savedipaddress);
					$savedipaddress = "$ip1.$ip2.$ip3.*";
				} else {
					$savedipaddress = "已設定保密";
				}
			}
			elsif ($membercode ne "ad") {
				if ($pvtip eq "on" && $inmembername ne "訪客") {
					my ($ip1, $ip2, $ip3, $ip4) = split(/\./, $savedipaddress);
					$savedipaddress = "$ip1.$ip2.*.*";
				} else {
					$savedipaddress = "已設定保密";
				}
			}

		    my $savedcometime = &dateformatshort($savedcometime + ($timezone+$timedifferencevalue)*3600);
		    my $savedtime = &dateformatshort($savedtime + ($timezone+$timedifferencevalue)*3600);

		    $savedwhere2 =~s/\<a \s*(.*?)\s*\>\s*(.*)/“$2”/isg;
		    $savedwhere2=~s/<a href=(.*?)>//isg;
		    $savedwhere2 =~s/\<\/a\>//isg;
		    $savedwhere2 =~s/\<b\>//isg;
		    $savedwhere2 =~s/\<\/b\>//isg;
		    $savedwhere2 =~s/\<\/br\>//isg;
		    $savedwhere2 =~s/\"/\\\"/isg;
		    if ($method=~/\<\>/) {
			my @method=split(/\<\>/,$method);
			chomp @method;
			$method=$method[0];
			$method_b=$method[1];
		    }
		    my $check_of_method_b=1;
		    my $wherebaomi = $method . "(密)";
		    my $wherebaomi_b = $method_b . "(密)";
		    if ($method_b ne "") {
			$check_of_method_b=($savedwhere2 eq $method_b)?1:0;
			$check_of_method_b=($savedwhere2 eq $wherebaomi_b)?1:0 if(!$check_of_method_b);
		    }

if ($tablewidth > 100) {
    if ($tablewidth > 1000) { $screenmodes = 10; } elsif ($tablewidth > 770) { $screenmodes = 8; } else { $screenmodes = 6; }
} else {
    $screenmodes = $screenmode;
}

 
			if (($savedwhere eq $method && $check_of_method_b) || ($savedwhere eq $wherebaomi && $check_of_method_b) || $method eq "both")
			{
				if ((($hiddened eq 1 && $membercode ne "ad") || ($savedusername =~ /^訪客/)) && (lc($savedusername) ne lc($inmembername)))
				{
					$XA = $XB = "";
					if (lc($savedusername) eq lc($inmembername) || $savedusername eq "訪客($trueipaddress)") {
						$XA = "<font color=$onlineselfcolor>";
						$XB = "</font>";
					}
					if ($hiddened eq 1) {
						$members++;
						$memberoutput .= qq~\nOHO("$savedcometime","$savedtime","$savedipaddress","$fromwhere","$XA","$XB")~;
						$memberoutput .= qq~\n</script></tr><tr>\n<script>~ if ($members == int($members / $screenmodes) * $screenmodes);
					} else {
						$guests++;
						$memberoutput1 .= qq~\nOGO("$savedwhere ","$savedwhere2 ","$savedcometime","$savedtime","$saveosinfo","$savebrowseinfo","$savedipaddress","$fromwhere","$XA","$XB")~;
						$memberoutput1 .= qq~\n</script></tr><tr>\n<script>~ if ($guests == int($guests / $screenmodes) * $screenmodes);
					}
				} else {
					$members++;
					my $cleanmember = $savedusername;
					$cleanmember =~ s/ /\_/g;
					$cleanmember =~ tr/A-Z/a-z/;
					$cleanmember = uri_escape($cleanmember);
					$XA = $XB = "";
					$XA = "<font color=$mcolor>" if ($savesex eq "m");
					$XA = "<font color=$fcolor>" if ($savesex eq "f");
					if (lc($savedusername) eq lc($inmembername)) {
						$XA = "<font color=$onlineselfcolor>";
						$XB = "</font>";
					}
					if ($hiddened eq 1) { $hiddeninfo = "\\n-=> 目前處於隱身狀態 <=-"; } else { $hiddeninfo = ""; }
					
					$memberoutput .= qq~\nOLO("$mspic","$savedusername","$cleanmember","$savedwhere ","$savedwhere2 ","$savedcometime","$savedtime","$saveosinfo","$savebrowseinfo","$savedipaddress","$fromwhere$hiddeninfo","$XA","$XB")~;
					$memberoutput .= qq~\n</script></tr><tr>\n<script>~ if ($members == int($members / $screenmodes) * $screenmodes);
				}
			}
		}
		$memberoutput  .= qq~\n<\/script>\n~;
		$memberoutput1 .= qq~\n<\/script>\n~;
		$memberoutput1 = "" if ($dispguest eq 3 || ($dispguest ne 2 && $members > 50 && $guests > 20));
		$memberoutput = "$memberoutput</tr><tr>" if ($memberoutput ne "" && $memberoutput1 ne "");
		$memberoutput .= $memberoutput1;
		undef $memberoutput1;
		my $totleonline = $members + $guests;
		$membertongji = $method eq "both" ? "目前總共有 <a href=whosonline.cgi><b>$totleonlineall</b></a> 人在線。其中註冊會員 <b>$members</b> 人，訪客 <b>$guests</b> 人。" : "&nbsp;目前論壇總在線 <b>$totleonlineall</b> 人，本子論壇共有 <b>$totleonline</b> 人在線。其中註冊會員 <b>$members</b> 人，訪客 <b>$guests</b> 人。";
	}
	undef @onlinedata if (($thisprog ne "whosonline.cgi")&&($thisprog ne "leobbs.cgi"));
	return;
}

sub output {
        my ($title, $output, $outtype) = @_;
        $title =~ s/\$/\&\#036\;/sg;

	if (-e "${lbdir}data/template/$skin.cgi") {
	    open(FILE,"${lbdir}data/template/$skin.cgi");
	} else {
	    open(FILE,"${lbdir}data/template/title.cgi");
	}
  	sysread(FILE, my $templatedata,(stat(FILE))[7]);
        close(FILE);
	$templatedata =~ s/\r//isg;

    	my $boardcopyright;
	my $copyright;
	if ($outtype ne "msg") {
 	    $procedurecopy = &HTML("$procedurecopy");
            if ($procedurecopy eq "") { $procedurecopy = qq~$cssprocedure~;}
 	    $boardcopyright = qq(&copy\; $copyrightinfo) if $copyrightinfo;
            $boardcopyright =~ s/&lt;/</g; $boardcopyright =~ s/&gt;/>/g; $boardcopyright =~ s/&quot;/\"/g;
            $copyright = qq~<center>~;

            if (($thisprog eq "topic.cgi")||($thisprog eq "forums.cgi")) {
		if ($useadfoot ne 0) {
		    $adfoot   = &HTML("$adfoot");
		    $adfoot   =~ s/\$imagesurl/$imagesurl/isg;
		    $adfoot   =~ s/\[br\]/\n/isg;
		}
		else { $adfoot =""; }
	    	$copyright .= $adfoot;
	    }

	    $copyright .= qq~<hr width=390 size=1><table width=80% align=center cellpadding=0 cellspacing=0><tr><td align=center>~;
	    $boardlastinfo =qq~<BR>本論壇言論純屬發表者個人意見，與<font color=$fonthighlight><b> $boardname </b></font>立場無關<br>~ if ($dispboardsm ne "no");
	    if ($noads ne "yes") { if ($regerid =~ m/^LEO/) {eval {$regerid = md5_hex($regerid);}; if ($@) {eval('use Digest::MD5 qw(md5_hex);$regerid = md5_hex($regerid);');};$regerid = "" if ($regerid =~ m/^LEO/);} else { $regerid = ""; }; $regerid = substr($regerid,8,16) if ($regerid ne ""); $copyright1 = qq~<BR><font color=$postfontcolorone>程式版權所有： <a href="http://www.leobbs.com" target=_blank>雷傲科技</a>　繁體化：<a href="http://www.hklight.net" target=_blank>勁秋論壇</a>　版本： <a href="http://www.leobbs.com/download" target=_blank title="按此可以下載最新版本論壇程式">$versionnumber</a></font></td><td width=10>&nbsp;</td><td width=28><a href=http://www.leobbs.com/leobbs/reg/reg.asp?id=$regerid target=_blank><img src=$imagesurl/images/leoca.gif width=32 height=24 border=0 title=雷傲極酷超級論壇認證></a>~;}
       	    $copyright .= qq~<table cellpadding=0 cellspacing=0 align=center><tr><td align=center><font color=$fontcolormisc>$boardcopyright$copyright1</td></tr></table><img src=$imagesurl/images/none.gif width=0 height=3>$boardlastinfo</font></td></tr></table></center>\n$footmark~;
	}
	else { undef $copyright; }

if ($coolclickdisp eq "1") {
    $coolclick = qq~<script src="$imagesurl/images/adv.js"></SCRIPT>
<script>Adv("","","","<img src=$imagesurl/images/leobbs.gif alt=極酷超級論壇 border=0>","極酷超級論壇 -- 提示訊息");</script>
<script>Adv("","");</script>
~;
} else { $coolclick = ""; }
if (($thisprog eq "topic.cgi")||($thisprog eq "profile.cgi")) {
    $coolclick .= qq~<script src="$imagesurl/images/show.js"></SCRIPT>~;
}

$coolmeta = qq~<META http-equiv="Page-Enter" content="revealTrans(Transition=$cinoption,Duration=1)">
<META http-equiv="Page-Exit" content="revealTrans(Transition=$cinoption,Duration=1)">~ if ($pagechange eq "yes");

$coolmeta .= qq~
<link title="$title" type="application/rss+xml" rel="alternate" href="rss.cgi?/leo.xml"></link>
~ ;
study($templatedata);
$templatedata=~ s/\$lbbody/$lbbody/;
$templatedata=~ s/\$page_title/$title/;
$templatedata=~ s/\$coolmeta/$coolmeta/;
$templatedata=~ s/\$coolclick/$coolclick/;
$templatedata=~ s/\$tablewidth/$tablewidth/;
$templatedata=~ s/\$imagesurl/$imagesurl\/images/isg;
$templatedata=~ s/\$lbboard_main/$onlinepopup$$output\n\n$copyright\n/;
$templatedata=~ s/\<meta name=keywords content=\"/\<meta name=keywords content=\"$title\,/i;

print $templatedata;
if (($cpudisp eq "1")||($membercode eq "ad")||($membercode eq "smo")||($membercode eq "cmo")||($membercode eq "amo")||($membercode eq "mo")) {
    $spenttime = sprintf("%.2f",((times)[0]+(times)[1]-$startingtime)*1000);
    print "<center><font color=$cpudispcolor>目前網頁執行消耗時間： $spenttime 毫秒　";
    unless ($usegzip ne 'yes' || WebGzip::getStatus()) { print "[Gzip: On, Level: $complevel]"; } else { print "[Gzip: Off]"; }
}
exit;
}

sub doonoff { #$mainoff 主，$mainonoff　子論壇
    return if ($membercode eq "ad");
    if (($mainoff == 2)&&($mainonoff ne 2)) {
	$mainoff = 1;
	my (undef, undef, $hour, $mday, undef, undef, $wday, undef) = localtime(time + $timezone * 3600);
	$mainautovalue =~ s/[^\d\-]//sg;
	my ($starttime, $endtime) = split(/-/, $mainautovalue);
	if ($mainauto eq "day") {
	    $mainoff = 0 if ($hour == $starttime && $endtime eq "");
	    $mainoff = 0 if ($hour >= $starttime && $hour < $endtime);
	}
	elsif ($mainauto eq "week") {
	    $wday = 7 if ($wday == 0);
	    $mainoff = 0 if ($wday == $starttime && $endtime eq "");
	    $mainoff = 0 if ($wday >= $starttime && $wday <= $endtime);
	}
	elsif ($mainauto eq "month") {
	    $mainoff = 0 if ($mday == $starttime && $endtime eq "");
	    $mainoff = 0 if ($mday >= $starttime && $mday <= $endtime);
	}
    }
    if ($mainonoff == 2) {
	$mainonoff = 1;
	my (undef, undef, $hour, $mday, undef, undef, $wday, undef) = localtime(time + $timezone * 3600);
	$mainautovalue1 =~ s/[^\d\-]//sg;
	my ($starttime, $endtime) = split(/-/, $mainautovalue1);
	if ($mainauto1 eq "day") {
	    $mainonoff = 0 if ($hour == $starttime && $endtime eq "");
	    $mainonoff = 0 if ($hour >= $starttime && $hour < $endtime);
	}
	elsif ($mainauto1 eq "week") {
	    $wday = 7 if ($wday == 0);
	    $mainonoff = 0 if ($wday == $starttime && $endtime eq "");
	    $mainonoff = 0 if ($wday >= $starttime && $wday <= $endtime);
	}
	elsif ($mainauto1 eq "month") {
	    $mainonoff = 0 if ($mday == $starttime && $endtime eq "");
	    $mainonoff = 0 if ($mday >= $starttime && $mday <= $endtime);
	}
    }

    if (($mainoff == 1)||($mainonoff == 1)) { require "doinmaintenance.pl"; }
}

sub error {
    my $errorinfo = shift;
    (my $where, my $errormsg,my $ismsg) = split(/\&/, $errorinfo);
    print header(-charset=>big5 , -expires=>"$EXP_MODE" , -cache=>"$CACHE_MODES");
    if (! $inmembername) { $inmembername = cookie("amembernamecookie"); }
    $inpassword = cookie("apasswordcookie");
    $inmembername =~ s/[\a\f\n\e\0\r\t\`\~\!\@\#\$\%\^\&\*\(\)\+\=\\\{\}\;\'\:\"\,\.\/\<\>\?]//isg;
    $inpassword =~ s/[\a\f\n\e\0\r\t\|\@\;\#\{\}\$]//isg;
    if ($ismsg ne "msg") {
	&title;

	if ($indexforum ne "no") {
	    $output .= qq~<BR><table width=$tablewidth align=center cellspacing=0 cellpadding=1 bgcolor=$navborder><tr><td><table width=100% cellspacing=0 cellpadding=3><tr><td bgcolor=$navbackground><img src=$imagesurl/images/item.gif align=absmiddle width=11> <font color=$navfontcolor><a href=leobbs.cgi>$boardname</a> → 錯$div_wrong： $where</td><td bgcolor=$navbackground align=right></td></tr></table></td></tr></table>~;
	} else {
	    $output .= qq~<BR><table width=$tablewidth align=center cellspacing=0 cellpadding=1 bgcolor=$navborder><tr><td><table width=100% cellspacing=0 cellpadding=3><tr><td bgcolor=$navbackground><img src=$imagesurl/images/item.gif align=absmiddle width=11> <font color=$navfontcolor>錯$div_wrong： $where</td><td bgcolor=$navbackground align=right></td></tr></table></td></tr></table>~;
	}
    }
    else {
	$output = "";
    }
if ($catbackpic !~ /^background\=/)  { $catbackpic = "background=$imagesurl/images/$skin/$catbackpic"; }

    $output .= qq~<p><SCRIPT>valigntop()</SCRIPT><table cellpadding=0 cellspacing=0 width=$tablewidth bgcolor=$tablebordercolor align=center><tr><td><table cellpadding=6 cellspacing=1 width=100%>~;
    
    $output .= qq~<tr><td bgcolor=$titlecolor $catbackpic align=center><font color=$fontcolormisc><b>錯$div_wrong： $where</b></font></td></tr>
<tr><td bgcolor=$miscbackone><font color=$fontcolormisc>
<b>關於$where的詳細原因：</b>
<ul><li><b>$errormsg</b>
<li>您是否需要查看<span style="cursor:hand" onClick="javascript:openScript('help.cgi',500,400)">說明檔案</span>?
</ul><b>產生$where錯$div_wrong的可能原因：</b>
<ul><li>密碼錯$div_wrong<li>會員名稱錯$div_wrong<li>您不是<a href="register.cgi" >註冊</a>會員</ul>
<br><br><center><font color=$fontcolormisc> << <a href="javascript:history.go(-1)">返回上$div_one頁</a></center>
</tr></td></table></td></tr></table><SCRIPT>valignend()</SCRIPT><BR>
~;
    &output($boardname,\$output,"$ismsg");
    exit;
}

sub myip {
    my $ipaddress      = $ENV{'REMOTE_ADDR'};
    my $trueipaddress  = $ENV{'HTTP_X_FORWARDED_FOR'};
    $trueipaddress     = $ipaddress if ($trueipaddress eq "" || $trueipaddress eq "unknown" || $trueipaddress =~ m/^192\.168\./ || $trueipaddress =~ m/^10\./);
    my $trueipaddress1 = $ENV{'HTTP_CLIENT_IP'};
    $trueipaddress     = $trueipaddress1 if ($trueipaddress1 ne "" && $trueipaddress1 ne "unknown" &&  $trueipaddress1 !~ m/^192\.168\./ &&  $trueipaddress1 !~ m/^10\./);
    return "$ipaddress=$trueipaddress";
}

1;
$div_one	='一';
$div_then	='才';
$div_lee	='年';
$div_out	='外';
$div_edit	='作';
$div_way	='途';
$div_bottle	='瓶';
$div_yip	='業';
$div_chinese	='漢';
$div_wrong	='誤';
$div_sco	='羯';
$div_run	='繼';
$div_beh	='品';
$div_live	='居';

$main::div_one		='一';
$main::div_then		='才';
$main::div_lee		='年';
$main::div_out		='外';
$main::div_edit		='作';
$main::div_way		='途';
$main::div_bottle	='瓶';
$main::div_yip		='業';
$main::div_chinese	='漢';
$main::div_wrong	='誤';
$main::div_sco		='羯';
$main::div_run		='繼';
$main::div_beh		='品';
$main::div_live		='居';
