[27] | 1 | #!/usr/bin/perl
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 | use warnings;
|
---|
| 5 | no warnings qw(uninitialized);
|
---|
| 6 | use CGI::Carp qw (fatalsToBrowser);
|
---|
| 7 | use CGI::Simple;
|
---|
| 8 | use HTML::Template;
|
---|
| 9 | use URIdb;
|
---|
| 10 |
|
---|
| 11 | # Set up the CGI object...
|
---|
| 12 | my $q = new CGI::Simple;
|
---|
| 13 | # ... and get query-string params as well as POST params if necessary
|
---|
| 14 | $q->parse_query_string;
|
---|
| 15 |
|
---|
| 16 | my %webvar;
|
---|
| 17 | # This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
|
---|
| 18 | foreach ($q->param()) {
|
---|
| 19 | $webvar{$_} = $q->param($_);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | my $uridb = new URIdb;
|
---|
| 23 |
|
---|
| 24 | print "Content-type: text/html\n\n";
|
---|
| 25 |
|
---|
| 26 | # default DB info - all other settings should be loaded from the DB.
|
---|
| 27 | my $dbhost = "localhost";
|
---|
| 28 | my $dbname = "uridb";
|
---|
| 29 | my $dbuser = "uridb";
|
---|
| 30 | my $dbpass = "spambgone";
|
---|
| 31 |
|
---|
| 32 | #my %status = (0 => "Don't list",
|
---|
| 33 | # 2 => "Black",
|
---|
| 34 | # 4 => "Grey",
|
---|
| 35 | # 8 => "Abused URL shortener/redirector"
|
---|
| 36 | # );
|
---|
| 37 |
|
---|
| 38 | # Load a config ref containing DB host, name, user, and pass info based on
|
---|
| 39 | # from the server name + full script web path. This allows us to host
|
---|
| 40 | # multiple instances without having to duplicate the code.
|
---|
| 41 | # This file is a Perl fragment to be processed inline.
|
---|
| 42 | my $cfgname = $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
|
---|
| 43 | $cfgname =~ s|[./-]|_|g;
|
---|
| 44 | $cfgname =~ s|_uridb_cgi.*||;
|
---|
| 45 | $cfgname =~ s|_$||;
|
---|
| 46 | if (-e "/etc/uridb/$cfgname.conf") {
|
---|
| 47 | my $cfg = `cat /etc/uridb/$cfgname.conf`;
|
---|
| 48 | ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
|
---|
| 49 | eval $cfg;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
|
---|
| 53 |
|
---|
| 54 | my $page;
|
---|
| 55 | my $templatedir = $ENV{SCRIPT_FILENAME};
|
---|
| 56 | $templatedir =~ s/uridb\.cgi//;
|
---|
| 57 | $templatedir .= "templates";
|
---|
| 58 | $ENV{HTML_TEMPLATE_ROOT} = $templatedir;
|
---|
| 59 |
|
---|
| 60 | my $cgiself = $ENV{SCRIPT_FILENAME};
|
---|
| 61 | $cgiself =~ s|.+/([^/]+\.cgi)$|$1|;
|
---|
| 62 |
|
---|
| 63 | my %config;
|
---|
| 64 | my $sth = $dbh->prepare("SELECT key,value FROM misc");
|
---|
| 65 | $sth->execute;
|
---|
| 66 | while (my ($key,$value) = $sth->fetchrow_array) {
|
---|
| 67 | $config{$key} = $value;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | # decide which page to spit out...
|
---|
| 71 | if (!$webvar{page}) {
|
---|
| 72 | $page = HTML::Template->new(filename => "index.tmpl");
|
---|
| 73 | } else {
|
---|
| 74 | $page = HTML::Template->new(filename => "$webvar{page}.tmpl");
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | $page->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle});
|
---|
| 78 | $page->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment});
|
---|
| 79 | $page->param(cgiself => $cgiself);
|
---|
| 80 |
|
---|
| 81 | my $uridbsiteroot = $ENV{REQUEST_URI};
|
---|
| 82 | $uridbsiteroot =~ s|/uridb\.cgi\?.+|/|;
|
---|
| 83 | $page->param(uridbsiteroot => $uridbsiteroot);
|
---|
| 84 |
|
---|
| 85 | if ($webvar{page} eq 'report') {
|
---|
| 86 |
|
---|
| 87 | my @dombase = split /\n/m, $webvar{domlist};
|
---|
| 88 | my @domlist;
|
---|
| 89 | my $domcount = 0;
|
---|
| 90 | foreach my $domain (@dombase) {
|
---|
| 91 | my %row;
|
---|
| 92 | $row{domindex} = $domcount++;
|
---|
| 93 | ($domain) = split /:/, $domain;
|
---|
| 94 | $domain =~ s/^\+//;
|
---|
| 95 | $domain =~ s/\.uribl.company.com//;
|
---|
| 96 | chomp $domain;
|
---|
| 97 | $row{domain} = $domain;
|
---|
| 98 | push @domlist, \%row;
|
---|
| 99 | }
|
---|
| 100 | $page->param(domlist => \@domlist);
|
---|
| 101 |
|
---|
| 102 | } elsif ($webvar{page} eq 'dbreport') {
|
---|
| 103 |
|
---|
| 104 | my $err = '';
|
---|
| 105 | my @domlist;
|
---|
[28] | 106 | my $i = 0;
|
---|
| 107 | while (defined ($webvar{"dom$i"})) {
|
---|
| 108 | my $key = "dom$i";
|
---|
[27] | 109 | my %row;
|
---|
| 110 | $row{domain} = $webvar{$key};
|
---|
| 111 | $row{listnum} = $webvar{$key."type"};
|
---|
| 112 | $row{listtext} = $URIdb::status{$webvar{$key."type"}};
|
---|
[28] | 113 | $row{comment} = $webvar{$key."comment"};
|
---|
[27] | 114 | if ($webvar{$key."type"} != 0) {
|
---|
| 115 | $uridb->report($webvar{$key},$webvar{$key."type"},$webvar{$key."comment"});
|
---|
| 116 | }
|
---|
| 117 | push @domlist, \%row;
|
---|
[28] | 118 | $i++;
|
---|
[27] | 119 | }
|
---|
| 120 | $page->param(domlist => \@domlist);
|
---|
| 121 | $page->param(err => $err);
|
---|
| 122 |
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | print $page->output;
|
---|
| 126 |
|
---|
| 127 | exit 0;
|
---|