source: trunk/uribl/uridb.cgi@ 27

Last change on this file since 27 was 27, checked in by Kris Deugau, 14 years ago

/trunk/uribl

Add URI blacklist database interface code

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 3.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5no warnings qw(uninitialized);
6use CGI::Carp qw (fatalsToBrowser);
7use CGI::Simple;
8use HTML::Template;
9use URIdb;
10
11# Set up the CGI object...
12my $q = new CGI::Simple;
13# ... and get query-string params as well as POST params if necessary
14$q->parse_query_string;
15
16my %webvar;
17# This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
18foreach ($q->param()) {
19 $webvar{$_} = $q->param($_);
20}
21
22my $uridb = new URIdb;
23
24print "Content-type: text/html\n\n";
25
26# default DB info - all other settings should be loaded from the DB.
27my $dbhost = "localhost";
28my $dbname = "uridb";
29my $dbuser = "uridb";
30my $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.
42my $cfgname = $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
43$cfgname =~ s|[./-]|_|g;
44$cfgname =~ s|_uridb_cgi.*||;
45$cfgname =~ s|_$||;
46if (-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
52my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
53
54my $page;
55my $templatedir = $ENV{SCRIPT_FILENAME};
56$templatedir =~ s/uridb\.cgi//;
57$templatedir .= "templates";
58$ENV{HTML_TEMPLATE_ROOT} = $templatedir;
59
60my $cgiself = $ENV{SCRIPT_FILENAME};
61$cgiself =~ s|.+/([^/]+\.cgi)$|$1|;
62
63my %config;
64my $sth = $dbh->prepare("SELECT key,value FROM misc");
65$sth->execute;
66while (my ($key,$value) = $sth->fetchrow_array) {
67 $config{$key} = $value;
68}
69
70# decide which page to spit out...
71if (!$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
81my $uridbsiteroot = $ENV{REQUEST_URI};
82$uridbsiteroot =~ s|/uridb\.cgi\?.+|/|;
83$page->param(uridbsiteroot => $uridbsiteroot);
84
85if ($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;
106 foreach my $key (keys %webvar) {
107 next unless $key =~ /^dom\d+$/;
108 my %row;
109 $row{domain} = $webvar{$key};
110 $row{listnum} = $webvar{$key."type"};
111 $row{listtext} = $URIdb::status{$webvar{$key."type"}};
112 if ($webvar{$key."type"} != 0) {
113 $uridb->report($webvar{$key},$webvar{$key."type"},$webvar{$key."comment"});
114 }
115 push @domlist, \%row;
116 }
117 $page->param(domlist => \@domlist);
118 $page->param(err => $err);
119
120}
121
122print $page->output;
123
124exit 0;
Note: See TracBrowser for help on using the repository browser.