use -V0 --vbr-new by default; add -O option
[soepkiptng.git] / soepkiptng.cgi
blobfaf5f3362501869d063c2001c6ba6802b74b6ca0
1 #!/usr/bin/speedy -- -M4 -t600 -r100 -gsoepkiptng
3 ############################################################################
4 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as 
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ############################################################################
21 use Cwd 'abs_path';
22 use CGI;
23 use CGI::SpeedyCGI;
24 use DBI;
25 use IO::Socket;
26 use LWP::UserAgent;
27 use Socket;
29 our $progdir;
30 if(!$progdir) {
31         # find program directory
32         $_ = $0;
33         while(-l) {
34                 my $l = readlink or die "readlink $_: $!\n";
35                 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
36         }
37         m|(.*)/|;
38         $progdir = abs_path($1);
41 require "$progdir/soepkiptng.lib";
42 require "$progdir/soepkiptng_web.lib";
44 ############################################################################
45 # SUBROUTINES
47 sub printhttphdr($) {
48         my ($cookies) = @_;
50         my $cookie;
51         if($cookies) {
52                 $cookie = $cgiquery->cookie(
53                         -name=>'sv',
54                         -value=>$cookies,
55                         -path=>'/',
56                         -expires=>'+365d');
57         }
58         print $cgiquery->header(
59                 -type=>"text/html; charset=ISO-8859-15",
60                 -cookie=>$cookie);
63 sub require_write_access() {
64         if($conf{write_access_func} &&
65                 !eval $conf{write_access_func}) {
67                 printhtmlhdr;
68                 printhdr($conf{allstyle});
69                 print "<b>Access Denied.</b>\n";
70                 printftr;
71                 exit;
72         }
76 ############################################################################
77 # MAIN
79 my $sp = CGI::SpeedyCGI->new;
81 our %conf;
82 %conf or read_configfile(\%conf);
84 #$conf{db_user} = "soepkiptng_pub";
85 #$conf{db_pass} = "soepkiptng_pub";
87 # (re)open database connection if necessary
88 our $dbh;
89 if(!$dbh || !$dbh->ping) {
90         $dbh = DBI->connect("DBI:mysql:$conf{db_name}:$conf{db_host}",
91                 $conf{db_user}, $conf{db_pass}, {mysql_client_found_rows => 1 })
92                 or die "Can't connect to database $conf{db_name}\@$conf{db_host} as user $conf{db_user}\n";
94 $sp->add_shutdown_handler(sub { $dbh and $dbh->logout; });
96 our $cgiquery = new CGI;
98 my $req;
99 $req->{dbh} = $dbh;
100 $req->{cgiquery} = $cgiquery;
101 $req->{self} = $cgiquery->script_name();
102 $req->{host} = $cgiquery->remote_host();
103 my %cookies = $cgiquery->cookie('sv');
104 $req->{cookies} = \%cookies;
106 handle_request($req);