#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # 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 with a 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. # $Id: nph-chat_check.html,v 1.13 2002/07/09 21:43:12 tstm Exp $ ############################################ # # # MimerDesk: I-Chat # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Design AY 1999 - 2000 # # # # Programmed by: Teemu Vainio # # # ############################################ use strict; use vars qw ($APPLICATION $ACTIVEGRP $ARTICLE $MONTH $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $time_limit $trans); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; sub tutki_selain; sub tulosta_tiedosto; sub print_template; sub send_ping; sub tapa_kummitus; sub tutki_idle; sub channel_name; $APPLICATION='Communication - Chat'; $time_limit = 120; # (2 minuuttia) ########### # Ohjelma # ########### # 1. Tarkistetaan onko käyttäjä mukana keskustelussa.. Jos ei niin potkitaan pellolle vakoilemasta # 2. Selvitetään käyttäjän käyttämä selain # 3. Heitetään ilmoille muutama edellinen viesti # 4. Ajetaan i-chat time_out disabling engine read_config('../config/mimerdesk.cfg'); initialize(); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $trans = lib::MimerDesk->new_gettext(program => 'nph-chat_check',language => $config{'language'}); $APPLICATION = $trans->gettext('Communication - Chat'); $form->{'kayttaja'} =~ tr/0-9//cd; my $kayttajan_alias = tutki_idle(); my $selain = tutki_selain(); $| = 1; my $raja = "_omituinenrajausriviiiisssdddisdhampurilainenisdsdsfzspdbl"; if ($selain eq 'ie') { print "HTTP/1.1 200 OK\n"; print "Content-Type: multipart/mixed;boundary=$raja\n\n"; } elsif ($selain eq 'ns') { print "HTTP/1.1 200 OK"; print "Content-Type: multipart/mixed;boundary=$raja\n"; print "--$raja\n"; print "Content-Type: text/html\n\n"; } elsif ($selain eq 'konq') { print "HTTP/1.0 200\n"; print "Content-type: multipart/x-mixed-replace;boundary=$raja\n\n"; print "--$raja\n"; print "Content-Type: text/html\n\n"; } elsif ($selain eq 'gecko') { print "HTTP/1.0 200\n"; print "Content-type: multipart/x-mixed-replace;boundary=$raja\n\n"; print "--$raja\n"; print "Content-Type: text/html\n\n"; } print_template('chat_nph_check', 1); $form->{'reloaded'} ? tulosta_tiedosto(0, 'no_private') : tulosta_tiedosto(10, 'no_private'); my $sec=0; my $rivit = row_count("chatroom_$form->{'kanava'}"); while(1) { $sec++; select(undef,undef,undef, 0.5); my $rowit = row_count("chatroom_$form->{'kanava'}"); if ($rivit != $rowit) { my $uudet = ($rowit - $rivit); $rivit = $rowit; tulosta_tiedosto($uudet, 'normal'); } if ($sec >= 60) { print "\n"; print "\n"; $sec = 0; send_ping(); $APPLICATION='Communication - Chat'; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $APPLICATION = $trans->gettext('Communication - Chat'); tutki_idle(); } } ################################################## # Tulostaa tietokannasta halutun määrän viestejä # # Jos toinen parametri on "normal", tulostetaan # # myös mahdolliset yksityiset viestit, muulloin # # tulostetaan ainoastaan julkiset viestit # ################################################## # 1. Jos viesti on ylläpitoviesti, käsitellään hieman erilailla sub tulosta_tiedosto { my ($uudet_rivit,$mode) = @_; my($time , $message, $line, $kohde,$sender,$me,$type,@aika,$chat_seconds,$kicked,$syy); my (@row); db_list("SELECT * FROM chatroom_$form->{'kanava'} order by LINE DESC LIMIT $uudet_rivit"); while (my $ref = $sth->fetchrow_hashref()) { $time = $ref->{'TIME'}; $message = $ref->{'MESSAGE'}; next if $message =~ /_omituinenrajausriviiiisssdddisdhampurilainenisdsdsfzspdbl/; $line = $ref->{'LINE'}; $type = $ref->{'TYPE'}; $kohde = $ref->{'TARGET'}; $sender = $ref->{'SENDER'}; @aika = utc_epoch2date($time); $chat_seconds ? $time = "$aika[2]:$aika[1]:$aika[0] " : $time = "$aika[2]:$aika[1] "; $message = urlify($message); $message =~ s/:b(.*?)b:/$1<\/b>/g; $message =~ s/:i(.*?)i:/$1<\/i>/g; $message =~ s/:u(.*?)u:/$1<\/u>/g; if ($type eq 'topic') { my ($name,$topic) = split "&", $message; $message = sprintf($trans->gettext("%s changes topic to %s"),$name,$topic); } elsif ($type eq 'nick') { my ($vanhanimi,$uusinimi) = split "&", $message; $message = sprintf($trans->gettext("%s is now known as %s"),$vanhanimi,$uusinimi); $kayttajan_alias = tutki_idle(); } elsif ($type eq 'partmsg') { my ($nimi,$channel_name,$viesti) = split "&", $message; $message = sprintf($trans->gettext("%s has left channel %s (%s)"),$nimi,$channel_name,$viesti); $type = 'partjoin'; } elsif ($type eq 'part') { my ($nimi,$channel_name) = split "&", $message; $message = sprintf($trans->gettext("%s has left channel %s"),$nimi,$channel_name); $type = 'partjoin'; } if ($sender eq 'i-system' && ($kohde eq 'kaikki' || $kohde eq $kayttajan_alias) > 0) { if ($message =~ / kicked / || $message =~ /joined/ || $message =~ /left/ || $message =~ /timed out/ || $message =~ /changes topic/ || $message =~ /known as/) {$message = $time."".$message."";unshift @row, $message;} elsif ($mode eq 'normal') {$message = "".$message."";unshift @row, $message;} } else { ($sender, $me) = split "&", $sender; if($kohde eq 'kaikki' && $me eq $USER) { $message = $time.'['.$sender.'] '.$message.""; unshift @row, $message; } elsif($kohde eq 'kaikki') { $message = $time.'['.$sender.'] '.$message.""; unshift @row, $message; } elsif ($me eq $USER && $mode eq 'normal') { $message = $time.'['.$sender.'] => ['.$kohde.'] '.$message.""; unshift @row, $message; } elsif($kohde eq $kayttajan_alias && $mode eq 'normal') { $message = $time.'['.$sender.'] => ['.$kohde.'] '.$message.""; unshift @row, $message; } else {next;} } } db_end(); foreach (@row) {print "$_\n
\n";} if ($sender eq 'i-system' && ($kohde eq 'kaikki' || $kohde eq $kayttajan_alias) > 0) { if ($message =~ / topic /) {print '';} # elsif ($message =~ / has kicked /) # { # $message =~ /ing>(.+?) has kicked (.+?) out of the channel \((.+?)\)/; # $form->{'kicker'} = $1; # $kicked = $2; # $kicked = html_escape($kicked, 'inverse'); # $form->{'reason'} = $3; # if ($kicked eq $kayttajan_alias) # { # $form->{'reason'} = html_escape($form->{'reason'}, 'inverse'); # $form->{'reason'} =~ s/ /+/g; # $syy =~ tr/A-ZÅÄÖa-zåäö0-9_-@!+//cd; # db_list("delete from chat_users where USER like '$form->{'kanava'}&$USER'"); # db_end(); # print ""; # } # print ''; # } elsif ($message =~ $trans->gettext('Clearing your screen')) {print '';} elsif ($message =~ $trans->gettext('Leaving the channel')) { if ($message =~ /Leaving the channel\.\.\. \(/) {print "";} else {print "";} } elsif ($message =~ / timed out/ || $message =~ / has left / || $message =~ / has joined / || $message =~ /known as/) {print '';} elsif ($message =~ $trans->gettext('Updated user list')) { print ''; print ''; } } } ########################### # Tutkii selaimen version # ########################### sub tutki_selain { my $tiedot = $ENV{'HTTP_USER_AGENT'}; if ($tiedot =~ /Opera/) {return 'op';} elsif ($tiedot =~ /MSIE/) {return 'ie';} elsif ($tiedot =~ /Gecko/) {return 'gecko';} elsif ($tiedot =~ /Konqueror/) {return 'konq';} else {return 'ns';} } ################################################### # ilmoittaa palvelimelle käyttäjän hereilläolosta # ################################################### sub send_ping { my $aika = time(); my $user = prepare_fordb($form->{'kanava'}."&".$USER); db_list("update chat_users set PING = '$aika' where USER = '$user'"); db_end(); } ################################## # Chekkaa onko joku timeoutannut # ################################## sub tutki_idle { my(@ghosts, $nimi); db_list("SELECT * FROM chat_users where USER like '$form->{'kanava'}&%'"); while (my $ref = $sth->fetchrow_hashref()) { (undef, $ref->{'USER'}) = split "&", $ref->{'USER'}; if ((time() - $ref->{'PING'}) >= $time_limit) { $ref->{'USER'} = $ref->{'USER'}."&".$ref->{'NICK'}; push @ghosts,$ref->{'USER'}; } if ($ref->{'USER'} eq $USER) {$nimi = $ref->{'NICK'};} } db_end(); foreach (@ghosts) { my ($user, $nick) = split "&", $_; tapa_kummitus($user, $nick); } if ($nimi) {return $nimi;} else { print_template('chat_nimea_ei_loydy'); exit; } } ################################################### # Poistaa timeoutanneen käyttäjän kummittelemasta # ################################################### # 1. Tiedotetaan muille poistumisesta sub tapa_kummitus { my ($user, $nick) = @_; $user = $form->{'kanava'}."&".$user; lock_tables('WRITE', "chat_users"); db_list("delete from chat_users where USER like '$user'"); db_end(); unlock_tables(); my $time = time(); my $messu = "$nick timed out"; lock_tables('WRITE', "chatroom_$form->{'kanava'}"); db_list("insert into chatroom_$form->{'kanava'} (LINE, TARGET, SENDER, TIME, TYPE, MESSAGE) values ('NULL','kaikki','i-system','$time','partjoin','$messu')"); db_end(); unlock_tables(); } ######################################################## # \/\/-----------Nicht für mich ------------------\/\/ # ######################################################## sub print_template { my ($template) = $_[0]; my ($channel_name) = channel_name($form->{'kanava'}); print_header('pragma') if !$_[1]; $ref = get_template($template); my $fulltemplate = $ref->{$template}; $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); $fulltemplate =~ s/<>/$form->{'kanava'}/mg; $fulltemplate =~ s/<>/$channel_name/mg; $fulltemplate =~ s/<>/$form->{'kohde'}/g; print $fulltemplate; exit if !$_[1]; } ################ # channel_name # ################ # # Hakee tietokannasta kanavan nimen id:n perusteella # sub channel_name { my ($name); lock_tables('READ', 'chatrooms'); db_list("select NAME from chatrooms where ID = @_"); while (my $ref = $sth->fetchrow_hashref()) { $name = $ref->{'NAME'}; } db_end(); unlock_tables(); return $name; }