Use python module to inject parameters to radius context
Hi All, I'm trying to urlencode a string and put that value in a vendor specific attribute via python; and later refer that in site configuration. Here's a snippet of the site configuration authenticate section authenticate { Auth-Type PAP { python_custom update reply { User-Name = "%{User-Name}" My-Redirection-URL = "%{*My-URL-Param*}" My-ACL-Policy = "default_unauth_sla" My-QoS-Policy = "32M_Full" Calling-Station-Id = "%{Calling-Station-Id}" } } } digest eap } Here's the python code snippet in python_custom module def authenticate(p): username = '' clientmac = '' apmac ='' ssid = 'Benu_Test' for authdata in p: if authdata[0] == 'User-Name': username = authdata[1] if authdata[0] == 'Calling-Station-Id': clientmac = authdata[1] if authdata[0] == 'Called-Station-Id': apmac = authdata[1] # how can I inject this VSA to radius context so that it can referenced in the site configuration? My-URL-Param = "http://my.org" + urllib.quote('?clientmac=' + clientmac + '&apmac=' + apmac + '&ssid=' + ssid ) return radiusd.RLM_MODULE_OK Appreciate your help in finding a solution for this. Thanks & Regards, -- *Anuruddha Premalala (MIEEE)Mobile : +94717213122E-mail : anuruddhapremalal@gmail.com <anuruddhapremalal@gmail.com>web : www.anuruddha.org <http://www.anuruddha.org>Sri Lanka.*
On 27-05-16 02:31, Anuruddha Premalal wrote:
Hi All,
I'm trying to urlencode a string and put that value in a vendor specific attribute via python; and later refer that in site configuration.
Here's a snippet of the site configuration authenticate section
authenticate { Auth-Type PAP { python_custom update reply { User-Name = "%{User-Name}" My-Redirection-URL = "%{*My-URL-Param*}" My-ACL-Policy = "default_unauth_sla" My-QoS-Policy = "32M_Full" Calling-Station-Id = "%{Calling-Station-Id}" }
} } digest eap }
Here's the python code snippet in python_custom module
def authenticate(p):
The parameter "p" to authenticate is the request key-value store, not the reply. This is documented at http://wiki.freeradius.org/modules/Rlm_python -- Herwin Weststrate
On 27-05-16 08:02, Herwin Weststrate wrote:
The parameter "p" to authenticate is the request key-value store, not the reply. This is documented at http://wiki.freeradius.org/modules/Rlm_python
Recall that, I just read your config snippet in the wrong order. Still, the wiki link explains how to add attributes in rlm_python. But if you just need to fix some url encoding, there is a urlquote xlat that does exactly this. You could replace the python script with just this: update reply { My-Redirection-URL := "http://my.org?clientmac=%{urlquote:Calling-Station-Id}&apmac=%{urlquote:Called-Station-Id}&ssid=Benu_Test" } -- Herwin Weststrate
Hi Herwin, Thanks for the information and the documentation link provided is really helpful. Regards, Anuruddha. On Fri, May 27, 2016 at 11:46 AM, Herwin Weststrate < herwin@quarantainenet.nl> wrote:
On 27-05-16 08:02, Herwin Weststrate wrote:
The parameter "p" to authenticate is the request key-value store, not the reply. This is documented at http://wiki.freeradius.org/modules/Rlm_python
Recall that, I just read your config snippet in the wrong order. Still, the wiki link explains how to add attributes in rlm_python.
But if you just need to fix some url encoding, there is a urlquote xlat that does exactly this. You could replace the python script with just this:
update reply { My-Redirection-URL := " http://my.org?clientmac=%{urlquote:Calling-Station-Id}&apmac=%{urlquote:Called-Station-Id}&ssid=Benu_Test " }
-- Herwin Weststrate - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- *Anuruddha Premalala (MIEEE)Mobile : +94717213122E-mail : anuruddhapremalal@gmail.com <anuruddhapremalal@gmail.com>web : www.anuruddha.org <http://www.anuruddha.org>Sri Lanka.*
participants (2)
-
Anuruddha Premalal -
Herwin Weststrate