Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
2818 rexy 1
<!DOCTYPE html>
324 richard 2
<?php
3
require('/etc/freeradius-web/config.php');
4
require('../lib/functions.php');
5
require('../lib/sql/functions.php');
6
require('../lib/acctshow.php');
2853 rexy 7
$Language = 'en';
8
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
9
	$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
10
	$Language = strtolower(substr(chop($Langue[0]), 0, 2)); 
11
}
12
if ($Language === 'fr') {
13
	$l_title	= "Journal des connexions";
14
	$l_select_attributes	= "Sélectionnez les attributs à afficher";
15
	$l_ordered	= "Classé par :";
16
	$l_max_return	= "Nbr. max. de résultats retournés :";
17
	$l_criteria	= "Critère de sélection :";
18
	$l_not_valid =	"L'opération demandé n'est pas valide. Sortie anormale.";
19
	$l_delete =	"Supprimer";
20
	$l_edit_user	= "Éditer l'utilisateur :";
21
} else if($Language === 'es') {
22
	$l_title	= "Registro de conexión";
23
	$l_select_attributes	= "Seleccione los atributos que desea mostrar";
24
	$l_ordered	= "ordenada por :";
25
	$l_max_return	= "Máximo número de resultados devueltos :";
26
	$l_criteria	= "Criterios de selección :";
27
	$l_not_valid =	"La operación solicitada no es válida. Salida anormal.";
28
	$l_delete =	"Eliminar";
29
	$l_edit_user	= "Editar usuario :";
30
} else {
31
	$l_title	= "Connections log";
32
	$l_select_attributes	= "Select the attributes you want to display";
33
	$l_ordered	= "Ordered by :";
34
	$l_max_return	= "Max. no. of results returned :";
35
	$l_criteria	= "Selection Criteria :";
36
	$l_not_valid =	"The requested operation is not valid. Abnormal exit.";
37
	$l_delete =	"Delete";
38
	$l_edit_user	= "Edit user :";
39
}
324 richard 40
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
41
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
42
else{
43
	echo <<<EOM
44
<html>
45
<head>
2818 rexy 46
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
47
<title>$l_title</title>
2817 rexy 48
<link rel="stylesheet" href="/css/acc.css">
324 richard 49
</head>
50
<body>
51
<center>
52
<b>Could not include SQL library functions. Aborting</b>
53
</body>
54
</html>
55
EOM;
56
	exit();
57
}
58
 
59
$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
1805 clement.si 60
if ($config['sql_type'] == 'pg'){
324 richard 61
	$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
62
}
1805 clement.si 63
$link = da_sql_pconnect ($config) or die('cannot connect to sql databse');
1831 raphael.pi 64
$fields = da_sql_list_fields($config['sql_accounting_table'],$link,$config);
324 richard 65
unset($items);
1831 raphael.pi 66
while($row = $fields->fetch_array())
67
{
68
	$key = strtolower($row[0]);
1805 clement.si 69
	$val = $sql_attrs[$key]['desc'];
324 richard 70
	if ($val == '')
71
		continue;
1805 clement.si 72
	$show = $sql_attrs[$key]['show'];
324 richard 73
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
74
	$items[$key] = "$val";
75
}
76
asort($items);
77
 
