source: trunk/uribl/uridb.cgi@ 95

Last change on this file since 95 was 91, checked in by Kris Deugau, 3 days ago

/trunk/uribl

Fix up misplaced home for key-values from the misc table

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 4.3 KB
RevLine 
[27]1#!/usr/bin/perl
[41]2# Web UI for adding URIs to blacklist
3##
4# $Id: uridb.cgi 91 2025-09-16 19:09:47Z kdeugau $
[80]5# Copyright 2010,2025 Kris Deugau <kdeugau@deepnet.cx>
[41]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##
[27]20
21use strict;
22use warnings;
23no warnings qw(uninitialized);
[80]24
[27]25use CGI::Carp qw (fatalsToBrowser);
26use CGI::Simple;
27use HTML::Template;
[62]28use Encode;
29
[80]30# push "the directory the script is in" into @INC
31use FindBin;
32use lib "$FindBin::RealBin/";
[27]33
[80]34use URIdb 2.0;
35
[27]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
[62]47print $q->header(-charset=>'utf8');
[27]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
[90]64my $uridb = new URIdb (configfile => "/etc/uridb/$cfgname.conf")
65 or die "urk: something went wrong creating UIRdb\n";
66$uridb->connect;
[27]67
68my $page;
[62]69
70my $cgiself = $ENV{SCRIPT_FILENAME};
71$cgiself =~ s|.+/([^/]+\.cgi)$|$1|;
72
[27]73my $templatedir = $ENV{SCRIPT_FILENAME};
[62]74$templatedir =~ s/$cgiself//;
[27]75$templatedir .= "templates";
76$ENV{HTML_TEMPLATE_ROOT} = $templatedir;
77
78# decide which page to spit out...
79if (!$webvar{page}) {
80 $page = HTML::Template->new(filename => "index.tmpl");
81} else {
82 $page = HTML::Template->new(filename => "$webvar{page}.tmpl");
83}
84
[91]85$page->param(pgtitle => $uridb->{misc}{pgtitle}) if defined($uridb->{misc}{pgtitle});
86$page->param(pgcomment => $uridb->{misc}{pgcomment}) if defined($uridb->{misc}{pgcomment});
[27]87$page->param(cgiself => $cgiself);
88
89my $uridbsiteroot = $ENV{REQUEST_URI};
[62]90$uridbsiteroot =~ s|/$cgiself\?.+|/|;
[27]91$page->param(uridbsiteroot => $uridbsiteroot);
92
93if ($webvar{page} eq 'report') {
94
95 my @dombase = split /\n/m, $webvar{domlist};
96 my @domlist;
97 my $domcount = 0;
98 foreach my $domain (@dombase) {
99 my %row;
[90]100 # strip off URL protocol
101 $domain =~ s{^https?://}{};
102 # clean up/strip off extraneous bits from extract-data's tinydns output
[27]103 ($domain) = split /:/, $domain;
104 $domain =~ s/^\+//;
[90]105 $domain =~ s/\.$uridb->{misc}{blzone}//;
106 # and a secondary zone name Just In Case(TM)
107 $domain =~ s/\.$uridb->{misc}{altblzone}//;
108 # trim any non-FQDN URI parts
109 $domain =~ s{/.+$}{};
110 # QoL: allow just pasting an email address
111 $domain =~ s/[^@]+\@//;
112 $domain =~ s/\>.*$//;
[27]113 chomp $domain;
[62]114 # now, see if it's multilisted
115 if ($domain =~ / on (\w+)\s*$/) {
116 my $sub = $1;
117 #$domain =~ s/ on \w+\s*$//;
118 $domlist[$domcount-1]->{otherlists} .= ",$sub";
119 next;
120 }
121 $row{domindex} = $domcount++;
[27]122 $row{domain} = $domain;
123 push @domlist, \%row;
124 }
[62]125
[27]126 $page->param(domlist => \@domlist);
127
128} elsif ($webvar{page} eq 'dbreport') {
129
130 my $err = '';
131 my @domlist;
[28]132 my $i = 0;
133 while (defined ($webvar{"dom$i"})) {
134 my $key = "dom$i";
[27]135 my %row;
136 $row{domain} = $webvar{$key};
137 $row{listnum} = $webvar{$key."type"};
138 $row{listtext} = $URIdb::status{$webvar{$key."type"}};
[28]139 $row{comment} = $webvar{$key."comment"};
[27]140 if ($webvar{$key."type"} != 0) {
141 $uridb->report($webvar{$key},$webvar{$key."type"},$webvar{$key."comment"});
142 }
143 push @domlist, \%row;
[28]144 $i++;
[27]145 }
146 $page->param(domlist => \@domlist);
147 $page->param(err => $err);
148
149}
150
151print $page->output;
152
153exit 0;
Note: See TracBrowser for help on using the repository browser.