Update my email addresses in the license headers
[project/luci.git] / modules / luci-mod-freifunk / luasrc / controller / freifunk / remote_update.lua
1 -- Copyright 2009 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.controller.freifunk.remote_update", package.seeall)
5
6 function index()
7 if not nixio.fs.access("/usr/sbin/remote-update") then
8 return
9 end
10
11 entry({"admin", "system", "remote_update"}, call("act_remote_update"),
12 _("Freifunk Remote Update"), 90)
13 end
14
15 function act_remote_update()
16 if luci.http.formvalue("flash") == "1" then
17 if luci.http.formvalue("confirm") == "1" then
18 local nobackup = ( luci.http.formvalue("keepcfg") ~= "1" )
19 local noverify = ( luci.http.formvalue("verify") ~= "1" )
20
21 luci.http.redirect("/luci-static/flashing.html")
22
23 os.execute("start-stop-daemon -S -b -x /usr/sbin/remote-update -- %s%s-s 5 -y" % {
24 noverify and "-v " or "",
25 nobackup and "-n " or ""
26 })
27 else
28 luci.template.render("freifunk/remote_update", {confirm=1})
29 end
30 else
31 local fd = io.popen("remote-update -c")
32 local update = { }
33
34 if fd then
35 while true do
36 local ln=fd:read("*l")
37
38 if not ln then break
39 elseif ln:find("Local: ") then update.locvar = ln:match("Local: (%d+)")
40 elseif ln:find("Remote: ") then update.remver = ln:match("Remote: (%d+)")
41 elseif ln == "--" then update.info = ""
42 elseif update.info ~= nil then
43 update.info = update.info .. ln .. "\n"
44 end
45 end
46
47 fd:close()
48 end
49
50 luci.template.render("freifunk/remote_update", {update=update})
51 end
52 end