rlm_perl hook for prepaid voip radius, RT#4100
authorivan <ivan>
Fri, 24 Oct 2008 19:13:53 +0000 (19:13 +0000)
committerivan <ivan>
Fri, 24 Oct 2008 19:13:53 +0000 (19:13 +0000)
fs_selfservice/FS-SelfService/SelfService.pm
fs_selfservice/FS-SelfService/SelfService/FreeRadiusVoip.pm [new file with mode: 0644]

index 4367aa1..66037d1 100644 (file)
@@ -1,7 +1,8 @@
 package FS::SelfService;
 
 use strict;
-use vars qw($VERSION @ISA @EXPORT_OK $DEBUG $dir $socket %autoload $tag);
+use vars qw( $VERSION @ISA @EXPORT_OK $DEBUG
+             $skip_uid_check $dir $socket %autoload $tag );
 use Exporter;
 use Socket;
 use FileHandle;
@@ -15,6 +16,10 @@ $VERSION = '0.03';
 
 $DEBUG = 0;
 
+#you can add BEGIN { $FS::SelfService::skip_uid_check = 1; } 
+#if you grant appropriate permissions to whatever user
+$skip_uid_check = 0;
+
 $dir = "/usr/local/freeside";
 $socket =  "$dir/selfservice_socket";
 $socket .= '.'.$tag if defined $tag && length($tag);
@@ -58,6 +63,9 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'agent_info'                => 'Agent/agent_info',
   'agent_list_customers'      => 'Agent/agent_list_customers',
   'mason_comp'                => 'MasonComponent/mason_comp',
+  'call_time'                 => 'PrepaidPhone/call_time',
+  'call_time_nanpa'           => 'PrepaidPhone/call_time_nanpa'
+  'phonenum_balance'          => 'PrepaidPhone/phonenum_balance'
 );
 @EXPORT_OK = ( keys(%autoload), qw( regionselector expselect popselector domainselector didselector) );
 
@@ -69,7 +77,8 @@ $ENV{'ENV'} = '';
 $ENV{'BASH_ENV'} = '';
 
 my $freeside_uid = scalar(getpwnam('freeside'));
-die "not running as the freeside user\n" if $> != $freeside_uid;
+die "not running as the freeside user\n"
+  if $> != $freeside_uid && ! $skip_uid_check;
 
 -e $dir or die "FATAL: $dir doesn't exist!";
 -d $dir or die "FATAL: $dir isn't a directory!";
diff --git a/fs_selfservice/FS-SelfService/SelfService/FreeRadiusVoip.pm b/fs_selfservice/FS-SelfService/SelfService/FreeRadiusVoip.pm
new file mode 100644 (file)
index 0000000..0ab4f14
--- /dev/null
@@ -0,0 +1,61 @@
+# Add this to the modules section of radiusd.conf
+#  #path to this module
+#  module=/usr/local/share/perl/5.8.8/FS/SelfService/FreeRadiusVoip.pm
+#  func_autheenticate = authenticate
+#
+#In the Authorize section 
+#Make sure that you have 'files' uncommented. Then add a line containing 'perl'
+# after it. 
+#
+#In the Authentication section add 
+# Auth-Type Perl { 
+#   perl 
+# } 
+#
+# #N/A# Add a line containing 'perl' to the Accounting section. 
+# 
+# In the users file comment the 'DEFAULT Auth-Type = System' lines 
+# and then add 
+#  DEFAULT Auth-Type = Perl 
+#  Fall-Through = 1 
+
+BEGIN { $FS::SelfService::skip_uid_check = 1; } 
+
+use strict;
+use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
+#use Data::Dumper;
+use FS::SelfService qw(call_time);
+
+use constant RLM_MODULE_REJECT=>   0; #immediately reject the request
+use constant RLM_MODULE_FAIL=>     1; #module failed, don't reply
+use constant RLM_MODULE_OK=>       2; #the module is OK, continue
+use constant RLM_MODULE_HANDLED=>  3; #the module handled the request, so stop
+use constant RLM_MODULE_INVALID=>  4; #the module considers the request invalid
+use constant RLM_MODULE_USERLOCK=> 5; #reject the request (user is locked out)
+use constant RLM_MODULE_NOTFOUND=> 6; #user not found
+use constant RLM_MODULE_NOOP=>     7; #module succeeded without doing anything
+use constant RLM_MODULE_UPDATED=>  8; #OK (pairs modified)
+use constant RLM_MODULE_NUMCODES=> 9; #How many return codes there are
+
+sub authenticate {
+
+  #my $src = $RAD_REQUEST{'User-Name'};
+
+#  my $response = call_time( 'src' => $RAD_REQUEST{'Calling-Station-Id'},
+#                            'dst' => $RAD_REQUEST{'Called-Station-Id'},  );
+#
+#  if $response{$
+
+  $RAD_REPLY{'Session-Timeout'} = 420;
+  return RLM_MODULE_UPDATED;
+
+}
+
+sub log_request_attributes {
+       # This shouldn't be done in production environments!
+       # This is only meant for debugging!
+       for (keys %RAD_REQUEST) {
+               &radiusd::radlog(1, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
+       }
+}
+