<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,4 @@
-CGI:IRC - http://cgiirc.sourceforge.net/
+CGI:IRC - http://cgiirc.org/
 ----------------------------------------
 
 CGI:IRC is a Perl/CGI program that lets you access IRC from a web browser, it</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,8 @@
+fcgi_socket = /tmp/cgiirc-fcgi
+prerequire_interfaces = 1
+default_server = 192.168.1.1
 # This is the default configuration file for CGI:IRC 0.5
-# See http://cgiirc.sourceforge.net/docs/config.php for help editing it.
+# See http://cgiirc.org/docs/config.php for help editing it.
 
 # If you want to allow the use of multiple servers or enable more 
 # advanced  options please copy cgiirc.config.full over this file,
@@ -7,7 +10,7 @@
 
 # Set the server(s) that access is allowed to, to allow more than one entry
 # seperate the servers with commas.
-default_server = irc.blitzed.org
+#default_server = irc.blitzed.org
 default_port = 6667
 # Channel(s) to allow access to, a comma seperated list
 default_channel = #cgiirc</diff>
      <filename>cgiirc.config</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 # This is the full access CGI:IRC 0.5 config file
 # It will allow access to *all* servers and channels
-# See http://cgiirc.sourceforge.net/docs/config.php for help editing it.
+# See http://cgiirc.org/docs/config.php for help editing it.
 
 # -----
 # These are the default settings to show on the login form
@@ -159,7 +159,7 @@ session_timeout = 18000
 #dnsbl = opm.blitzed.org
 
 # Redirect to a different URL (eg. custom login form) instead of the default.
-#form_redirect = http://cgiirc.sourceforge.net/docs/custom.php
+#form_redirect = http://cgiirc.org/docs/custom.php
 
 # List of URLs (seperated with ,) which this copy of CGI:IRC should
 # balance requests over. All the URLs should be within the domain set for</diff>
      <filename>cgiirc.config.full</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 #! /usr/bin/perl -w
-# CGI:IRC - http://cgiirc.sourceforge.net/
+# CGI:IRC - http://cgiirc.org/
 # Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc@dgl.cx&gt;
 # vim:set ts=3 expandtab shiftwidth=3 cindent:
 
@@ -25,7 +25,7 @@ use vars qw($VERSION $PREFIX);
 $PREFIX = &quot;/tmp/cgiirc-&quot;;
 
 ($VERSION =
-'$Name:  $ 0_5_CVS $Id: client-perl.cgi,v 1.10 2006/04/30 16:09:28 dgl Exp $'
+'$Name:  $ 0_5_CVS $Id: client-perl.cgi,v 1.11 2007/05/06 01:05:35 dgl Exp $'
 ) =~ s/^.*?(\d\S+) .*$/$1/;
 $VERSION =~ s/_/./g;
 </diff>
      <filename>client-perl.cgi</filename>
    </modified>
    <modified>
      <diff>@@ -48,4 +48,4 @@ There are several shortcuts to help make using CGI:IRC nicer.
 
 &lt;h3&gt;About CGI:IRC&lt;/h3&gt;
 CGI:IRC is written in Perl by David Leadbeater with help from lots of people. See the &lt;a
- href=&quot;http://cgiirc.sourceforge.net/&quot; target=&quot;cgiirc-web&quot;&gt;website&lt;/a&gt; for more information.
+ href=&quot;http://cgiirc.org/&quot; target=&quot;cgiirc-web&quot;&gt;website&lt;/a&gt; for more information.</diff>
      <filename>docs/help.html</filename>
    </modified>
    <modified>
      <diff>@@ -50,5 +50,5 @@
 
 &lt;h3&gt;&#1054; &#1087;&#1088;&#1086;&#1075;&#1088;&#1072;&#1084;&#1084;&#1077; CGI:IRC&lt;/h3&gt;
 CGI:IRC &#1085;&#1072;&#1087;&#1080;&#1089;&#1072;&#1085; &#1085;&#1072; Perl David'&#1086;&#1084; Leadbeater'&#1086;&#1084; &#1074; &#1089;&#1086;&#1072;&#1074;&#1090;&#1086;&#1088;&#1089;&#1090;&#1074;&#1077; &#1089; &#1076;&#1088;&#1091;&#1075;&#1080;&#1084;&#1080;. &#1057;&#1084;&#1086;&#1090;&#1088;&#1080;&#1090;&#1077; &lt;a
