modules/freifunk: add webpages for remote-update
[project/luci.git] / modules / freifunk / luasrc / controller / freifunk / remote_update.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2009 Jo-Philipp Wich <xm@subsignal.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 $Id: freifunk.lua 4649 2009-05-26 18:30:00Z jow $
13 ]]--
14
15 local nixio = require "nixio"
16
17 module("luci.controller.freifunk.remote_update", package.seeall)
18
19 function index()
20 local i18n = luci.i18n.translate
21
22 entry({"admin", "system", "remote_update"}, call("act_remote_update"),
23 i18n("ff_remote_update", "Freifunk Remote Update"), 90)
24 end
25
26 function act_remote_update()
27 if luci.http.formvalue("flash") == "1" then
28 if luci.http.formvalue("confirm") == "1" then
29 local nobackup = ( luci.http.formvalue("keepcfg") ~= "1" )
30 local noverify = ( luci.http.formvalue("verify") ~= "1" )
31
32 luci.http.redirect("/luci-static/flashing.html")
33
34 os.execute("start-stop-daemon -S -b -x /usr/sbin/remote-update -- %s%s-s 5 -y" % {
35 noverify and "-v " or "",
36 nobackup and "-n " or ""
37 })
38 else
39 luci.template.render("freifunk/remote_update", {confirm=1})
40 end
41 else
42 local fd = io.popen("remote-update -c")
43 local update = { }
44
45 if fd then
46 while true do
47 local ln=fd:read("*l")
48
49 if not ln then break
50 elseif ln:find("Local: ") then update.locvar = ln:match("Local: (%d+)")
51 elseif ln:find("Remote: ") then update.remver = ln:match("Remote: (%d+)")
52 elseif ln == "--" then update.info = ""
53 elseif update.info ~= nil then
54 update.info = update.info .. ln .. "\n"
55 end
56 end
57
58 fd:close()
59 end
60
61 luci.template.render("freifunk/remote_update", {update=update})
62 end
63 end