78
class Qi {
79
	var $name;
80
	var $item;
81
	var $_item;
82
	var $operator;
83
	var $type;
84
	var $typestr;
85
	var $value;
86
	function Qi($name,$item,$operator) {
87
				$this->name=$name;
88
				$this->item=$item;
89
				$this->operator=$operator;
90
	}
91
 
92
	function show() {	global $operators;
93
				global $items;
94
		$nam = $this->item;
95
			echo <<<EOM
96
	<tr><td align=left>
97
	<i>$items[$nam]</i>
98
	<input type=hidden name="item_of_$this->name" value="$this->item">
99
	</td><td align=left>
100
	<select name=operator_of_$this->name>
101
EOM;
102
		foreach($operators as $operator){
103
			if($this->operator == $operator)
104
				$selected=" selected ";
105
			else
106
				$selected='';
107
			print("<option value=\"$operator\" $selected>$operator</option>\n");
108
		 }
109
	echo <<<EOM
110
	</select>
111
	</td><td align=left>
112
	<input name="value_of_$this->name" type=text value="$this->value">
113
	</td><td align=left>
114
	<input type=hidden name="delete_$this->name" value=0>
2853 rexy 115
	<input type=submit class=button size=5 value="$l_delete" onclick="this.form.delete_$this->name.value=1">
324 richard 116
	</td></tr>
117
EOM;
118
	}
119
 
120
	function get($designator) {  	global ${"item_of_$designator"};
121
			global ${"value_of_$designator"};
122
			global ${"operator_of_$designator"};
123
			if(${"item_of_$designator"}){
124
				$this->value= ${"value_of_$designator"};
125
				$this->operator=${"operator_of_$designator"};
126
				$this->item=${"item_of_$designator"};
127
			}
128
		}
129
	function query(){
130
		global $operators;
131
		global $items;
132
		return $items[$this->item]."  $this->operator  '$this->value'";
133
	}
134
}
135
 
136
?>
137
<html>
138
<head>
2818 rexy 139
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
140
	<title><?= $l_title ?></title>
141
	<link rel="stylesheet" href="/css/acc.css">
324 richard 142
</head>
143
<body>
2818 rexy 144
<div class="panel">
145
	<div class="panel-header"><?= $l_title ?></div>
146
	<div class="panel-row">
