Subversion Repositories ALCASAR

Rev

Rev 2853 | Rev 2926 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
require('/etc/freeradius-web/config.php');
3
require('../lib/functions.php');
4
require('../lib/sql/functions.php');
5
require('../lib/acctshow.php');
2854 rexy 6
?>
7
<!DOCTYPE html>
8
<html>
9
<head>
10
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11
<?php
12
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
13
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
14
else{
15
	echo <<<EOM
16
<title>$l_title</title>
17
<link rel="stylesheet" href="/css/acc.css">
18
</head>
19
<body>
20
<center>
21
<b>Could not include SQL library functions. Aborting</b>
22
</body>
23
</html>
24
EOM;
25
	exit();
26
}
27
#choice of language
2853 rexy 28
$Language = 'en';
29
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
30
	$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
31
	$Language = strtolower(substr(chop($Langue[0]), 0, 2)); 
32
}
33
if ($Language === 'fr') {
34
	$l_title	= "Journal des connexions";
35
	$l_select_attributes	= "Sélectionnez les attributs à afficher";
36
	$l_ordered	= "Classé par :";
37
	$l_max_return	= "Nbr. max. de résultats retournés :";
38
	$l_criteria	= "Critère de sélection :";
39
	$l_not_valid =	"L'opération demandé n'est pas valide. Sortie anormale.";
40
	$l_delete =	"Supprimer";
41
	$l_edit_user	= "Éditer l'utilisateur :";
42
} else if($Language === 'es') {
43
	$l_title	= "Registro de conexión";
44
	$l_select_attributes	= "Seleccione los atributos que desea mostrar";
45
	$l_ordered	= "ordenada por :";
46
	$l_max_return	= "Máximo número de resultados devueltos :";
47
	$l_criteria	= "Criterios de selección :";
48
	$l_not_valid =	"La operación solicitada no es válida. Salida anormal.";
49
	$l_delete =	"Eliminar";
50
	$l_edit_user	= "Editar usuario :";
51
} else {
52
	$l_title	= "Connections log";
53
	$l_select_attributes	= "Select the attributes you want to display";
54
	$l_ordered	= "Ordered by :";
55
	$l_max_return	= "Max. no. of results returned :";
56
	$l_criteria	= "Selection Criteria :";
57
	$l_not_valid =	"The requested operation is not valid. Abnormal exit.";
58
	$l_delete =	"Delete";
59
	$l_edit_user	= "Edit user :";
60
}
324 richard 61
 
62
$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
1805 clement.si 63
if ($config['sql_type'] == 'pg'){
324 richard 64
	$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
65
}
1805 clement.si 66
$link = da_sql_pconnect ($config) or die('cannot connect to sql databse');
1831 raphael.pi 67
$fields = da_sql_list_fields($config['sql_accounting_table'],$link,$config);
324 richard 68
unset($items);
1831 raphael.pi 69
while($row = $fields->fetch_array())
70
{
71
	$key = strtolower($row[0]);
1805 clement.si 72
	$val = $sql_attrs[$key]['desc'];
324 richard 73
	if ($val == '')
74
		continue;
1805 clement.si 75
	$show = $sql_attrs[$key]['show'];
324 richard 76
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
77
	$items[$key] = "$val";
78
}
79
asort($items);
80
 
81
class Qi {
82
	var $name;
83
	var $item;
84
	var $_item;
85
	var $operator;
86
	var $type;
87
	var $typestr;
88
	var $value;
89
	function Qi($name,$item,$operator) {
90
				$this->name=$name;
91
				$this->item=$item;
92
				$this->operator=$operator;
93
	}
94
 
95
	function show() {	global $operators;
96
				global $items;
97
		$nam = $this->item;
98
			echo <<<EOM
99
	<tr><td align=left>
100
	<i>$items[$nam]</i>
101
	<input type=hidden name="item_of_$this->name" value="$this->item">
102
	</td><td align=left>
103
	<select name=operator_of_$this->name>
104
EOM;
105
		foreach($operators as $operator){
106
			if($this->operator == $operator)
107
				$selected=" selected ";
108
			else
109
				$selected='';
110
			print("<option value=\"$operator\" $selected>$operator</option>\n");
111
		 }
112
	echo <<<EOM
113
	</select>
114
	</td><td align=left>
115
	<input name="value_of_$this->name" type=text value="$this->value">
116
	</td><td align=left>
117
	<input type=hidden name="delete_$this->name" value=0>
2853 rexy 118
	<input type=submit class=button size=5 value="$l_delete" onclick="this.form.delete_$this->name.value=1">
324 richard 119
	</td></tr>
120
EOM;
121
	}
122
 
123
	function get($designator) {  	global ${"item_of_$designator"};
124
			global ${"value_of_$designator"};
125
			global ${"operator_of_$designator"};
126
			if(${"item_of_$designator"}){
127
				$this->value= ${"value_of_$designator"};
128
				$this->operator=${"operator_of_$designator"};
129
				$this->item=${"item_of_$designator"};
130
			}
131
		}
132
	function query(){
133
		global $operators;
134
		global $items;
135
		return $items[$this->item]."  $this->operator  '$this->value'";
136
	}
137
}
138
 
139
?>
2818 rexy 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>