Просмотр исходного кода

Added luci protocol module for openconnect.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Nikos Mavrogiannopoulos 10 лет назад
Родитель
Сommit
b62d07991c

+ 57
- 0
net/luci-proto-openconnect/Makefile Просмотреть файл

@@ -0,0 +1,57 @@
1
+#    Copyright (C) 2014 Nikos Mavrogiannopoulos
2
+#
3
+#    This program is free software; you can redistribute it and/or modify
4
+#    it under the terms of the GNU General Public License as published by
5
+#    the Free Software Foundation; either version 2 of the License, or
6
+#    (at your option) any later version.
7
+#
8
+#    This program is distributed in the hope that it will be useful,
9
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+#    GNU General Public License for more details.
12
+#
13
+#    You should have received a copy of the GNU General Public License along
14
+#    with this program; if not, write to the Free Software Foundation, Inc.,
15
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+#
17
+#    The full GNU General Public License is included in this distribution in
18
+#    the file called "COPYING".
19
+
20
+include $(TOPDIR)/rules.mk
21
+
22
+PKG_NAME:=luci-proto-openconnect
23
+PKG_RELEASE:=1
24
+
25
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
26
+
27
+include $(INCLUDE_DIR)/package.mk
28
+
29
+define Package/luci-proto-openconnect
30
+  SECTION:=luci
31
+  CATEGORY:=LuCI
32
+  SUBMENU:=6. Protocols
33
+  TITLE:= OpenConnect VPN protocol configuration
34
+  DEPENDS:=+luci-mod-admin-core +openconnect
35
+  MAINTAINER:= Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
36
+endef
37
+
38
+define Package/luci-proto-openconnect/description
39
+	openconnect web module for LuCi web interface
40
+endef
41
+
42
+define Build/Prepare
43
+endef
44
+
45
+define Build/Configure
46
+endef
47
+
48
+define Build/Compile
49
+endef
50
+
51
+# Fixme: How can we add <%+openconnect_status%> in view/admin_status/index.htm?
52
+define Package/luci-proto-openconnect/install
53
+	$(CP) ./files/* $(1)/
54
+endef
55
+
56
+$(eval $(call BuildPackage,luci-proto-openconnect))
57
+

+ 78
- 0
net/luci-proto-openconnect/files/usr/lib/lua/luci/model/cbi/admin_network/proto_openconnect.lua Просмотреть файл

@@ -0,0 +1,78 @@
1
+--[[
2
+LuCI - Lua Configuration Interface
3
+
4
+Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
5
+
6
+Licensed under the Apache License, Version 2.0 (the "License");
7
+you may not use this file except in compliance with the License.
8
+You may obtain a copy of the License at
9
+
10
+	http://www.apache.org/licenses/LICENSE-2.0
11
+]]--
12
+
13
+local map, section, net = ...
14
+
15
+local server, username, password, cert, ca
16
+local oc_cert_file, oc_key_file, oc_ca_file
17
+
18
+local ifc = net:get_interface():name()
19
+
20
+oc_cert_file = "/etc/openconnect/user-cert-" .. ifc .. ".pem"
21
+oc_key_file = "/etc/openconnect/user-key-" .. ifc .. ".pem"
22
+oc_ca_file = "/etc/openconnect/ca-" .. ifc .. ".pem"
23
+
24
+server = section:taboption("general", Value, "server", translate("VPN Server"))
25
+server.datatype = "host"
26
+
27
+port = section:taboption("general", Value, "port", translate("VPN Server port"))
28
+port.placeholder = "443"
29
+port.datatype    = "port"
30
+
31
+section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
32
+
33
+section:taboption("general", Value, "authgroup", translate("AuthGroup"))
34
+
35
+username = section:taboption("general", Value, "username", translate("Username"))
36
+password = section:taboption("general", Value, "password", translate("Password"))
37
+password.password = true
38
+
39
+
40
+cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
41
+cert.template = "cbi/tvalue"
42
+cert.rows = 10
43
+
44
+function cert.cfgvalue(self, section)
45
+	return nixio.fs.readfile(oc_cert_file)
46
+end
47
+
48
+function cert.write(self, section, value)
49
+	value = value:gsub("\r\n?", "\n")
50
+	nixio.fs.writefile(oc_cert_file, value)
51
+end
52
+
53
+cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
54
+cert.template = "cbi/tvalue"
55
+cert.rows = 10
56
+
57
+function cert.cfgvalue(self, section)
58
+	return nixio.fs.readfile(oc_key_file)
59
+end
60
+
61
+function cert.write(self, section, value)
62
+	value = value:gsub("\r\n?", "\n")
63
+	nixio.fs.writefile(oc_key_file, value)
64
+end
65
+
66
+
67
+ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
68
+ca.template = "cbi/tvalue"
69
+ca.rows = 10
70
+
71
+function ca.cfgvalue(self, section)
72
+	return nixio.fs.readfile(oc_ca_file)
73
+end
74
+
75
+function ca.write(self, section, value)
76
+	value = value:gsub("\r\n?", "\n")
77
+	nixio.fs.writefile(oc_ca_file, value)
78
+end

+ 61
- 0
net/luci-proto-openconnect/files/usr/lib/lua/luci/model/network/proto_openconnect.lua Просмотреть файл

@@ -0,0 +1,61 @@
1
+--[[
2
+LuCI - Network model - dhcpv6 protocol extension
3
+
4
+Copyright 2012 David Woodhouse
5
+
6
+Licensed under the Apache License, Version 2.0 (the "License");
7
+you may not use this file except in compliance with the License.
8
+You may obtain a copy of the License at
9
+
10
+	http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+Unless required by applicable law or agreed to in writing, software
13
+distributed under the License is distributed on an "AS IS" BASIS,
14
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+See the License for the specific language governing permissions and
16
+limitations under the License.
17
+
18
+]]--
19
+
20
+local netmod = luci.model.network
21
+local interface = luci.model.network.interface
22
+local proto = netmod:register_protocol("openconnect")
23
+
24
+function proto.get_i18n(self)
25
+	return luci.i18n.translate("OpenConnect (CISCO AnyConnect)")
26
+end
27
+
28
+function proto.ifname(self)
29
+	return "vpn-" .. self.sid
30
+end
31
+
32
+function proto.get_interface(self)
33
+	return interface(self:ifname(), self)
34
+end
35
+
36
+function proto.opkg_package(self)
37
+	return "openconnect"
38
+end
39
+
40
+function proto.is_installed(self)
41
+	return nixio.fs.access("/lib/netifd/proto/openconnect.sh")
42
+end
43
+
44
+function proto.is_floating(self)
45
+	return true
46
+end
47
+
48
+function proto.is_virtual(self)
49
+	return true
50
+end
51
+
52
+function proto.get_interfaces(self)
53
+	return nil
54
+end
55
+
56
+function proto.contains_interface(self, ifc)
57
+	 return (netmod:ifnameof(ifc) == self:ifname())
58
+
59
+end
60
+
61
+netmod:register_pattern_virtual("^vpn-%w")