- href=&quot;http://cgiirc.sourceforge.net/&quot; target=&quot;cgiirc-web&quot;&gt;&#1101;&#1090;&#1091; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1095;&#1082;&#1091;&lt;/a&gt; &#1076;&#1083;&#1103; &#1076;&#1086;&#1087;&#1086;&#1083;&#1085;&#1080;&#1090;&#1077;&#1083;&#1100;&#1085;&#1086;&#1081;
+ href=&quot;http://cgiirc.org/&quot; target=&quot;cgiirc-web&quot;&gt;&#1101;&#1090;&#1091; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1095;&#1082;&#1091;&lt;/a&gt; &#1076;&#1083;&#1103; &#1076;&#1086;&#1087;&#1086;&#1083;&#1085;&#1080;&#1090;&#1077;&#1083;&#1100;&#1085;&#1086;&#1081;
  &#1080;&#1085;&#1092;&#1086;&#1088;&#1084;&#1072;&#1094;&#1080;&#1080;.</diff>
      <filename>docs/help.ru.html</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# CGI:IRC - http://cgiirc.sourceforge.net/
+# CGI:IRC - http://cgiirc.org/
 # Copyright (C) 2000-2002 David Leadbeater &lt;http://contact.dgl.cx/&gt;
 # vim:set ts=3 expandtab shiftwidth=3 cindent:
 
@@ -22,7 +22,7 @@ use vars qw($VERSION);
 use Socket;
 
 ($VERSION =
- '$Name:  $ 0_5_CVS $Id: viewconnects.pl,v 1.4 2005/01/06 00:44:18 dgl Exp $'
+ '$Name:  $ 0_5_CVS $Id: viewconnects.pl,v 1.5 2007/05/06 01:05:35 dgl Exp $'
 ) =~ s/^.*?(\d\S+) .*$/$1/;
 $VERSION =~ s/_/./g;
 </diff>
      <filename>docs/viewconnects.pl</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@ use vars qw/$standardheader/;
 use strict;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;</diff>
      <filename>interfaces/default.pm</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ use strict;
 use vars qw/@ISA $standardheader/;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;
@@ -436,7 +436,7 @@ print q~
 &lt;script language=&quot;JavaScript&quot;&gt;
 &lt;!--
 // This javascript code is released under the same terms as CGI:IRC itself
-// http://cgiirc.sourceforge.net/
+// http://cgiirc.org/
 // Copyright (C) 2000-2003 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
 
 //               none      joins    talk       directed talk</diff>
      <filename>interfaces/ie.pm</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ print q~
 &lt;script language=&quot;JavaScript&quot;&gt;
 &lt;!--
 // This javascript code is released under the same terms as CGI:IRC itself
-// http://cgiirc.sourceforge.net/
+// http://cgiirc.org/
 // Copyright (C) 2000-2003 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
 
 //               none      joins    talk       directed talk</diff>
      <filename>interfaces/interface-make/fwindowlist.pm</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ use strict;
 use vars qw/@ISA $standardheader/;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;</diff>
      <filename>interfaces/interface-make/main.pm</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ use strict;
 use vars qw/@ISA $standardheader/;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;
@@ -437,7 +437,7 @@ print q~
 &lt;script language=&quot;JavaScript&quot;&gt;
 &lt;!--
 // This javascript code is released under the same terms as CGI:IRC itself
-// http://cgiirc.sourceforge.net/
+// http://cgiirc.org/
 // Copyright (C) 2000-2003 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
 
 //               none      joins    talk       directed talk</diff>
      <filename>interfaces/konqueror.pm</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ use strict;
 use vars qw/@ISA $standardheader/;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;
@@ -437,7 +437,7 @@ print q~
 &lt;script language=&quot;JavaScript&quot;&gt;
 &lt;!--
 // This javascript code is released under the same terms as CGI:IRC itself
