source: branches/stable/cgi-bin/combineblocks.pl@ 455

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

/branches/stable

Bring /branches/stable up to date with /trunk. See #13.

  • 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-07-26 21:00:00 +0000 (Mon, 26 Jul 2010) $
7# SVN revision $Rev: 445 $
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.