-
Notifications
You must be signed in to change notification settings - Fork 0
/
iptunnel_server.php
45 lines (38 loc) · 1 KB
/
iptunnel_server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$con= shell_exec ("/opt/cjdns/tools/cexec \"IpTunnel_listConnections()\"");
$con2=json_decode($con);
foreach ($con2->connections as $k) {
$res=shell_exec("/opt/cjdns/tools/cexec \"IpTunnel_showConnection(" . $k . ")\"");
$c=json_decode($res);
$d['ip']=$c->ip4Address;
$d['key']=$c->key;
$tmp=explode(".",$d['ip']);
$d['index']=$tmp[3];
$connI[$d['index']]=$c->key;
$conn[$c->key]=$d;
unset($d);
}
$k=$_REQUEST['key'];
$index=1;
while ($index<255) {
$index++;
if (!isset($connI[$index])) {
break;
}
}
if (isset($conn[$k])) {
echo "OK";
} else {
if ($index==255) {
die("error");
}
$ip="192.168.1." . $index;
$cmd="/opt/cjdns/tools/cexec \"IpTunnel_allowConnection('" . $k . "',null,null,null,0,null,'" . $ip . "')\"";
$r=shell_exec($cmd);
$res=json_decode($r);
if ($res->error=="none") {
echo "OK";
} else {
echo $res->error;
}
}