home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- $chat_name = "My Chat";
- $update = "10";
- $chat_window_bg = "#ffffff";
- $options_window_bg = "#ffffff";
- $show_mes = 30;
- $killtags = 1;
-
- $temp=$ENV{'QUERY_STRING'};
- @pairs=split(/&/,$temp);
- foreach $item(@pairs) {
- ($key,$content)=split (/=/,$item,2);
- $content=~tr/+/ /;
- $content=~ s/%(..)/pack("c",hex($1))/ge;
- $FORM{$key}=$content;
- }
-
- if($killtags eq 1) {
- $FORM{'chat'} =~ s/</</g;
- $FORM{'chat'} =~ s/>/>/g;
- $FORM{'nick'} =~ s/</</g;
- $FORM{'nick'} =~ s/>/>/g;
- }
-
- $timeout = time;
-
- open (LOG,"+<log.txt");
- flock(LOG,2);
- @log = <LOG>;
-
- foreach $log (@log) {
- @log_params = split(/\|\|/,$log);
- $timelog = $timeout - $log_params[2];
- if ($timelog > 150) {
- $log = "";
- open(CHAT,"chat.txt");
- flock(CHAT,2);
- @chat = <CHAT>;
- close(CHAT);
- $str = "||System message||black||<i>$log_params[1] φas quitted from chat.</i>||\n";
- push(@chat,$str);
- $chat_many = @chat;
- if ($chat_many > 99) {$chat[0] = "";}
-
- open(CHAT,">chat.txt");
- flock(CHAT,2);
- print CHAT @chat;
- close(CHAT);
- }
- $a++;
- }
-
- seek (LOG, 0, 0);
- truncate (LOG,0);
- print LOG @log;
- close (LOG);
-
- $link = "<a href=http://www.agfreesoft.com</a>";
-
- if($ENV{'QUERY_STRING'} eq '') {&login;}
- elsif($FORM{'action'} eq 'enter') {&enter;}
- elsif($FORM{'action'} eq 'chat') {&chat;}
- elsif($FORM{'action'} eq 'options') {&options;}
-
- sub login {
-
- print "Content-Type: text/html\n\n";
- print "<html>\n";
- print "<head>\n";
- print "<title>$chat_name</title>\n";
- print "<style>\n";
- print "INPUT, SELECT, BODY, TD {font-family: Tahoma; font-size: 11}\n";
- print "</style>\n";
- print "</head>\n";
- print "<body>\n";
- print "<center>\n";
- print "<font face=Tahoma size=2>Please, enter yours nickname enter a chat $chat_name.\n";
- print "<table>\n";
- print "<form action=chat.cgi method=GET>\n";
- print "<tr><td>Nickname:</td><td><input type=hidden name=action value=enter><input type=text
- name=nick size=10></td></tr>\n";
- print "<tr><td>Color:</td><td><select name=color>";
- print "<option value=black>black</option>";
- print "<option value=green>green</option>";
- print "<option value=yellow>yellow</option>";
- print "<option value=blue>blue</option>";
- print "<option value=red>red</option>";
- print "</select></td></tr>";
- print "<tr><td colspan=2><input type=submit value=Enter></td></tr>\n";
- print "</form></table></font>\n";
- print "</center>\n";
- print "</body>\n";
- print "</html>\n";
-
- exit;
-
- }
-
- sub enter {
-
- if ($FORM{'nick'} eq '') { &error('You have not entered nickname.'); }
- $nick = $FORM{'nick'};
- $time = time;
-
- open(LOG,"log.txt");
- @log = <LOG>;
- foreach $log (@log) {
- if($log =~ /^\|\|$nick\|\|/) {
- $found = 1;
- }
- }
- close(LOG);
- if (!($found)) {
- open(LOG,">>log.txt");
- print LOG "||$nick||$time||\n";
- close(LOG);
- open(CHAT,"chat.txt");
- flock(CHAT,2);
- @chat = <CHAT>;
- close(CHAT);
- $str = "||System message||black||<i>$FORM{'nick'} φas quitted from chat.</i>||\n";
- push(@chat,$str);
- $chat_many = @chat;
- if ($chat_many > 99) {$chat[0] = "";}
-
- open(CHAT,">chat.txt");
- flock(CHAT,2);
- print CHAT @chat;
- close(CHAT);
- }
-
- print "Content-Type: text/html\n\n";
- print "<html>\n";
- print "<head>\n";
- print "<title>$chat_name</title>\n";
- print "</head>\n";
- print "<frameset rows=\"*,70\" border=0 frameborder=0>\n";
- print "<frame name=\"chat\" noresize src=\"chat.cgi?nick=$nick&action=chat\">\n";
- print "<frame name=\"options\" src=\"chat.cgi?nick=$nick&action=options&color=$FORM{'color'}\">\n";
- print "<noframes>\n";
- print "<body>\n";
- print "<font face=Tahoma size=2>Unfortunately your browser does not support frames, necessary for
- dialogue.</font>\n";
- print "</body>\n";
- print "</noframes>\n";
- print "</frameset>\n";
- print "</html>\n";
-
- exit;
-
- }
-
- sub chat {
-
- &update;
- open(LOG,"log.txt");
- @members = <LOG>;
- close(LOG);
-
- foreach $member (@members) {
- @member_params = split(/\|\|/,$member);
- push(@online,$member_params[1]);
- }
-
- open(CHAT,"chat.txt");
- @chat = <CHAT>;
- close(CHAT);
-
- @chat = reverse @chat;
-
- $end = $show_mes - 1;
- $end = @chat - 1 if scalar(@chat) < 30;
-
- foreach $chat (@chat[0..$end]) {
- @chat_params = split(/\|\|/,$chat);
- $str = "$chat_params[1]: <font color=$chat_params[2]>$chat_params[3]</font>";
- push(@text_chat,$str);
- }
-
- print "Content-Type: text/html\n\n";
- print "<html>\n";
- print "<head>\n";
- print "<meta http-equiv=\"Refresh\" CONTENT=\"$update\;
- URL=chat.cgi?action=chat\&nick=$FORM{'nick'}\">";
- print "<style>\n";
- print "BODY {font-family: Tahoma; font-size: 12}\n";
- print "</style>\n";
- print "</head>\n";
- print "<body bgcolor=$chat_window_bg>\n";
- print "<b>On-line: ";
- foreach (@online) {
- print "$_, ";
- }
- print "</b><br>\n";
- print "<br>\n";
- foreach $str (@text_chat) {
- print "$str\n<br>\n";
- }
- print "</body>\n";
- print "</html>\n";
-
- exit;
-
- }
-
- sub options {
-
- &update;
- if($FORM{'chat'} ne '') {
- open(CHAT,"chat.txt");
- flock(CHAT,2);
- @chat = <CHAT>;
- close(CHAT);
- $str = "||$FORM{'nick'}||$FORM{'color'}||$FORM{'chat'}||\n";
- push(@chat,$str);
- $chat_many = @chat;
- if ($chat_many > 99) {$chat[0] = "";}
-
- open(CHAT,">chat.txt");
- flock(CHAT,2);
- print CHAT @chat;
- close(CHAT);
- }
-
- print "Content-Type: text/html\n\n";
- print "<html>\n";
- print "<head>\n";
- print "<style>\n";
- print "INPUT, SELECT {font-family: Tahoma; font-size: 11}\n";
- print "</style>\n";
- print "</head>\n";
- print "<body bgcolor=$options_window_bg>\n";
- print "<center>\n";
- print "<form action=chat.cgi method=GET>\n";
- print "<input type=hidden name=action value=options>";
- print "<input type=hidden name=nick value=$FORM{'nick'}>";
- print "<input type=text name=chat size=45>";
- print "<input type=hidden name=color value=$FORM{'color'}>";
- print "<input type=submit value=Tell><br>$link\n";
- print "</form></font>\n";
- print "</center>\n";
- print "</body>\n";
- print "</html>\n";
-
- exit;
-
- }
-
- sub update {
-
- open (LOG,"+<log.txt");
- flock(LOG,2);
- @log = <LOG>;
-
- $a=0;
- foreach (@log) {
- @log_params = split(/\|\|/,$log[$a]);
- if ($log_params[1] eq $FORM{'nick'}) {
- $log_params[2] = time;
- $log[$a] = join("\|\|",@log_params);
- }
- $a++;
- }
-
- seek (LOG, 0, 0);
- truncate (LOG,0);
- print LOG @log;
- close (LOG);
-
- }
-
- sub error {
-
- $err = $_[0];
-
- print "Content-Type: text/html\n\n";
- print "<html>\n";
- print "<head>\n";
- print "<title>$chat_name error</title>\n";
- print "<style>\n";
- print "BODY {font-family: Tahoma; font-size: 11}\n";
- print "</style>\n";
- print "</head>\n";
- print "<body>\n";
- print "<center>\n";
- print "<font size=2 face=Tahoma>$err</font>\n";
- print "</center>\n";
- print "</body>\n";
- print "</html>\n";
-
- exit;
-
- }
-
-