-// http://cgiirc.sourceforge.net/
+// http://cgiirc.org/
 // Copyright (C) 2000-2003 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
 
 //               none      joins    talk       directed talk</diff>
      <filename>interfaces/mozilla.pm</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ use vars qw/@ISA $standardheader/;
 
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;
@@ -167,7 +167,7 @@ sub error {
 
 sub help {
    my($self) = shift;
-   $self-&gt;line(&quot;Full help can be found at http://cgiirc.sourceforge.net/docs/usage.php&quot;);
+   $self-&gt;line(&quot;Full help can be found at http://cgiirc.org/docs/usage.php&quot;);
 }
 
 sub frameset {</diff>
      <filename>interfaces/nonjs.pm</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ use vars qw/@ISA $standardheader/;
 
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2002 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;</diff>
      <filename>interfaces/opera.pm</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ use strict;
 use vars qw/@ISA $standardheader/;
 $standardheader = &lt;&lt;EOF;
 &lt;!-- This is part of CGI:IRC 0.5
-  == http://cgiirc.sourceforge.net/
+  == http://cgiirc.org/
   == Copyright (C) 2000-2006 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
   == Released under the GNU GPL
   --&gt;
@@ -437,7 +437,7 @@ print q~
 &lt;script language=&quot;JavaScript&quot;&gt;
 &lt;!--
 // This javascript code is released under the same terms as CGI:IRC itself
-// http://cgiirc.sourceforge.net/
+// http://cgiirc.org/
 // Copyright (C) 2000-2003 David Leadbeater &lt;cgiirc\@dgl.cx&gt;
 
 //               none      joins    talk       directed talk</diff>
      <filename>interfaces/opera7.pm</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# CGI:IRC - http://cgiirc.sourceforge.net/
+# CGI:IRC - http://cgiirc.org/
 # Copyright (C) 2000-2006 David Leadbeater &lt;http://contact.dgl.cx/&gt;
 # vim:set ts=3 expandtab shiftwidth=3 cindent:
 
@@ -26,7 +26,7 @@ use lib qw/modules interfaces/;
 no warnings 'uninitialized';
 
 ($VERSION =
- '$Name:  $ 0_5_CVS $Id: irc.cgi,v 1.42 2007/02/05 13:43:17 dgl Exp $'
+ '$Name:  $ 0_5_CVS $Id: irc.cgi,v 1.43 2007/05/06 01:05:35 dgl Exp $'
 ) =~ s/^.*?(\d\S+) .*?(\d{4}\/\S+) .*$/$1/;
 $VERSION .= &quot; ($2)&quot;;
 $VERSION =~ s/_/./g;
@@ -63,7 +63,7 @@ print join(&quot;\r\n&quot;,
 
 # Please leave this.
 my $copy = &lt;&lt;EOF;
-&lt;a href=&quot;http://cgiirc.sourceforge.net/&quot;&gt;CGI:IRC&lt;/a&gt; $VERSION&lt;br /&gt;
+&lt;a href=&quot;http://cgiirc.org/&quot;&gt;CGI:IRC&lt;/a&gt; $VERSION&lt;br /&gt;
 EOF
 
 my $scriptname = $config-&gt;{script_login} || 'irc.cgi';</diff>
      <filename>irc.cgi</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# CGI:IRC - http://cgiirc.sourceforge.net/
+# CGI:IRC - http://cgiirc.org/
 # Copyright (C) 2000-2006 David Leadbeater &lt;http://contact.dgl.cx/&gt;
 # vim:set ts=3 expandtab shiftwidth=3 cindent:
 
@@ -32,7 +32,7 @@ use vars qw(
    );
 
 ($VERSION =
-'$Name:  $ 0_5_CVS $Id: nph-irc.cgi,v 1.121 2006/09/26 22:14:48 dgl Exp $'
+'$Name:  $ 0_5_CVS $Id: nph-irc.cgi,v 1.122 2007/05/06 01:05:35 dgl Exp $'
 ) =~ s/^.*?(\d\S+) .*?(\d{4}\/\S+) .*$/$1/;
 $VERSION .= &quot; ($2)&quot;;
 $VERSION =~ s/_/./g;
@@ -69,13 +69,6 @@ for('docs/', '/usr/share/doc/cgiirc/') {
 }
 
 my $needtodie = 0;
-$SIG{HUP} = $SIG{INT} = $SIG{TERM} = sub { $needtodie = 1 };
-# Pipe isn't bad..
-$SIG{PIPE} = 'IGNORE';
-
-$SIG{__DIE__} = sub { 
-   error(&quot;Program ending: @_&quot;);
-};
 
 # DEBUG
 #use Carp;
@@ -1098,10 +1091,11 @@ sub error {
 
 #### Init
 
-sub init {
+sub global_init {
    $timer = new Timer;
    $event = new Event;
    $timer-&gt;addforever(interval =&gt; 15, code =&gt; \&amp;interface_keepalive);
+   $timer-&gt;addforever(interval =&gt; 30, code =&gt; \&amp;session_timeout);
    $event-&gt;add('irc out', code =&gt; \&amp;irc_out);
    $event-&gt;add('unhandled', code =&gt; \&amp;irc_event);
    $event-&gt;add('server connected', code =&gt; \&amp;irc_connected);
@@ -1113,10 +1107,30 @@ sub init {
    $config-&gt;{access_command} = '!quote' unless exists $config-&gt;{access_command};
    $config-&gt;{format} ||= 'default';
 
-   $timer-&gt;addforever(interval =&gt; 30, code =&gt; \&amp;session_timeout);
+   format_init_smilies();
+
+   if(config_set('login secret')) {
+      require Digest::MD5;
+   }
+
+   if(config_set('prerequire_interfaces')) {
+      for my $iface(&lt;./interfaces/*.pm&gt;) {
+         require($iface);
+      }
+   }
+}
+
+sub init {
+   # Set up some sig handlers..
+   $SIG{HUP} = $SIG{INT} = $SIG{TERM} = sub { $needtodie = 1 };
+   # Pipe isn't bad..
+   $SIG{PIPE} = 'IGNORE';
+
+   $SIG{__DIE__} = sub { 
+      error(&quot;Program ending: @_&quot;);
+   };
 
    $cgi = parse_query($ENV{QUERY_STRING});
-   format_init_smilies();
    $format = load_format($cgi-&gt;{format});
    $cookie = parse_cookie();
 
@@ -1141,7 +1155,6 @@ sub init {
    $interface = load_interface();
 
    if(config_set('login secret')) {
-      require Digest::MD5;
       my $token = Digest::MD5::md5_hex($cgi-&gt;{time}
          . $config-&gt;{'login secret'} . $cgi-&gt;{R});
       if($token ne $cgi-&gt;{token}) {
@@ -1295,6 +1308,91 @@ sub main_loop {
    }
 }
 
-init();
-main_loop();
+global_init();
+
+if(config_set('fcgi_socket')) {
+   # FastCGI external server mode
+   my $running = 1;
+   
+   require FCGI;
+   die &quot;FCGI module required for FCGI mode\n&quot; if $@;
+
+   my $fcgi = FCGI::OpenSocket($config-&gt;{fcgi_socket}, 10);
+   die &quot;FCGI open failed: $!\n&quot; unless $fcgi;
+
+   # Just so the child can get rid of it easily.
+   my $fcgi_fh;
+   open($fcgi_fh, &quot;&lt;&amp;=$fcgi&quot;) or die &quot;FCGI re-open() failed\n&quot;;
+
+   my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $fcgi);
+
+   # This isn't great, as we'll accept once more, but this is good enough for
+   # now, hopefully.
+   $SIG{USR1} = sub {
+      $request-&gt;LastCall;
+      $running = 0;
+   };
+
+   $SIG{HUP} = sub {
+      $config = parse_config($config_path . 'cgiirc.config');
+   };
+   
+   # XXX: need to do this properly for non-Linux
+   $SIG{CHLD} = 'IGNORE';
+
+   # Due to the FCGI API sucking we can't easily call accept in the parent and
+   # then fork, so we do it in a child. This probably gives us a tiny speed
+   # increase due to pre-forking too.
+   
+   my($parentfh, $childfh);
+   pipe($parentfh, $childfh);
+
+   while($running) {
+      my $pid = fork;
+      if($pid) {
+         # parent - wait for child to accept a connection
+         my $tmp;
+         my $ret = sysread($parentfh, $tmp, 1);
+         if($ret != 1) {
+            # Really shouldn't happen, just delay things to hopefully make this
+            # less of a fork bomb.
+            print STDERR &quot;Read returned $ret ($!) from child, sleeping 10s\n&quot;;
+            sleep 10;
+         } else {
+            my $accept_ret = unpack(&quot;c&quot;, $tmp);
+            if($accept_ret &lt; 0) {
+               # XXX: maybe try to reopen socket or something?
+               print STDERR &quot;Child accept got $accept_ret, sleeping 10s\n&quot;;
+               sleep 10;
+            } else {
+               #print &quot;Accepted new client..\n&quot;;
+            }
+         }
+      } elsif($pid == 0) {
+         # child
+         close $parentfh;
+
+         # Wait to accept something
+         my $ret = $request-&gt;Accept;
+         syswrite($childfh, pack(&quot;c&quot;, $ret));
+         # up to here should be fast, as the write limits the speed of the
+         # accept loop
+         exit if $ret &lt; 0;
+         close $fcgi_fh;
+         close $childfh;
+
+         init();
+         main_loop();
+         exit(1);
+      } else {
+         # uh-oh, failed, wait a bit for things to calm down
+         print STDERR &quot;Fork failed\n&quot;;
+         sleep 10;
+      }
+   }
+} else {
+   # Normal CGI
+   init();
+   main_loop();
+}
 </diff>
      <filename>nph-irc.cgi</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1144032f8403f3f851584002273b3d4262e44438</id>
    </parent>
  </parents>
  <author>
    <name>dgl</name>
    <email>dgl</email>
  </author>
  <url>http://github.com/dgl/cgiirc/commit/d659ba117bda5aafc92172608c62be5e5f4064d2</url>
  <id>d659ba117bda5aafc92172608c62be5e5f4064d2</id>
  <committed-date>2007-05-05T18:05:35-07:00</committed-date>
  <authored-date>2007-05-05T18:05:35-07:00</authored-date>
  <message>Update stuff to point at cgiirc.org</message>
  <tree>d36556696d20fa5fde499d00bd72cad9a933f399</tree>
  <committer>
    <name>dgl</name>
    <email>dgl</email>
  </committer>
</commit>
