-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.php
More file actions
122 lines (103 loc) · 5.35 KB
/
Copy pathaction.php
File metadata and controls
122 lines (103 loc) · 5.35 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?
session_start();
global $config;
require "cjdns.inc.php";
require "token.inc.php";
require "Bencode.php";
require "Cjdns.php";
$out = array('error' => false);
//// Uncomment the next line to dump all sorts of shit to the log file
//error_log(print_r($_REQUEST,true));
if(!isset($_REQUEST['token'])) {
$out['error'] = "no token";
} elseif(checktoken($_REQUEST['token'])) {
$cjdns = new Cjdns($config['admin']['password']);
switch($_REQUEST['action']) {
// AuthorizedPasswords
case "AuthorizedPasswords_Add":
$config['authorizedPasswords'][] = array("password" => $_REQUEST['password'], "user" => $_REQUEST['name']);
$out['AuthorizedPassword_List'] = $config['authorizedPasswords'];
$cjdns->call("AuthorizedPasswords_add", array("password" => $_REQUEST['password']));
break;
case "AuthorizedPasswords_Delete":
unset($config['authorizedPasswords'][intval($_REQUEST['key'])]);
$config['authorizedPasswords'] = array_values($config['authorizedPasswords']);
$out['AuthorizedPassword_List'] = $config['authorizedPasswords'];
break;
case "AuthorizedPasswords_Edit":
$config['authorizedPasswords'][intval($_REQUEST['key'])] = array("password" => $_REQUEST['password'], "user" => $_REQUEST['name']);
$out['AuthorizedPassword_List'] = $config['authorizedPasswords'];
$cjdns->call("AuthorizedPasswords_add", array("password" => $_REQUEST['password']));
break;
case "AuthorizedPasswords_List":
foreach($config['authorizedPasswords'] as $key=>$pass) {
if(isset($config['authorizedPasswords'][$key]['name'])) {
$config['authorizedPasswords'][$key]['user'] = $config['authorizedPasswords'][$key]['name'];
unset($config['authorizedPasswords'][$key]['name']);
}
if(isset($config['authorizedPasswords'][$key]['person'])) {
$config['authorizedPasswords'][$key]['user'] = $config['authorizedPasswords'][$key]['person'];
unset($config['authorizedPasswords'][$key]['person']);
}
}
$out['AuthorizedPassword_List'] = $config['authorizedPasswords'];
break;
// Peers
case "Peer_List":
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
break;
case "UDPPeer_List":
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
break;
case "UDPPeer_Update":
$config['interfaces']['UDPInterface'][0]['connectTo'][$_REQUEST['ip']] = array("name"=>$_REQUEST['name'],"publicKey"=>$_REQUEST['key'],"password"=>$_REQUEST['password'],"ipv6"=>$_REQUEST['ipv6']);
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
$cjdns->call("UDPInterface_beginConnection", array("pubkey" => $_REQUEST['key'], "address" => $_REQUEST['ip'], "password" => $_REQUEST['password']));
break;
case "UDPPeer_Delete":
unset($config['interfaces']['ETHInterface'][0]['connectTo'][$_REQUEST['ip']]);
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
break;
case "ETHPeer_List":
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
break;
case "ETHPeer_Update":
$config['interfaces']['ETHInterface'][0]['connectTo'][$_REQUEST['mac']] = array("name"=>$_REQUEST['name'],"publicKey"=>$_REQUEST['key'],"password"=>$_REQUEST['password'],"ipv6"=>$_REQUEST['ipv6']);
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
$cjdns->call("ETHInterface_beginConnection", array("pubkey" => $_REQUEST['key'], "macAddress" => $_REQUEST['mac'], "password" => $_REQUEST['password']));
break;
case "ETHPeer_Delete":
unset($config['interfaces']['ETHInterface'][0]['connectTo'][$_REQUEST['ip']]);
$out['ETHPeer_List'] = $config['interfaces']['ETHInterface'][0]['connectTo'];
$out['UDPPeer_List'] = $config['interfaces']['UDPInterface'][0]['connectTo'];
break;
// Node Config
case "MyInfo_Update":
$config['myname'] = $_REQUEST['myname'];
$config['ipv4'] = $_REQUEST['ipv4'];
break;
case "autofillv4":
$bind = explode(":",$config['interfaces']['UDPInterface'][0]['bind']);
$ip = explode("\n",file_get_contents("http://icanhazip.com"));
$out['ip'] = $ip[0].":".$bind[1];
break;
// General Config
case "GetConfig_ipv6":
$out['ipv6'] = $config['ipv6'];
break;
case "GetConfig_pubkey":
$out['pubkey'] = $config['pubkey'];
break;
}
if(!save_config()) {
$out['error'] = "unable to save config";
}
} else {
$out['error'] = "bad token";
}
$out['token'] = maketoken();
echo json_encode($out, JSON_UNESCAPED_SLASHES);