enable CardFortress in test database, #71513
[freeside.git] / FS / FS / svc_IP_Mixin.pm
index 5b06082..c89245f 100644 (file)
@@ -1,9 +1,12 @@
 package FS::svc_IP_Mixin;
+use base 'FS::IP_Mixin';
 
 use strict;
-use base 'FS::IP_Mixin';
-use FS::Record qw(qsearchs qsearch);
 use NEXT;
+use FS::Record qw(qsearchs qsearch);
+use FS::Conf;
+use FS::router;
+use FS::part_svc_router;
 
 =item addr_block
 
@@ -183,17 +186,21 @@ means "Framed-Route" if there's an attached router.
 
 sub radius_reply {
   my $self = shift;
-  my %reply;
-  my ($block) = $self->attached_block;
-  if ( $block ) {
+
+  my %reply = ();
+
+  if ( my $block = $self->attached_block ) {
     # block routed over dynamic IP: "192.168.100.0/29 0.0.0.0 1"
     # or
     # block routed over fixed IP: "192.168.100.0/29 192.168.100.1 1"
     # (the "1" at the end is the route metric)
-    $reply{'Framed-Route'} =
-    $block->cidr . ' ' .
-    ($self->ip_addr || '0.0.0.0') . ' 1';
+    $reply{'Framed-Route'} = $block->cidr . ' ' .
+                             ($self->ip_addr || '0.0.0.0') . ' 1';
   }
+
+  $reply{'Motorola-Canopy-Gateway'} = $self->addr_block->ip_gateway
+    if FS::Conf->new->exists('radius-canopy') && $self->addr_block;
+
   %reply;
 }
 
@@ -215,4 +222,41 @@ sub replace_check {
   ref($err_or_ref) ? '' : $err_or_ref;
 }
 
+=item addr_status
+
+Returns the ping status record for this service's address, if there
+is one.
+
+=cut
+
+sub addr_status {
+  my $self = shift;
+  my $addr = $self->ip_addr or return;
+  qsearchs('addr_status', { 'ip_addr'  => $addr });
+}
+
+=item addr_status_color
+
+Returns the CSS color for the ping status of this service.
+
+=cut
+
+# subject to change; should also show high/low latency (yellow?) and
+# staleness of data (probably means the daemon is not running) and packet
+# loss (once we measure that)
+
+sub addr_status_color {
+  my $self = shift;
+  if ( my $addr_status = $self->addr_status ) {
+    if ( $addr_status->up ) {
+      return 'green';
+    } else {
+      return 'red';
+    }
+  } else {
+    return 'gray';
+  }
+}
+  
+
 1;