Subversion Repositories ALCASAR

Rev

Rev 2403 | Rev 2818 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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