1 | #!/usr/bin/perl
|
---|
2 | # Spit out the allocated IPs in an IP pool as a CSV.
|
---|
3 | ##
|
---|
4 | # $Id: pool2csv.pl 933 2022-12-08 18:44:35Z kdeugau $
|
---|
5 | # Copyright (C) 2016 - 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 |
|
---|
21 |
|
---|
22 | use strict;
|
---|
23 | use warnings;
|
---|
24 |
|
---|
25 | use CGI::Simple;
|
---|
26 |
|
---|
27 |
|
---|
28 | # Taint-safe (ish) voodoo to push "the directory the script is in" into @INC.
|
---|
29 | use File::Spec ();
|
---|
30 | use File::Basename ();
|
---|
31 | my $path;
|
---|
32 | BEGIN {
|
---|
33 | $path = File::Basename::dirname(File::Spec->rel2abs($0));
|
---|
34 | if ($path =~ /(.*)/) {
|
---|
35 | $path = $1;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | use lib $path;
|
---|
39 |
|
---|
40 | use MyIPDB;
|
---|
41 |
|
---|
42 | # grab CGI parameters, and stash them in a convenient hash
|
---|
43 | my $q = new CGI::Simple;
|
---|
44 | $q->parse_query_string;
|
---|
45 | my %webvar = $q->Vars;
|
---|
46 |
|
---|
47 | # Live production experience says that text/csv doesn't work as intended
|
---|
48 | #print "Content-type: text/csv\n\n";
|
---|
49 | print "Content-type: text/plain\n\n";
|
---|
50 |
|
---|
51 | my $ip_dbh;
|
---|
52 | ($ip_dbh,$errstr) = connectDB_My;
|
---|
53 |
|
---|
54 | print qq("IP","CustID","Description"\n);
|
---|
55 |
|
---|
56 | my $sth = $ip_dbh->prepare("SELECT ip,custid,description FROM poolips".
|
---|
57 | " WHERE parent_id = ? AND available = 'n' ORDER BY ip");
|
---|
58 | $sth->execute($webvar{pool});
|
---|
59 | while (my ($ip,$cust,$desc) = $sth->fetchrow_array) {
|
---|
60 | print qq("$ip","$cust","$desc"\n);
|
---|
61 | }
|
---|