1 |
root |
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énérateur de rapports de comptes</title>
|
|
|
15 |
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
|
|
|
16 |
<link rel="stylesheet" href="/css/style.css">
|
|
|
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' );
|
|
|
28 |
if ($config[sql_type] == 'pg'){
|
|
|
29 |
$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
$link = @da_sql_pconnect ($config) or die('cannot connect to sql databse');
|
|
|
33 |
$fields = @da_sql_list_fields($config[sql_accounting_table],$link,$config);
|
|
|
34 |
$no_fields = @da_sql_num_fields($fields,$config);
|
|
|
35 |
|
|
|
36 |
unset($items);
|
|
|
37 |
|
|
|
38 |
for($i=0;$i<$no_fields;$i++){
|
|
|
39 |
$key = strtolower(@da_sql_field_name($fields,$i,$config));
|
|
|
40 |
$val = $sql_attrs[$key][desc];
|
|
|
41 |
if ($val == '')
|
|
|
42 |
continue;
|
|
|
43 |
$show = $sql_attrs[$key][show];
|
|
|
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>
|
|
|
111 |
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
|
|
|
112 |
<link rel="stylesheet" href="/css/style.css">
|
|
|
113 |
</head>
|
|
|
114 |
<body>
|
|
|
115 |
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
|
116 |
<tr><th>Journal des connexions</th></tr>
|
|
|
117 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1"
|
|
|
118 |
height="2"></td></tr>
|
|
|
119 |
</TABLE>
|
|
|
120 |
<?php
|
|
|
121 |
if(!$queryflag) {
|
|
|
122 |
echo <<<EOM
|
|
|
123 |
<form method=post>
|
|
|
124 |
<table border=0 width=740 cellpadding=1 cellspacing=1>
|
|
|
125 |
<tr>
|
|
|
126 |
<td>
|
|
|
127 |
<b>Afficher les attributs suivants :</b><br>
|
|
|
128 |
<select name="accounting_show_attrs[]" size=5 multiple>
|
|
|
129 |
EOM;
|
|
|
130 |
foreach($items as $key => $val)
|
|
|
131 |
echo <<<EOM
|
|
|
132 |
<option $selected[$key] value="$key">$val</option>
|
|
|
133 |
EOM;
|
|
|
134 |
|
|
|
135 |
echo <<<EOM
|
|
|
136 |
</select>
|
|
|
137 |
<br><br>
|
|
|
138 |
<b>Classé par :</b><br>
|
|
|
139 |
<select name="order_by">
|
|
|
140 |
EOM;
|
|
|
141 |
|
|
|
142 |
foreach($items as $key => $val)
|
|
|
143 |
if ($val == 'username')
|
|
|
144 |
echo <<<EOM
|
|
|
145 |
<option selected value="$key">$val</option>
|
|
|
146 |
EOM;
|
|
|
147 |
else
|
|
|
148 |
echo <<<EOM
|
|
|
149 |
<option value="$key">$val</option>
|
|
|
150 |
EOM;
|
|
|
151 |
|
|
|
152 |
echo <<<EOM
|
|
|
153 |
</select>
|
|
|
154 |
<br><br>
|
|
|
155 |
<b>Nbr. Max. de résultats retournés :</b><br>
|
|
|
156 |
<input name=maxresults value=$config[sql_row_limit] size=5>
|
|
|
157 |
</td>
|
|
|
158 |
<td valign=top>
|
|
|
159 |
<input type=hidden name=add value=0>
|
|
|
160 |
<table border=0 width=340 cellpadding=1 cellspacing=1>
|
|
|
161 |
<tr><td>
|
|
|
162 |
<b>Critère de sélection :</b>
|
|
|
163 |
</td></tr>
|
|
|
164 |
<tr><td>
|
|
|
165 |
<select name=item_name onchange="this.form.add.value=1;this.form.submit()">
|
|
|
166 |
<option>--Attribute--</option>
|
|
|
167 |
EOM;
|
|
|
168 |
|
|
|
169 |
foreach($items as $key => $val)
|
|
|
170 |
print("<option value=\"$key\">$val</option>");
|
|
|
171 |
|
|
|
172 |
echo <<<EOM
|
|
|
173 |
</select>
|
|
|
174 |
</td></tr>
|
|
|
175 |
EOM;
|
|
|
176 |
|
|
|
177 |
$number=1;
|
|
|
178 |
$offset=0;
|
|
|
179 |
while (${"item_of_w$number"}) {
|
|
|
180 |
if(${"delete_w$number"}==1) {$offset=1;$number++;}
|
|
|
181 |
else {
|
|
|
182 |
$designator=$number-$offset;
|
|
|
183 |
${"w$designator"} = new Qi("w$designator","","");
|
|
|
184 |
${"w$designator"}->get("w$number");
|
|
|
185 |
${"w$designator"}->show();
|
|
|
186 |
$number++;
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
if($add==1) {
|
|
|
190 |
${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
|
|
|
191 |
${"w$number"}->show();
|
|
|
192 |
}
|
|
|
193 |
echo <<<EOM
|
|
|
194 |
</table>
|
|
|
195 |
</td>
|
|
|
196 |
<tr>
|
|
|
197 |
<td>
|
|
|
198 |
<input type=hidden name=queryflag value=0>
|
|
|
199 |
<br><input type=submit class=button onclick="this.form.queryflag.value=1">
|
|
|
200 |
</td>
|
|
|
201 |
</tr>
|
|
|
202 |
</table>
|
|
|
203 |
</form>
|
|
|
204 |
</body>
|
|
|
205 |
</html>
|
|
|
206 |
EOM;
|
|
|
207 |
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
if ($queryflag == 1){
|
|
|
211 |
$i = 1;
|
|
|
212 |
while (${"item_of_w$i"}){
|
|
|
213 |
$op_found = 0;
|
|
|
214 |
foreach ($operators as $operator){
|
|
|
215 |
if (${"operator_of_w$i"} == $operator){
|
|
|
216 |
$op_found = 1;
|
|
|
217 |
break;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
if (!$op_found)
|
|
|
221 |
die("L'opération demandé n'est pas valide. Sortie anormale.");
|
|
|
222 |
${"item_of_w$i"} = preg_replace('/\s/','',${"item_of_w$i"});
|
|
|
223 |
${"value_of_w$i"} = da_sql_escape_string(${"value_of_w$i"});
|
|
|
224 |
$where .= ($i == 1) ? ' WHERE ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" :
|
|
|
225 |
' AND ' . ${"item_of_w$i"} . ' ' . ${"operator_of_w$i"} . " '" . ${"value_of_w$i"} . "'" ;
|
|
|
226 |
$i++;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
$order = ($order_by != '') ? "$order_by" : 'username';
|
|
|
230 |
|
|
|
231 |
if (preg_match("/[\s;]/",$order))
|
|
|
232 |
die("ORDER BY pattern is illegal. Exiting abnornally.");
|
|
|
233 |
|
|
|
234 |
if (!is_numeric($maxresults))
|
|
|
235 |
die("Max Results is not in numeric form. Exiting abnormally.");
|
|
|
236 |
|
|
|
237 |
unset($query_view);
|
|
|
238 |
foreach ($accounting_show_attrs as $val)
|
|
|
239 |
$query_view .= $val . ',';
|
|
|
240 |
$query_view = ereg_replace(',$','',$query_view);
|
|
|
241 |
unset($sql_extra_query);
|
|
|
242 |
if ($config[sql_accounting_extra_query] != '')
|
|
|
243 |
$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
|
|
|
244 |
$sql_extra_query = da_sql_escape_string($sql_extra_query);
|
|
|
245 |
$query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
|
|
|
246 |
$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
|
|
|
247 |
" ORDER BY $order " . da_sql_limit($maxresults,2,$config) . ";";
|
|
|
248 |
|
|
|
249 |
echo <<<EOM
|
|
|
250 |
<table border="0" width="100%" cellpadding="1" cellspacing="1">
|
|
|
251 |
<tr bgcolor="black" valign=top><td colspan=2>
|
|
|
252 |
<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
|
|
|
253 |
<tr><td>
|
|
|
254 |
<p>
|
|
|
255 |
<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
|
|
|
256 |
<tr bgcolor="#d0ddb0">
|
|
|
257 |
</tr>
|
|
|
258 |
EOM;
|
|
|
259 |
foreach($accounting_show_attrs as $val){
|
|
|
260 |
$desc = $sql_attrs[$val][desc];
|
|
|
261 |
echo "<th>$desc</th>\n";
|
|
|
262 |
}
|
|
|
263 |
echo "</tr>\n";
|
|
|
264 |
|
|
|
265 |
$search = @da_sql_query($link,$config,$query);
|
|
|
266 |
if ($search){
|
|
|
267 |
while( $row = @da_sql_fetch_array($search,$config) ){
|
|
|
268 |
$num++;
|
|
|
269 |
echo "<tr align=center>\n";
|
|
|
270 |
foreach($accounting_show_attrs as $val){
|
|
|
271 |
$info = $row[$val];
|
|
|
272 |
if ($info == '')
|
|
|
273 |
$info = '-';
|
|
|
274 |
$info = $sql_attrs[$val][func]($info);
|
|
|
275 |
if ($val == 'username'){
|
|
|
276 |
$Info = urlencode($info);
|
|
|
277 |
$info = "<a href=\"user_admin.php?login=$Info\" title=\"Edit user $info\">$info<a/>";
|
|
|
278 |
}
|
|
|
279 |
echo <<<EOM
|
|
|
280 |
<td>$info</td>
|
|
|
281 |
EOM;
|
|
|
282 |
}
|
|
|
283 |
echo "</tr>\n";
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
else
|
|
|
287 |
echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
288 |
echo <<<EOM
|
|
|
289 |
</table>
|
|
|
290 |
</td></tr>
|
|
|
291 |
</table>
|
|
|
292 |
</td></tr>
|
|
|
293 |
</table>
|
|
|
294 |
</body>
|
|
|
295 |
</html>
|
|
|
296 |
EOM;
|
|
|
297 |
}
|
|
|
298 |
?>
|