mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add glorytun packages and LuCI app
This commit is contained in:
parent
fc579c849e
commit
1b9ebf5ac2
15 changed files with 727 additions and 0 deletions
12
luci-app-glorytun/luasrc/controller/glorytun.lua
Normal file
12
luci-app-glorytun/luasrc/controller/glorytun.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
-- Copyright 2017 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
module("luci.controller.glorytun", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/glorytun") then
|
||||
return
|
||||
end
|
||||
entry({"admin", "services", "glorytun"}, cbi("glorytun"), _("Glorytun") )
|
||||
entry({"admin", "services", "glorytun", "settings"}, cbi("glorytun-settings"), nil ).leaf = true
|
||||
end
|
80
luci-app-glorytun/luasrc/model/cbi/glorytun-settings.lua
Normal file
80
luci-app-glorytun/luasrc/model/cbi/glorytun-settings.lua
Normal file
|
@ -0,0 +1,80 @@
|
|||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
require("luci.ip")
|
||||
require("luci.model.uci")
|
||||
|
||||
|
||||
local basicParams = {
|
||||
--
|
||||
-- Widget, Name, Default(s), Description
|
||||
--
|
||||
|
||||
{ Value,"port",65001, translate("TCP port # for both local and remote") },
|
||||
{ Value,"dev","tun0", translate("Interface name") },
|
||||
{ Value,"host","vpnserver.example.org", translate("Remote host name or ip address") },
|
||||
{ Value,"localip","192.168.99.2", translate("Local tunnel ip address") },
|
||||
{ Value,"remoteip","192.168.99.1", translate("Remote tunnel ip address") },
|
||||
{ Value,"key","secretkey", translate("The secret key") },
|
||||
{ ListValue,"proto",{ "TCP", "UDP" }, translate("Protocol") },
|
||||
{ Flag,"listener",0, translate("Server mode") },
|
||||
|
||||
{ Value,"bind","", translate("Bind address") },
|
||||
--{ Value,"bind-backup","", translate("Bind backup") },
|
||||
{ Value,"bindport",65002, translate("Bind port") },
|
||||
{ Value,"mtu",1500, translate("MTU") },
|
||||
{ Flag,"mtuauto",0, translate("MTU auto") },
|
||||
|
||||
{ Flag,"mptcp",0, translate("MPTCP") }
|
||||
}
|
||||
|
||||
|
||||
local m = Map("glorytun")
|
||||
local p = m:section( SimpleSection )
|
||||
|
||||
p.template = "glorytun/pageswitch"
|
||||
p.mode = "settings"
|
||||
p.instance = arg[1]
|
||||
|
||||
|
||||
local s = m:section( NamedSection, arg[1], "glorytun" )
|
||||
|
||||
for _, option in ipairs(basicParams) do
|
||||
local o = s:option(
|
||||
option[1], option[2],
|
||||
option[2], option[4]
|
||||
)
|
||||
|
||||
o.optional = true
|
||||
|
||||
if option[1] == DummyValue then
|
||||
o.value = option[3]
|
||||
else
|
||||
if option[1] == DynamicList then
|
||||
function o.cfgvalue(...)
|
||||
local val = AbstractValue.cfgvalue(...)
|
||||
return ( val and type(val) ~= "table" ) and { val } or val
|
||||
end
|
||||
end
|
||||
|
||||
if type(option[3]) == "table" then
|
||||
if o.optional then o:value("", "-- remove --") end
|
||||
for _, v in ipairs(option[3]) do
|
||||
v = tostring(v)
|
||||
o:value(v)
|
||||
end
|
||||
o.default = tostring(option[3][1])
|
||||
else
|
||||
o.default = tostring(option[3])
|
||||
end
|
||||
end
|
||||
|
||||
for i=5,#option do
|
||||
if type(option[i]) == "table" then
|
||||
o:depends(option[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
||||
|
139
luci-app-glorytun/luasrc/model/cbi/glorytun.lua
Normal file
139
luci-app-glorytun/luasrc/model/cbi/glorytun.lua
Normal file
|
@ -0,0 +1,139 @@
|
|||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local testfullps = luci.sys.exec("ps --help 2>&1 | grep BusyBox") --check which ps do we have
|
||||
local psstring = (string.len(testfullps)>0) and "ps w" or "ps axfw" --set command we use to get pid
|
||||
|
||||
local m = Map("glorytun", translate("Glorytun"))
|
||||
local s = m:section( TypedSection, "glorytun", translate("Glorytun instances"), translate("Below is a list of configured Glorytun instances and their current state") )
|
||||
s.template = "cbi/tblsection"
|
||||
s.template_addremove = "glorytun/cbi-select-input-add"
|
||||
s.addremove = true
|
||||
s.add_select_options = { }
|
||||
s.extedit = luci.dispatcher.build_url(
|
||||
"admin", "services", "glorytun", "settings", "%s"
|
||||
)
|
||||
|
||||
uci:load("glorytun_recipes")
|
||||
uci:foreach( "glorytun_recipes", "glorytun_recipe",
|
||||
function(section)
|
||||
s.add_select_options[section['.name']] =
|
||||
section['_description'] or section['.name']
|
||||
end
|
||||
)
|
||||
|
||||
function s.getPID(section) -- Universal function which returns valid pid # or nil
|
||||
local pid = sys.exec("%s | grep -w %s | grep glorytun | grep -v grep | awk '{print $1}'" % { psstring,section} )
|
||||
if pid and #pid > 0 and tonumber(pid) ~= nil then
|
||||
return tonumber(pid)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
function s.parse(self, section)
|
||||
local recipe = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".select"
|
||||
)
|
||||
|
||||
if recipe and not s.add_select_options[recipe] then
|
||||
self.invalid_cts = true
|
||||
else
|
||||
TypedSection.parse( self, section )
|
||||
end
|
||||
end
|
||||
|
||||
function s.create(self, name)
|
||||
local recipe = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".select"
|
||||
)
|
||||
name = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".text"
|
||||
)
|
||||
if string.len(name)>3 and not name:match("[^a-zA-Z0-9_]") then
|
||||
uci:section(
|
||||
"glorytun", "glorytun", name,
|
||||
uci:get_all( "glorytun_recipes", recipe )
|
||||
)
|
||||
|
||||
uci:delete("glorytun", name, "_role")
|
||||
uci:delete("glorytun", name, "_description")
|
||||
uci:save("glorytun")
|
||||
|
||||
luci.http.redirect( self.extedit:format(name) )
|
||||
else
|
||||
self.invalid_cts = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
s:option( Flag, "enable", translate("Enabled") )
|
||||
|
||||
local active = s:option( DummyValue, "_active", translate("Started") )
|
||||
function active.cfgvalue(self, section)
|
||||
local pid = s.getPID(section)
|
||||
if pid ~= nil then
|
||||
return (sys.process.signal(pid, 0))
|
||||
and translatef("yes (%i)", pid)
|
||||
or translate("no")
|
||||
end
|
||||
return translate("no")
|
||||
end
|
||||
|
||||
local updown = s:option( Button, "_updown", translate("Start/Stop") )
|
||||
updown._state = false
|
||||
updown.redirect = luci.dispatcher.build_url(
|
||||
"admin", "services", "glorytun"
|
||||
)
|
||||
function updown.cbid(self, section)
|
||||
local pid = s.getPID(section)
|
||||
self._state = pid ~= nil and sys.process.signal(pid, 0)
|
||||
self.option = self._state and "stop" or "start"
|
||||
return AbstractValue.cbid(self, section)
|
||||
end
|
||||
function updown.cfgvalue(self, section)
|
||||
self.title = self._state and "stop" or "start"
|
||||
self.inputstyle = self._state and "reset" or "reload"
|
||||
end
|
||||
|
||||
local port = s:option( DummyValue, "port", translate("Port") )
|
||||
function port.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
return val or "65001"
|
||||
end
|
||||
local dev = s:option( DummyValue, "dev", translate("Interface") )
|
||||
function dev.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
return val or "tun"
|
||||
end
|
||||
local proto = s:option( DummyValue, "proto", translate("Protocol") )
|
||||
function proto.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
return val or "tcp"
|
||||
end
|
||||
|
||||
function updown.write(self, section, value)
|
||||
if self.option == "stop" then
|
||||
local pid = s.getPID(section)
|
||||
if pid ~= nil then
|
||||
sys.process.signal(pid,15)
|
||||
end
|
||||
else
|
||||
local type = proto.cfgvalue(self,section)
|
||||
if type == 'udp' then
|
||||
luci.sys.call("/etc/init.d/glorytun-udp start %s" % section)
|
||||
else
|
||||
luci.sys.call("/etc/init.d/glorytun start %s" % section)
|
||||
end
|
||||
end
|
||||
luci.http.redirect( self.redirect )
|
||||
end
|
||||
|
||||
|
||||
return m
|
|
@ -0,0 +1,11 @@
|
|||
<div class="cbi-section-create">
|
||||
<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
|
||||
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.text" />
|
||||
<select class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.select">
|
||||
<%- for k, v in luci.util.kspairs(self.add_select_options) do %>
|
||||
<option value="<%=k%>"><%=luci.util.pcdata(v)%></option>
|
||||
<% end -%>
|
||||
</select>
|
||||
<input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" title="<%:Add%>" />
|
||||
<% if self.invalid_cts then %><br /><%:Invalid%></div><% end %>
|
||||
</div>
|
12
luci-app-glorytun/luasrc/view/glorytun/pageswitch.htm
Normal file
12
luci-app-glorytun/luasrc/view/glorytun/pageswitch.htm
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%#
|
||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<legend>
|
||||
<a href="<%=url('admin/services/glorytun')%>"><%:Overview%></a> »
|
||||
<%=luci.i18n.translatef("Instance \"%s\"", self.instance)%>
|
||||
</legend>
|
||||
</fieldset>
|
Loading…
Add table
Add a link
Reference in a new issue