source: trunk/dnsbl/orgmove@ 25

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

/trunk/dnsbl

Changes across the board to support multi-instance without code changes.
DB config is now loaded from a fragment in /etc/dnsbl, and the DB in turn
contains the autolist thresholds and some visual sugar for the web
interface so you know which DB you're dealing with.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 1.4 KB
Line 
1#!/usr/bin/perl
2# move blocks listed with one org to another. intended for orgs that have several bytestrings as names in WHOIS.
3
4use strict;
5use warnings;
6use DBI;
7
8use DNSBL;
9
10my $dnsbl = new DNSBL;
11
12# default DB info - all other settings should be loaded from the DB.
13my $dbhost = "localhost";
14my $dbname = "dnsbl";
15my $dbuser = "dnsbl";
16my $dbpass = "spambgone";
17
18die "Usage: orgmove <config name> <old orgid> <new orgid>\n" if !$ARGV[2];
19my $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.
25if (-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
31my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
32
33$dbh->{AutoCommit} = 0;
34
35my $sth1 = $dbh->prepare("update blocks set orgid=? where orgid=?");
36my $sth2 = $dbh->prepare("delete from orgs where orgid=?");
37
38print "updating orgid $ARGV[0] to $ARGV[1]...\n";
39$sth1->execute($ARGV[1],$ARGV[0]) or die "died horribly: $!\n";
40print "failed org change ($ARGV[0] -> $ARGV[1]): ".$sth1->errstr."\n" if $sth1->err;
41$sth2->execute($ARGV[0]);
42print "failed org delete ($ARGV[0]): ".$sth2->errstr."\n" if $sth2->err;
43
44$dbh->commit;
Note: See TracBrowser for help on using the repository browser.