fix ticketing system error on bootstrap of new install
[freeside.git] / fs_selfservice / FS-SelfService / SelfService / FreeRadiusVoip.pm
1 #Add this to the modules section of radiusd.conf
2 # perl {
3 #   #path to this module
4 #   # deb 6 example
5 #   #module=/usr/local/share/perl/5.10.1/FS/SelfService/FreeRadiusVoip.pm
6 #   # deb 7 example
7 #   module=/usr/local/share/perl/5.14.2/FS/SelfService/FreeRadiusVoip.pm
8 #
9 #   func_authorize = authorize;
10 #
11 # }
12 #
13 #In the Authorize section 
14 #Make sure that you have 'files' uncommented. Then add a line containing 'perl'
15 # after it. 
16 #
17 # #N/A# Add a line containing 'perl' to the Accounting section. 
18
19 # and on debian 6 systems, add this to /etc/init.d/freeradius, with the
20 # correct path (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=416266)
21 #               LD_PRELOAD=/usr/lib/libperl.so.5.10
22 #               export LD_PRELOAD
23
24 BEGIN { $FS::SelfService::skip_uid_check = 1; } 
25
26 use strict;
27 use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
28 #use Data::Dumper;
29 use FS::SelfService qw(call_time);
30
31 use constant RLM_MODULE_REJECT=>   0; #immediately reject the request
32 use constant RLM_MODULE_FAIL=>     1; #module failed, don't reply
33 use constant RLM_MODULE_OK=>       2; #the module is OK, continue
34 use constant RLM_MODULE_HANDLED=>  3; #the module handled the request, so stop
35 use constant RLM_MODULE_INVALID=>  4; #the module considers the request invalid
36 use constant RLM_MODULE_USERLOCK=> 5; #reject the request (user is locked out)
37 use constant RLM_MODULE_NOTFOUND=> 6; #user not found
38 use constant RLM_MODULE_NOOP=>     7; #module succeeded without doing anything
39 use constant RLM_MODULE_UPDATED=>  8; #OK (pairs modified)
40 use constant RLM_MODULE_NUMCODES=> 9; #How many return codes there are
41
42 sub authorize {
43
44   #&log_request_attributes();
45
46   my $response = call_time( 'src' => $RAD_REQUEST{'Calling-Station-Id'},
47                             'dst' => $RAD_REQUEST{'Called-Station-Id'},  );
48
49   if ( $response->{'error'} ) {
50     $RAD_REPLY{'Reply-Message'} = $response->{'error'};
51     return RLM_MODULE_REJECT;
52   } elsif ( $response->{'seconds'} ) {
53     $RAD_REPLY{'Session-Timeout'} = $response->{'seconds'};
54     $RAD_REPLY{'Termination-Action'} = 0;
55     return RLM_MODULE_OK;
56   } else {
57     # if the called number is free, put 1 in the Termination-Action attribute
58     $RAD_REPLY{'Termination-Action'} = 1;
59     return RLM_MODULE_OK;
60   }
61
62 }
63
64 sub log_request_attributes {
65        # This shouldn't be done in production environments!
66        # This is only meant for debugging!
67        for (keys %RAD_REQUEST) {
68                &radiusd::radlog(1, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
69        }
70 }
71