option to show both open and closed RADIUS sessions, #21483
authorMark Wells <mark@freeside.biz>
Sat, 23 Mar 2013 20:45:47 +0000 (13:45 -0700)
committerMark Wells <mark@freeside.biz>
Sat, 23 Mar 2013 20:45:47 +0000 (13:45 -0700)
FS/FS/part_export/sqlradius.pm
httemplate/search/sqlradius.cgi
httemplate/search/sqlradius.html

index 18ee304..db66c39 100644 (file)
@@ -597,7 +597,8 @@ New-style: pass a hashref with the following keys:
 
 =item stoptime_end - Upper bound for AcctStopTime, as a UNIX timestamp
 
-=item open_sessions - Only show records with no AcctStopTime (typically used without stoptime_* options and with starttime_* options instead)
+=item session_status - 'closed' to only show records with AcctStopTime,
+'open' to only show records I<without> AcctStopTime, empty to show both.
 
 =item starttime_start - Lower bound for AcctStartTime, as a UNIX timestamp
 
@@ -727,20 +728,23 @@ sub usage_sessions {
     push @where, " CalledStationID LIKE 'sip:$prefix\%'";
   }
 
-  if ( $opt->{open_sessions} ) {
-    push @where, 'AcctStopTime IS NULL';
-  } else {
-
+  my $acctstoptime = '';
+  if ( $opt->{session_status} ne 'open' ) {
     if ( $start ) {
-      push @where, "$str2time AcctStopTime ) >= ?";
+      $acctstoptime .= "$str2time AcctStopTime ) >= ?";
       push @param, $start;
+      $acctstoptime .= ' AND ' if $end;
     }
     if ( $end ) {
-      push @where, "$str2time AcctStopTime ) <= ?";
+      $acctstoptime .= "$str2time AcctStopTime ) <= ?";
       push @param, $end;
     }
-
   }
+  if ( $opt->{session_status} ne 'closed' ) {
+    $acctstoptime = "( $acctstoptime ) OR " if $acctstoptime;
+    $acctstoptime .= 'AcctStopTime IS NULL';
+  }
+  push @where, $acctstoptime;
 
   if ( $opt->{starttime_start} ) {
     push @where, "$str2time AcctStartTime ) >= ?";
index 5363944..2298473 100644 (file)
@@ -51,7 +51,7 @@
 %       @{ $part_export->usage_sessions( {
 %            'stoptime_start'  => $beginning,
 %            'stoptime_end'    => $ending,
-%            'open_sessions'   => $open_sessions,
+%            'session_status'  => $status,
 %            'starttime_start' => $starttime_beginning,
 %            'starttime_end'   => $starttime_ending,
 %            'svc_acct'        => $cgi_svc_acct,
@@ -117,9 +117,9 @@ if ( $cgi->param('end') && $cgi->param('end') =~ /^(\d+)$/ ) {
   $ending = $1;
 }
 
-my $open_sessions = '';
-if ( $cgi->param('open_sessions') =~ /^(\d*)$/ ) {
-  $open_sessions = $1;
+my $status = '';
+if ( $cgi->param('session_status') =~ /^(closed|open)$/ ) {
+  $status = $1;
 }
 
 my( $starttime_beginning, $starttime_ending ) = ( '', '' );
@@ -242,8 +242,15 @@ my $time_format = sub {
   $pretty;
 };
 
+my $time_format_or_open = sub {
+  my $time = shift;
+  return '<CENTER>OPEN</CENTER>' if $time == 0;
+  &{$time_format}($time);
+};
+
 my $duration_format = sub {
   my $seconds = shift;
+  return '' if $seconds eq ''; # open session
   my $hour = int($seconds/3600);
   my $min = int( ($seconds%3600) / 60 );
   my $sec = $seconds%60;
@@ -339,7 +346,7 @@ tie %fields, 'Tie::IxHash',
   'acctstoptime'      => {
                            name    => 'End&nbsp;time',
                            attrib  => 'Acct-Stop-Time',
-                           fmt     => $time_format,
+                           fmt     => $time_format_or_open,
                            align   => 'left',
                          },
   'acctsessiontime'   => {
index 7b9fce3..547a9bb 100644 (file)
@@ -52,8 +52,9 @@
   <TR>
     <TD>Show:</TD>
     <TD>
-      <INPUT TYPE="radio" NAME="open_sessions" VALUE="0" onClick="open_changed(this);" CHECKED>Completed sessions<BR>
-      <INPUT TYPE="radio" NAME="open_sessions" VALUE="1" onClick="open_changed(this);">Open sessions
+      <INPUT TYPE="radio" NAME="session_status" VALUE="" onClick="enable_stop(true);" CHECKED>All sessions<BR>
+      <INPUT TYPE="radio" NAME="session_status" VALUE="closed" onClick="enable_stop(true);">Completed sessions<BR>
+      <INPUT TYPE="radio" NAME="session_status" VALUE="open" onClick="enable_stop(false);">Open sessions
     </TD>
   </TR>
 
 
   <SCRIPT TYPE="text/javascript">
 
-    function open_changed(what) {
-
-      var value=get_open_value(what); 
-      if ( value == '1' ) {
-        what.form.stoptime_beginning_text.disabled = true;
-        what.form.stoptime_ending_text.disabled = true;
-        what.form.stoptime_beginning_text.style.backgroundColor = '#dddddd';
-        what.form.stoptime_ending_text.style.backgroundColor = '#dddddd';
-        what.form.stoptime_beginning_button.style.display = 'none';
-        what.form.stoptime_ending_button.style.display = 'none';
-        what.form.stoptime_beginning_disabled.style.display = '';
-        what.form.stoptime_ending_disabled.style.display = '';
-      } else if ( value == '0' ) {
-        what.form.stoptime_beginning_text.disabled = false;
-        what.form.stoptime_ending_text.disabled = false;
-        what.form.stoptime_beginning_text.style.backgroundColor = '#ffffff';
-        what.form.stoptime_ending_text.style.backgroundColor = '#ffffff';
-        what.form.stoptime_beginning_button.style.display = '';
-        what.form.stoptime_ending_button.style.display = '';
-        what.form.stoptime_beginning_disabled.style.display = 'none';
-        what.form.stoptime_ending_disabled.style.display = 'none';
+    function enable_stop(value) {
+
+      var f = document.OneTrueForm;
+      if ( value ) {
+        f.stoptime_beginning_text.disabled = false;
+        f.stoptime_ending_text.disabled = false;
+        f.stoptime_beginning_text.style.backgroundColor = '#ffffff';
+        f.stoptime_ending_text.style.backgroundColor = '#ffffff';
+        f.stoptime_beginning_button.style.display = '';
+        f.stoptime_ending_button.style.display = '';
+        f.stoptime_beginning_disabled.style.display = 'none';
+        f.stoptime_ending_disabled.style.display = 'none';
+      } else {
+        f.stoptime_beginning_text.disabled = true;
+        f.stoptime_ending_text.disabled = true;
+        f.stoptime_beginning_text.style.backgroundColor = '#dddddd';
+        f.stoptime_ending_text.style.backgroundColor = '#dddddd';
+        f.stoptime_beginning_button.style.display = 'none';
+        f.stoptime_ending_button.style.display = 'none';
+        f.stoptime_beginning_disabled.style.display = '';
+        f.stoptime_ending_disabled.style.display = '';
       }
 
     }
 
-    function get_open_value(what) {
-      var rad_val = '';
-      for (var i=0; i < what.form.open_sessions.length; i++) {
-        if (what.form.open_sessions[i].checked) {
-          var rad_val = what.form.open_sessions[i].value;
-        }
-     }
-     return rad_val;
-   }
-
   </SCRIPT>
 
   <TR>