Old "problem" with backquote and Mikrotik-Rate-Limit (fixed)
Alan DeKok
aland at deployingradius.com
Fri Sep 28 15:06:09 CEST 2018
On Sep 28, 2018, at 8:34 AM, Rafael Labiak Olivastro <rolivastro at hotmail.com> wrote:
> I was facing a problem with backquotes and the Mikrotik-Rate-Limit atribute, this problem happened when I put something like “%{sql: select....}” in the attribute´s value, everything worked fine BUT in the final result the backquotes is not removed, causing problems in the NAS.
If the value in SQL has back quotes, they can be removed. I'm not sure where the extra back quotes would come from.
> 1 – Create a new file called “/usr/bin/echo2” with following contents and make it executable (chmod 755 /usr/sbin/echo2):
>
> #!/bin/bash
> echo $1 | sed -r "s/\`//g"
>
> 2 – Edit file /etc/raddb/sites-available/default and ADD the following in the post-auth section:
>
> if (reply:Mikrotik-Rate-Limit =~ /.*\`$/i) {
> update reply {
> &Mikrotik-Rate-Limit := `/usr/bin/echo2 %{0}`
> }
There's a better solution. Just do this:
if (reply:Mikrotik-Rate-Limit =~ /\`(.*)\`$/i) {
update reply {
&Mikrotik-Rate-Limit := "%{1}"
}
}
You can do a regex match on just a substring, and then give that substring to an attribute.
It also avoids forking an external program, which is *slow*, and therefore fragile.
> Again, thanks a lot for the work with FreeRadius, you and your team deserve all my respects.
You're welcome. We try hard.
Alan DeKok.
More information about the Freeradius-Users
mailing list