source: trunk/uribl/uridb.cgi@ 81

Last change on this file since 81 was 80, checked in by Kris Deugau, 6 days ago

/trunk/uribl

Convert module to more proper object with embedded DB bits
Add module-finding blurb

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 4.0 KB
Line 
1#!/usr/bin/perl
2# Web UI for adding URIs to blacklist
3##
4# $Id: uridb.cgi 80 2025-09-11 20:28:23Z kdeugau $
5# Copyright 2010,2025 Kris Deugau <kdeugau@deepnet.cx>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19##
20
21use strict;
22use warnings;
23no warnings qw(uninitialized);
24
25use CGI::Carp qw (fatalsToBrowser);
26use CGI::Simple;
27use HTML::Template;
28use Encode;
29
30# push "the directory the script is in" into @INC
31use FindBin;
32use lib "$FindBin::RealBin/";
33
34use URIdb 2.0;
35
36# Set up the CGI object...
37my $q = new CGI::Simple;
38# ... and get query-string params as well as POST params if necessary
39$q->parse_query_string;
40
41my %webvar;
42# This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
43foreach ($q->param()) {
44 $webvar{$_} = $q->param($_);
45}
46
47print $q->header(-charset=>'utf8');
48
49#my %status = (0 => "Don't list",
50# 2 => "Black",
51# 4 => "Grey",
52# 8 => "Abused URL shortener/redirector"
53# );
54
55# Load a config ref containing DB host, name, user, and pass info based on
56# from the server name + full script web path. This allows us to host
57# multiple instances without having to duplicate the code.
58# This file is a Perl fragment to be processed inline.
59my $cfgname = $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
60$cfgname =~ s|[./-]|_|g;
61$cfgname =~ s|_uridb_cgi.*||;
62$cfgname =~ s|_$||;
63
64my $uridb = new URIdb (configfile => "/etc/uridb/$cfgname.conf");
65
66my $page;
67
68my $cgiself = $ENV{SCRIPT_FILENAME};
69$cgiself =~ s|.+/([^/]+\.cgi)$|$1|;
70
71my $templatedir = $ENV{SCRIPT_FILENAME};
72$templatedir =~ s/$cgiself//;
73$templatedir .= "templates";
74$ENV{HTML_TEMPLATE_ROOT} = $templatedir;
75
76my %config;
77my $sth = $dbh->prepare("SELECT key,value FROM misc");
78$sth->execute;
79while (my ($key,$value) = $sth->fetchrow_array) {
80 $config{$key} = $value;
81}
82
83# decide which page to spit out...
84if (!$webvar{page}) {
85 $page = HTML::Template->new(filename => "index.tmpl");
86} else {
87 $page = HTML::Template->new(filename => "$webvar{page}.tmpl");
88}
89
90$page->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle});
91$page->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment});
92$page->param(cgiself => $cgiself);
93
94my $uridbsiteroot = $ENV{REQUEST_URI};
95$uridbsiteroot =~ s|/$cgiself\?.+|/|;
96$page->param(uridbsiteroot => $uridbsiteroot);
97
98if ($webvar{page} eq 'report') {
99
100 my @dombase = split /\n/m, $webvar{domlist};
101 my @domlist;
102 my $domcount = 0;
103 foreach my $domain (@dombase) {
104 my %row;
105 ($domain) = split /:/, $domain;
106 $domain =~ s/^\+//;
107 $domain =~ s/\.uribl.company.com//;
108 chomp $domain;
109 # now, see if it's multilisted
110 if ($domain =~ / on (\w+)\s*$/) {
111 my $sub = $1;
112 #$domain =~ s/ on \w+\s*$//;
113 $domlist[$domcount-1]->{otherlists} .= ",$sub";
114 next;
115 }
116 $row{domindex} = $domcount++;
117 $row{domain} = $domain;
118 push @domlist, \%row;
119 }
120
121 $page->param(domlist => \@domlist);
122
123} elsif ($webvar{page} eq 'dbreport') {
124
125 my $err = '';
126 my @domlist;
127 my $i = 0;
128 while (defined ($webvar{"dom$i"})) {
129 my $key = "dom$i";
130 my %row;
131 $row{domain} = $webvar{$key};
132 $row{listnum} = $webvar{$key."type"};
133 $row{listtext} = $URIdb::status{$webvar{$key."type"}};
134 $row{comment} = $webvar{$key."comment"};
135 if ($webvar{$key."type"} != 0) {
136 $uridb->report($webvar{$key},$webvar{$key."type"},$webvar{$key."comment"});
137 }
138 push @domlist, \%row;
139 $i++;
140 }
141 $page->param(domlist => \@domlist);
142 $page->param(err => $err);
143
144}
145
146print $page->output;
147
148exit 0;
Note: See TracBrowser for help on using the repository browser.