mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-11-01 10:57:47 +00:00
firstcontact: convert to using gateway.json
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
@@ -6,9 +6,10 @@ copy_certificates() {
|
||||
[ -f /certificates/key.pem ] || return
|
||||
|
||||
cp /certificates/*.pem /etc/ucentral/
|
||||
[ -f /certificates/dev-id ] && cp /certificates/dev-id /etc/ucentral/
|
||||
chown root.network /etc/ucentral/*.pem
|
||||
chmod 0440 root.network /etc/ucentral/*.pem
|
||||
[ -f /certificates/gateway.json ] && cp /certificates/gateway.json /etc/ucentral/
|
||||
[ -f /certificates/dev-id ] && cp /certificates/dev-id /etc/ucentral/
|
||||
[ -f /etc/ucentral/dev-id] && chmod 0400 /etc/ucentral/dev-id
|
||||
[ -f /certificates/restrictions.json ] && cp /certificates/restrictions.json /etc/ucentral/
|
||||
[ -f /certificates/sign_pubkey.pem ] && cp /certificates/sign_pubkey.pem /etc/ucentral/
|
||||
@@ -16,7 +17,7 @@ copy_certificates() {
|
||||
}
|
||||
|
||||
boot() {
|
||||
[ -f /etc/ucentral/dev-id ] && return
|
||||
[ -f /etc/ucentral/key.pem ] && return
|
||||
/usr/bin/mount_certs
|
||||
copy_certificates
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ endef
|
||||
|
||||
define Package/firstcontact/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/firstcontact $(1)/usr/sbin/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/digicert $(1)/usr/sbin/
|
||||
$(CP) ./files/* $(1)
|
||||
endef
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
[ -f "/etc/ucentral/redirector.json" ] && /etc/init.d/firstcontact disable
|
||||
[ -f "/etc/ucentral/redirector.json" ] || /etc/init.d/ucentral disable
|
||||
[ -f "/etc/ucentral/gateway.json" ] && /etc/init.d/firstcontact disable
|
||||
[ -f "/etc/ucentral/gateway.json" ] || /etc/init.d/ucentral disable
|
||||
|
||||
@@ -1,70 +1,71 @@
|
||||
let devid;
|
||||
let fd = fs.open("/etc/ucentral/dev-id", "r");
|
||||
if (!fd) {
|
||||
warn("firstcontact: failed to find device id");
|
||||
exit(1);
|
||||
}
|
||||
devid = fd.read("all");
|
||||
fd.close();
|
||||
|
||||
let config = {};
|
||||
|
||||
function store_config(path) {
|
||||
let cursor = uci.cursor(path);
|
||||
function store_config() {
|
||||
let redir = split(config.Redirector, ":");
|
||||
|
||||
cursor.load("ucentral");
|
||||
cursor.set("ucentral", "config", "server", redir[0]);
|
||||
cursor.set("ucentral", "config", "port", redir[1] || 15002);
|
||||
cursor.commit();
|
||||
let gw = {
|
||||
server: redir[0],
|
||||
port: redir[1] || 15002
|
||||
};
|
||||
fs.writefile('/etc/ucentral/gateway.json', gw);
|
||||
}
|
||||
|
||||
ret = system(sprintf('/usr/sbin/firstcontact -i %s', devid));
|
||||
if (ret) {
|
||||
warn("firstcontact failed to contact redirector, check DHCP option\n");
|
||||
let fd = fs.open("/tmp/capwap/dhcp_opt.txt", "r");
|
||||
function digicert() {
|
||||
let devid;
|
||||
let fd = fs.open("/etc/ucentral/dev-id", "r");
|
||||
if (!fd) {
|
||||
warn("No redirector found\n");
|
||||
warn("firstcontact: failed to find device id");
|
||||
exit(1);
|
||||
} else {
|
||||
config.Redirector = fd.read("all");
|
||||
fd.close();
|
||||
}
|
||||
} else {
|
||||
let redirector = { };
|
||||
let fd = fs.open("/etc/ucentral/redirector.json", "r");
|
||||
if (fd) {
|
||||
let data = fd.read("all");
|
||||
fd.close();
|
||||
devid = fd.read("all");
|
||||
fd.close();
|
||||
|
||||
try {
|
||||
redirector = json(data);
|
||||
ret = system(sprintf('/usr/sbin/digicert -i %s', devid));
|
||||
if (ret) {
|
||||
warn("firstcontact failed to contact redirector, check DHCP option\n");
|
||||
let fd = fs.open("/tmp/capwap/dhcp_opt.txt", "r");
|
||||
if (!fd) {
|
||||
warn("No redirector found\n");
|
||||
exit(1);
|
||||
} else {
|
||||
config.Redirector = fd.read("all");
|
||||
fd.close();
|
||||
}
|
||||
catch (e) {
|
||||
warn("firstcontact: Unable to parse JSON data in %s: %s", path, e);
|
||||
} else {
|
||||
let redirector = { };
|
||||
let fd = fs.open("/etc/ucentral/redirector.json", "r");
|
||||
if (fd) {
|
||||
let data = fd.read("all");
|
||||
fd.close();
|
||||
|
||||
try {
|
||||
redirector = json(data);
|
||||
}
|
||||
catch (e) {
|
||||
warn("firstcontact: Unable to parse JSON data in %s: %s", path, e);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (let r in redirector.fields)
|
||||
if (r.name && r.value)
|
||||
config[r.name] = r.value;
|
||||
if (!config.Redirector) {
|
||||
warn("Reply is missing Redirector field\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (let r in redirector.fields)
|
||||
if (r.name && r.value)
|
||||
config[r.name] = r.value;
|
||||
if (!config.Redirector) {
|
||||
warn("Reply is missing Redirector field\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
store_config();
|
||||
store_config("/etc/config-shadow/");
|
||||
|
||||
warn("firstcontact: managed to look up redirector\n");
|
||||
if (!fs.stat('/etc/ucentral/gateway.json')) {
|
||||
digicert();
|
||||
store_config();
|
||||
warn("firstcontact: managed to look up redirector\n");
|
||||
}
|
||||
|
||||
system("/etc/init.d/ucentral enable");
|
||||
system("/etc/init.d/firstcontact disable");
|
||||
|
||||
system("reload_config");
|
||||
system("/etc/init.d/ucentral start");
|
||||
system("/etc/init.d/firstcontact stop");
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
PROJECT(firstcontact C)
|
||||
PROJECT(digicert C)
|
||||
INCLUDE(GNUInstallDirs)
|
||||
ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations)
|
||||
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
|
||||
ADD_EXECUTABLE(firstcontact firstcontact.c)
|
||||
TARGET_LINK_LIBRARIES(firstcontact curl crypto ssl ubox)
|
||||
INSTALL(TARGETS firstcontact
|
||||
ADD_EXECUTABLE(digicert digicert.c)
|
||||
TARGET_LINK_LIBRARIES(digicert curl crypto ssl ubox)
|
||||
INSTALL(TARGETS digicert
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
static const char *file_cert = "/etc/ucentral/cert.pem";
|
||||
static const char *file_key = "/etc/ucentral/key.pem";
|
||||
static const char *file_json = "/etc/ucentral/redirector.json";
|
||||
static const char *file_dbg = "/tmp/firstcontact.hdr";
|
||||
static const char *file_dbg = "/tmp/digicert.hdr";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
default:
|
||||
case 'h':
|
||||
printf("Usage: firstcontact OPTIONS\n"
|
||||
printf("Usage: digicert OPTIONS\n"
|
||||
" -k <keyfile>\n"
|
||||
" -c <certfile>\n"
|
||||
" -o <outfile>\n"
|
||||
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ulog_open(ULOG_SYSLOG | ULOG_STDIO, LOG_DAEMON, "firstcontact");
|
||||
ulog_open(ULOG_SYSLOG | ULOG_STDIO, LOG_DAEMON, "digicert");
|
||||
ULOG_INFO("attempting first contact\n");
|
||||
|
||||
fp_dbg = fopen(file_dbg, "wb");
|
||||
@@ -27,8 +27,8 @@ start_service() {
|
||||
cp /etc/config-shadow/ucentral /etc/config/
|
||||
config_load 'ucentral'
|
||||
config_get serial 'config' 'serial'
|
||||
config_get server 'config' 'server'
|
||||
config_get port 'config' 'port'
|
||||
#config_get server 'config' 'server'
|
||||
#config_get port 'config' 'port'
|
||||
config_get debug 'config' 'debug' 0
|
||||
config_get insecure 'config' 'insecure' 0
|
||||
|
||||
@@ -37,6 +37,9 @@ start_service() {
|
||||
[ "${selfsigned}" == "true" ] && insecure=1
|
||||
fi
|
||||
|
||||
server=$(cat /etc/ucentral/gateway.json | jsonfilter -e '@["server"]')
|
||||
port=$(cat /etc/ucentral/gateway.json | jsonfilter -e '@["port"]')
|
||||
|
||||
boot_cause=$(cat /tmp/pstore | jsonfilter -e '@["pstore"][-1]'.boot_cause)
|
||||
[ -z $boot_cause ] && boot_cause=coldboot
|
||||
procd_open_instance
|
||||
|
||||
@@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git
|
||||
PKG_MIRROR_HASH:=410887e51b2e530603f725114e8758e3a360212c94d570951ffe345a1b069f0e
|
||||
PKG_MIRROR_HASH:=1eb48137a2611fb1208a4ff6b6aece74cca76ae1d4b928df786f099ff31db91f
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_DATE:=2022-05-29
|
||||
PKG_SOURCE_VERSION:=41e3b038d1073bd5a9c30f45523a7b691442f4ff
|
||||
PKG_SOURCE_VERSION:=b3f972ae12365d7a9e2e567f8e2a7d976d5d7276
|
||||
PKG_MAINTAINER:=John Crispin <john@phrozen.org>
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
|
||||
|
||||
Reference in New Issue
Block a user