www.pudn.com > coolchat.zip > chatmanager.pl
sub Manager_Main
{
&somerror("出错了, 你不是管理员耶!") if($UserData{'Group'} ne 99);
my($qry_string) = shift;
($action,$param)=split(/\*/,$qry_string,2);
if($action eq "lk")
{#Lock/Unlock a room
&setroom;
}
elsif($action eq "li")
{
&listrooter;
}
elsif($action eq "am")
{
&setmanager($param);
}
elsif($action eq "dm")
{
&deluser($param);
}
elsif($action eq "dr")
{
&clearoom($param);
}
elsif($action eq "sm")
{
&setmaster;
}
else
{
&somerror("$ErrorMessage","$ChatURLpath",1);
}
}
sub setroom
{#/x -r 9 roomname
&get_form_data;
$command = $formdata{'message'};
my($state,$targetroom,$mastername) = split(/ /,$command);
$state =~s/\D//g;
$state = 0 if(($state <= 0)||($state eq ""));
$state = 9 if($state > 9);
&somerror("Sorry, you must input the room name!") if($targetroom eq "");
&lock("$ChatRoomListFile");
if(open(ROOMLIST, "$ChatRoomListFile"))
{
@roomlines=;
close ROOMLIST;
if(open(ROOMLIST, ">$ChatRoomListFile"))
{
foreach $roomline(@roomlines)
{
($roomname,$usernum,$master,$visible,$attrib,$tails)=split(/:/,$roomline,6);
if($roomname eq $targetroom)
{
$attrib = $state;
if(defined $mastername)
{
if($mastername ne "")
{
$master = lc($mastername);
}
}
$roomline = "$roomname:$usernum:$master:$visible:$attrib:$tails";
}
print ROOMLIST $roomline;
}
close ROOMLIST;
}
}
&unlock("$ChatRoomListFile");
&chatshowmsg;
}
sub setmanager
{#/x -m 99 username
&get_form_data;
$command = $formdata{'message'};
my($state,$targetuser) = split(/ /,$command);
$state =~s/\D//g;
$state = 0 if(($state <= 0)||($state eq ""));
$state = 99 if($state > 99);
&somerror("出错了, 你必须输入用户名称!") if($targetuser eq "");
$targetuser = lc($targetuser);
#Get user data path
$first_id='!';
my $idpath = $LOGOpath.$first_id."/";
my $datapath = $idpath.$targetuser;
&somerror("对不起,我找不到用户$targetuser!") unless(-e "$datapath");
&lock($datapath);
if(open(DATA,"<$datapath"))
{
@userlines=;
close DATA;
($id,$crykey,$rightgroup,$tails)=split(/:/,$userlines[0],4);
($UsrRight,$UsrGroup)=split(/\|/,$rightgroup);
if($UsrGroup eq $state)
{
&unlock($datapath);
&somerror("出错了, 用户$targetuser 已经有了这个权限了呀!");
}
$userlines[0] = "$id:$crykey:$UsrRight|$state:$tails";
if(open(DATA,">$datapath"))
{
foreach $line(@userlines)
{
print DATA $line;
}
close DATA;
}
}
&unlock($datapath);
my $nowtime = time;
if($state eq 99)
{#Add user to root list!
&lock($ChatRootUserFile);
if(open(DATA,">>$ChatRootUserFile"))
{
print DATA "$targetuser:$state:$nowtime:$UserData{'User'}:$ENV{'REMOTE_ADDR'}:0:0:0:E\n";
close DATA;
}
&unlock($ChatRootUserFile);
}
elsif($UsrGroup eq 99)
{#Del from the root list
&lock($ChatRootUserFile);
if(open(DATA,"$ChatRootUserFile"))
{
@rootlines = ;
close DATA;
if(open(DATA,">$ChatRootUserFile"))
{
foreach $line(@rootlines)
{
($id,$tails)=split(/:/,$line,2);
next if($id eq $targetuser);
print DATA $line;
}
close DATA;
}
}
&unlock($ChatRootUserFile);
}
&chatshowmsg;
}
sub deluser
{#/x -d username
my $targetuser = shift;
$targetuser=lc($targetuser);
&somerror("出错了耶, 你不能删除管理员!小心。。。。嘿嘿嘿!") if($targetuser eq "sysop");
&lock($ChatUserListFile);
if(open(DATA,"$ChatUserListFile"))
{
@lines = ;
close DATA;
if(open(DATA,">$ChatUserListFile"))
{
foreach $line(@lines)
{
($id,$tails)=split(/:/,$line,2);
next if($id eq $targetuser);
print DATA $line;
}
close DATA;
}
}
&unlock($ChatUserListFile);
my @filelist = ();
$first_id='!';
my $idpath = $LOGOpath.$first_id."/";
my $datapath = $idpath.$targetuser;
$filelist[0] = $datapath;
$filelist[1] = $datapath.$DATA;
$filelist[2] = "$Userdatapath/$targetuser$COUNTER";
$filelist[3] = "$Userdatapath/$targetuser.KEY";
unlink(@filelist);
&chatshowmsg;
}
sub listrooter
{#/x -l
print "Content-type: text/html\nPragma: no-cache\n\n";
print "\n";
print "$Chat_Roomname 管理员列表 \n";
print "用户ID 权限 设置时间 设置者 设置者IP \n";
if(open(DATA,"$ChatRootUserFile"))
{
@rootusers = ;
close DATA;
foreach $rootuser(@rootusers)
{
($user,$state,$time,$setuser,$ip,$tails) = split(/:/,$rootuser,6);
$time = &convert_time($time);
print "$user $state $time $setuser $ip \n";
}
}
print "
";
}
sub clearoom
{
my $targetroom = shift;
&somerror("你必须输入聊天室的名字耶!") if($targetroom eq "");
unlink "$chatdatadir/$targetroom$AllMsgExt";
&chatshowmsg;
}
sub setmaster
{
&get_form_data;
$command = $formdata{'message'};
my($state,$targetroom,$mastername) = split(/ /,$command);
$state = lc($state);
&somerror("出错了, 你必须输入聊天室的名字和管理员的名称呀!") if(($targetroom eq "")||($mastername eq "")||($state eq ""));
$mastername = lc($mastername);
&lock("$ChatRoomListFile");
if(open(ROOMLIST, "<$ChatRoomListFile"))
{
@roomlines=;
close ROOMLIST;
if(open(ROOMLIST, ">$ChatRoomListFile"))
{
foreach $roomline(@roomlines)
{
($roomname,$usernum,$themasterlist,$tails)=split(/:/,$roomline,4);
if($targetroom eq $roomname)
{
@masterlist = split(/\|/,$themasterlist);
$themasterlist = "";
$haveit = 0;
foreach $themaster(@masterlist)
{
if($mastername eq $themaster)
{
next if($state eq "d");
$haveit = 1;
}
$themasterlist .= "$themaster|";
}
$themasterlist .= "$mastername" if(($haveit eq 0)&&($state eq "a"));
$themasterlist = substr($themasterlist,0,length($themasterlist)-1) if(substr($themasterlist,length($themasterlist)-1,1) eq "|");
$roomline = "$roomname:$usernum:$themasterlist:$tails";
}
print ROOMLIST "$roomline";
}
close ROOMLIST;
}
}
&unlock("$ChatRoomListFile");
&chatshowmsg;
}
1;