Title: [opsview] [10578] merge in 10549,10577 (Opsview::Utils::Network)
Revision
10578
Author
aburzynski
Date
2012-10-23 13:05:47 +0100 (Tue, 23 Oct 2012)

Log Message

merge in 10549,10577 (Opsview::Utils::Network)

Modified Paths


Added Paths

Removed Paths

Property Changed


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10481,10560-10562,10565,10568,10571
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
   + /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10481,10549,10560-10562,10565,10568,10571,10577
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837

Modified: trunk/opsview-core/filelist
===================================================================
--- trunk/opsview-core/filelist	2012-10-23 12:03:48 UTC (rev 10577)
+++ trunk/opsview-core/filelist	2012-10-23 12:05:47 UTC (rev 10578)
@@ -466,6 +466,7 @@
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/NotificationTemplate.pm lib/Opsview/Utils/NotificationTemplate.pm
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/PerfdatarrdImporter.pm  lib/Opsview/Utils/PerfdatarrdImporter.pm
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/QueryHost.pm    lib/Opsview/Utils/QueryHost.pm
+f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/Network.pm    lib/Opsview/Utils/Network.pm
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/SnmpInterfaces.pm    lib/Opsview/Utils/SnmpInterfaces.pm
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/Time.pm    lib/Opsview/Utils/Time.pm
 f nagios:nagios 0644 /usr/local/nagios/lib/Opsview/Utils/XMLSerialisation.pm    lib/Opsview/Utils/XMLSerialisation.pm

Copied: trunk/opsview-core/lib/Opsview/Utils/Network.pm (from rev 10549, branches/enterprise/DEV-professional/opsview-core/lib/Opsview/Utils/Network.pm)
===================================================================
--- trunk/opsview-core/lib/Opsview/Utils/Network.pm	                        (rev 0)
+++ trunk/opsview-core/lib/Opsview/Utils/Network.pm	2012-10-23 12:05:47 UTC (rev 10578)
@@ -0,0 +1,50 @@
+
+package Opsview::Utils::Network;
+
+use strict;
+use warnings;
+
+use Sub::Exporter -setup => { exports => [qw( count_ips ipanyto4 )], };
+
+use Math::BigInt;
+use NetAddr::IP;
+use NetAddr::IP::Util qw(inet_ntoa ipv6to4 ipanyto6 inet_any2n);
+
+sub count_ips {
+    my ( $first, $last ) = @_;
+
+    unless ( ref $first eq 'NetAddr::IP' ) {
+        $first = NetAddr::IP->new($first);
+    }
+
+    my $count = Math::BigInt->new(0);
+
+    if ($last) {
+        unless ( ref $last eq 'NetAddr::IP' ) {
+            $last = NetAddr::IP->new($last);
+        }
+
+        my ( $start, $end ) = (
+            NetAddr::IP->new( $first->addr, 0 ),
+            NetAddr::IP->new( $last->addr,  0 )
+        );
+
+        $count++;
+        $count++ while ( $start++ < $end );
+    }
+    else {
+        my ( $addr, $mask ) = map { Math::BigInt->new($_) } $first->numeric;
+        my $broadcast = Math::BigInt->new( $first->broadcast->numeric );
+
+        $count = $broadcast - ( $addr & $mask ) + 1;
+    }
+
+    return $count->bstr;
+}
+
+sub ipanyto4 {
+    return inet_ntoa( ipv6to4( ipanyto6( inet_any2n( $_[0] ) ) ) );
+}
+
+1;
+

Deleted: trunk/opsview-core/t/tests/Test/Opsview/Utils/Network.pm
===================================================================
--- branches/enterprise/DEV-professional/opsview-core/t/tests/Test/Opsview/Utils/Network.pm	2012-10-19 12:49:30 UTC (rev 10549)
+++ trunk/opsview-core/t/tests/Test/Opsview/Utils/Network.pm	2012-10-23 12:05:47 UTC (rev 10578)
@@ -1,63 +0,0 @@
-
-package Test::Opsview::Utils::Network;
-
-use strict;
-use warnings;
-
-use base qw( Test::Opsview );
-
-use FindBin '$Bin';
-use lib "$Bin/../lib";
-use Test::More;
-
-use NetAddr::IP;
-
-sub _setup_testing : Test(setup => no_plan) {
-    my $self = shift;
-
-    use_ok 'Opsview::Utils::Network'
-      or die "Cannot load Opsview::Utils::Network";
-}
-
-sub count_ips : Test(2) {
-    my $self = shift;
-
-    my %tests = (
-        "192.168.0.1-192.168.0.10"                    => 10,
-        "192.168.0.1-192.168.7.254"                   => 2046,
-        "192.168.0.0/24"                              => 256,
-        "192.168.0.0/27"                              => 32,
-        "192.168.0.0/8"                               => 16777216,
-        "1234:5678:90AB:CDEF:0123:4567:890A:BCDE/127" => 2,
-        "1234:5678:90AB:CDEF:0123:4567:890A:BCDE/64"  => '18446744073709551616',
-    );
-
-    subtest "Strings as input" => sub {
-        plan tests => scalar keys %tests;
-
-        while ( my ( $test, $count ) = each %tests ) {
-            my ( $first, $last ) = split( /\-/, $test );
-
-            is(
-                Opsview::Utils::Network::count_ips( $first, $last ),
-                $count, "$test has $count IPs"
-            );
-        }
-    };
-    subtest "NetAddr::IP objects as input" => sub {
-        plan tests => scalar keys %tests;
-
-        while ( my ( $test, $count ) = each %tests ) {
-            my ( $first, $last ) =
-              map { NetAddr::IP->new($_) } split( /\-/, $test );
-
-            is(
-                Opsview::Utils::Network::count_ips( $first, $last ),
-                $count, "$test has $count IPs"
-            );
-        }
-    };
-
-}
-
-1;

