Subversion Repositories ALCASAR

Rev

Rev 597 | Rev 613 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 597 Rev 606
Line 1... Line 1...
1
<?php
1
<?php
2
require('/etc/freeradius-web/config.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"))
3
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
5
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
4
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
6
else{
5
else{
7
	echo <<<EOM
6
	echo <<<EOM
8
<title>Fermeture des sessions ouvertes pour l'utilisateur $login</title>
7
<title>Fermeture des sessions ouvertes pour l'utilisateur $login</title>
Line 45... Line 44...
45
<table border=0 width=400 cellpadding=0 cellspacing=2>
44
<table border=0 width=400 cellpadding=0 cellspacing=2>
46
EOM;
45
EOM;
47
 
46
 
48
include("../html/user_toolbar.html.php");
47
include("../html/user_toolbar.html.php");
49
 
48
 
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
49
print <<<EOM
59
</table>
50
</table>
60
 
51
 
61
<br>
52
<br>
62
<table border=0 width=540 cellpadding=1 cellspacing=1>
53
<table border=0 width=540 cellpadding=1 cellspacing=1>
Line 72... Line 63...
72
<tr bgcolor="black" valign=top><td colspan=2>
63
<tr bgcolor="black" valign=top><td colspan=2>
73
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
64
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
74
	<tr><td>
65
	<tr><td>
75
EOM;
66
EOM;
76
 
67
 
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)
68
if ($clear_sessions == 1)
127
	{
69
	{
-
 
70
# close active sessions
128
	exec ("sudo /usr/local/sbin/alcasar-logout.sh $login");
71
	exec ("sudo /usr/local/sbin/alcasar-logout.sh $login");
129
	$sql_servers = array();
72
# delete open accounting sessions
130
	if ($config[sql_extra_servers] != '')
73
	$link = @da_sql_pconnect($config);
131
		$sql_servers = explode(' ',$config[sql_extra_servers]);
-
 
132
	$quer = '= 0';
74
	if ($link)
133
	if ($config[sql_type] == 'pg')
-
 
134
		$quer = 'IS NULL';
-
 
135
	$sql_servers[] = $config[sql_server];
-
 
136
	foreach ($sql_servers as $server)
-
 
137
		{
75
		{
138
		$link = @da_sql_host_connect($server,$config);
-
 
139
		if ($link)
-
 
140
			{
-
 
141
			$res = @da_sql_query($link,$config,
76
		$res = @da_sql_query($link,$config,
142
			"DELETE FROM $config[sql_accounting_table]
77
		"DELETE FROM $config[sql_accounting_table]
143
			WHERE username='$login' AND acctstoptime $quer $sql_extra_query;");
78
		WHERE username='$login' AND acctstoptime IS NULL;");
144
			if ($res)
79
		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";
80
			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
		}
81
		}
-
 
82
	else
-
 
83
		echo "<b>Could not connect to SQL database</b><br>\n";
152
	}
84
	}
-
 
85
# Count of accounting open sessions (in database)
-
 
86
$open_accnt_sessions = 0;
153
$link = @da_sql_pconnect($config);
87
$link = @da_sql_pconnect($config);
154
if ($link){
88
if ($link){
155
	$search = @da_sql_query($link,$config,
89
	$search = @da_sql_query($link,$config,
156
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table]
90
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table]
157
	WHERE username = '$login' AND acctstoptime IS NULL $sql_extra_query;");
91
	WHERE username = '$login' AND acctstoptime IS NULL;");
158
	if ($search){
92
	if ($search){
159
		if ($row = @da_sql_fetch_array($search,$config))
93
		if ($row = @da_sql_fetch_array($search,$config))
160
			$open_sessions = $row[counter];
94
			$open_accnt_sessions = $row['counter'];
161
	}
95
	}
162
	else
96
	else
163
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
97
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
164
}
98
}
165
else
99
else
166
	echo "<b>Could not connect to SQL database</b><br>\n";
100
	echo "<b>Could not connect to SQL database</b><br>\n";
-
 
101
 
-
 
102
# Count of chilli open sessions (for coova-chilli)
-
 
103
$open_chilli_sessions = 0;
-
 
104
exec ("sudo /usr/sbin/chilli_query list|cut -d\" \" -f5,6|grep $login|grep ^1|wc -l" , $open_chilli_sessions);
-
 
105
 
167
?>
106
?>
168
   <form method=post>
107
   <form method=post>
169
      <input type=hidden name=login value=<?php print $login ?>>
108
      <input type=hidden name=login value=<?php print $login ?>>
170
      <input type=hidden name=clear_sessions value="0">
109
      <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>
110
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
172
<tr>
111
<tr>
173
<td align=center>
112
<td align=center>
174
<?
113
<?
175
if ($open_sessions == 0)
114
if (($open_accnt_sessions == 0) && ($open_chilli_sessions[0] == 0))
176
	{
115
	{
177
	echo "L'usager $login n'a pas de session ouverte";
116
	echo "L'usager $login n'a pas de session ouverte";
178
	}
117
	}
179
else	{
118
else	{
180
	echo "L'usager $login a <i>$open_sessions</i> session(s) ouverte(s)<br><br>";
119
	echo "L'usager '$login' a <i>$open_chilli_sessions[0]</i> session(s) ouverte(s) et <i>$open_accnt_sessions</i> comptabilité(s) actives(s)<br><br>";
181
	echo "&Ecirc;tes-vous certain de vouloir ";
120
	echo "Voulez-vous les fermer?";
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\">";
121
	echo "<input type=submit class=button value=\"Oui, Fermer\" OnClick=\"this.form.clear_sessions.value=1\">";
185
	}
122
	}
186
?>
123
?>
187
</form>
124
</form>
188
</td></tr></table>
125
</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>
126
</td></tr></table>
191
</TD></TR></TABLE>
127
</TD></TR></TABLE>
192
</body>
128
</body>
193
</html>
129
</html>