add quick start

This commit is contained in:
YGAS 2022-01-21 18:42:16 +08:00
parent a99b774416
commit 24806d04b1
13 changed files with 382 additions and 0 deletions

View File

@ -0,0 +1,17 @@
# Copyright (C) 2016 Openwrt.org
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for quickstart
LUCI_DEPENDS:=+shadow-useradd
LUCI_PKGARCH:=all
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,172 @@
local http = require "luci.http"
local nixio = require "nixio"
local ltn12 = require "luci.ltn12"
local table = require "table"
local util = require "luci.util"
module("luci.controller.istore_backend", package.seeall)
local BLOCKSIZE = 2048
local ISTOREOS_PORT = 3000
function index()
entry({"istore"}, call("istore_backend")).leaf=true
end
function sink_socket(sock, io_err)
if sock then
return function(chunk, err)
if not chunk then
return 1
else
return sock:send(chunk)
end
end
else
return ltn12.sink.error(io_err or "unable to send socket")
end
end
local function session_retrieve(sid, allowed_users)
local sdat = util.ubus("session", "get", { ubus_rpc_session = sid })
if type(sdat) == "table" and
type(sdat.values) == "table" and
type(sdat.values.token) == "string" and
(not allowed_users or
util.contains(allowed_users, sdat.values.username))
then
return sid, sdat.values
end
return nil, nil
end
function istore_backend()
local sock = nixio.connect("127.0.0.1", ISTOREOS_PORT)
if not sock then
http.status(500, "connect failed")
return
end
local input = {}
input[#input+1] = http.getenv("REQUEST_METHOD") .. " " .. http.getenv("REQUEST_URI") .. " HTTP/1.1"
local req = http.context.request
local start = "HTTP_"
local start_len = string.len(start)
local ctype = http.getenv("CONTENT_TYPE")
if ctype then
input[#input+1] = "Content-Type: " .. ctype
end
for k, v in pairs(req.message.env) do
if string.sub(k, 1, start_len) == start and not string.find(k, "FORWARDED") then
input[#input+1] = string.sub(k, start_len+1, string.len(k)) .. ": " .. v
end
end
local sid = http.getcookie("sysauth")
if sid then
local sid, sdat = session_retrieve(sid, nil)
if sdat ~= nil then
input[#input+1] = "X-Forwarded-Sid: " .. sid
input[#input+1] = "X-Forwarded-Token: " .. sdat.token
end
end
input[#input+1] = "X-Forwarded-For: " .. http.getenv("REMOTE_HOST") ..":".. http.getenv("REMOTE_PORT")
local num = tonumber(http.getenv("CONTENT_LENGTH")) or 0
input[#input+1] = "Content-Length: " .. tostring(num)
input[#input+1] = "\r\n"
local source = ltn12.source.cat(ltn12.source.string(table.concat(input, "\r\n")), http.source())
local ret = ltn12.pump.all(source, sink_socket(sock, "write sock error"))
if ret ~= 1 then
sock:close()
http.status(500, "proxy error")
return
end
local linesrc = sock:linesource()
local line, code, error = linesrc()
if not line then
sock:close()
http.status(500, "response parse failed")
return
end
local protocol, status, msg = line:match("^([%w./]+) ([0-9]+) (.*)")
if not protocol then
sock:close()
http.status(500, "response protocol error")
return
end
num = tonumber(status) or 0
http.status(num, msg)
local chunked = 0
line = linesrc()
while line and line ~= "" do
local key, val = line:match("^([%w-]+)%s?:%s?(.*)")
if key and key ~= "Status" then
if key == "Transfer-Encoding" and val == "chunked" then
chunked = 1
end
if key ~= "Connection" and key ~= "Transfer-Encoding" then
http.header(key, val)
end
end
line = linesrc()
end
if not line then
sock:close()
http.status(500, "parse header failed")
return
end
local body_buffer = linesrc(true)
if chunked == 1 then
ltn12.pump.all(chunksource(sock, body_buffer), http.write)
else
local body_source = ltn12.source.cat(ltn12.source.string(body_buffer), sock:blocksource())
ltn12.pump.all(body_source, http.write)
end
sock:close()
end
function chunksource(sock, buffer)
buffer = buffer or ""
return function()
local output
local _, endp, count = buffer:find("^([0-9a-fA-F]+);?.-\r\n")
while not count and #buffer <= 1024 do
local newblock, code = sock:recv(1024 - #buffer)
if not newblock then
return nil, code
end
buffer = buffer .. newblock
_, endp, count = buffer:find("^([0-9a-fA-F]+);?.-\r\n")
end
count = tonumber(count, 16)
if not count then
return nil, -1, "invalid encoding"
elseif count == 0 then
return nil
elseif count + 2 <= #buffer - endp then
output = buffer:sub(endp+1, endp+count)
buffer = buffer:sub(endp+count+3)
return output
else
output = buffer:sub(endp+1, endp+count)
buffer = ""
if count - #output > 0 then
local remain, code = sock:recvall(count-#output)
if not remain then
return nil, code
end
output = output .. remain
count, code = sock:recvall(2)
else
count, code = sock:recvall(count+2-#buffer+endp)
end
if not count then
return nil, code
end
return output
end
end
end

View File

@ -0,0 +1,23 @@
local http = require "luci.http"
module("luci.controller.quickstart", package.seeall)
local page_index = {"admin", "quickstart", "pages"}
function index()
entry({"admin", "quickstart"}, call("redirect_index"), _("QuickStart"), 1)
entry({"admin", "network_guide"}, call("networkguide_index"), _("NetworkGuide"), 2)
entry({"admin", "quickstart", "pages"}, call("quickstart_index")).leaf = true
end
function networkguide_index()
luci.http.redirect(luci.dispatcher.build_url("admin","quickstart","pages","network"))
end
function redirect_index()
luci.http.redirect(luci.dispatcher.build_url(unpack(page_index)))
end
function quickstart_index()
luci.template.render("quickstart/main", {prefix=luci.dispatcher.build_url(unpack(page_index))})
end

View File

@ -0,0 +1,13 @@
<%+header%>
<script>
(function(){
var vue_prefix="<%=prefix%>";
window.vue_base = vue_prefix + '/';
})();
</script>
<div id="app">
</div>
<script type="module" crossorigin src="/luci-static/quickstart/index.js"></script>
<link rel="modulepreload" href="/luci-static/quickstart/vendor.js">
<link rel="stylesheet" href="/luci-static/quickstart/style.css">
<%+footer%>

View File

@ -0,0 +1,7 @@
msgid "NetworkGuide"
msgstr "网络向导"
msgid "QuickStart"
msgstr "首页"

View File

@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common
START=98
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /usr/sbin/quickstart
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}

View File

@ -0,0 +1,4 @@
#!/bin/sh
rm -f /tmp/luci-indexcache
exit 0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,63 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
# Copyright (C) 2020 jjm2473@gmail.com
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_ARCH_quickstart:=$(ARCH)
PKG_NAME:=quickstart
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-binary-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://fw.koolcenter.com/binary/quickstart/
PKG_HASH:=9acba95e0194adbad93745d5d4269cd27475ad625add4f1b0fad9589eb7b7c1b
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-binary-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Guide
SUBMENU:=Web Servers/Proxies
TITLE:=Quickstart, the quick start.
DEPENDS:=
URL:=https://easepi.linkease.com/
endef
define Package/$(PKG_NAME)/description
Quickstart is a dashboard & user guide
endef
define Package/$(PKG_NAME)/conffiles
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
[ -f /etc/uci-defaults/quickstart ] && /etc/uci-defaults/quickstart && rm -f /etc/uci-defaults/quickstart
fi
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/uci-defaults
$(INSTALL_BIN) $(PKG_BUILD_DIR)/quickstart.$(PKG_ARCH_quickstart) $(1)/usr/sbin/quickstart
$(INSTALL_BIN) ./files/quickstart.init $(1)/etc/init.d/quickstart
$(INSTALL_BIN) ./files/quickstart.uci-default $(1)/etc/uci-defaults/quickstart
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@ -0,0 +1,13 @@
##!/bin/sh /etc/rc.common
START=98
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /usr/sbin/quickstart
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}

View File

@ -0,0 +1,6 @@
#!/bin/sh
/etc/init.d/quickstart enable
/etc/init.d/quickstart start
exit 0