From: Scott Armitage Date: Wed, 27 Jun 2012 21:15:43 +0000 (+0100) Subject: Added postgres sql and conf for cui X-Git-Tag: release_3_0_0_beta0~142^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F63%2Fhead;p=thirdparty%2Ffreeradius-server.git Added postgres sql and conf for cui --- diff --git a/raddb/mods-available/cui b/raddb/mods-available/cui index 246461369a..b1ba225273 100644 --- a/raddb/mods-available/cui +++ b/raddb/mods-available/cui @@ -5,10 +5,15 @@ # # Write Chargeable-User-Identity to the database. # -# Schema raddb/sql/mysql/cui.sql -# Queries raddb/sql/mysql/cui.conf +# Schema raddb/sql/DB/cui.sql +# Queries raddb/sql/DB/cui.conf # sql cui { + # + # Set the database to one of: + # + # mysql, postgresql + # database = "mysql" driver = "rlm_sql_${database}" server = "localhost" diff --git a/raddb/sql/postgresql/cui.conf b/raddb/sql/postgresql/cui.conf new file mode 100644 index 0000000000..d90eccc64c --- /dev/null +++ b/raddb/sql/postgresql/cui.conf @@ -0,0 +1,31 @@ +# -*- text -*- + +## +## Queries to update the CUI table. +## +postauth_query = "INSERT INTO ${cui_table} \ + (clientipaddress, callingstationid, username, cui) \ + VALUES \ + ('%{Client-IP-Address}', '%{Calling-Station-Id}', '%{User-Name}', '%{reply:Chargeable-User-Identity}')"; + +accounting_start_query = "UPDATE ${cui_table} \ + SET \ + lastaccounting = now() \ + WHERE clientipaddress = '%{Client-IP-Address}' \ + AND callingstationid = '%{Calling-Station-Id}' \ + AND username = '%{User-Name}' \ + AND cui = '%{Chargeable-User-Identity}'"; + +accounting_update_query = "UPDATE ${cui_table} \ + SET \ + lastaccounting = now() \ + WHERE clientipaddress = '%{Client-IP-Address}' \ + AND callingstationid = '%{Calling-Station-Id}' \ + AND username = '%{User-Name}' \ + AND cui = '%{Chargeable-User-Identity}'"; + +accounting_stop_query = "DELETE FROM ${cui_table} WHERE \ + clientipaddress = '%{Client-IP-Address}' \ + AND callingstationid = '%{Calling-Station-Id}' \ + AND username = '%{User-Name}' \ + AND cui = '%{Chargeable-User-Identity}'"; diff --git a/raddb/sql/postgresql/cui.sql b/raddb/sql/postgresql/cui.sql new file mode 100644 index 0000000000..34346da8d2 --- /dev/null +++ b/raddb/sql/postgresql/cui.sql @@ -0,0 +1,14 @@ +CREATE TABLE cui ( + clientipaddress INET NOT NULL DEFAULT '0.0.0.0', + callingstationid varchar(50) NOT NULL DEFAULT '', + username varchar(64) NOT NULL DEFAULT '', + cui varchar(32) NOT NULL DEFAULT '', + creationdate TIMESTAMP with time zone NOT NULL default 'now()', + lastaccounting TIMESTAMP with time zone NOT NULL default '-infinity'::timestamp, + PRIMARY KEY (username, clientipaddress, callingstationid) +); + +CREATE RULE postauth_query AS ON INSERT TO cui + WHERE EXISTS(SELECT 1 FROM cui WHERE (username, clientipaddress, callingstationid)=(NEW.username, NEW.clientipaddress, NEW.callingstationid)) + DO INSTEAD UPDATE cui SET lastaccounting ='-infinity'::timestamp with time zone, cui=NEW.cui WHERE (username, clientipaddress, callingstationid)=(NEW.username, NEW.clientipaddress, NEW.callingstationid); +