summaryrefslogtreecommitdiff
path: root/0.8.1/ychatd.pl
blob: f804436543c57893628ea577cd4746aa158e6b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl
use CGI;
$q = new CGI;

use config;
use modules::commands;
use modules::changeroom;
use modules::divcom;
use modules::hierachie;
use modules::htdocs;
use modules::input;		
use modules::loggedin;
use modules::online;
use modules::postmessage;
use modules::shared;
use modules::start;		
use modules::statistic;
use modules::stream;
use modules::webchat;
use IO::Socket;
use Socket;
use POSIX;

$SIG{'CHLD'} = 'IGNORE';

$mainsocket = 'IO::Socket::INET'->new('LocalHost', "$localhost", 'LocalPort', $localport, 'Porto', 'tcp', 'Listen', $limit + 10, 'Reuse', 1);
die "Kann Server-Socket nicht erzeugen: $!\n" unless $mainsocket;

print "yChat wurde auf $localhost:$localport gestartet...\n";

$STARTIME = time;

#Debugging only
#open AWAKE, ">data/online/awake/-$$-";
#print AWAKE "$STARTIME - Daemon";
#close AWAKE;

while ($client = $mainsocket->accept) {
    print $client "HTTP/1.1 200 OK\nContent-type:text/html\n\n";

    ++$HITS;
    $pid = fork;
    if ($pid == 0) {
	my @reqheader;

	$rv = $client->recv($reqheader[0], POSIX::BUFSIZ, 0);
	@reqheader = split "\n", $reqheader[0];

        my $requeststring;
        my(@tmp) = split(/\s+/, $reqheader[0], 0);

            if ($tmp[0] eq 'GET') {
                $requeststring = $tmp[1];

	    } else {
		$requeststring = 'chat?'.$reqheader[-1];
	    }

	    #Debug only
	    #open AWAKE, ">data/online/awake/$$";
	    #print AWAKE $requeststring;
            #close AWAKE;
          
            @tmp = split(/\?/, $requeststring, 0);
            @tmp = split(/&/, $tmp[1], 0);
            my %variables;

            foreach $_ (@tmp) {
                my(@tmp) = split(/=/, $_, 0);
                next if $tmp[0] eq 'admin' or $tmp[0] eq 'mogeladmin';
                $tmp[0] =~ s[/][];
                $variables{$tmp[0]} = &url_decode($tmp[1]);
            }

            foreach $_ (keys %variables) {
		$variables{$_} =~ s/'/\\'/g;
                my $eval = "\$$_ = '" . $variables{$_} . "';";
               # print "$eval\n";
		eval $eval;
            }
	    *STD = *STDOUT;
            *STDOUT = $client;
            if ($request) {
                &secure_checkid($alias, $tmpid) if $request != 'start';
                eval "&$request";
            }
            else {
                &start;
            }
	    &del_awake();
            $client->shutdown(2);
            exit 0;
    }
}