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

Last change on this file since 707 was 593, checked in by Kris Deugau, 11 years ago

/branches/stable

Merge /trunk r517 (merge /branches/htmlform)
Conflicts all resolved towards /trunk.
Fix a minor syntax error with "while (@data..." -> "while (my @data..."
(may cause merge conflicts later)

  • 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: 2013-05-14 22:10:22 +0000 (Tue, 14 May 2013) $
7# SVN revision $Rev: 593 $
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
18# don't remove! required for GNU/FHS-ish install from tarball
19##uselib##
20
21use MyIPDB;
22
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.