source: trunk/uribl/uridb.cgi@ 86

Last change on this file since 86 was 86, checked in by Kris Deugau, 5 days ago

/trunk/uribl

Move the %config blurb inside the module so it's not splattered across all
the scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 3.8 KB
Line 
1#!/usr/bin/perl
2# Web UI for adding URIs to blacklist
3##
4# $Id: uridb.cgi 86 2025-09-11 21:57:24Z 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
76# decide which page to spit out...
77if (!$webvar{page}) {
78 $page = HTML::Template->new(filename => "index.tmpl");
79} else {
80 $page = HTML::Template->new(filename => "$webvar{page}.tmpl");
81}
82
83$page->param(pgtitle => $uridb->{cfg}{pgtitle}) if defined($uridb->{cfg}{pgtitle});
84$page->param(pgcomment => $uridb->{cfg}{pgcomment}) if defined($uridb->{cfg}{pgcomment});
85$page->param(cgiself => $cgiself);
86
87my $uridbsiteroot = $ENV{REQUEST_URI};
88$uridbsiteroot =~ s|/$cgiself\?.+|/|;
89$page->param(uridbsiteroot => $uridbsiteroot);
90
91if ($webvar{page} eq 'report') {
92
93 my @dombase = split /\n/m, $webvar{domlist};
94 my @domlist;
95 my $domcount = 0;
96 foreach my $domain (@dombase) {
97 my %row;
98 ($domain) = split /:/, $domain;
99 $domain =~ s/^\+//;
100 $domain =~ s/\.uribl.company.com//;
101 chomp $domain;
102 # now, see if it's multilisted
103 if ($domain =~ / on (\w+)\s*$/) {
104 my $sub = $1;
105 #$domain =~ s/ on \w+\s*$//;
106 $domlist[$domcount-1]->{otherlists} .= ",$sub";
107 next;
108 }
109 $row{domindex} = $domcount++;
110 $row{domain} = $domain;
111 push @domlist, \%row;
112 }
113
114 $page->param(domlist => \@domlist);
115
116} elsif ($webvar{page} eq 'dbreport') {
117
118 my $err = '';
119 my @domlist;
120 my $i = 0;
121 while (defined ($webvar{"dom$i"})) {
122 my $key = "dom$i";
123 my %row;
124 $row{domain} = $webvar{$key};
125 $row{listnum} = $webvar{$key."type"};
126 $row{listtext} = $URIdb::status{$webvar{$key."type"}};
127 $row{comment} = $webvar{$key."comment"};
128 if ($webvar{$key."type"} != 0) {
129 $uridb->report($webvar{$key},$webvar{$key."type"},$webvar{$key."comment"});
130 }
131 push @domlist, \%row;
132 $i++;
133 }
134 $page->param(domlist => \@domlist);
135 $page->param(err => $err);
136
137}
138
139print $page->output;
140
141exit 0;
Note: See TracBrowser for help on using the repository browser.