Subversion Repositories ALCASAR

Rev

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