[RADIATOR] Define a global array

Steve Phillips steve at focb.co.nz
Tue Apr 1 18:59:37 CDT 2014


Hi there,

I am trying to setup a system that, on startup reads a DB table into a 
hashed array and then makes this available to the rest of the hooks. A 
later hook then takes this hashed array and parses it to add a value to 
a custom attribute which is then used for later processing within a handler.

While I understand that globals are bad and should never be used, I 
believe that making a DB request on every radius packet would have more 
of an impact on performance for something that rarely changes (maybe 
once a week or so) and so the positives outweigh the negatives.

What I had which doesn't seem to work was something along these lines.

<from radius.cfg>

# Hooks
StartupHook file:"%D/hooks/StartupHook-SetupGlobals.pl"

.
.
<Client>
   Secret blah
   PreHandlerHook file:"$D/hooks/AddAttribute.pl"
</Client>

<Handler MyAtttribute = /something/>
.
  Do Stuff
</Handler>

in the SetupGlobals file I have something like;

# Define a global (obviously, there is where I'd read in the DB table)
our %global_steve = (
   'message1' => 'Steve was here',
   'message2' => 'woot'
);

and then, when trying to reference it I have in the PreHandler hook

sub {
   &main::log($main::LOG_INFO, "Test: $main::global_steve{'messsage1'}");
}

Which ends up printing out a blank.

Does anyone know of either, a way to get this going, or a way to read in 
a db table of data and cache it for use in later hooks without having 
each radius request generate another database call?

Thanks in advance,

-- 
Steve.




More information about the radiator mailing list