~ubuntu-branches/ubuntu/karmic/cgiirc/karmic-updates

« back to all changes in this revision

Viewing changes to irc.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2006-09-30 00:15:44 UTC
  • mfrom: (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20060930001544-t2jjhvc00rnikdw0
Tags: 0.5.9-2
* Fix postinst by moving chgrp and chmod to build-time
* Cleanup debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/perl -w
 
1
#!/usr/bin/perl
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:
5
5
 
6
6
# This program is free software; you can redistribute it and/or modify
21
21
# BEGIN { (my $dir = $0) =~ s|[^/]+$||; chdir($dir) }
22
22
 
23
23
use strict;
24
 
use vars qw($VERSION);
 
24
use vars qw($VERSION $config $config_path);
25
25
use lib qw/modules interfaces/;
 
26
no warnings 'uninitialized';
26
27
 
27
28
($VERSION =
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;
32
33
 
33
34
require 'parse.pl';
34
35
 
 
36
my $cgi = cgi_read();
 
37
 
 
38
for('', '/etc/cgiirc/', '/etc/') {
 
39
   last if -r ($config_path = $_) . 'cgiirc.config';
 
40
}
 
41
 
 
42
$config = parse_config($config_path . 'cgiirc.config');
 
43
 
35
44
if(!parse_cookie()) {
36
 
   print "Set-cookie: cgiircauth=". random(25) .";path=/\n";
 
45
   print "Set-cookie: cgiircauth=". random(25) .";path=/\r\n";
37
46
}
38
 
print join("\r\n", 
39
 
          'Content-type: text/html',
 
47
print join("\r\n",
 
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 />
47
61
EOF
48
62
 
49
 
my $config = parse_config('cgiirc.config');
50
 
my $cgi = cgi_read();
51
 
 
52
63
my $scriptname = $config->{script_login} || 'irc.cgi';
53
64
 
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]+)/;
 
67
$interface = $1;
 
68
require($interface . '.pm');
57
69
 
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',
76
 
         Format => 'format'
 
88
         Format => 'format',
 
89
         'Character_set' => 'charset',
77
90
      );
78
91
   my $out;
79
92
   for(keys %p) {
 
93
     if(exists $cgi->{"${_}_text"}) {
 
94
       if(!defined $cgi->{$_} or $cgi->{$_} eq '') {
 
95
         $cgi->{$_} = $cgi->{"${_}_text"};
 
96
       }
 
97
     }      
80
98
          next unless exists $cgi->{$_};
81
99
          $out .= cgi_encode($p{$_}) . '=' . cgi_encode($cgi->{$_}) . '&';
82
100
   }
85
103
            ? $cgi->{Format} 
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';
90
108
 
91
109
   $out .= "R=$r";
92
 
   $out =~ s/\&$//;
 
110
 
 
111
   if(defined $config->{'login secret'}) {
 
112
      require Digest::MD5;
 
113
      my $t = time;
 
114
      my $token = Digest::MD5::md5_hex($t . $config->{'login secret'} . $r);
 
115
      $out .= "&token=$token&time=$t";
 
116
   }
 
117
 
93
118
   $interface->frameset($scriptname, $config, $r, $out, $interface, $style);
94
119
 
95
120
}elsif(defined $config->{form_redirect}) {
101
126
}else{
102
127
   print "\r\n"; # send final header
103
128
 
 
129
   my $have_entities = 0;
 
130
   eval { require HTML::Entities; $have_entities = 1; };
 
131
 
104
132
   my(%items,@order);
105
133
 
106
134
   my $server = dolist($config->{default_server});
107
135
   my $channel = dolist($config->{default_channel});
108
136
   my $port = dolist($config->{default_port});
 
137
   
 
138
   my $charset = [ $config->{'irc charset'} || 'Unicode (UTF-8)' ];
 
139
 
 
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
 
145
   }
 
146
 
 
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 =~ /\*/;
 
150
         $set =~ s/;.*//;
 
151
         push @$charset, $set unless grep { /$set/i } @$charset; 
 
152
      }
 
153
   }
109
154
 
110
155
   if(ref $cgi && $cgi->{chan}) {
111
156
      $channel = $cgi->{chan};
112
157
   }
113
158
 
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);
 
162
       add_disabled($port);
 
163
   }else{
 
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};
120
167
   }
121
168
 
122
 
   opendir(FORMATS, "formats");
 
169
   opendir(FORMATS, $config_path . "formats");
123
170
   my @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, $_);
128
175
      }else{
139
186
      Password => '-PASSWORD-',
140
187
      Realname => $config->{default_name},
141
188
      Format => \@formats,
 
189
      'Character set' => $charset
142
190
   );
143
191
 
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->($_) } @$_]
 
196
         : $func->($_) }
 
197
      values %items;
145
198
 
146
199
   $items{Nickname} =~ s/\?/int rand 10/eg;
147
200
 
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'});
151
204
          }else{
152
205
                 @order = qw/Nickname Realname Server Port Channel Password Format/;
 
206
       push @order, 'Character set';
153
207
          }
154
208
   }else{
155
209
          if($config->{'login basic'}) {
156
 
                 @order = split(' ', $config->{'login basic'});
 
210
                 @order = split(/,\s*/, $config->{'login basic'});
157
211
          }else{
158
212
                 @order = qw/Nickname Server Channel/;
159
213
          }
174
228
   return $var;
175
229
}
176
230
 
 
231
sub add_disabled {
 
232
   if(ref $_[0]) {
 
233
      unshift @{$_[0]}, "-DISABLED-";
 
234
   } else {
 
235
      $_[0] = "-DISABLED- $_[0]";
 
236
   }
 
237
}
 
238
 
177
239
sub cgi_read { 
178
240
   return unless defined $ENV{REQUEST_METHOD};
179
241
   if($ENV{REQUEST_METHOD} eq 'GET' && $ENV{QUERY_STRING}) {