Subversion Repositories ALCASAR

Rev

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