首页 > 解决方案 > 无法匹配 freeradius 中的 mysql 字符串响应

问题描述

当达到带宽配额时,我使用 freeradius 2.2.8 和 mysql 通过 freeradius 发送我们的 coa/disconnect 消息。这部分代码运行良好。对我来说不幸的是,即使 NAS 发出了记帐停止,也会发出 coa/disconnect 消息。为了防止这种情况发生,我设置了一个条件,即从 mysql radacct 表中提取帐户终止原因并将其与一些字符串进行比较。

根据会计,

update control {
....
Tmp-String-0 := "%{sql:SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}'}}"

 ***if ("%{control:Tmp-String-0}" != "User-Request")***{
      if (("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") || ("%{control:Tmp-Integer-1}" > "%{control:Tmp-Integer-3}")){
        if ("%{control:coa_dm}" == "coa"){
            update coa {
               User-Name = "%{User-Name}"
               Acct-Session-Id = "%{Acct-Session-Id}"
               NAS-IP-Address = "%{NAS-IP-Address}"
               #Filter-Id = "UN-AUTHORIZED-PROFILE"
               Framed-IP-Address = "%{Framed-IP-Address}"
               Session-Timeout = 10
            }
         }
        if ("%{control:coa_dm}" == "dm"){
            update disconnect {
                User-Name = "%{User-Name}"
                NAS-IP-Address = "%{NAS-IP-Address}"
            }
         }

}
}

根据 freeradius 调试日志,我们可以看到字符串应该是匹配的,并且程序应该避免内部 if 条件。不幸的是,情况并非如此,第一个 IF 条件总是返回 true。

***Thu May 17 17:43:41 2018 : Info:        expand: SELECT acctterminatecause  AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}' -> SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='kiranc' AND radacct.acctsessionid='5AFD71CB-3FE1C000'
Thu May 17 17:43:41 2018 : Debug: rlm_sql (sql): Reserving sql socket id: 16
Thu May 17 17:43:41 2018 : Info: sql_xlat finished
Thu May 17 17:43:41 2018 : Debug: rlm_sql (sql): Released sql socket id: 16
Thu May 17 17:43:41 2018 : Info:        expand: %{sql:SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}'}} -> User-Request}
Thu May 17 17:43:41 2018 : Info: ++} # update control = noop
Thu May 17 17:43:41 2018 : Info: ++? if ("%{control:Tmp-String-0}" != "User-Request")
Thu May 17 17:43:41 2018 : Info:        expand: %{control:Tmp-String-0} -> User-Request}
Thu May 17 17:43:41 2018 : Info: ? Evaluating ("%{control:Tmp-String-0}" != "User-Request") -> TRUE***
Thu May 17 17:43:41 2018 : Info: ++? if ("%{control:Tmp-String-0}" != "User-Request") -> TRUE
Thu May 17 17:43:41 2018 : Info: ++if ("%{control:Tmp-String-0}" != "User-Request") {
Thu May 17 17:43:41 2018 : Info: +++? if (("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") || ("%{control:Tmp-Integer-1}" > "%{control:Tmp-Integer-3}"))
Thu May 17 17:43:41 2018 : Info:        expand: %{control:Tmp-Integer-0} -> 3169
Thu May 17 17:43:41 2018 : Info:        expand: %{control:Tmp-Integer-2} -> 25000000
Thu May 17 17:43:41 2018 : Info: ?? Evaluating ("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") -> FALSE
Thu May 17 17:43:41 2018 : Info:        expand: %{control:Tmp-Integer-1} -> 13402
Thu May 17 17:43:41 2018 : Info:        expand: %{control:Tmp-Integer-3} -> 50000000

我尝试了使用 & 而不是 % 的单引号、双引号,但无济于事。其他条件在命中时正确满足,因为它们以整数形式返回。

感谢您的帮助。

标签: mysqlfreeradius

解决方案


我忘了提到我已经让它工作了。我没有使用 Tmp-String-0 变量进行比较,而是使用了实际的半径属性名称并让它工作。

if (("%{Acct-Terminate-Cause}" != "User-Request")

感谢您的帮助。


推荐阅读