Subversion Repositories ALCASAR

Rev

Rev 1805 | Rev 1846 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1805 Rev 1831
1
<?php
1
<?php
2
 
2
 
3
require('/etc/freeradius-web/config.php');
3
require('/etc/freeradius-web/config.php');
4
require('../lib/functions.php');
4
require('../lib/functions.php');
5
require('../lib/sql/functions.php');
5
require('../lib/sql/functions.php');
6
require('../lib/acctshow.php');
6
require('../lib/acctshow.php');
7
 
7
 
8
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
8
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
9
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
9
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
10
else{
10
else{
11
	echo <<<EOM
11
	echo <<<EOM
12
<html>
12
<html>
13
<head>
13
<head>
14
<title>G&eacute;n&eacute;rateur de rapports de comptes</title>
14
<title>G&eacute;n&eacute;rateur de rapports de comptes</title>
15
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
15
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
16
<link rel="stylesheet" href="/css/style.css">
16
<link rel="stylesheet" href="/css/style.css">
17
</head>
17
</head>
18
<body>
18
<body>
19
<center>
19
<center>
20
<b>Could not include SQL library functions. Aborting</b>
20
<b>Could not include SQL library functions. Aborting</b>
21
</body>
21
</body>
22
</html>
22
</html>
23
EOM;
23
EOM;
24
	exit();
24
	exit();
25
}
25
}
26
 
26
 
27
$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
27
$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
28
if ($config['sql_type'] == 'pg'){
28
if ($config['sql_type'] == 'pg'){
29
	$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
29
	$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
30
}
30
}
31
 
-
 
32
$link = da_sql_pconnect ($config) or die('cannot connect to sql databse');
31
$link = da_sql_pconnect ($config) or die('cannot connect to sql databse');
33
$fields = da_sql_list_fields($config[sql_accounting_table],$link,$config);
32
$fields = da_sql_list_fields($config['sql_accounting_table'],$link,$config);
34
$no_fields = da_sql_num_fields($fields,$config);
-
 
-
 
33
 
35
 
34
 
36
unset($items);
35
unset($items);
37
 
36
 
38
for($i=0;$i<$no_fields;$i++){
37
while($row = $fields->fetch_array())
-
 
38
{
39
	$key = strtolower(da_sql_field_name($fields,$i,$config));
39
	$key = strtolower($row[0]);
40
	$val = $sql_attrs[$key]['desc'];
40
	$val = $sql_attrs[$key]['desc'];
41
	if ($val == '')
41
	if ($val == '')
42
		continue;
42
		continue;
43
	$show = $sql_attrs[$key]['show'];
43
	$show = $sql_attrs[$key]['show'];
44
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
44
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
45
	$items[$key] = "$val";
45
	$items[$key] = "$val";
46
}
46
}
47
asort($items);
47
asort($items);
48
 
48
 
