luci-mod-admin-full: switch to POST action for reboot
[project/luci.git] / modules / luci-mod-admin-full / luasrc / controller / admin / system.lua
index 5fa4c3a..64af555 100644 (file)
@@ -1,28 +1,19 @@
---[[
-LuCI - Lua Configuration Interface
-
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-]]--
+-- Copyright 2008 Steven Barth <steven@midlink.org>
+-- Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
+-- Licensed to the public under the Apache License 2.0.
 
 module("luci.controller.admin.system", package.seeall)
 
 function index()
+       local fs = require "nixio.fs"
+
        entry({"admin", "system"}, alias("admin", "system", "system"), _("System"), 30).index = true
        entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1)
        entry({"admin", "system", "clock_status"}, call("action_clock_status"))
 
        entry({"admin", "system", "admin"}, cbi("admin_system/admin"), _("Administration"), 2)
 
-       if nixio.fs.access("/bin/opkg") then
+       if fs.access("/bin/opkg") then
                entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10)
                entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg"))
        end
@@ -30,20 +21,21 @@ function index()
        entry({"admin", "system", "startup"}, form("admin_system/startup"), _("Startup"), 45)
        entry({"admin", "system", "crontab"}, form("admin_system/crontab"), _("Scheduled Tasks"), 46)
 
-       if nixio.fs.access("/etc/config/fstab") then
+       if fs.access("/sbin/block") then
                entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), _("Mount Points"), 50)
                entry({"admin", "system", "fstab", "mount"}, cbi("admin_system/fstab/mount"), nil).leaf = true
                entry({"admin", "system", "fstab", "swap"},  cbi("admin_system/fstab/swap"),  nil).leaf = true
        end
 
-       if nixio.fs.access("/sys/class/leds") then
+       if fs.access("/sys/class/leds") then
                entry({"admin", "system", "leds"}, cbi("admin_system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60)
        end
 
        entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70)
        entry({"admin", "system", "flashops", "backupfiles"}, form("admin_system/backupfiles"))
 
-       entry({"admin", "system", "reboot"}, call("action_reboot"), _("Reboot"), 90)
+       entry({"admin", "system", "reboot"}, template("admin_system/reboot"), _("Reboot"), 90)
+       entry({"admin", "system", "reboot", "call"}, post("action_reboot"))
 end
 
 function action_clock_status()
@@ -62,7 +54,8 @@ function action_clock_status()
 end
 
 function action_packages()
-       local ipkg = require("luci.model.ipkg")
+       local fs = require "nixio.fs"
+       local ipkg = require "luci.model.ipkg"
        local submit = luci.http.formvalue("submit")
        local changes = false
        local install = { }
@@ -142,12 +135,11 @@ function action_packages()
        -- List state
        local no_lists = true
        local old_lists = false
-       local tmp = nixio.fs.dir("/var/opkg-lists/")
-       if tmp then
-               for tmp in tmp do
+       if fs.access("/var/opkg-lists/") then
+               local list
+               for list in fs.dir("/var/opkg-lists/") do
                        no_lists = false
-                       tmp = nixio.fs.stat("/var/opkg-lists/"..tmp)
-                       if tmp and tmp.mtime < (os.time() - (24 * 60 * 60)) then
+                       if (fs.stat("/var/opkg-lists/"..list, "mtime") or 0) < (os.time() - (24 * 60 * 60)) then
                                old_lists = true
                                break
                        end
@@ -171,15 +163,15 @@ function action_packages()
 
        -- Remove index cache
        if changes then
-               nixio.fs.unlink("/tmp/luci-indexcache")
+               fs.unlink("/tmp/luci-indexcache")
        end
 end
 
 function action_flashops()
        local sys = require "luci.sys"
-       local fs  = require "luci.fs"
+       local fs  = require "nixio.fs"
 
-       local upgrade_avail = nixio.fs.access("/lib/upgrade/platform.sh")
+       local upgrade_avail = fs.access("/lib/upgrade/platform.sh")
        local reset_avail   = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
 
        local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
@@ -187,13 +179,7 @@ function action_flashops()
        local image_tmp   = "/tmp/firmware.img"
 
        local function image_supported()
-               -- XXX: yay...
-               return ( 0 == os.execute(
-                       ". /lib/functions.sh; " ..
-                       "include /lib/upgrade; " ..
-                       "platform_check_image %q >/dev/null"
-                               % image_tmp
-               ) )
+               return (os.execute("sysupgrade -T %q >/dev/null" % image_tmp) == 0)
        end
 
        local function image_checksum()
@@ -202,7 +188,7 @@ function action_flashops()
 
        local function storage_size()
                local size = 0
-               if nixio.fs.access("/proc/mtd") then
+               if fs.access("/proc/mtd") then
                        for l in io.lines("/proc/mtd") do
                                local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"')
                                if n == "linux" or n == "firmware" then
@@ -210,7 +196,7 @@ function action_flashops()
                                        break
                                end
                        end
-               elseif nixio.fs.access("/proc/partitions") then
+               elseif fs.access("/proc/partitions") then
                        for l in io.lines("/proc/partitions") do
                                local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)')
                                if b and n and not n:match('[0-9]') then
@@ -270,11 +256,11 @@ function action_flashops()
                                luci.template.render("admin_system/upgrade", {
                                        checksum = image_checksum(),
                                        storage  = storage_size(),
-                                       size     = nixio.fs.stat(image_tmp).size,
+                                       size     = (fs.stat(image_tmp, "size") or 0),
                                        keep     = (not not luci.http.formvalue("keep"))
                                })
                        else
-                               nixio.fs.unlink(image_tmp)
+                               fs.unlink(image_tmp)
                                luci.template.render("admin_system/flashops", {
                                        reset_avail   = reset_avail,
                                        upgrade_avail = upgrade_avail,
@@ -331,11 +317,7 @@ function action_passwd()
 end
 
 function action_reboot()
-       local reboot = luci.http.formvalue("reboot")
-       luci.template.render("admin_system/reboot", {reboot=reboot})
-       if reboot then
-               luci.sys.reboot()
-       end
+       luci.sys.reboot()
 end
 
 function fork_exec(command)