Subversion Repositories ALCASAR

Rev

Rev 580 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
require('/etc/freeradius-web/config.php');
3
require_once('../lib/xlat.php');
4
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
5
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
6
else{
7
	echo <<<EOM
8
<title>Fermeture des sessions ouvertes pour l'utilisateur $login</title>
9
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
10
<link rel="stylesheet" href="style.css">
11
</head>
12
<body>
13
<center>
14
<b>Could not include SQL library functions. Aborting</b>
15
</body>
16
</html>
17
EOM;
18
        exit();
19
}
20
 
21
echo <<<EOM
22
<html>
23
<head>
24
<title>Fermeture des sessions ouvertes pour l'usager : $login</title>
25
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
26
<link rel="stylesheet" href="/css/style.css">
27
</head>
28
<body>
29
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
30
	<tr><th>Gestion des usagers</th></tr>
31
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" 
32
height="2"></td></tr>
33
</TABLE>
34
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
35
	<tr bgcolor="#666666"><td>
36
	<TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
37
		<tr><td valign="middle" align="left">
38
<center>
39
<table border=0 width=550 cellpadding=0 cellspacing=0>
40
<tr valign=top>
41
<!--<td align=center><img src="images/title2.gif"></td>-->
42
</tr>
43
</table>
44
 
45
<table border=0 width=400 cellpadding=0 cellspacing=2>
46
EOM;
47
 
48
include("../html/user_toolbar.html.php");
49
 
50
$open_sessions = 0;
51
 
52
$sql_extra_query = '';
53
if ($config[sql_accounting_extra_query] != ''){
54
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
55
	$sql_extra_query = da_sql_escape_string($sql_extra_query);
56
}
57
 
58
print <<<EOM
59
</table>
60
 
61
<br>
62
<table border=0 width=540 cellpadding=1 cellspacing=1>
63
<tr valign=top>
64
<td width=340></td>
65
<td bgcolor="black" width=200>
66
	<table border=0 width=100% cellpadding=2 cellspacing=0>
67
	<tr bgcolor="#907030" align=right valign=top><th>
68
	<font color="white">Fermeture des sessions ouvertes pour l'usager : $login</font>&nbsp;
69
	</th></tr>
70
	</table>
71
</td></tr>
72
<tr bgcolor="black" valign=top><td colspan=2>
73
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
74
	<tr><td>
75
EOM;
76
 
77
if ($drop_conns == 1){
78
	$method = 'snmp';
79
	$nastype = 'cisco';
80
	if ($config[general_sessionclear_method] != '')
81
		$method = $config[general_sessionclear_method];
82
	if ($config[general_nas_type] != '')
83
		$nastype = $config[general_nas_type];
84
	if ($config[general_ld_library_path] != '')
85
		putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
86
	$nas_by_ip = array();
87
	$meth_by_ip = array();
88
	$nastype_by_ip = array();
89
	foreach ($nas_list as $nas){
90
		if ($nas[ip] != ''){
91
			$ip = $nas[ip];
92
			$nas_by_ip[$ip] = $nas[community];
93
			$meth_by_ip[$ip] = $nas[sessionclear_method];
94
			$nastype_by_ip[$ip] = $nas[nas_type];
95
		}
96
	}
97
 
98
	$link = @da_sql_pconnect($config);
99
	if ($link){
100
		$search = @da_sql_query($link,$config,
101
		"SELECT nasipaddress,acctsessionid FROM $config[sql_accounting_table]
102
		WHERE username = '$login' AND acctstoptime IS NULL;");
103
		if ($search){
104
			while($row = @da_sql_fetch_array($search,$config)){
105
				$sessionid = $row[acctsessionid];
106
				$sessionid = hexdec($sessionid);
107
				$nas = $row[nasipaddress];
108
				$port = $row[nasportid];
109
				$meth = $meth_by_ip[$nas];
110
				$nastype = ($nastype_by_ip[$nas] != '') ? $nastype_by_ip[$nas] : $nastype;
111
				$comm = $nas_by_ip[$nas];
112
				if ($meth == '')
113
					$meth = $method;
114
				if ($meth == 'snmp' && $comm != '')
115
					exec("$config[general_sessionclear_bin] $nas snmp $nastype $login $sessionid $comm");
116
				if ($meth == 'telnet')
117
					exec("$config[general_sessionclear_bin] $nas telnet $nastype $login $sessionid $port");
118
			}
119
		}
120
		else
121
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
122
	}
123
	else
124
		echo "<b>Could not connect to SQL database</b><br>\n";
125
}
126
if ($clear_sessions == 1)
127
	{
128
	exec ("sudo /usr/local/sbin/alcasar-logout.sh $login");
129
	$sql_servers = array();
130
	if ($config[sql_extra_servers] != '')
131
		$sql_servers = explode(' ',$config[sql_extra_servers]);
132
	$quer = '= 0';
133
	if ($config[sql_type] == 'pg')
134
		$quer = 'IS NULL';
135
	$sql_servers[] = $config[sql_server];
136
	foreach ($sql_servers as $server)
137
		{
138
		$link = @da_sql_host_connect($server,$config);
139
		if ($link)
140
			{
141
			$res = @da_sql_query($link,$config,
142
			"DELETE FROM $config[sql_accounting_table]
143
			WHERE username='$login' AND acctstoptime $quer $sql_extra_query;");
144
			if ($res)
145
				echo "<b>La comptabilit&eacute; des sessions pour cet usager a &eacute;t&eacute; arr&eacute;t&eacute;e</b><br>\n";
146
			else
147
				echo "<b>Error deleting open sessions for user" . da_sql_error($link,$config) . "</b><br>\n";
148
			}
149
		else
150
			echo "<b>Could not connect to SQL database</b><br>\n";
151
		}
152
	}
153
$link = @da_sql_pconnect($config);
154
if ($link){
155
	$search = @da_sql_query($link,$config,
156
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table]
157
	WHERE username = '$login' AND acctstoptime IS NULL $sql_extra_query;");
158
	if ($search){
159
		if ($row = @da_sql_fetch_array($search,$config))
160
			$open_sessions = $row[counter];
161
	}
162
	else
163
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
164
}
165
else
166
	echo "<b>Could not connect to SQL database</b><br>\n";
167
?>
168
   <form method=post>
169
      <input type=hidden name=login value=<?php print $login ?>>
170
      <input type=hidden name=clear_sessions value="0">
171
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
172
<tr>
173
<td align=center>
174
<?
175
if ($open_sessions == 0)
176
	{
177
	echo "L'usager $login n'a pas de session ouverte";
178
	}
179
else	{
180
	echo "L'usager $login a <i>$open_sessions</i> session(s) ouverte(s)<br><br>";
181
	echo "&Ecirc;tes-vous certain de vouloir ";
182
	if ($open_sessions == 1) { echo "la"; } else {echo "les"; }
183
	echo " fermer ? ";
184
	echo "<input type=submit class=button value=\"Oui, Fermer\" OnClick=\"this.form.clear_sessions.value=1\">";
185
	}
186
?>
187
</form>
188
</td></tr></table>
189
<!--<input type=submit class=button value="Oui, poubelliser les connexions" OnClick="this.form.drop_conns.value=1">-->
190
</td></tr></table>
191
</TD></TR></TABLE>
192
</body>
193
</html>