1 module("luci.controller.cjdns", package.seeall)
3 cjdns = require "cjdns/init"
4 dkjson = require "dkjson"
7 if not nixio.fs.access("/etc/config/cjdns") then
11 entry({"admin", "services", "cjdns"},
12 cbi("cjdns/overview"), _("cjdns")).dependent = true
14 entry({"admin", "services", "cjdns", "overview"},
15 cbi("cjdns/overview"), _("Overview"), 1).leaf = false
17 entry({"admin", "services", "cjdns", "peering"},
18 cbi("cjdns/peering"), _("Peers"), 2).leaf = false
20 entry({"admin", "services", "cjdns", "iptunnel"},
21 cbi("cjdns/iptunnel"), _("IP Tunnel"), 3).leaf = false
23 entry({"admin", "services", "cjdns", "settings"},
24 cbi("cjdns/settings"), _("Settings"), 4).leaf = false
26 entry({"admin", "services", "cjdns", "cjdrouteconf"},
27 cbi("cjdns/cjdrouteconf"), _("cjdroute.conf"), 5).leaf = false
29 entry({"admin", "services", "cjdns", "peers"}, call("act_peers")).leaf = true
30 entry({"admin", "services", "cjdns", "ping"}, call("act_ping")).leaf = true
35 admin = cjdns.uci.makeInterface()
41 local response, err = admin:auth({
42 q = "InterfaceController_peerStats",
46 if err or response.error then
47 luci.http.status(502, "Bad Gateway")
48 luci.http.prepare_content("application/json")
49 luci.http.write_json({ err = err, response = response })
53 for i,peer in pairs(response.peers) do
54 peer.ipv6 = publictoip6(peer.publicKey)
55 if peer.user == nil then
57 uci.cursor():foreach("cjdns", "udp_peer", function(udp_peer)
58 if peer.publicKey == udp_peer.public_key then
59 peer.user = udp_peer.user
63 peers[#peers + 1] = peer
73 luci.http.status(200, "OK")
74 luci.http.prepare_content("application/json")
75 luci.http.write_json(peers)
80 admin = cjdns.uci.makeInterface()
82 local response, err = admin:auth({
83 q = "SwitchPinger_ping",
84 path = luci.http.formvalue("label"),
85 timeout = tonumber(luci.http.formvalue("timeout"))
88 if err or response.error then
89 luci.http.status(502, "Bad Gateway")
90 luci.http.prepare_content("application/json")
91 luci.http.write_json({ err = err, response = response })
95 luci.http.status(200, "OK")
96 luci.http.prepare_content("application/json")
97 luci.http.write_json(response)
100 function publictoip6(publicKey)
101 local process = io.popen("/usr/bin/publictoip6 " .. publicKey, "r")
102 local ipv6 = process:read()