cjdns: support the supernodes feature (#884)
[feed/routing.git] / luci-app-cjdns / luasrc / model / cbi / cjdns / peering.lua
1 uci = require "luci.model.uci"
2 cursor = uci:cursor_state()
3
4 cjdns = require("cjdns")
5 require("cjdns/uci")
6
7 m = Map("cjdns", translate("cjdns"),
8 translate("Implements an encrypted IPv6 network using public-key \
9 cryptography for address allocation and a distributed hash table for \
10 routing. This provides near-zero-configuration networking, and prevents \
11 many of the security and scalability issues that plague existing \
12 networks."))
13
14 m.on_after_commit = function(self)
15 os.execute("/etc/init.d/cjdns restart")
16 end
17
18 -- Authorized Passwords
19 passwords = m:section(TypedSection, "password", translate("Authorized Passwords"),
20 translate("Anyone offering one of the these passwords will be allowed to peer with you on the existing UDP and Ethernet interfaces."))
21 passwords.anonymous = true
22 passwords.addremove = true
23 passwords.template = "cbi/tblsection"
24
25 passwords:option(Value, "user", translate("User/Name"),
26 translate("Must be unique.")
27 ).default = "user-" .. cjdns.uci.random_string(6)
28 passwords:option(Value, "contact", translate("Contact"), translate("Optional, for out-of-band communication."))
29 passwords:option(Value, "password", translate("Password"),
30 translate("Hand out to your peer, in accordance with the peering best practices of the network.")
31 ).default = cjdns.uci.random_string(32)
32
33 -- UDP Peers
34 udp_peers = m:section(TypedSection, "udp_peer", translate("Outgoing UDP Peers"),
35 translate("For peering via public IP networks, the peer handed you their Public Key and IP address/port along with a password. IPv6 addresses should be entered with square brackets, like so: <code>[2001::1]</code>."))
36 udp_peers.anonymous = true
37 udp_peers.addremove = true
38 udp_peers.template = "cbi/tblsection"
39 udp_peers:option(Value, "user", translate("User/Name")).datatype = "string"
40
41 udp_interface = udp_peers:option(Value, "interface", translate("UDP interface"))
42 local index = 1
43 for i,section in pairs(cursor:get_all("cjdns")) do
44 if section[".type"] == "udp_interface" then
45 udp_interface:value(index, section.address .. ":" .. section.port)
46 end
47 end
48 udp_interface.default = 1
49 udp_peers:option(Value, "address", translate("IP address"))
50 udp_peers:option(Value, "port", translate("Port")).datatype = "portrange"
51 udp_peers:option(Value, "public_key", translate("Public key"))
52 udp_peers:option(Value, "password", translate("Password"))
53
54 -- Ethernet Peers
55 eth_peers = m:section(TypedSection, "eth_peer", translate("Outgoing Ethernet Peers"),
56 translate("For peering via local Ethernet networks, the peer handed you their Public Key and MAC address along with a password."))
57 eth_peers.anonymous = true
58 eth_peers.addremove = true
59 eth_peers.template = "cbi/tblsection"
60
61 eth_interface = eth_peers:option(Value, "interface", translate("Ethernet interface"))
62 local index = 1
63 for i,section in pairs(cursor:get_all("cjdns")) do
64 if section[".type"] == "eth_interface" then
65 eth_interface:value(index, section.bind)
66 end
67 end
68 eth_interface.default = 1
69 eth_peers:option(Value, "address", translate("MAC address")).datatype = "macaddr"
70 eth_peers:option(Value, "public_key", translate("Public key"))
71 eth_peers:option(Value, "password", translate("Password"))
72
73 -- Supernodes
74 supernodes = m:section(TypedSection, "supernodes", translate("List of Supernodes"),
75 translate("If none are specified they'll be taken from your peers"))
76 supernodes.anonymous = true
77 supernodes.addremove = true
78 supernodes.template = "cbi/tblsection"
79
80 supernodes:option(Value, "public_key", translate("Public Key")).size = 55
81
82 return m