BGPmon-CPM-1
view release on metacpan or search on metacpan
www/cgi-bin/cpm_workflow.cgi view on Meta::CPAN
## get the list object for the list we are currently workingon
my $list = BGPmon::CPM::PList::Manager->getListByName($list_name);
## go through each one and determine if it can be added to the list
foreach my $prefix (@prefixes){
my @search_paths;
my $key = $cgi->param($prefix.'IP');
push @search_paths,{path=>"Whois Expansion",param_prefix=>{prefix=>$key,
watch_more_specifics=>1,
watch_covering=>1}};
$list->add_or_edit_prefixes({prefix=>$prefix,watch_more_specifics=>1,
watch_covering=>1,
search_paths=>\@search_paths});
}
$list->save;
return &ListDetailsHandler($cgi);
}
###############################################################################
# this handler will allow the user to view the containing net and decide
# if additional nets should be included based on ownership
###############################################################################
sub WhoisExpansionHandler{
my $cgi = shift;
my @prefixes = $cgi->param($_PREFIX_NAME_INPUT);
my $tmpl = "whoisExpansion.tt";
my %var = ('NUM' => scalar(@prefixes),'DATA'=>[],'LIST' => $cgi->param($_LIST_STRING));
my @ranges;
foreach my $p (@prefixes){
## figure out if we have expanded a previous prefix that covers this one.
## don't do the same range twice
my $covered = 0;
my $elligible = 1;
foreach my $range (@ranges){
use Net::IP qw(ip_prefix_to_range ip_bincomp ip_iptobin);
my ($start,$end) = ip_prefix_to_range($range);
my $binp = ip_iptobin($p);
if(ip_bincomp($binp,'le',$end) && ip_bincomp($binp,'ge',$start)){
$covered = $range;
$elligible = 0;
last;
}
}
if($p =~ /(\d+\.\d+\.\d+\.\d+)\/(\d+)/){
if($2 == 32){
$p = $1;
}else{
next;
}
}
my %ipExpanded;
if(!$covered && $elligible){
%ipExpanded = BGPmon::CPM::Prefix::Finder::expandIP($p);
if(defined($ipExpanded{'orghandle'})){
$ipExpanded{'orgid'} = $ipExpanded{'orghandle'};
my @nets = BGPmon::CPM::Prefix::Finder::orghandle2nets($ipExpanded{'orghandle'});
my @new_prefixes;
foreach my $net (@nets){
push @new_prefixes,BGPmon::CPM::Prefix::Finder::inetnum2prefixes($net);
}
$ipExpanded{'nets'} = \@new_prefixes;
}
my @new_ranges = BGPmon::CPM::Prefix::Finder::inetnum2prefixes($ipExpanded{'inetnum'});
push @ranges,@new_ranges;
$ipExpanded{'range'} = \@new_ranges;
$ipExpanded{'ip'} = $p;
}elsif($covered){
$ipExpanded{'msg'} = "$p is covered by $covered (above)";
$ipExpanded{'ip'} = $p;
}else{
$ipExpanded{'msg'} = "$p is not elligible for expansion";
}
push @{$var{'DATA'}},\%ipExpanded;
}
return ($tmpl, %var);
}
###############################################################################
# This handler takes the domain name given and expands it to a list
# of prefixes, which are then added to the DB
###############################################################################
sub AddDomainHandler{
my $cgi = shift;
my $list_name = $cgi->param($_LIST_STRING);
my $domain = $cgi->param($_DOMAIN_NAME_INPUT);
my $domainlist_str = $cgi->param($_DOMAIN_LIST_INPUT);
my @domainlist = split /\s+/,$domainlist_str;
## get the list object for the list we are currently workingon
my $list = BGPmon::CPM::PList::Manager->getListByName($list_name);
## check to see that they entered something
if(!defined($domain) or $domain eq ""){
if(scalar(@domainlist) == 0){
return ErrorHandler({MESSAGE => "No Domain Specified"});
}
}else{
push @domainlist,$domain;
}
my %ip_list = BGPmon::CPM::Prefix::Finder::expandDomainToIPs(\@domainlist);
foreach my $prefix (keys %ip_list){
## add the search paths to the DB
my @search_paths;
foreach my $sp ( uniq( @{$ip_list{$prefix}{'search'}})){
push @search_paths,{path=>$sp};
}
my @domains;
foreach my $d (keys %{$ip_list{$prefix}{'domain'}}){
push @domains,{domain=>$d};
}
( run in 2.879 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )