3 # FreeRADIUS "dialup" SQL Queries for the MySQL Dialect
5 # Safe characters list for sql queries. Everything else is replaced
6 # with their mime-encoded equivalents.
7 # The default list should be ok
8 #safe-characters = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"
10 #######################################################################
11 # Query config: Username
12 #######################################################################
13 # This is the username that will get substituted, escaped, and added
14 # as attribute 'SQL-User-Name'. '%{SQL-User-Name}' should be used below
15 # everywhere a username substitution is needed so you you can be sure
16 # the username passed from the client is escaped properly.
18 # Uncomment the next line, if you want the sql_user_name to mean:
20 # Use Stripped-User-Name, if it's there.
21 # Else use User-Name, if it's there,
22 # Else use hard-coded string "DEFAULT" as the user name.
23 #sql_user_name = "%{Stripped-User-Name:-%{User-Name:-DEFAULT}}"
25 sql_user_name = "%{User-Name}"
27 #######################################################################
29 #######################################################################
30 # This is the default profile. It is found in SQL by group membership.
31 # That means that this profile must be a member of at least one group
32 # which will contain the corresponding check and reply items.
33 # This profile will be queried in the authorize section for every user.
34 # The point is to assign all users a default profile without having to
35 # manually add each one to a group that will contain the profile.
36 # The SQL module will also honor the User-Profile attribute. This
37 # attribute can be set anywhere in the authorize section (ie the users
38 # file). It is found exactly as the default profile is found.
39 # If it is set then it will *overwrite* the default profile setting.
40 # The idea is to select profiles based on checks on the incoming packets,
41 # not on user group membership. For example:
43 # DEFAULT Service-Type == Outbound-User, User-Profile := "outbound"
44 # DEFAULT Service-Type == Framed-User, User-Profile := "framed"
46 # By default the default_user_profile is not set
48 #default_user_profile = "DEFAULT"
50 #######################################################################
52 #######################################################################
53 # This query retrieves the radius clients
55 # 0. Row ID (currently unused)
56 # 1. Name (or IP address)
60 #######################################################################
62 nas_query = "SELECT id, nasname, shortname, type, secret FROM ${nas_table}"
64 #######################################################################
65 # Authorization Queries
66 #######################################################################
67 # These queries compare the check items for the user
68 # in ${authcheck_table} and setup the reply items in
69 # ${authreply_table}. You can use any query/tables
70 # you want, but the return data for each row MUST
71 # be in the following order:
73 # 0. Row ID (currently unused)
74 # 1. UserName/GroupName
77 # 4. Item Attr Operation
78 #######################################################################
79 # Use these for case sensitive usernames.
80 # authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
81 # FROM ${authcheck_table} \
82 # WHERE Username = BINARY '%{SQL-User-Name}' \
84 # authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
85 # FROM ${authreply_table} \
86 # WHERE Username = BINARY '%{SQL-User-Name}' \
89 # The default queries are case insensitive. (for compatibility with
90 # older versions of FreeRADIUS)
91 authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
92 FROM ${authcheck_table} \
93 WHERE Username = '%{SQL-User-Name}' \
95 authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
96 FROM ${authreply_table} \
97 WHERE Username = '%{SQL-User-Name}' \
100 # Use these for case sensitive usernames.
101 # group_membership_query = "SELECT GroupName \
102 # FROM ${usergroup_table} \
103 # WHERE UserName = BINARY '%{SQL-User-Name}' \
106 group_membership_query = "SELECT GroupName \
107 FROM ${usergroup_table} \
108 WHERE UserName = '%{SQL-User-Name}' \
111 authorize_group_check_query = "SELECT id, GroupName, Attribute, Value, op \
112 FROM ${groupcheck_table} \
113 WHERE GroupName = '%{Sql-Group}' \
115 authorize_group_reply_query = "SELECT id, GroupName, Attribute, Value, op \
116 FROM ${groupreply_table} \
117 WHERE GroupName = '%{Sql-Group}' \
120 #######################################################################
122 #######################################################################
123 # accounting_onoff_query - query for Accounting On/Off packets
124 # accounting_update_query - query for Accounting update packets
125 # accounting_update_query_alt - query for Accounting update packets
126 # (alternate in case first query fails)
127 # accounting_start_query - query for Accounting start packets
128 # accounting_start_query_alt - query for Accounting start packets
129 # (alternate in case first query fails)
130 # accounting_stop_query - query for Accounting stop packets
131 # accounting_stop_query_alt - query for Accounting start packets
132 # (alternate in case first query doesn't
133 # affect any existing rows in the table)
134 #######################################################################
135 accounting_onoff_query = "UPDATE ${acct_table1} SET AcctStopTime='%S', AcctSessionTime=unix_timestamp('%S') - unix_timestamp(AcctStartTime), AcctTerminateCause='%{Acct-Terminate-Cause}', AcctStopDelay = %{Acct-Delay-Time:-0} WHERE AcctSessionTime=0 AND AcctStopTime=0 AND NASIPAddress= '%{NAS-IP-Address}' AND AcctStartTime <= '%S'"
137 accounting_update_query = "UPDATE ${acct_table1} \
138 SET FramedIPAddress = '%{Framed-IP-Address}', \
139 AcctSessionTime = '%{Acct-Session-Time}', \
140 AcctInputOctets = '%{Acct-Input-Octets}', \
141 AcctOutputOctets = '%{Acct-Output-Octets}' \
142 WHERE AcctSessionId = '%{Acct-Session-Id}' \
143 AND UserName = '%{SQL-User-Name}' \
144 AND NASIPAddress= '%{NAS-IP-Address}'"
146 accounting_update_query_alt = "INSERT into ${acct_table1} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', DATE_SUB('%S',INTERVAL (%{Acct-Session-Time:-0} + %{Acct-Delay-Time:-0}) SECOND), '%{Acct-Session-Time}', '%{Acct-Authentic}', '', '%{Acct-Input-Octets}', '%{Acct-Output-Octets}', '%{Called-Station-Id}', '%{Calling-Station-Id}', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '0')"
148 accounting_start_query = "INSERT into ${acct_table1} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', '%S', '0', '0', '%{Acct-Authentic}', '%{Connect-Info}', '', '0', '0', '%{Called-Station-Id}', '%{Calling-Station-Id}', '', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '%{Acct-Delay-Time:-0}', '0')"
150 accounting_start_query_alt = "UPDATE ${acct_table1} SET AcctStartTime = '%S', AcctStartDelay = '%{Acct-Delay-Time:-0}', ConnectInfo_start = '%{Connect-Info}' WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' AND NASIPAddress = '%{NAS-IP-Address}'"
152 accounting_stop_query = "UPDATE ${acct_table2} SET AcctStopTime = '%S', AcctSessionTime = '%{Acct-Session-Time}', AcctInputOctets = '%{Acct-Input-Octets}', AcctOutputOctets = '%{Acct-Output-Octets}', AcctTerminateCause = '%{Acct-Terminate-Cause}', AcctStopDelay = '%{Acct-Delay-Time:-0}', ConnectInfo_stop = '%{Connect-Info}' WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' AND NASIPAddress = '%{NAS-IP-Address}'"
154 accounting_stop_query_alt = "INSERT into ${acct_table2} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', DATE_SUB('%S', INTERVAL (%{Acct-Session-Time:-0} + %{Acct-Delay-Time:-0}) SECOND), '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', '%{Connect-Info}', '%{Acct-Input-Octets}', '%{Acct-Output-Octets}', '%{Called-Station-Id}', '%{Calling-Station-Id}', '%{Acct-Terminate-Cause}', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '0', '%{Acct-Delay-Time:-0}')"
156 #######################################################################
157 # Simultaneous Use Checking Queries
158 #######################################################################
159 # simul_count_query - query for the number of current connections
160 # - If this is not defined, no simultaneouls use checking
161 # - will be performed by this module instance
162 # simul_verify_query - query to return details of current connections for verification
163 # - Leave blank or commented out to disable verification step
164 # - Note that the returned field order should not be changed.
165 #######################################################################
167 # Uncomment simul_count_query to enable simultaneous use checking
168 # simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
169 simul_verify_query = "SELECT RadAcctId, AcctSessionId, UserName, NASIPAddress, NASPortId, FramedIPAddress, CallingStationId, FramedProtocol FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
171 #######################################################################
172 # Authentication Logging Queries
173 #######################################################################
174 # postauth_query - Insert some info after authentication
175 #######################################################################
177 postauth_query = "INSERT into ${postauth_table} (id, user, pass, reply, date) values ('', '%{User-Name}', '%{User-Password:-Chap-Password}', '%{reply:Packet-Type}', '%S')"