-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mesh-vpn: fully abstract VPN methods
This fully abstracts VPN methods, making gluon-mesh-vpn-fastd and gluon-mesh-vpn-tunneldigger completely self-contained. Provide a LUA interface for generic interacting with VPN methods in gluon-mesh-vpn-core and web packages. This also adds the ability to install tunneldigger and fastd to the same image, selecting the VPN method based on the selected domain.
- Loading branch information
1 parent
0ac3061
commit e4b5414
Showing
12 changed files
with
155 additions
and
69 deletions.
There are no files selected for viewing
26 changes: 8 additions & 18 deletions
26
package/gluon-config-mode-mesh-vpn/luasrc/lib/gluon/config-mode/reboot/0100-mesh-vpn.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 42 additions & 2 deletions
44
package/gluon-mesh-vpn-core/luasrc/usr/lib/lua/gluon/mesh-vpn.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,47 @@ | ||
local uci = require('simple-uci').cursor() | ||
|
||
local util = require 'gluon.util' | ||
|
||
local M = {} | ||
|
||
function M.get_mesh_vpn_interface() | ||
return 'mesh-vpn' | ||
function M.enabled() | ||
return uci:get_bool('gluon', 'mesh_vpn', 'enabled') | ||
end | ||
|
||
function M.enable(val) | ||
return uci:set('gluon', 'mesh_vpn', 'enabled', val) | ||
end | ||
|
||
function M.get_interface() | ||
return 'mesh-vpn' | ||
end | ||
|
||
function M.get_proto(name) | ||
return require('gluon.mesh-vpn.proto.' .. name) | ||
end | ||
|
||
function M.get_proto_names() | ||
local out = {} | ||
|
||
for _, v in ipairs(util.glob('/lib/gluon/mesh-vpn/proto/*')) do | ||
table.insert(out, v:match('([^/]+)$')) | ||
end | ||
|
||
return out | ||
end | ||
|
||
function M.get_active_proto() | ||
-- Active proto is the proto in use by the currently | ||
-- active site / domain | ||
|
||
for _, name in ipairs(M.get_proto_names()) do | ||
local proto = M.get_proto(name) | ||
if proto.active() then | ||
return name, proto | ||
end | ||
end | ||
|
||
return nil, nil | ||
end | ||
|
||
return M |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
package/gluon-mesh-vpn-fastd/luasrc/usr/lib/lua/gluon/mesh-vpn/proto/fastd.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local uci = require('simple-uci').cursor() | ||
|
||
local site = require 'gluon.site' | ||
local util = require 'gluon.util' | ||
local vpn_core = require 'gluon.mesh-vpn' | ||
|
||
local M = {} | ||
|
||
function M.public_key() | ||
return util.trim(util.exec('/etc/init.d/fastd show_key mesh_vpn')) | ||
end | ||
|
||
function M.enable(val) | ||
uci:set('fastd', 'mesh_vpn', 'enabled', val) | ||
uci:save('fastd') | ||
end | ||
|
||
function M.active() | ||
return site.mesh_vpn.fastd() ~= nil | ||
end | ||
|
||
function M.set_limit(ingress_limit, egress_limit) | ||
uci:delete('simple-tc', 'mesh_vpn') | ||
if ingress_limit ~= nil and egress_limit ~= nil then | ||
uci:section('simple-tc', 'interface', 'mesh_vpn', { | ||
ifname = vpn_core.get_interface(), | ||
enabled = 1, | ||
limit_egress = egress_limit, | ||
limit_ingress = ingress_limit, | ||
}) | ||
end | ||
|
||
uci:save('simple-tc') | ||
end | ||
|
||
function M.uci_sections() | ||
return {'fastd', 'simple-tc'} | ||
end | ||
|
||
return M |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
package/gluon-mesh-vpn-tunneldigger/luasrc/lib/lua/gluon/mesh-vpn/proto/tunneldigger.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local uci = require('simple-uci').cursor() | ||
|
||
local site = require 'gluon.site' | ||
|
||
local M = {} | ||
|
||
function M.public_key() | ||
return nil | ||
end | ||
|
||
function M.enable(val) | ||
uci:set('tunneldigger', 'mesh_vpn', 'enabled', val) | ||
uci:save('tunneldigger') | ||
end | ||
|
||
function M.active() | ||
return site.mesh_vpn.tunneldigger() ~= nil | ||
end | ||
|
||
function M.set_limit(ingress_limit, _) | ||
if ingress_limit ~= nil then | ||
uci:set('tunneldigger', 'mesh_vpn', 'limit_bw_down', ingress_limit) | ||
else | ||
uci:delete('tunneldigger', 'mesh_vpn', 'limit_bw_down') | ||
end | ||
uci:save('tunneldigger') | ||
end | ||
|
||
function M.uci_sections() | ||
return {'tunneldigger'} | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters