Skip to content

Commit

Permalink
web config web UI now using ssl on port 443
Browse files Browse the repository at this point in the history
  • Loading branch information
DEvil0000 committed Jan 15, 2022
1 parent 9e9443c commit c9a8966
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 13 deletions.
26 changes: 26 additions & 0 deletions ffbsee-config-mode-core/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2012 Nils Schneider <nils at nilsschneider.net>
# This is free software, licensed under the Apache 2.0 license.

include $(TOPDIR)/rules.mk

PKG_NAME:=ffbsee-config-mode-core
PKG_VERSION:=0.1

include $(TOPDIR)/../package/gluon.mk

define Package/ffbsee-config-mode-core
TITLE:=Configuration wizard for user friendly setup of new mesh nodes
DEPENDS:=+gluon-setup-mode +gluon-web-model +gluon-config-mode-theme +uhttpd +libuhttpd-openssl +openssl-util
PROVIDES:=gluon-config-mode-core
endef

define Package/ffbsee-config-mode-core/install
$(Gluon/Build/Install)

$(INSTALL_DIR) $(1)/lib/gluon/config-mode/view/ $(1)/lib/gluon/config-mode/www/static/
$(LN) /lib/gluon/web/i18n $(1)/lib/gluon/config-mode/
$(LN) /lib/gluon/web/view/{error,model} $(1)/lib/gluon/config-mode/view/
$(LN) /lib/gluon/web/www/static/gluon-web-model.js $(1)/lib/gluon/config-mode/www/static/
endef

$(eval $(call BuildPackageGluon,ffbsee-config-mode-core))
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2><%:Your node's setup is now complete.%></h2>
<%
local util = require "gluon.util"

local parts = {}
for _, entry in ipairs(util.glob('/lib/gluon/config-mode/reboot/*')) do
local p = assert(loadfile(entry))
setfenv(p, getfenv())
table.insert(parts, p)
end

for _, p in ipairs(parts) do
p()
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%-
local site_i18n = i18n 'gluon-site'

local sysconfig = require 'gluon.sysconfig'

local msg = site_i18n._translate('gluon-config-mode:welcome')
if not msg then return end
-%>
<p>
<%
renderer.render_string(msg, {
hostname = hostname,
sysconfig = sysconfig,
})
%>
</p>
11 changes: 11 additions & 0 deletions ffbsee-config-mode-core/files/lib/gluon/config-mode/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="refresh" content="0; URL=/cgi-bin/config" />
</head>
<body>
</body>
</html>
14 changes: 14 additions & 0 deletions ffbsee-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh /etc/rc.common

START=50

USE_PROCD=1

UHTTPD_BIN="/usr/sbin/uhttpd"

start_service() {
procd_open_instance
procd_set_param respawn
procd_set_param command "$UHTTPD_BIN" -f -h /lib/gluon/config-mode/www -x /cgi-bin -A 1 -R -C /etc/uhttpd.crt -K /etc/uhttpd.key -s 0.0.0.0:443 -s :::443
procd_close_instance
}
23 changes: 23 additions & 0 deletions ffbsee-config-mode-core/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: 2015-03-19 02:07+0100\n"
"Last-Translator: Matthias Schiffer <[email protected]>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Save & restart"
msgstr "Speichern & Neustarten"

msgid "Welcome!"
msgstr "Willkommen!"

msgid "Wizard"
msgstr "Wizard"

msgid "Your node's setup is now complete."
msgstr "Dein Knoten ist nun fertig eingerichtet."
23 changes: 23 additions & 0 deletions ffbsee-config-mode-core/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: 2015-08-12 23:30+0100\n"
"Last-Translator:Tobias Bernot <[email protected]>\n"
"Language-Team: French\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Save & restart"
msgstr "Enregistrer & Redémarer"

msgid "Welcome!"
msgstr "Bienvenue!"

msgid "Wizard"
msgstr "Assistant"

msgid "Your node's setup is now complete."
msgstr "La configuration de votre nœud est terminée."
14 changes: 14 additions & 0 deletions ffbsee-config-mode-core/i18n/gluon-config-mode-core.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"

msgid "Save & restart"
msgstr ""

msgid "Welcome!"
msgstr ""

msgid "Wizard"
msgstr ""

