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

Last change on this file since 518 was 517, checked in by Kris Deugau, 12 years ago

/trunk

Finally merge conversion to HTML::Template from /branches/htmlform

  • Node "hack" showed conflict due to having been added to all branches in parallel
  • editDisplay.html was apparently changed enough that the merged delete caused an irrelevant conflict

Closes #3.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.6 KB
RevLine 
[306]1#!/usr/bin/perl
2# ipdb/cgi-bin/combineblocks.pl
3# Quick hack to clean up mangled deallocations
4###
5# Revision info
6# $Date: 2012-10-18 20:53:10 +0000 (Thu, 18 Oct 2012) $
7# SVN revision $Rev: 517 $
8# Last update by $Author: kdeugau $
9###
10
11use strict;
12use warnings;
13#use CGI::Carp qw(fatalsToBrowser);
14use DBI;
15#use POSIX qw(ceil);
16use NetAddr::IP;
17
[417]18# don't remove! required for GNU/FHS-ish install from tarball
19##uselib##
[306]20
[417]21use MyIPDB;
22
[306]23my $null = new NetAddr::IP "255.255.255.255/32";
24
25my @fbtypes;
26
27my ($dbh,$ret) = connectDB_My;
28initIPDBGlobals($dbh);
29my $sth;
30
31# Get the types of freeblocks
32$sth = $dbh->prepare("select distinct routed from freeblocks");
33$sth->execute;
34while (my @data = $sth->fetchrow_array) {
35 push @fbtypes, @data;
36}
37
38foreach my $type (@fbtypes) {
39
40 my $i=0;
41 my @compacted;
42
43 my $sth = $dbh->prepare("select cidr from freeblocks where routed='$type'");
44 $sth->execute;
45 while (my @data = $sth->fetchrow_array) {
46 my $temp = new NetAddr::IP $data[0];
47 @compacted = $temp->compact(@compacted);
48 $i++;
49 }
50
51#print $compacted[0];
52my $numcomp = @compacted;
53#print " $numcomp";
54
55 if ($i == $numcomp) {
56 print "No compactable blocks for type $type ($i free)\n";
57 next;
58 }
59 print "Type $type: $i free blocks to start, $numcomp to finish\n";
60
61 $sth = $dbh->prepare("select cidr from freeblocks where cidr << ?");
62 foreach my $cip (@compacted) {
63 $sth->execute("$cip");
64 if ($sth->rows > 0) {
65 print " $cip combines from:\n";
66 while (my @data = $sth->fetchrow_array) {
67 print " $data[0]\n";
68 }
69# } else {
70# print " $cip does not compact\n";
71 }
72 }
73
74} # each @fbtype
75
76finish($dbh);
Note: See TracBrowser for help on using the repository browser.