Copied: trunk/opsview-core/t/tests/Test/Opsview/Utils/Network.pm (from rev 10549, branches/enterprise/DEV-professional/opsview-core/t/tests/Test/Opsview/Utils/Network.pm)
===================================================================
--- trunk/opsview-core/t/tests/Test/Opsview/Utils/Network.pm	                        (rev 0)
+++ trunk/opsview-core/t/tests/Test/Opsview/Utils/Network.pm	2012-10-23 12:05:47 UTC (rev 10578)
@@ -0,0 +1,82 @@
+
+package Test::Opsview::Utils::Network;
+
+use strict;
+use warnings;
+
+use base qw( Test::Opsview );
+
+use FindBin '$Bin';
+use lib "$Bin/../lib";
+use Test::More;
+
+use NetAddr::IP;
+
+sub _setup_testing : Test(setup => no_plan) {
+    my $self = shift;
+
+    use_ok 'Opsview::Utils::Network'
+      or die "Cannot load Opsview::Utils::Network";
+}
+
+sub count_ips : Test(2) {
+    my $self = shift;
+
+    my %tests = (
+        "192.168.0.1-192.168.0.10"                    => 10,
+        "192.168.0.1-192.168.7.254"                   => 2046,
+        "192.168.0.0/24"                              => 256,
+        "192.168.0.0/27"                              => 32,
+        "192.168.0.0/8"                               => 16777216,
+        "1234:5678:90AB:CDEF:0123:4567:890A:BCDE/127" => 2,
+        "1234:5678:90AB:CDEF:0123:4567:890A:BCDE/64"  => '18446744073709551616',
+    );
+
+    subtest "Strings as input" => sub {
+        plan tests => scalar keys %tests;
+
+        while ( my ( $test, $count ) = each %tests ) {
+            my ( $first, $last ) = split( /\-/, $test );
+
+            is(
+                Opsview::Utils::Network::count_ips( $first, $last ),
+                $count, "$test has $count IPs"
+            );
+        }
+    };
+    subtest "NetAddr::IP objects as input" => sub {
+        plan tests => scalar keys %tests;
+
+        while ( my ( $test, $count ) = each %tests ) {
+            my ( $first, $last ) =
+              map { NetAddr::IP->new($_) } split( /\-/, $test );
+
+            is(
+                Opsview::Utils::Network::count_ips( $first, $last ),
+                $count, "$test has $count IPs"
+            );
+        }
+    };
+}
+
+sub anyip_to_ipv4 : Test(2) {
+    my $self = shift;
+
+    my %tests = (
+        "127.0.0.1"                               => "127.0.0.1",
+        "::ffff:127.0.0.1"                        => "127.0.0.1",
+        "0.0.0.0"                                 => "0.0.0.0",
+        "255.255.255.255"                         => "255.255.255.255",
+        "1234:5678:90AB:CDEF:0123:4567:890A:BCDE" => "137.10.188.222",
+        "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" => "255.255.255.255",
+    );
+
+    while ( my ( $test, $expected ) = each %tests ) {
+        is(
+            Opsview::Utils::Network::ipanyto4($test),
+            $expected, "Convert $test to $expected"
+        );
+    }
+}
+
+1;

Modified: trunk/opsview-web/lib/Opsview/Web/Controller/Root.pm
===================================================================
--- trunk/opsview-web/lib/Opsview/Web/Controller/Root.pm	2012-10-23 12:03:48 UTC (rev 10577)
+++ trunk/opsview-web/lib/Opsview/Web/Controller/Root.pm	2012-10-23 12:05:47 UTC (rev 10578)
@@ -34,6 +34,7 @@
 use Opsview::Config;
 use Opsview::Utils;
 use Utils::Weberrors;
+use Opsview::Utils::Network qw(ipanyto4);
 
 __PACKAGE__->mk_accessors(
     qw/start_url languages authtkt_ignoreip always_show_welcome_page/);
@@ -257,7 +258,9 @@
       Apache::AuthTkt->new( secret => Opsview::Config->authtkt_shared_secret()
       );
 
-    my $request_ip = $self->authtkt_ignoreip ? "0.0.0.0" : $c->req->address;
+    my $request_ip =
+      $self->authtkt_ignoreip ? "0.0.0.0" : ipanyto4( $c->req->address );
+
     my $info = $tkt->valid_ticket( $c->request->cookies->{'auth_tkt'}->value(),
         ip_addr => $request_ip );
 
@@ -366,14 +369,22 @@
     if ( $c->user->has_access("ADMINACCESS") ) {
         $access_list = "OPSVIEW_ADMIN,$access_list";
     }
-    my $request_ip = $self->authtkt_ignoreip ? "0.0.0.0" : $c->req->address;
+    my $request_ip =
+      $self->authtkt_ignoreip ? "0.0.0.0" : ipanyto4( $c->req->address );
+
+    my $ticket = $tkt->ticket(
+        uid     => $c->user->username,
+        ip_addr => $request_ip,
+        tokens  => $access_list,
+    );
+    unless ($ticket) {
+        $c->log->error( "Auth cookie not created: ", $tkt->errstr );
+        return;
+    }
+
     $c->response->cookies->{'auth_tkt'} = {
-        'value' => $tkt->ticket(
-            uid     => $c->user->username,
-            ip_addr => $request_ip,
-            tokens  => $access_list,
-        ),
-        'path' => '/'
+        'value' => $ticket,
+        'path'  => '/'
     };
     $c->log->debug( 'auth_tkt ticket extended to ' . $c->user->name );
 }

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to