49
class Qi {
49
class Qi {
50
	var $name;
50
	var $name;
51
	var $item;
51
	var $item;
52
	var $_item;
52
	var $_item;
53
	var $operator;
53
	var $operator;
54
	var $type;
54
	var $type;
55
	var $typestr;
55
	var $typestr;
56
	var $value;
56
	var $value;
57
	function Qi($name,$item,$operator) {
57
	function Qi($name,$item,$operator) {
58
				$this->name=$name;
58
				$this->name=$name;
59
				$this->item=$item;
59
				$this->item=$item;
60
				$this->operator=$operator;
60
				$this->operator=$operator;
61
	}
61
	}
62
 
62
 
63
	function show() {	global $operators;
63
	function show() {	global $operators;
64
				global $items;
64
				global $items;
65
		$nam = $this->item;
65
		$nam = $this->item;
66
			echo <<<EOM
66
			echo <<<EOM
67
	<tr><td align=left>
67
	<tr><td align=left>
68
	<i>$items[$nam]</i>
68
	<i>$items[$nam]</i>
69
	<input type=hidden name="item_of_$this->name" value="$this->item">
69
	<input type=hidden name="item_of_$this->name" value="$this->item">
70
	</td><td align=left>
70
	</td><td align=left>
71
	<select name=operator_of_$this->name>
71
	<select name=operator_of_$this->name>
72
EOM;
72
EOM;
73
		foreach($operators as $operator){
73
		foreach($operators as $operator){
74
			if($this->operator == $operator)
74
			if($this->operator == $operator)
75
				$selected=" selected ";
75
				$selected=" selected ";
76
			else
76
			else
77
				$selected='';
77
				$selected='';
78
			print("<option value=\"$operator\" $selected>$operator</option>\n");
78
			print("<option value=\"$operator\" $selected>$operator</option>\n");
79
		 }
79
		 }
80
	echo <<<EOM
80
	echo <<<EOM
81
	</select>
81
	</select>
82
	</td><td align=left>
82
	</td><td align=left>
83
	<input name="value_of_$this->name" type=text value="$this->value">
83
	<input name="value_of_$this->name" type=text value="$this->value">
84
	</td><td align=left>
84
	</td><td align=left>
85
	<input type=hidden name="delete_$this->name" value=0>
85
	<input type=hidden name="delete_$this->name" value=0>
86
	<input type=submit class=button size=5 value=del onclick="this.form.delete_$this->name.value=1">
86
	<input type=submit class=button size=5 value=del onclick="this.form.delete_$this->name.value=1">
87
	</td></tr>
87
	</td></tr>
88
EOM;
88
EOM;
89
	}
89
	}
90
 
90
 
91
	function get($designator) {  	global ${"item_of_$designator"};
91
	function get($designator) {  	global ${"item_of_$designator"};
92
			global ${"value_of_$designator"};
92
			global ${"value_of_$designator"};
93
			global ${"operator_of_$designator"};
93
			global ${"operator_of_$designator"};
94
			if(${"item_of_$designator"}){
94
			if(${"item_of_$designator"}){
95
				$this->value= ${"value_of_$designator"};
95
				$this->value= ${"value_of_$designator"};
96
				$this->operator=${"operator_of_$designator"};
96
				$this->operator=${"operator_of_$designator"};
97
				$this->item=${"item_of_$designator"};
97
				$this->item=${"item_of_$designator"};
98
			}
98
			}
99
		}
99
		}
100
	function query(){
100
	function query(){
101
		global $operators;
101
		global $operators;
102
		global $items;
102
		global $items;
103
		return $items[$this->item]."  $this->operator  '$this->value'";
103
		return $items[$this->item]."  $this->operator  '$this->value'";
104
	}
104
	}
105
}
105
}
106
 
106
 
107
?>
107
?>
108
<html>
108
<html>
109
<head>
109
<head>
110
<title>Journal des connexions</title>
110
<title>Journal des connexions</title>
111
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
111
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
112
<link rel="stylesheet" href="/css/style.css">
112
<link rel="stylesheet" href="/css/style.css">
113
</head>
113
</head>
114
<body>
114
<body>
115
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
115
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
116
	<tr><th>Journal des connexions</th></tr>
116
	<tr><th>Journal des connexions</th></tr>
117
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2">
117
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2">
118
	</td></tr>
118
	</td></tr>
119
</TABLE>
119
</TABLE>
120
<TABLE width="100%" border="1" cellspacing="0" cellpadding="1">
120
<TABLE width="100%" border="1" cellspacing="0" cellpadding="1">
121
<tr><td>
121
<tr><td>
122
<?php
122
<?php
-
 
123
if(!isset($queryflag))
-
 
