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 |
|
---|
4 | use strict;
|
---|
5 | use warnings;
|
---|
6 | use DBI;
|
---|
7 |
|
---|
8 | use DNSBL;
|
---|
9 |
|
---|
10 | my $dnsbl = new DNSBL;
|
---|
11 |
|
---|
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);
|
---|
32 |
|
---|
33 | $dbh->{AutoCommit} = 0;
|
---|
34 |
|
---|
35 | my $sth1 = $dbh->prepare("update blocks set orgid=? where orgid=?");
|
---|
36 | my $sth2 = $dbh->prepare("delete from orgs where orgid=?");
|
---|
37 |
|
---|
38 | print "updating orgid $ARGV[0] to $ARGV[1]...\n";
|
---|
39 | $sth1->execute($ARGV[1],$ARGV[0]) or die "died horribly: $!\n";
|
---|
40 | print "failed org change ($ARGV[0] -> $ARGV[1]): ".$sth1->errstr."\n" if $sth1->err;
|
---|
41 | $sth2->execute($ARGV[0]);
|
---|
42 | print "failed org delete ($ARGV[0]): ".$sth2->errstr."\n" if $sth2->err;
|
---|
43 |
|
---|
44 | $dbh->commit;
|
---|