Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,32 @@ public static function execute()
exit;
}

$ip = gethostbyname($host);
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE || $ip == '127.0.0.1')
{
echo "<script>parent.alert('请输入正确的IP地址或域名');</script>";
echo '<script>parent.req_complete()</script>';
exit;
}

if (isset($commands[$cmd]))
{
if ($cmd == "ping6" || $cmd == "traceroute6")
{
$result = dns_get_record($host, DNS_AAAA);
if (!empty($result))
{
$ip = $result[0]["ipv6"];
}
else
{
$ip = "";
}
}
else
{
$ip = gethostbyname($host);
}

if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE || $ip == '127.0.0.1')
{
echo "<script>parent.alert('请输入正确的IP地址或域名$ip');</script>";
echo '<script>parent.req_complete()</script>';
exit;
}

call_user_func(array(__CLASS__, $cmd), $ip, $commands[$cmd]);

echo '<script>parent.req_complete()</script>';
Expand Down Expand Up @@ -142,4 +158,22 @@ protected static function ping6($host, $cmd)
flush();
});
}
}

protected static function traceroute6($host, $cmd)
{
$args = [
'cmd' => $cmd,
'ip' => $host,
];

echo '<script>parent.update_start()</script>';
ob_flush();
flush();

command\traceroute::execute($args, function($line, $json) {
echo '<script>parent.update_view("' . trim($line) . '", ' . json_encode($json) . ')</script>';
ob_flush();
flush();
});
}
}