Converting attributes from hex to ASCII

Aaron Paetznick aaronp at
Tue Mar 30 23:05:51 CEST 2010

I am receiving certain accounting attributes as hex encoded strings, and 
I would like to convert them back to cleartext ASCII before sending them 
to MySQL.

I can't simply update the SQL with UNHEX() functions, as not all of the 
requests are hex encoded this way.

If I could use perl, I would do something like this:

preacct {
   if ("%{SomeAtribute}" =~ /^MATCHING\:(.+)\:MATCHING$/) {
     update request {
       Calling-Station-Id := s/([a-fA-F0-9]{2})/chr(hex(%{1}))/eg

Maybe I can simply flag these attributes somehow by prefixing them with 
"FLAG::", and use the MySQL IF() function to "post process" them with 
the UNHEX() function?

Any help would be appreciated.  Thanks!


More information about the Freeradius-Users mailing list