Add IPPOOL setup for Oracle (Untested by me but reported to work)
[freeradius.git] / raddb / sql / oracle / msqlippool.txt
1 CREATE OR REPLACE FUNCTION msqlippool(user varchar2, pool varchar2)\r
2 RETURN varchar2 IS\r
3 \r
4         PRAGMA AUTONOMOUS_TRANSACTION;\r
5         ip_temp varchar2(20);\r
6 BEGIN\r
7 \r
8     -- If the user's pool is dynamic, get an ipaddress (oldest one) from the corresponding pool\r
9 \r
10     if pool = 'Dynamic' then\r
11         select framedipaddress into ip_temp from (select framedipaddress from radippool where expiry_time < current_timestamp and pool_name = pool ORDER BY expiry_time) where rownum = 1;\r
12         return (ip_temp);\r
13 \r
14     -- Else, then get the static ipaddress for that user from the corresponding pool\r
15 \r
16     else\r
17         select framedipaddress into ip_temp from radippool where username = user and pool_name = pool;\r
18         return (ip_temp);\r
19     end if;\r
20 \r
21 exception\r
22 \r
23  -- This block is executed if there's no free ipaddresses or no static ip assigned to the user\r
24 \r
25  when NO_DATA_FOUND then\r
26         if pool = 'Dynamic' then\r
27                 return(''); -- so sqlippool can log it on radius.log\r
28         end if;\r
29 \r
30         -- Else, grabs a free IP from the static pool and saves it in radippool so the user will always get the same IP the next time\r
31 \r
32         select framedipaddress into ip_temp from (select framedipaddress from radippool where expiry_time < current_timestamp and username is null and pool_name = pool) where rownum = 1;\r
33         UPDATE radippool SET username = user where framedipaddress = ip_temp;\r
34         commit;\r
35         return (ip_temp);\r
36 \r
37  when others\r
38   then return('Oracle Exception');\r
39 \r
40 END;\r
41 /\r