source: trunk/cgi-bin/combineblocks.pl@ 500

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

/trunk

Rearrangements and tweaks toward releaseability:

  • Add Makefile to install halfway-sanely
  • Add .spec file
  • Shuffle "use IPDB;" and "use MyIPDB;" lines so that we can automagically insert a suitable "use lib..." line during 'make install'
  • Check copyright statements
  • Clear up some defaults, and place a number of "constants" in IPDB/MyIPDB rather than having them hardcoded all over the place (Still need to think of a sane way to do this for ipdb.psql's alloctype preseeding)
  • Tweak $VERSION identifier in IPDB.pm so it can be defined in the Makefile
  • Clean up some dangling bits from repository history conversion, remove unneeded "use ..." statements
  • Tweak rWHOIS export script to use more globals and "constants" from (My)IPDB.pm, and more Perl internals than system()-equivalents. Add a few fixme comments for longer-term flexibility improvements.
  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.6 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/combineblocks.pl
3# Quick hack to clean up mangled deallocations
4###
5# Revision info
6# $Date: 2010-06-30 21:48:03 +0000 (Wed, 30 Jun 2010) $
7# SVN revision $Rev: 417 $
8# Last update by $Author: kdeugau $
9###
10
11use strict;
12use warnings;
13#use CGI::Carp qw(fatalsToBrowser);
14use DBI;
15#use CommonWeb qw(:ALL);
16#use POSIX qw(ceil);
17use NetAddr::IP;
18
19# don't remove! required for GNU/FHS-ish install from tarball
20##uselib##
21
22use MyIPDB;
23
24my $null = new NetAddr::IP "255.255.255.255/32";
25
26my @fbtypes;
27
28my ($dbh,$ret) = connectDB_My;
29initIPDBGlobals($dbh);
30my $sth;
31
32# Get the types of freeblocks
33$sth = $dbh->prepare("select distinct routed from freeblocks");
34$sth->execute;
35while (my @data = $sth->fetchrow_array) {
36 push @fbtypes, @data;
37}
38
39foreach my $type (@fbtypes) {
40
41 my $i=0;
42 my @compacted;
43
44 my $sth = $dbh->prepare("select cidr from freeblocks where routed='$type'");
45 $sth->execute;
46 while (my @data = $sth->fetchrow_array) {
47 my $temp = new NetAddr::IP $data[0];
48 @compacted = $temp->compact(@compacted);
49 $i++;
50 }
51
52#print $compacted[0];
53my $numcomp = @compacted;
54#print " $numcomp";
55
56 if ($i == $numcomp) {
57 print "No compactable blocks for type $type ($i free)\n";
58 next;
59 }
60 print "Type $type: $i free blocks to start, $numcomp to finish\n";
61
62 $sth = $dbh->prepare("select cidr from freeblocks where cidr << ?");
63 foreach my $cip (@compacted) {
64 $sth->execute("$cip");
65 if ($sth->rows > 0) {
66 print " $cip combines from:\n";
67 while (my @data = $sth->fetchrow_array) {
68 print " $data[0]\n";
69 }
70# } else {
71# print " $cip does not compact\n";
72 }
73 }
74
75} # each @fbtype
76
77finish($dbh);
Note: See TracBrowser for help on using the repository browser.