2
2
# CGI:IRC - http://cgiirc.sourceforge.net/
3
# Copyright (C) 2000-2003 David Leadbeater <cgiirc@dgl.cx>
3
# Copyright (C) 2000-2006 David Leadbeater <http://contact.dgl.cx/>
4
4
# vim:set ts=3 expandtab shiftwidth=3 cindent:
6
6
# This program is free software; you can redistribute it and/or modify
21
21
# BEGIN { (my $dir = $0) =~ s|[^/]+$||; chdir($dir) }
24
use vars qw($VERSION);
24
use vars qw($VERSION $config $config_path);
25
25
use lib qw/modules interfaces/;
26
no warnings 'uninitialized';
28
'$Name: rel_0_5_4 $ 0_5_CVS $Id: irc.cgi,v 1.28 2004/01/29 14:50:27 dgl Exp $'
29
'$Name: rel_0_5_9 $ 0_5_CVS $Id: irc.cgi,v 1.41 2006/06/06 18:53:50 dgl Exp $'
29
30
) =~ s/^.*?(\d\S+) .*?(\d{4}\/\S+) .*$/$1/;
30
31
$VERSION .= " ($2)";
31
32
$VERSION =~ s/_/./g;
33
34
require 'parse.pl';
38
for('', '/etc/cgiirc/', '/etc/') {
39
last if -r ($config_path = $_) . 'cgiirc.config';
42
$config = parse_config($config_path . 'cgiirc.config');
35
44
if(!parse_cookie()) {
36
print "Set-cookie: cgiircauth=". random(25) .";path=/\n";
45
print "Set-cookie: cgiircauth=". random(25) .";path=/\r\n";
39
'Content-type: text/html',
48
# Hack to make sure we print the correct type for stylesheets too..
49
'Content-type: text/' . (ref $cgi && defined $cgi->{item} &&
50
$cgi->{item} eq 'style' ? 'css' : 'html')
51
# We need this for some JavaScript magic that detects the character set.
52
# Basically don't send a character set for the login page..
53
. (ref $cgi && ($cgi->{item} || $cgi->{Nickname}) ? '; charset=utf-8' : ''),
40
54
'Pragma: no-cache',
41
55
'Cache-control: must-revalidate, no-cache',
42
56
'Expires: -1') . "\r\n";
46
60
<a href="http://cgiirc.sourceforge.net/">CGI:IRC</a> $VERSION<br />
49
my $config = parse_config('cgiirc.config');
52
63
my $scriptname = $config->{script_login} || 'irc.cgi';
54
65
my $interface = ref $cgi && defined $cgi->{interface} ? $cgi->{interface} : 'default';
55
$interface =~ s/[^a-z0-9]//gi;
56
require('interfaces/' . $interface . '.pm');
66
$interface =~ /^([a-z0-9]+)/;
68
require($interface . '.pm');
58
70
if(ref $cgi && defined $cgi->{item}) {
59
71
print "\r\n"; # send final header
73
85
Realname => 'name',
74
86
interface => 'interface',
75
87
Password => 'pass',
89
'Character_set' => 'charset',
93
if(exists $cgi->{"${_}_text"}) {
94
if(!defined $cgi->{$_} or $cgi->{$_} eq '') {
95
$cgi->{$_} = $cgi->{"${_}_text"};
80
98
next unless exists $cgi->{$_};
81
99
$out .= cgi_encode($p{$_}) . '=' . cgi_encode($cgi->{$_}) . '&';
86
104
: $config->{format} || 'default';
87
105
$format =~ s/[^a-z]//gi;
88
$format = parse_config("formats/$format");
106
$format = parse_config($config_path . "formats/$format");
89
107
$style = exists $format->{style} ? $format->{style} : 'default';
111
if(defined $config->{'login secret'}) {
114
my $token = Digest::MD5::md5_hex($t . $config->{'login secret'} . $r);
115
$out .= "&token=$token&time=$t";
93
118
$interface->frameset($scriptname, $config, $r, $out, $interface, $style);
95
120
}elsif(defined $config->{form_redirect}) {
102
127
print "\r\n"; # send final header
129
my $have_entities = 0;
130
eval { require HTML::Entities; $have_entities = 1; };
104
132
my(%items,@order);
106
134
my $server = dolist($config->{default_server});
107
135
my $channel = dolist($config->{default_channel});
108
136
my $port = dolist($config->{default_port});
138
my $charset = [ $config->{'irc charset'} || 'Unicode (UTF-8)' ];
140
# Add some useful suggestions for character sets:
141
for my $set('Western (ISO-8859-1)', 'Cyrillic (ISO-8859-5)',
142
'Cyrillic (KOI8-R)', 'Japanese (ShiftJIS)', 'Chinese (Big5)',
143
'Chinese (GB2312)', 'Korean (EUC-KR)') {
144
push @$charset, $set unless grep { $set =~ /$_/i } @$charset
147
if(defined $ENV{HTTP_ACCEPT_CHARSET}) {
148
for my $set(split ',', $ENV{HTTP_ACCEPT_CHARSET}) {
149
next if $set =~ /;q=0($|\.0$)/ or $set =~ /\*/;
151
push @$charset, $set unless grep { /$set/i } @$charset;
110
155
if(ref $cgi && $cgi->{chan}) {
111
156
$channel = $cgi->{chan};
114
159
if(!defined $config->{allow_non_default} || !$config->{allow_non_default}) {
115
$server = "-DISABLED- $server" unless ref $server;
116
$channel = "-DISABLED- $channel" unless ref $channel;
117
$port = "-DISABLED- $port" unless ref $port;
118
}elsif(!defined $config->{access_server} || !$config->{access_server}) {
119
$server = "-DISABLED- $server" unless ref $server;
160
add_disabled($server);
161
add_disabled($channel);
164
add_disabled($server) unless defined $config->{access_server};
165
add_disabled($port) unless defined $config->{access_port};
166
add_disabled($channel) unless defined $config->{access_channel};
122
opendir(FORMATS, "formats");
169
opendir(FORMATS, $config_path . "formats");
124
171
for(sort readdir FORMATS) {
125
next unless !/^\./ && -f "formats/$_";
172
next unless !/^\./ && -f $config_path . "formats/$_";
126
173
if($_ eq ($config->{format} || 'default')) {
127
174
unshift(@formats, $_);
139
186
Password => '-PASSWORD-',
140
187
Realname => $config->{default_name},
141
188
Format => \@formats,
189
'Character set' => $charset
144
@items{keys %items} = map(ref $_ ? $_ : escape_html($_), values %items);
192
my $func = \&escape_html;
193
$func = \&HTML::Entities::encode_entities if $have_entities;
194
@items{keys %items} = map { ref $_
195
? [map { $func->($_) } @$_]
146
199
$items{Nickname} =~ s/\?/int rand 10/eg;
148
201
if(ref $cgi && $cgi->{adv}) {
149
202
if($config->{'login advanced'}) {
150
@order = split(' ', $config->{'login advanced'});
203
@order = split(/,\s*/, $config->{'login advanced'});
152
205
@order = qw/Nickname Realname Server Port Channel Password Format/;
206
push @order, 'Character set';
155
209
if($config->{'login basic'}) {
156
@order = split(' ', $config->{'login basic'});
210
@order = split(/,\s*/, $config->{'login basic'});
158
212
@order = qw/Nickname Server Channel/;
233
unshift @{$_[0]}, "-DISABLED-";
235
$_[0] = "-DISABLED- $_[0]";
178
240
return unless defined $ENV{REQUEST_METHOD};
179
241
if($ENV{REQUEST_METHOD} eq 'GET' && $ENV{QUERY_STRING}) {