2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
//TODO: Move to somewhere more appropriate, doesn't really belong under users, tools maybe but we don't have that page publicly accessible.
|
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
if (isset($_GET['ip']) && isset($_GET['port'])) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Octets = explode('.', $_GET['ip']);
|
2013-04-20 08:01:01 +00:00
|
|
|
if (
|
2013-08-28 23:08:41 +00:00
|
|
|
empty($_GET['ip'])
|
|
|
|
|| !preg_match('/'.IP_REGEX.'/', $_GET['ip'])
|
|
|
|
|| $Octets[0] < 0
|
|
|
|
|| $Octets[0] > 255
|
|
|
|
|| $Octets[1] < 0
|
|
|
|
|| $Octets[1] > 255
|
|
|
|
|| $Octets[2] < 0
|
|
|
|
|| $Octets[2] > 255
|
|
|
|
|| $Octets[3] < 0
|
|
|
|
|| $Octets[3] > 255
|
2013-05-01 08:00:16 +00:00
|
|
|
/*
|
|
|
|
* Per RFC 1918, the following CIDR blocks should never be found on the public Internet.
|
|
|
|
* 10.0.0.0/8
|
|
|
|
* 172.16.0.0/12
|
|
|
|
* 192.168.0.0/16
|
|
|
|
*
|
|
|
|
* Per RFC 3330, the block 127.0.0.0/8 should never appear on any network.
|
|
|
|
*
|
|
|
|
*/
|
2013-08-28 23:08:41 +00:00
|
|
|
|| $Octets[0] == 127
|
|
|
|
|| $Octets[0] == 10
|
|
|
|
|| ($Octets[0] == 172 && ((16 <= $Octets[1]) && ($Octets[1] <= 31)))
|
|
|
|
|| ($Octets[0] == 192 && $Octets[1] == 168)
|
2011-03-28 14:21:28 +00:00
|
|
|
) {
|
2013-05-01 08:00:16 +00:00
|
|
|
die('Invalid IPv4 address');
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-05-01 08:00:16 +00:00
|
|
|
// Valid port numbers are defined in RFC 1700
|
2013-04-20 08:01:01 +00:00
|
|
|
if (empty($_GET['port']) || !is_number($_GET['port']) || $_GET['port'] < 1 || $_GET['port'] > 65535) {
|
2013-05-01 08:00:16 +00:00
|
|
|
die('Invalid port');
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 08:00:16 +00:00
|
|
|
// Error suppression, ugh.
|
2013-04-20 08:01:01 +00:00
|
|
|
if (@fsockopen($_GET['ip'], $_GET['port'], $Errno, $Errstr, 20)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
die('Port '.$_GET['port'].' on '.$_GET['ip'].' connected successfully.');
|
|
|
|
} else {
|
|
|
|
die('Port '.$_GET['port'].' on '.$_GET['ip'].' failed to connect.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
View::show_header('Connectability Checker');
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<div class="thin">
|
2012-08-19 08:00:19 +00:00
|
|
|
<div class="header">
|
|
|
|
<h2><a href="user.php?id=<?=$LoggedUser['ID']?>"><?=$LoggedUser['Username']?></a> > Connectability Checker</h2>
|
|
|
|
</div>
|
2012-09-15 08:00:25 +00:00
|
|
|
<form class="manage_form" name="connections" action="javascript:check_ip();" method="get">
|
2012-09-01 08:00:24 +00:00
|
|
|
<table class="layout">
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr>
|
2013-02-07 08:00:47 +00:00
|
|
|
<td class="label">IP address</td>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td>
|
|
|
|
<input type="text" id="ip" name="ip" value="<?=$_SERVER['REMOTE_ADDR']?>" size="20" />
|
|
|
|
</td>
|
|
|
|
<td class="label">Port</td>
|
|
|
|
<td>
|
|
|
|
<input type="text" id="port" name="port" size="10" />
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<input type="submit" value="Check" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
<div id="result" class="box pad"></div>
|
|
|
|
</div>
|
2013-02-07 08:00:47 +00:00
|
|
|
<script type="text/javascript">//<![CDATA[
|
2011-03-28 14:21:28 +00:00
|
|
|
var result = $('#result').raw();
|
|
|
|
|
|
|
|
function check_ip() {
|
|
|
|
var intervalid = setInterval("result.innerHTML += '.';",999);
|
|
|
|
result.innerHTML = 'Checking.';
|
|
|
|
ajax.get('user.php?action=connchecker&ip=' + $('#ip').raw().value + '&port=' + $('#port').raw().value, function (response) {
|
|
|
|
clearInterval(intervalid);
|
|
|
|
result.innerHTML = response;
|
|
|
|
});
|
|
|
|
}
|
2013-02-07 08:00:47 +00:00
|
|
|
//]]>
|
2011-03-28 14:21:28 +00:00
|
|
|
</script>
|
2013-02-07 08:00:47 +00:00
|
|
|
<? View::show_footer(); ?>
|