124
{
-
 
125
	$queryflag = 0;
-
 
126
}
123
if(!$queryflag) {
127
if(!$queryflag) {
124
	echo <<<EOM
128
	echo <<<EOM
125
<form method=post>
129
<form method=post>
126
<table border=0 width=740 cellpadding=1 cellspacing=1>
130
<table border=0 width=740 cellpadding=1 cellspacing=1>
127
<tr>
131
<tr>
128
<td>
132
<td>
129
<b>Afficher les attributs suivants :</b><br>
133
<b>Afficher les attributs suivants :</b><br>
130
<select name="accounting_show_attrs[]" size=5 multiple>
134
<select name="accounting_show_attrs[]" size=5 multiple>
131
EOM;
135
EOM;
132
foreach($items as $key => $val)
136
foreach($items as $key => $val)
133
	echo <<<EOM
137
	echo <<<EOM
134
<option $selected[$key] value="$key">$val</option>
138
<option $selected[$key] value="$key">$val</option>
135
EOM;
139
EOM;
136
 
140
 
137
echo <<<EOM
141
echo <<<EOM
138
</select>
142
</select>
139
<br><br>
143
<br><br>
140
<b>Class&eacute; par :</b><br>
144
<b>Class&eacute; par :</b><br>
141
<select name="order_by">
145
<select name="order_by">
142
EOM;
146
EOM;
143
 
147
 
144
foreach($items as $key => $val)
148
foreach($items as $key => $val)
145
	if ($val == 'username')
149
	if ($val == 'username')
146
		echo <<<EOM
150
		echo <<<EOM
147
	<option selected value="$key">$val</option>
151
	<option selected value="$key">$val</option>
148
EOM;
152
EOM;
149
	else
153
	else
150
	echo <<<EOM
154
	echo <<<EOM
151
<option value="$key">$val</option>
155
<option value="$key">$val</option>
152
EOM;
156
EOM;
153
 
157
 
154
echo <<<EOM
158
echo <<<EOM
155
</select>
159
</select>
156
<br><br>
160
<br><br>
157
<b>Nbr. Max. de r&eacute;sultats retourn&eacute;s :</b><br>
161
<b>Nbr. Max. de r&eacute;sultats retourn&eacute;s :</b><br>
158
<input name=maxresults value=$config[sql_row_limit] size=5>
162
<input name=maxresults value=$config[sql_row_limit] size=5>
159
</td>
163
</td>
160
<td valign=top>
164
<td valign=top>
161
<input type=hidden name=add value=0>
165
<input type=hidden name=add value=0>
162
<table border=0 width=340 cellpadding=1 cellspacing=1>
166
<table border=0 width=340 cellpadding=1 cellspacing=1>
163
<tr><td>
167
<tr><td>
164
<b>Crit&egrave;re de s&eacute;lection :</b>
168
<b>Crit&egrave;re de s&eacute;lection :</b>
165
</td></tr>
169
</td></tr>
166
<tr><td>
170
<tr><td>
167
<select name=item_name onchange="this.form.add.value=1;this.form.submit()">
171
<select name=item_name onchange="this.form.add.value=1;this.form.submit()">
168
<option>--Attribute--</option>
172
<option>--Attribute--</option>
169
EOM;
173
EOM;
170
 
174
 
171
foreach($items as $key => $val)
175
foreach($items as $key => $val)
172
	print("<option value=\"$key\">$val</option>");
176
	print("<option value=\"$key\">$val</option>");
173
 
177
 
174
echo <<<EOM
178
echo <<<EOM
175
</select>
179
</select>
176
</td></tr>
180
</td></tr>
177
EOM;
181
EOM;
178
 
182
 
179
$number=1;
183
$number=1;
180
$offset=0;
184
$offset=0;
181
while (${"item_of_w$number"}) {
185
while (isset(${"item_of_w$number"}) && ${"item_of_w$number"}) {
182
	if(${"delete_w$number"}==1) {$offset=1;$number++;}
186
	if(${"delete_w$number"}==1) {$offset=1;$number++;}
183
		else {
187
		else {
184
		$designator=$number-$offset;
188
		$designator=$number-$offset;
185
		${"w$designator"} = new Qi("w$designator","","");
189
		${"w$designator"} = new Qi("w$designator","","");
186
		${"w$designator"}->get("w$number");
190
		${"w$designator"}->get("w$number");
187
		${"w$designator"}->show();
191
		${"w$designator"}->show();
188
		$number++;
192
		$number++;
189
		}
193
		}
190
	}
194
	}
191
if($add==1) {
195
if(isset($add) && $add==1) {
192
	${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
196
	${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
193
	${"w$number"}->show();
197
	${"w$number"}->show();
194
	}
198
	}
195
echo <<<EOM
199
echo <<<EOM
196
</table>
200
</table>
197
</td>
201
</td>
198
<tr>
202
<tr>
199
<td>
203
<td>
200
<input type=hidden name=queryflag value=0>
204
<input type=hidden name=queryflag value=0>
201
<br><input type=submit class=button onclick="this.form.queryflag.value=1">
205
<br><input type=submit class=button onclick="this.form.queryflag.value=1">
202
</td>
206
</td>
203
</tr>
207
</tr>
204
</table>
208
</table>
205
</form>
209
</form>
206
</table>
210
</table>
207
</body>
211
</body>
208
</html>
212
</html>
209
EOM;
213
EOM;
210
 
214
 
211
}
215
}
212
 
216
 
213
if ($queryflag == 1){
217
if ($queryflag == 1){
-
 
218
	if(!isset($where))
-
 
219
		$where = "";
214
$i = 1;
220
$i = 1;
215
while (${"item_of_w$i"}){
221
while (isset(${"item_of_w$i"}) && ${"item_of_w$i"}){
216
	$op_found = 0;
222
	$op_found = 0;
217
	foreach ($operators as $operator){
223
	foreach ($operators as $operator){
218
		if (${"operator_of_w$i"} == $operator){
224
		if (${"operator_of_w$i"} == $operator){
219
			$op_found = 1;
225
			$op_found = 1;
220
			break;
226
			break;
221
		}
227
		}
222
	}
228
	}
223
	if (!$op_found)
229
	if (!$op_found)
224
		die("L'op&eacute;ration demand&eacute; n'est pas valide. Sortie anormale.");
230
		die("L'op&eacute;ration demand&eacute; n'est pas valide. Sortie anormale.");
225
	${"item_of_w$i"} = preg_replace('/\s/','',${"item_of_w$i"});
231
	${"item_of_w$i"} = preg_replace('/\s/','',${"item_of_w$i"});
226
	${"value_of_w$i"} = da_sql_escape_string(${"value_of_w$i"});
232
	${"value_of_w$i"} = da_sql_escape_string($link,${"value_of_w$i"});
227
	$where .= ($i == 1) ? ' WHERE ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" :
233
	$where .= ($i == 1) ? ' WHERE ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" :
228
				' AND ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" ;
234
				' AND ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" ;
229
	$i++;
235
	$i++;
230
}
236
}
231
 
237
 
232
$order = ($order_by != '') ? "$order_by" : 'username';
238
$order = ($order_by != '') ? "$order_by" : 'username';
233
 
239
 
234
if (preg_match("/[\s;]/",$order))
240
if (preg_match("/[\s;]/",$order))
235
	die("ORDER BY pattern is illegal. Exiting abnornally.");
241
	die("ORDER BY pattern is illegal. Exiting abnornally.");
236
 
242
 
237
if (!is_numeric($maxresults))
243
if (!is_numeric($maxresults))
238
	die("Max Results is not in numeric form. Exiting abnormally.");
244
	die("Max Results is not in numeric form. Exiting abnormally.");
239
 
245
 
240
unset($query_view);
246
$query_view = '';
241
foreach ($accounting_show_attrs as $val)
247
foreach ($accounting_show_attrs as $val)
242
	$query_view .= $val . ',';
248
	$query_view .= $val . ',';
243
$query_view = ereg_replace(',$','',$query_view);
249
$query_view = ereg_replace(',$','',$query_view);
244
unset($sql_extra_query);
250
unset($sql_extra_query);
245
if ($config[sql_accounting_extra_query] != '')
251
if (isset($config['sql_accounting_extra_query'])){
246
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
252
	$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
247
	$sql_extra_query = da_sql_escape_string($sql_extra_query);
253
	$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
-
 
254
}
-
 
255
else
-
 
256
{
-
 
257
	$sql_extra_query = "";
-
 
258
}
-
 
259
 
-
 
260
if(!isset($where))
-
 
261
{
-
 
262
	$where = "";
-
 
263
}
-
 
264
 
248
$query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
265
$query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
249
	$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
266
	$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
250
	" ORDER BY $order DESC " . da_sql_limit($maxresults,2,$config) . ";";
267
	" ORDER BY $order DESC " . da_sql_limit($maxresults,2,$config) . ";";
251
 
268
 
252
echo <<<EOM
269
echo <<<EOM
253
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
270
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
254
	<tr><td>
271
	<tr><td>
255
<p>
272
<p>
256
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
273
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
257
	<tr bgcolor="#d0ddb0">
274
	<tr bgcolor="#d0ddb0">
258
	</tr>
275
	</tr>
259
EOM;
276
EOM;
-
 
277
 
-
 
278
 
260
foreach($accounting_show_attrs as $val){
279
foreach($accounting_show_attrs as $val){
261
	$desc = $sql_attrs[$val][desc];
280
	$desc = $sql_attrs[$val]['desc'];
-
 
281
	if($val == 'acctoutputoctets')
-
 
282
		$desc = "Upload";
-
 
283
	if($val == 'acctinputoctets')
-
 
284
		$desc = "Download";
262
	echo "<th>$desc</th>\n";
285
	echo "<th>$desc</th>\n";
263
}
286
}
264
echo "</tr>\n";
287
echo "</tr>\n";
265
 
288
 
266
	$search = da_sql_query($link,$config,$query);
289
	$search = da_sql_query($link,$config,$query);
267
	if ($search){
290
	if ($search){
268
		while( $row = da_sql_fetch_array($search,$config) ){
291
		while( $row = da_sql_fetch_array($search,$config) ){
269
			$num++;
292
			//$num++;
270
			echo "<tr align=center>\n";
293
			echo "<tr align=center>\n";
271
			foreach($accounting_show_attrs as $val){
294
			foreach($accounting_show_attrs as $val){
272
				$info = $row[$val];
295
				$info = $row[$val];
-
 
296
				if($val == "acctoutputoctets" || $val == "acctinputoctets")
-
 
297
					$info = bytes2str($info);
-
 
298
				if($val == "acctsessiontime")
-
 
299
					$info = time2strclock($info);
273
				if ($info == '')
300
				if ($info == '')
274
					$info = '-';
301
					$info = '-';
275
				$info = $sql_attrs[$val][func]($info);
-
 
276
				if ($val == 'username'){
302
				if ($val == 'username'){
277
					$Info = urlencode($info);
303
					$Info = urlencode($info);
278
					$info = "<a href=\"user_admin.php?login=$Info\" title=\"Edit user $info\">$info<a/>";
304
					$info = "<a href=\"user_admin.php?login=$Info\" title=\"Edit user $info\">$info<a/>";
279
				}
305
				}
280
				echo <<<EOM
306
				echo <<<EOM
281
			<td>$info</td>
307
			<td>$info</td>
282
EOM;
308
EOM;
283
			}
309
			}
284
			echo "</tr>\n";
310
			echo "</tr>\n";
285
		}
311
		}
286
	}
312
	}
287
	else
313
	else
288
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
314
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
289
echo <<<EOM
315
echo <<<EOM
290
	</table>
316
	</table>
291
	</td></tr>
317
	</td></tr>
292
	</table>
318
	</table>
293
</td></tr>
319
</td></tr>
294
</table>
320
</table>
295
</table>
321
</table>
296
</body>
322
</body>
297
</html>
323
</html>
298
EOM;
324
EOM;
299
}
325
}
300
?>
326
?>
301
 
327