Changeset 25
- Timestamp:
- 09/03/10 15:18:51 (14 years ago)
- Location:
- trunk/dnsbl
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dnsbl/DNSBL.pm
r24 r25 100 100 sub DESTROY { 101 101 my $self = shift; 102 $self->dbclose() ;102 $self->dbclose() if $dbh; 103 103 } 104 104 … … 112 112 113 113 sub connect { 114 my $DSN = "DBI:Pg:host=dbhost;dbname=dnsbl"; 115 # my $DSN = "DBI:Pg:dbname=dnsbl"; 116 my $user = "dnsbl"; 117 my $pass = "spambgone"; 114 my $self = shift; 115 my $dbhost = shift; 116 my $dbname = shift; 117 my $dbuser = shift; 118 my $dbpass = shift; 118 119 ## want to NOT autocommit everything, it's unlikely we'll step on our own toes but... 119 $dbh = DBI->connect( $DSN, $user, $pass, {120 $dbh = DBI->connect("DBI:Pg:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, { 120 121 AutoCommit => 0, 121 122 PrintError => 1 -
trunk/dnsbl/browse.cgi
r19 r25 12 12 my $dnsbl = new DNSBL; 13 13 14 my $dbh = $dnsbl->connect; 14 # default DB info - all other settings should be loaded from the DB. 15 my $dbhost = "localhost"; 16 my $dbname = "dnsbl"; 17 my $dbuser = "dnsbl"; 18 my $dbpass = "spambgone"; 19 20 # Load a config ref containing DB host, name, user, and pass info based on 21 # from the server name + full script web path. This allows us to host 22 # multiple instances without having to duplicate the code. 23 # This file is a Perl fragment to be processed inline. 24 my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME}; 25 $cfgname =~ s|[./-]|_|g; 26 $cfgname =~ s|_browse_cgi||; 27 if (-e "/etc/dnsbl/$cfgname.conf") { 28 my $cfg = `cat /etc/dnsbl/$cfgname.conf`; 29 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 30 eval $cfg; 31 } 32 33 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass); 15 34 16 35 print "Content-Type: text/html\n\n"; 17 36 18 my @lvl0 = ("foo", "bar", "bax"); 19 my $template = HTML::Template->new(filename => 'templates/browse.tmpl'); 37 my $templatedir = $ENV{SCRIPT_FILENAME}; 38 $templatedir =~ s/browse\.cgi//; 39 $templatedir .= "templates"; 40 $ENV{HTML_TEMPLATE_ROOT} = $templatedir; 41 42 my %config; 43 my $sth = $dbh->prepare("SELECT key,value FROM misc"); 44 $sth->execute; 45 while (my ($key,$value) = $sth->fetchrow_array) { 46 $config{$key} = $value; 47 } 48 49 my $template = HTML::Template->new(filename => "browse.tmpl"); 50 51 $template->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle}); 52 $template->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment}); 20 53 21 54 my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ". … … 28 61 my $sthiplist = $dbh->prepare("select * from iplist where ip <<= ? order by ip"); 29 62 30 print $template->output;31 32 63 my %ipseen; 33 64 … … 36 67 $sth0->execute; 37 68 while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) { 38 my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');69 my $tmpl0 = new HTML::Template(filename => "browse-block.tmpl"); 39 70 $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : '')); 40 71 $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : '')); … … 48 79 if ($sth1->rows > 0) { 49 80 while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) { 50 my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');81 my $tmpl1 = new HTML::Template(filename => "browse-block.tmpl"); 51 82 $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : '')); 52 83 $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : '')); … … 61 92 if ($sth2->rows > 0) { 62 93 while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) { 63 my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');94 my $tmpl2 = new HTML::Template(filename => "browse-block.tmpl"); 64 95 $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : '')); 65 96 $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : '')); … … 120 151 } 121 152 122 print $out; 153 # probably more efficient ways to do this somewhere... 154 $template->param(enchilada => $out); 155 print $template->output; -
trunk/dnsbl/check-iplist.pl
r2 r25 9 9 my $dnsbl = new DNSBL; 10 10 11 my $dbh = $dnsbl->connect; 11 # default DB info - all other settings should be loaded from the DB. 12 my $dbhost = "localhost"; 13 my $dbname = "dnsbl"; 14 my $dbuser = "dnsbl"; 15 my $dbpass = "spambgone"; 16 17 die "Need config argument\n" if !$ARGV[0]; 18 my $cfgname = shift @ARGV; 19 20 # Load a config ref containing DB host, name, user, and pass info based on 21 # from the server name + full script web path. This allows us to host 22 # multiple instances without having to duplicate the code. 23 # This file is a Perl fragment to be processed inline. 24 if (-e "/etc/dnsbl/$cfgname.conf") { 25 my $cfg = `cat /etc/dnsbl/$cfgname.conf`; 26 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 27 eval $cfg; 28 } 29 30 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass); 12 31 13 32 print "checking IP containment...\n"; -
trunk/dnsbl/dnsbl.cgi
r24 r25 24 24 print "Content-type: text/html\n\n"; 25 25 26 my $dbh = $dnsbl->connect; 26 # default DB info - all other settings should be loaded from the DB. 27 my $dbhost = "localhost"; 28 my $dbname = "dnsbl"; 29 my $dbuser = "dnsbl"; 30 my $dbpass = "spambgone"; 31 32 # Load a config ref containing DB host, name, user, and pass info based on 33 # from the server name + full script web path. This allows us to host 34 # multiple instances without having to duplicate the code. 35 # This file is a Perl fragment to be processed inline. 36 my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME}; 37 $cfgname =~ s|[./-]|_|g; 38 $cfgname =~ s|_dnsbl_cgi||; 39 if (-e "/etc/dnsbl/$cfgname.conf") { 40 my $cfg = `cat /etc/dnsbl/$cfgname.conf`; 41 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 42 eval $cfg; 43 } 44 45 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass); 27 46 28 47 my $page; 29 my $templatedir = "templates"; 48 my $templatedir = $ENV{SCRIPT_FILENAME}; 49 $templatedir =~ s/dnsbl\.cgi//; 50 $templatedir .= "templates"; 51 $ENV{HTML_TEMPLATE_ROOT} = $templatedir; 52 53 my %config; 54 my $sth = $dbh->prepare("SELECT key,value FROM misc"); 55 $sth->execute; 56 while (my ($key,$value) = $sth->fetchrow_array) { 57 $config{$key} = $value; 58 } 30 59 31 60 # decide which page to spit out... 32 61 if (!$webvar{page}) { 33 $page = HTML::Template->new(filename => " $templatedir/index.tmpl");62 $page = HTML::Template->new(filename => "index.tmpl"); 34 63 } else { 35 $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl"); 36 } 64 $page = HTML::Template->new(filename => "$webvar{page}.tmpl"); 65 } 66 67 $page->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle}); 68 $page->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment}); 37 69 38 70 if ($webvar{page} eq 'report') { … … 92 124 $page->param(browsebits => browse($dbh,$webvar{ip})); 93 125 } 126 94 127 print $page->output; 95 128 -
trunk/dnsbl/dnsbl.sql
r2 r25 5 5 SET client_encoding = 'UTF8'; 6 6 SET check_function_bodies = false; 7 SET client_min_messages = warning;8 7 9 8 -- 10 -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres 11 -- 12 13 COMMENT ON SCHEMA public IS 'Standard public schema'; 14 15 16 SET search_path = public, pg_catalog; 17 18 SET default_tablespace = ''; 19 20 SET default_with_oids = false; 21 22 -- 23 -- Name: blocks; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace: 9 -- TOC entry 7 (OID 196077) 10 -- Name: blocks; Type: TABLE; Schema: public; Owner: dnsbl 24 11 -- 25 12 … … 34 21 35 22 -- 36 -- Name: iplist; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace: 23 -- TOC entry 8 (OID 196085) 24 -- Name: iplist; Type: TABLE; Schema: public; Owner: dnsbl 37 25 -- 38 26 … … 46 34 47 35 -- 48 -- Name: orgs; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace: 36 -- TOC entry 9 (OID 196090) 37 -- Name: orgs; Type: TABLE; Schema: public; Owner: dnsbl 49 38 -- 50 39 … … 58 47 59 48 -- 60 -- Name: blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace: 49 -- TOC entry 10 (OID 196099) 50 -- Name: autolist; Type: TABLE; Schema: public; Owner: dnsbl 51 -- 52 53 CREATE TABLE autolist ( 54 masklen smallint NOT NULL, 55 ipcount bigint 56 ); 57 58 59 -- 60 -- TOC entry 11 (OID 196147) 61 -- Name: misc; Type: TABLE; Schema: public; Owner: dnsbl 62 -- 63 64 CREATE TABLE misc ( 65 "key" character varying(30), 66 value character varying(255) 67 ); 68 69 70 -- 71 -- Data for TOC entry 23 (OID 196099) 72 -- Name: autolist; Type: TABLE DATA; Schema: public; Owner: dnsbl 73 -- 74 75 COPY autolist (masklen, ipcount) FROM stdin; 76 31 1 77 30 1 78 29 2 79 28 3 80 27 4 81 26 5 82 25 6 83 24 7 84 23 8 85 22 10 86 21 13 87 20 16 88 19 19 89 18 22 90 17 26 91 16 30 92 15 34 93 14 38 94 13 42 95 12 46 96 11 50 97 10 54 98 9 58 99 8 62 100 7 2147483648 101 6 2147483648 102 5 2147483648 103 4 2147483648 104 3 2147483648 105 2 2147483648 106 1 2147483648 107 0 2147483648 108 \. 109 110 111 -- 112 -- TOC entry 12 (OID 196101) 113 -- Name: blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl 61 114 -- 62 115 … … 66 119 67 120 -- 68 -- Name: iplist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace: 121 -- TOC entry 13 (OID 196103) 122 -- Name: iplist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl 69 123 -- 70 124 … … 74 128 75 129 -- 76 -- Name: orgs_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace: 130 -- TOC entry 14 (OID 196105) 131 -- Name: orgs_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl 77 132 -- 78 133 … … 82 137 83 138 -- 139 -- TOC entry 15 (OID 196215) 140 -- Name: autolist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl 141 -- 142 143 ALTER TABLE ONLY autolist 144 ADD CONSTRAINT autolist_pkey PRIMARY KEY (masklen); 145 146 147 -- 148 -- TOC entry 25 (OID 196107) 84 149 -- Name: blocks_orgid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnsbl 85 150 -- … … 88 153 ADD CONSTRAINT blocks_orgid_fkey FOREIGN KEY (orgid) REFERENCES orgs(orgid); 89 154 90 91 --92 -- Name: public; Type: ACL; Schema: -; Owner: postgres93 --94 95 REVOKE ALL ON SCHEMA public FROM PUBLIC;96 REVOKE ALL ON SCHEMA public FROM postgres;97 GRANT ALL ON SCHEMA public TO postgres;98 GRANT ALL ON SCHEMA public TO PUBLIC;99 100 101 --102 -- PostgreSQL database dump complete103 --104 -
trunk/dnsbl/export-dnsbl
r23 r25 14 14 my $dnsbl = new DNSBL; 15 15 16 $dnsbl->connect; 16 # default DB info - all other settings should be loaded from the DB. 17 my $dbhost = "localhost"; 18 my $dbname = "dnsbl"; 19 my $dbuser = "dnsbl"; 20 my $dbpass = "spambgone"; 21 22 die "Need config argument\n" if !$ARGV[0]; 23 my $cfgname = shift @ARGV; 24 25 # Load a config ref containing DB host, name, user, and pass info based on 26 # from the server name + full script web path. This allows us to host 27 # multiple instances without having to duplicate the code. 28 # This file is a Perl fragment to be processed inline. 29 if (-e "/etc/dnsbl/$cfgname.conf") { 30 my $cfg = `cat /etc/dnsbl/$cfgname.conf`; 31 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 32 eval $cfg; 33 } 34 35 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass); 17 36 18 37 my %iplist; -
trunk/dnsbl/orgmove
r2 r25 10 10 my $dnsbl = new DNSBL; 11 11 12 my $dbh = $dnsbl->connect; 12 # default DB info - all other settings should be loaded from the DB. 13 my $dbhost = "localhost"; 14 my $dbname = "dnsbl"; 15 my $dbuser = "dnsbl"; 16 my $dbpass = "spambgone"; 17 18 die "Usage: orgmove <config name> <old orgid> <new orgid>\n" if !$ARGV[2]; 19 my $cfgname = shift @ARGV; 20 21 # Load a config ref containing DB host, name, user, and pass info based on 22 # from the server name + full script web path. This allows us to host 23 # multiple instances without having to duplicate the code. 24 # This file is a Perl fragment to be processed inline. 25 if (-e "/etc/dnsbl/$cfgname.conf") { 26 my $cfg = `cat /etc/dnsbl/$cfgname.conf`; 27 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 28 eval $cfg; 29 } 30 31 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass); 13 32 14 33 $dbh->{AutoCommit} = 0; -
trunk/dnsbl/templates/browse.tmpl
r7 r25 1 <html><head><title>show all IPs and listing status</title> 1 <html> 2 <head> 3 <title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF> - show all IPs and listing status</title> 2 4 <link rel="stylesheet" type="text/css" href="templates/dnsbl.css" /> 3 5 </head> 4 6 <body> 7 <TMPL_VAR NAME=pgcomment> 8 <TMPL_VAR NAME=enchilada> 9 </body> 10 </html> -
trunk/dnsbl/templates/dbreport.tmpl
r22 r25 1 1 <html> 2 2 <head> 3 <title> added <TMPL_VAR NAME=ip></title>3 <title><TMPL_IF pgtitle><TMPL_VAR NAME=pgtitle><TMPL_ELSE>DNSBL Database</TMPL_IF> - added <TMPL_VAR NAME=ip></title> 4 4 <link rel="stylesheet" type="text/css" href="templates/dnsbl.css" /> 5 5 </head> 6 6 <body> 7 <TMPL_VAR NAME=pgcomment> 7 8 <table><tr><td valign=top> 8 9 added <TMPL_VAR NAME=ip> -
trunk/dnsbl/templates/index.tmpl
r22 r25 1 1 <html> 2 2 <head> 3 <title> DNSBL database</title>3 <title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF></title> 4 4 </head> 5 5 <body> 6 <TMPL_VAR NAME=pgcomment> 6 7 <table> 7 8 <form action="dnsbl.cgi"><input type=hidden name=page value=report> -
trunk/dnsbl/templates/report.tmpl
r17 r25 1 1 <html> 2 2 <head> 3 <title> adding <TMPL_VAR NAME=ip></title>3 <title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF> - adding <TMPL_VAR NAME=ip></title> 4 4 <link rel="stylesheet" type="text/css" href="templates/dnsbl.css" /> 5 5 </head> 6 6 <body> 7 <TMPL_VAR NAME=pgcomment> 7 8 <table><tr><td valign=top> 8 9 <table border=1><tr><td>
Note:
See TracChangeset
for help on using the changeset viewer.