msgid "Your node's setup is now complete."
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package 'gluon-config-mode-core'

entry({}, alias("wizard"))
entry({"wizard"}, model("gluon-config-mode/wizard"), _("Wizard"), 5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local util = require "gluon.util"
local uci = require("simple-uci").cursor()

local f = Form(translate("Welcome!"))
f.submit = translate('Save & restart')
f.reset = false

local s = f:section(Section)
s.template = "wizard/welcome"
s.package = "gluon-config-mode-core"

for _, entry in ipairs(util.glob('/lib/gluon/config-mode/wizard/*')) do
local section = assert(loadfile(entry))
setfenv(section, getfenv())
section()(f, uci)
end

function f:write()
local fcntl = require 'posix.fcntl'
local unistd = require 'posix.unistd'

uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", true)
uci:save("gluon-setup-mode")

os.execute('gluon-reconfigure')

f.template = "wizard/reboot"
f.package = "gluon-config-mode-core"
f.hidenav = true

if unistd.fork() == 0 then
-- Replace stdout with /dev/null
local null = fcntl.open('/dev/null', fcntl.O_WRONLY)
unistd.dup2(null, unistd.STDOUT_FILENO)

-- Sleep a little so the browser can fetch everything required to
-- display the reboot page, then reboot the device.
unistd.sleep(1)

unistd.execp('reboot', {[0] = 'reboot'})
end
end

return f
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local site_i18n = i18n 'gluon-site'

local site = require 'gluon.site'
local sysconfig = require 'gluon.sysconfig'
local pretty_hostname = require 'pretty_hostname'

local uci = require("simple-uci").cursor()

local hostname = pretty_hostname.get(uci)
local contact = uci:get_first('gluon-node-info', 'owner', 'contact')

local msg = site_i18n._translate('gluon-config-mode:reboot')
if not msg then return end

renderer.render_string(msg, {
hostname = hostname,
site = site,
sysconfig = sysconfig,
contact = contact,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/lua

require 'gluon.web.cgi' {
base_path = '/lib/gluon/config-mode',

layout_package = 'gluon-config-mode-theme',
layout_template = 'theme/layout',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/lua

local uci = require('simple-uci').cursor()

uci:section('firewall', 'rule', 'loc_client' .. '_https', {
src = 'loc_client',
dest_port = '443',
proto = 'tcp',
target = 'ACCEPT',
})

uci:save('firewall')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/ash

openssl req -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout /etc/uhttpd.key -days 365 -out /etc/uhttpd.crt
6 changes: 3 additions & 3 deletions ffbsee-setup-mode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ffbsee-setup-mode
PKG_VERSION:=0.1
PKG_VERSION:=0.2

include $(TOPDIR)/../package/gluon.mk

Expand All @@ -19,8 +19,8 @@ define Package/ffbsee-setup-mode/description
It will act the same for the first boot but every
other time a button is pressed for config mode it
will not reboot to a save mode but instead provide
a config web UI with only link local access
for a period of 1h.
a config web UI with only lan/wifi (local) access
via ffbsee nexthop 10.15.239.127 for a period of 1h.
endef

init_links := \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh


wait=3
cwait=3600

Expand All @@ -14,17 +13,11 @@ wait_config_mode() {
fi
# turn off config page
/lib/gluon/setup-mode/rc.d/S50uhttpd stop
sleep 1
# turn on status page
/etc/rc.d/S50uhttpd start
}

start_config_web_ui() {
uci set 'gluon-setup-mode.@setup_mode[0].enabled=1'
uci commit gluon-setup-mode
# turn off status page
/etc/rc.d/S50uhttpd stop
sleep 1
# turn on config page
/lib/gluon/setup-mode/rc.d/S50uhttpd start
local PID=$!
Expand Down
4 changes: 2 additions & 2 deletions ffbsee-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh /etc/rc.common

SETUP_MODE_ADDR=192.168.1.1
SETUP_MODE_NETMASK=255.255.255.0
SETUP_MODE_ADDR=10.15.239.127
SETUP_MODE_NETMASK=255.255.240.0

START=20
STOP=90
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh /etc/rc.common

SETUP_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254
SETUP_MODE_DHCP_RANGE=10.15.239.128,10.15.239.254


START=60
Expand Down

0 comments on commit c9a8966

Please sign in to comment.