9cc5b18f7f92d03bacc13d84a540bf5b0a9767cb
[project/luci.git] / modules / admin-mini / luasrc / controller / mini / system.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 module("luci.controller.mini.system", package.seeall)
17
18 function index()
19 luci.i18n.loadc("admin-core")
20 local i18n = luci.i18n.translate
21
22 entry({"mini", "system"}, call("action_reboot"), i18n("system"))
23 entry({"mini", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw"), 10)
24 entry({"mini", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash"), 90)
25 entry({"mini", "system", "reboot"}, call("action_reboot"), i18n("reboot"), 100)
26 end
27
28 function action_reboot()
29 local reboot = luci.http.formvalue("reboot")
30 luci.template.render("mini/reboot", {reboot=reboot})
31 if reboot then
32 luci.sys.reboot()
33 end
34 end
35
36 function action_upgrade()
37 require("luci.model.uci")
38
39 local ret = nil
40 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
41 local tmpfile = "/tmp/firmware.img"
42
43 local file
44 luci.http.setfilehandler(
45 function(meta, chunk, eof)
46 if not file then
47 file = io.open(tmpfile, "w")
48 end
49 if chunk then
50 file:write(chunk)
51 end
52 if eof then
53 file:close()
54 end
55 end
56 )
57
58 local fname = luci.http.formvalue("image")
59 local keepcfg = luci.http.formvalue("keepcfg")
60
61 if plat and fname then
62 local kpattern = nil
63 if keepcfg then
64 local files = luci.model.uci.get_all("luci", "flash_keep")
65 if files.luci and files.luci.flash_keep then
66 kpattern = ""
67 for k,v in pairs(files.luci.flash_keep) do
68 kpattern = kpattern .. " " .. v
69 end
70 end
71 end
72 ret = luci.sys.flash(tmpfile, kpattern)
73 end
74
75 luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret})
76 end
77
78 function action_passwd()
79 local p1 = luci.http.formvalue("pwd1")
80 local p2 = luci.http.formvalue("pwd2")
81 local stat = nil
82
83 if p1 or p2 then
84 if p1 == p2 then
85 stat = luci.sys.user.setpasswd("root", p1)
86 else
87 stat = 10
88 end
89 end
90
91 luci.template.render("mini/passwd", {stat=stat})
92 end