modules/admin-full: hide system software tab if opkg is not present
[project/luci.git] / modules / admin-full / luasrc / controller / admin / system.lua
index 8c28cf9..f5b6b14 100644 (file)
@@ -12,31 +12,34 @@ You may obtain a copy of the License at
 
 $Id$
 ]]--
+
 module("luci.controller.admin.system", package.seeall)
 
 function index()
-       luci.i18n.loadc("base")
-       local i18n = luci.i18n.translate
+       entry({"admin", "system"}, alias("admin", "system", "system"), _("System"), 30).index = true
+       entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1)
+       entry({"admin", "system", "admin"}, cbi("admin_system/admin"), _("Administration"), 2)
+
+       if nixio.fs.access("/bin/opkg") then
+               entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10)
+               entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg"))
+       end
 
-       entry({"admin", "system"}, alias("admin", "system", "system"), i18n("System"), 30).index = true
-       entry({"admin", "system", "system"}, cbi("admin_system/system"), i18n("System"), 1)
-       entry({"admin", "system", "packages"}, call("action_packages"), i18n("Software"), 10)
-       entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg"))
-       entry({"admin", "system", "passwd"}, form("admin_system/passwd"), i18n("Admin Password"), 20)
-       entry({"admin", "system", "sshkeys"}, form("admin_system/sshkeys"), i18n("<abbr title=\"Secure Shell\">SSH</abbr>-Keys"), 30)
-       entry({"admin", "system", "processes"}, form("admin_system/processes"), i18n("Processes"), 45)
+       entry({"admin", "system", "startup"}, form("admin_system/startup"), _("Startup"), 45)
 
        if nixio.fs.access("/etc/config/fstab") then
-               entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("Mount Points"), 50)
+               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
-               entry({"admin", "system", "leds"}, cbi("admin_system/leds"), i18n("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60)
+               entry({"admin", "system", "leds"}, cbi("admin_system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60)
        end
 
-       entry({"admin", "system", "backup"}, call("action_backup"), i18n("Backup / Restore"), 70)
-       entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("Flash Firmware"), 80)
-       entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("Reboot"), 90)
+       entry({"admin", "system", "backup"}, call("action_backup"), _("Backup / Restore"), 70)
+       entry({"admin", "system", "upgrade"}, call("action_upgrade"), _("Flash Firmware"), 80)
+       entry({"admin", "system", "reboot"}, call("action_reboot"), _("Reboot"), 90)
 end
 
 function action_packages()
@@ -45,6 +48,9 @@ function action_packages()
        local changes = false
        local install = { }
        local remove  = { }
+       local stdout  = { "" }
+       local stderr  = { "" }
+       local out, err
 
        -- Search query
        local query = luci.http.formvalue("query")
@@ -63,19 +69,25 @@ function action_packages()
 
        -- Do install
        if ninst then
-               _, install[ninst] = ipkg.install(ninst)
+               install[ninst], out, err = ipkg.install(ninst)
+               stdout[#stdout+1] = out
+               stderr[#stderr+1] = err
                changes = true
        end
 
        if uinst then
-               _, install[uinst] = ipkg.install(uinst)
+               install[uinst], out, err = ipkg.install(uinst)
+               stdout[#stdout+1] = out
+               stderr[#stderr+1] = err
                changes = true
        end
 
        -- Remove packets
        local rem = submit and luci.http.formvalue("remove")
        if rem then
-               _, remove[rem] = ipkg.remove(rem)
+               remove[rem], out, err = ipkg.remove(rem)
+               stdout[#stdout+1] = out
+               stderr[#stderr+1] = err
                changes = true
        end
 
@@ -83,19 +95,29 @@ function action_packages()
        -- Update all packets
        local update = luci.http.formvalue("update")
        if update then
-               _, update = ipkg.update()
+               update, out, err = ipkg.update()
+               stdout[#stdout+1] = out
+               stderr[#stderr+1] = err
        end
 
 
        -- Upgrade all packets
        local upgrade = luci.http.formvalue("upgrade")
        if upgrade then
-               _, upgrade = ipkg.upgrade()
+               upgrade, out, err = ipkg.upgrade()
+               stdout[#stdout+1] = out
+               stderr[#stderr+1] = err
        end
 
 
        luci.template.render("admin_system/packages", {
-               query=query, install=install, remove=remove, update=update, upgrade=upgrade
+               query   = query,
+               install = install,
+               remove  = remove,
+               update  = update,
+               upgrade = upgrade,
+               stdout  = table.concat(stdout, ""),
+               stderr  = table.concat(stderr, "")
        })
 
        -- Remove index cache
@@ -105,9 +127,12 @@ function action_packages()
 end
 
 function action_backup()
+       local sys = require "luci.sys"
+       local fs  = require "luci.fs"
+
        local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
        local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
-       local backup_cmd  = "tar -cz %s 2>/dev/null"
+       local backup_cmd  = "tar -czT %s 2>/dev/null"
 
        local restore_fpi
        luci.http.setfilehandler(
@@ -132,11 +157,22 @@ function action_backup()
                luci.template.render("admin_system/applyreboot")
                luci.sys.reboot()
        elseif backup then
-               local reader = ltn12_popen(backup_cmd:format(_keep_pattern()))
-               luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' % {
-                       luci.sys.hostname(), os.date("%Y-%m-%d")})
-               luci.http.prepare_content("application/x-targz")
-               luci.ltn12.pump.all(reader, luci.http.write)
+               local filelist = "/tmp/luci-backup-list.%d" % os.time()
+
+               sys.call(
+                       "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
+                       "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
+                       "opkg list-changed-conffiles ) | sort -u > %s" % filelist
+               )
+
+               if fs.access(filelist) then
+                       local reader = ltn12_popen(backup_cmd:format(filelist))
+                       luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' % {
+                               luci.sys.hostname(), os.date("%Y-%m-%d")})
+                       luci.http.prepare_content("application/x-targz")
+                       luci.ltn12.pump.all(reader, luci.http.write)
+                       fs.unlink(filelist)
+               end
        elseif reset then
                luci.template.render("admin_system/applyreboot")
                luci.util.exec("mtd -r erase rootfs_data")
@@ -249,8 +285,9 @@ function action_upgrade()
 
                        -- Now invoke sysupgrade
                        local keepcfg = keep_avail and luci.http.formvalue("keepcfg") == "1"
-                       --local flash = ltn12_popen("/sbin/sysupgrade %q" % tmpfile)
-                       local flash = ltn12_popen("hexdump %q" % tmpfile)
+                       local flash = ltn12_popen("/sbin/sysupgrade %s %q" %{
+                               keepcfg and "" or "-n", tmpfile
+                       })
 
                        luci.ltn12.pump.all(flash, luci.http.write)
                end