Old "problem" with backquote and Mikrotik-Rate-Limit (fixed)
Hello Alan, 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. Well, at first sight I thought that was a FreeRadius problem, BUT it wasn´t. FreeRadius is so well forged that sometimes we need to do a deep dive into it to figure out how to overcome some “problems”. So, this is what I did to “fix” this, note that NOTHING WAS CHANGED in FreeRadius source code, just the CONFIGURATION was done to adapt everything. 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}` } } 3 – Restart radius. So, the “1” is just a way to execute echo and sed together, because “inside” the FreeRadius conf this doesn´t work, number “2” just identify where exist backquotes in the EXPANSION of the atribute, and, in afirmative case, remove they. SO SIMPLE.... Again, thanks a lot for the work with FreeRadius, you and your team deserve all my respects. Best regards, Rafael Labiak Olivastro http://www.vigo.com.br
On Sep 28, 2018, at 8:34 AM, Rafael Labiak Olivastro <rolivastro@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.
Perfect, fits like a glove. =) I spent almost 3 days to figure out that way and now with just minutes you explain a much beter way, just the freeradius´s creator could be done this. Thanks again, when you need something from Brazil let me know, maybe I can help you. 😉 De: Alan DeKok<mailto:aland@deployingradius.com> Enviado:sexta-feira, 28 de setembro de 2018 09:06 Para: FreeRadius users mailing list<mailto:freeradius-users@lists.freeradius.org> Assunto: Re: Old "problem" with backquote and Mikrotik-Rate-Limit (fixed) On Sep 28, 2018, at 8:34 AM, Rafael Labiak Olivastro <rolivastro@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. - List info/subscribe/unsubscribe? See https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freeradius.org%2Flist%2Fusers.html&data=02%7C01%7C%7Ca547876a0a0e435bf1d808d625433f7d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636737368094638695&sdata=zvd76C9c3NhKljyF2Q9wU1VWdZiUfgUZ3l%2BkTWZJ41M%3D&reserved=0
participants (2)
-
Alan DeKok -
Rafael Labiak Olivastro