324 richard 147
<?php
1831 raphael.pi 148
if(!isset($queryflag))
149
{
150
	$queryflag = 0;
151
}
324 richard 152
if(!$queryflag) {
153
	echo <<<EOM
154
<form method=post>
155
<table border=0 width=740 cellpadding=1 cellspacing=1>
156
<tr>
157
<td>
2853 rexy 158
<b>$l_select_attributes</b><br>
324 richard 159
<select name="accounting_show_attrs[]" size=5 multiple>
160
EOM;
161
foreach($items as $key => $val)
162
	echo <<<EOM
163
<option $selected[$key] value="$key">$val</option>
164
EOM;
165
 
166
echo <<<EOM
167
</select>
168
<br><br>
2853 rexy 169
<b>$l_ordered</b><br>
324 richard 170
<select name="order_by">
171
EOM;
172
 
173
foreach($items as $key => $val)
174
	if ($val == 'username')
175
		echo <<<EOM
176
	<option selected value="$key">$val</option>
177
EOM;
178
	else
179
	echo <<<EOM
180
<option value="$key">$val</option>
181
EOM;
182
 
183
echo <<<EOM
184
</select>
185
<br><br>
2853 rexy 186
<b>$l_max_return</b><br>
324 richard 187
<input name=maxresults value=$config[sql_row_limit] size=5>
188
</td>
189
<td valign=top>
190
<input type=hidden name=add value=0>
191
<table border=0 width=340 cellpadding=1 cellspacing=1>
192
<tr><td>
2853 rexy 193
<b>$l_criteria</b>
324 richard 194
</td></tr>
195
<tr><td>
196
<select name=item_name onchange="this.form.add.value=1;this.form.submit()">
197
<option>--Attribute--</option>
198
EOM;
199
 
200
foreach($items as $key => $val)
201
	print("<option value=\"$key\">$val</option>");
202
 
203
echo <<<EOM
204
</select>
205
</td></tr>
206
EOM;
207
 
208
$number=1;
209
$offset=0;
1831 raphael.pi 210
while (isset(${"item_of_w$number"}) && ${"item_of_w$number"}) {
324 richard 211
	if(${"delete_w$number"}==1) {$offset=1;$number++;}
212
		else {
213
		$designator=$number-$offset;
214
		${"w$designator"} = new Qi("w$designator","","");
215
		${"w$designator"}->get("w$number");
216
		${"w$designator"}->show();
217
		$number++;
218
		}
219
	}
1831 raphael.pi 220
if(isset($add) && $add==1) {
324 richard 221
	${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
222
	${"w$number"}->show();
223
	}
224
echo <<<EOM
225
</table>
226
</td>
227
<tr>
228
<td>
229
<input type=hidden name=queryflag value=0>
230
<br><input type=submit class=button onclick="this.form.queryflag.value=1">
231
</td>
232
</tr>
233
</table>
234
</form>
235
EOM;
236
}
237
 
238
if ($queryflag == 1){
1831 raphael.pi 239
	if(!isset($where))
240
		$where = "";
324 richard 241
$i = 1;
1831 raphael.pi 242
while (isset(${"item_of_w$i"}) && ${"item_of_w$i"}){
324 richard 243
	$op_found = 0;
244
	foreach ($operators as $operator){
245
		if (${"operator_of_w$i"} == $operator){
246
			$op_found = 1;
247
			break;
248
		}
249
	}
250
	if (!$op_found)
2853 rexy 251
		die("$l_not_valid");
324 richard 252
	${"item_of_w$i"} = preg_replace('/\s/','',${"item_of_w$i"});
1831 raphael.pi 253
	${"value_of_w$i"} = da_sql_escape_string($link,${"value_of_w$i"});
324 richard 254
	$where .= ($i == 1) ? ' WHERE ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" :
255
				' AND ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" ;
256
	$i++;
257
}
258
 
259
$order = ($order_by != '') ? "$order_by" : 'username';
260
 
261
if (preg_match("/[\s;]/",$order))
262
	die("ORDER BY pattern is illegal. Exiting abnornally.");
263
 
264
if (!is_numeric($maxresults))
265
	die("Max Results is not in numeric form. Exiting abnormally.");
266
 
1831 raphael.pi 267
$query_view = '';
324 richard 268
foreach ($accounting_show_attrs as $val)
269
	$query_view .= $val . ',';
2403 tom.houday 270
$query_view = preg_replace('/,$/','',$query_view);
324 richard 271
unset($sql_extra_query);
1831 raphael.pi 272
if (isset($config['sql_accounting_extra_query'])){
273
	$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
274
	$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
275
}
276
else
277
{
278
	$sql_extra_query = "";
279
}
280
 
281
if(!isset($where))
282
{
283
	$where = "";
284
}
285
 
324 richard 286
$query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
287
	$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
486 franck 288
	" ORDER BY $order DESC " . da_sql_limit($maxresults,2,$config) . ";";
324 richard 289
 
290
echo <<<EOM
291
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
292
	<tr><td>
2818 rexy 293
		<table border=1 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
294
		<tr bgcolor="#d0ddb0">
324 richard 295
EOM;
1831 raphael.pi 296
 
324 richard 297
foreach($accounting_show_attrs as $val){
1831 raphael.pi 298
	$desc = $sql_attrs[$val]['desc'];
299
	if($val == 'acctoutputoctets')
300
		$desc = "Upload";
301
	if($val == 'acctinputoctets')
302
		$desc = "Download";
324 richard 303
	echo "<th>$desc</th>\n";
304
}
305
echo "</tr>\n";
306
 
1805 clement.si 307
	$search = da_sql_query($link,$config,$query);
324 richard 308
	if ($search){
1805 clement.si 309
		while( $row = da_sql_fetch_array($search,$config) ){
1831 raphael.pi 310
			//$num++;
324 richard 311
			echo "<tr align=center>\n";
312
			foreach($accounting_show_attrs as $val){
313
				$info = $row[$val];
1831 raphael.pi 314
				if($val == "acctoutputoctets" || $val == "acctinputoctets")
315
					$info = bytes2str($info);
316
				if($val == "acctsessiontime")
317
					$info = time2strclock($info);
324 richard 318
				if ($info == '')
319
					$info = '-';
320
				if ($val == 'username'){
321
					$Info = urlencode($info);
2853 rexy 322
					$info = "<a href=\"user_admin.php?login=$Info\" title=\"$l_edit_user $info\">$info</a>";
324 richard 323
				}
324
				echo <<<EOM
325
			<td>$info</td>
326
EOM;
327
			}
328
			echo "</tr>\n";
329
		}
330
	}
331
	else
332
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
2818 rexy 333
		echo <<<EOM
334
		</table>
324 richard 335
	</td></tr>
2818 rexy 336
	</table>\n
324 richard 337
EOM;
338
}
339
?>
2818 rexy 340
	</div>
341
</div>
342
</body>
343
</html>