source: trunk/cgi-bin/pool2csv.pl@ 941

Last change on this file since 941 was 933, checked in by Kris Deugau, 2 years ago

/trunk

Merge inexplicably unmerged get-pool-IPs-as-CSV feature from production
Fix long-missing VLAN display snafu on allocation update "done OK" page
Update @INC-munger in main.cgi
Update copyright block and style

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
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
22use strict;
23use warnings;
24
25use CGI::Simple;
26
27
28# Taint-safe (ish) voodoo to push "the directory the script is in" into @INC.
29use File::Spec ();
30use File::Basename ();
31my $path;
32BEGIN {
33 $path = File::Basename::dirname(File::Spec->rel2abs($0));
34 if ($path =~ /(.*)/) {
35 $path = $1;
36 }
37}
38use lib $path;
39
40use MyIPDB;
41
42# grab CGI parameters, and stash them in a convenient hash
43my $q = new CGI::Simple;
44$q->parse_query_string;
45my %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";
49print "Content-type: text/plain\n\n";
50
51my $ip_dbh;
52($ip_dbh,$errstr) = connectDB_My;
53
54print qq("IP","CustID","Description"\n);
55
56my $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});
59while (my ($ip,$cust,$desc) = $sth->fetchrow_array) {
60 print qq("$ip","$cust","$desc"\n);
61}
Note: See TracBrowser for help on using the repository browser.