From a39e9f31242c93e99e417fb4496c8667f34ba7d1 Mon Sep 17 00:00:00 2001 From: Scott Armitage Date: Wed, 27 Jun 2012 22:15:43 +0100 Subject: [PATCH] Added postgres sql and conf for cui --- raddb/mods-available/cui | 9 +++++++-- raddb/sql/postgresql/cui.conf | 31 +++++++++++++++++++++++++++++++ raddb/sql/postgresql/cui.sql | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 raddb/sql/postgresql/cui.conf create mode 100644 raddb/sql/postgresql/cui.sql 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); + -- 2.47.3