Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1279 richard 1
# -*- text -*-
2
##
3
## counter.conf -- PostgreSQL queries for rlm_sqlcounter
4
##
5
##	$Id$
6
 
7
#  Rather than maintaining seperate (GDBM) databases of
8
#  accounting info for each counter, this module uses the data
9
#  stored in the raddacct table by the sql modules. This
10
#  module NEVER does any database INSERTs or UPDATEs.  It is
11
#  totally dependent on the SQL module to process Accounting
12
#  packets.
13
#
14
#  The 'sqlmod_inst' parameter holds the instance of the sql
15
#  module to use when querying the SQL database. Normally it
16
#  is just "sql".  If you define more and one SQL module
17
#  instance (usually for failover situations), you can
18
#  specify which module has access to the Accounting Data
19
#  (radacct table).
20
#
21
#  The 'reset' parameter defines when the counters are all
22
#  reset to zero.  It can be hourly, daily, weekly, monthly or
23
#  never.  It can also be user defined. It should be of the
24
#  form:
25
#  	num[hdwm] where:
26
#  	h: hours, d: days, w: weeks, m: months
27
#  	If the letter is ommited days will be assumed. In example:
28
#  	reset = 10h (reset every 10 hours)
29
#  	reset = 12  (reset every 12 days)
30
#
31
#  The 'key' parameter specifies the unique identifier for the
32
#  counter records (usually 'User-Name').
33
#
34
#  The 'query' parameter specifies the SQL query used to get
35
#  the current Counter value from the database. There are 3
36
#  parameters that can be used in the query:
1289 richard 37
#		${key}	'key' parameter
1279 richard 38
#		%b	unix time value of beginning of reset period
39
#		%e	unix time value of end of reset period
40
#
41
#  The 'check-name' parameter is the name of the 'check'
42
#  attribute to use to access the counter in the 'users' file
43
#  or SQL radcheck or radcheckgroup tables.
44
#
45
#  DEFAULT  Max-Daily-Session > 3600, Auth-Type = Reject
46
#      Reply-Message = "You've used up more than one hour today"
47
#
48
sqlcounter dailycounter {
49
	counter-name = Daily-Session-Time
50
	check-name = Max-Daily-Session
51
	reply-name = Session-Timeout
52
	sqlmod-inst = sql
53
	key = User-Name
54
	reset = daily
55
 
56
	# This query properly handles calls that span from the
57
	# previous reset period into the current period but
58
	# involves more work for the SQL server than those
59
	# below
60
 
1420 richard 61
		# Ancienne requete
62
#	query = "SELECT SUM(acctsessiontime - \
63
#                 GREATEST((%b - UNIX_TIMESTAMP(acctstarttime)), 0)) \
64
#                 FROM radacct WHERE username = '%{${key}}' AND \
65
#                 UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%b'"
66
 
67
 
68
		# Requete modifiée
69
       query = "SELECT IFNULL((SELECT SUM(acctsessiontime -  \
70
		GREATEST((%b - UNIX_TIMESTAMP(acctstarttime)),0)) \
71
		FROM radacct WHERE username = '%{${key}}' AND \
72
		UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%b'),0)"
73
 
74
 
1279 richard 75
	# This query ignores calls that started in a previous
76
	# reset period and continue into into this one. But it
77
	# is a little easier on the SQL server
78
#	query = "SELECT SUM(acctsessiontime) FROM radacct WHERE \
1289 richard 79
#                username = '%{${key}}' AND acctstarttime > FROM_UNIXTIME('%b')"
1279 richard 80
 
81
	# This query is the same as above, but demonstrates an
82
	# additional counter parameter '%e' which is the
83
	# timestamp for the end of the period
84
#	query = "SELECT SUM(acctsessiontime) FROM radacct \
1289 richard 85
#                WHERE username = '%{${key}}' AND acctstarttime BETWEEN \
1279 richard 86
#                FROM_UNIXTIME('%b') AND FROM_UNIXTIME('%e')"
87
}
88
 
89
sqlcounter monthlycounter {
90
	counter-name = Monthly-Session-Time
91
		check-name = Max-Monthly-Session
92
		reply-name = Session-Timeout
93
		sqlmod-inst = sql
94
		key = User-Name
95
		reset = monthly
96
 
97
	# This query properly handles calls that span from the
98
	# previous reset period into the current period but
99
	# involves more work for the SQL server than those
100
	# below
1420 richard 101
 
102
 
103
		# Ancienne requete
104
#        query = "SELECT SUM(acctsessiontime - \
105
#                 GREATEST((%b - UNIX_TIMESTAMP(acctstarttime)), 0)) \
106
#                 FROM radacct WHERE username='%{${key}}' AND \
107
#                 UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%b'"
108
 
109
 
110
		# Requete modifiée
111
	query = "SELECT IFNULL((SELECT SUM(acctsessiontime - \
1279 richard 112
                 GREATEST((%b - UNIX_TIMESTAMP(acctstarttime)), 0)) \
1289 richard 113
                 FROM radacct WHERE username='%{${key}}' AND \
1420 richard 114
                 UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%b'),0)"
1279 richard 115
 
1420 richard 116
 
1279 richard 117
	# This query ignores calls that started in a previous
118
	# reset period and continue into into this one. But it
119
	# is a little easier on the SQL server
120
#	query = "SELECT SUM(acctsessiontime) FROM radacct WHERE \
1289 richard 121
#                username='%{${key}}' AND acctstarttime > FROM_UNIXTIME('%b')"
1279 richard 122
 
123
	# This query is the same as above, but demonstrates an
124
	# additional counter parameter '%e' which is the
125
	# timestamp for the end of the period
126
#	query = "SELECT SUM(acctsessiontime) FROM radacct \
1289 richard 127
#                WHERE username='%{${key}}' AND acctstarttime BETWEEN \
1279 richard 128
#                FROM_UNIXTIME('%b') AND FROM_UNIXTIME('%e')"
129
}
130
 
131
sqlcounter noresetcounter {
132
        counter-name = Max-All-Session-Time 
133
                check-name = Max-All-Session 
134
                sqlmod-inst = sql 
135
                key = User-Name 
136
                reset = never 
137
	# This is the original query
1289 richard 138
#       query = "SELECT IFNULL(SUM(AcctSessionTime),0) FROM radacct WHERE UserName='%{${key}}'" 
1279 richard 139
	# This is the query modified for ALCASAR needs (thanks to Daniel Laliberte --> authorized period after the first connection)
140
	query = "SELECT IFNULL((SELECT TIME_TO_SEC(TIMEDIFF(NOW(), acctstarttime)) \
141
                 FROM radacct \
1289 richard 142
                 WHERE UserName='%{${key}}' \
1279 richard 143
                 ORDER BY acctstarttime \
144
                 LIMIT 1),0)"
145
}