-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig-openwrt.php
71 lines (54 loc) · 2.18 KB
/
config-openwrt.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
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
<?php
// this file should make $config->key availiable
function drcomfucker_get_config() {
$config = new stdClass;
$config->username="drcomfucker";
$config->password="114514";
// OpenWrt (UCI) interface name
// NOT Linux device name (e.g. eth*)
$uci_interface = "wan";
// will send challenge to 202.1.1.1, 1.1.1.1, 192.168.255.251 if not set
// not guranteed availiable
$config->server = "";
$config->CONTROLCHECKSTATUS = "\x20";
$config->ADAPTERNUM = "\x01";
$config->IPDOG = "\x01";
$config->AUTH_VERSION = "\x2d\x00";
$config->KEEP_ALIVE_VERSION = "\xd8\x02";
$config->ror_version = true;
// OpenWrt doesn't provide us DHCP server address
// leave it blank will use auth server
$config->dhcp_server = "";
// socket will bind to host_ip
$config->host_ip = "";
$config->PRIMARY_DNS = "0.0.0.0";
$config->mac = hex2bin('010203040506');
$config->host_name = "Sprite";
$config->host_os = "DrCOM\x00\xbd\x00\x2a\x00" .
str_repeat("\x00", 54) .
"e8fdd1bbb9c96f285be0e883b482db8faeb69af0" .
str_repeat("\x00", 24);
logger2("DEBUG", "getting network configuration from OpenWrt");
$json = shell_exec("ifstatus $uci_interface");
$ifstatus = json_decode($json);
if($ifstatus === NULL) {
logger2("FATAL", "JSON decode failed");
exit(1);
}
if(property_exists($ifstatus, "device") !== TRUE) {
logger2("FATAL", "UCI interface $uci_interface has no associated Linux interface");
exit(1);
}
if($ifstatus->up !== TRUE) {
logger2("FATAL", "interface $uci_interface is down");
exit(1);
}
$config->iface = $ifstatus->device;
$mac = trim(file_get_contents("/sys/class/net/$config->iface/address"));
logger2("DEBUG", 'found interface %s with MAC %s', $config->iface, $mac);
$config->host_ip = $ifstatus->{'ipv4-address'}[0]->address;
$config->PRIMARY_DNS = $ifstatus->{'dns-server'}[0];
$config->mac = hex2bin(str_replace(':', '', $mac));
logger2("DEBUG", 'using host_ip %s, PRIMARY_DNS %s', $config->host_ip, $config->PRIMARY_DNS);
return $config;
}