Release
This commit is contained in:
62
web/api/reach.php
Normal file
62
web/api/reach.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require __DIR__ . '/../lib/app.php'; auth_require();
|
||||
require __DIR__ . '/../lib/torctl.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$cfg = read_torpanel_conf();
|
||||
$orport = (int)($cfg['ORPort'] ?? 9001);
|
||||
|
||||
$info = torctl(["GETINFO fingerprint","GETINFO address"]);
|
||||
$fp_raw = trim($info['fingerprint'] ?? '');
|
||||
$fingerprint = strtoupper(str_replace([' ', "\n", "\r", "\t"], '', $fp_raw));
|
||||
$tor_addr = trim($info['address'] ?? '');
|
||||
|
||||
$lan_ip = trim(shell_exec('hostname -I 2>/dev/null'));
|
||||
$lan_ip = $lan_ip ? preg_split('/\s+/', $lan_ip)[0] : '';
|
||||
|
||||
$onionoo = [
|
||||
'found' => false, 'running' => false, 'flags' => [],
|
||||
'last_seen' => null, 'nickname' => ($cfg['Nickname'] ?? 'RaspberryRelay'),
|
||||
'or_addresses' => [], 'country' => null
|
||||
];
|
||||
|
||||
if ($fingerprint !== '') {
|
||||
$url = 'https://onionoo.torproject.org/details?lookup=' . urlencode($fingerprint);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 6,
|
||||
CURLOPT_USERAGENT => 'TorPanel/1.0 (+relay reachability check)',
|
||||
]);
|
||||
$res = curl_exec($ch);
|
||||
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($res !== false && $http === 200) {
|
||||
$j = json_decode($res, true);
|
||||
if (!empty($j['relays']) && count($j['relays']) > 0) {
|
||||
$r = $j['relays'][0];
|
||||
$onionoo['found'] = true;
|
||||
$onionoo['running'] = (bool)($r['running'] ?? false);
|
||||
$onionoo['flags'] = $r['flags'] ?? [];
|
||||
$onionoo['last_seen'] = $r['last_seen'] ?? null;
|
||||
$onionoo['nickname'] = $r['nickname'] ?? $onionoo['nickname'];
|
||||
$onionoo['or_addresses']= $r['or_addresses'] ?? [];
|
||||
$onionoo['country'] = $r['country'] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'fingerprint' => $fingerprint,
|
||||
'nickname' => $onionoo['nickname'],
|
||||
'orport' => $orport,
|
||||
'tor_address' => $tor_addr,
|
||||
'lan_ip' => $lan_ip,
|
||||
'onionoo' => $onionoo,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['ok'=>false,'error'=>$e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user