diff --git a/package/ctcgfw/luci-app-diskman/Makefile b/package/ctcgfw/luci-app-diskman/Makefile index d040d9fd15..a790f30a55 100644 --- a/package/ctcgfw/luci-app-diskman/Makefile +++ b/package/ctcgfw/luci-app-diskman/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-diskman -PKG_VERSION:=v0.2.7 +PKG_VERSION:=v0.2.8 PKG_RELEASE:=beta PKG_MAINTAINER:=lisaac PKG_LICENSE:=AGPL-3.0 diff --git a/package/ctcgfw/luci-app-diskman/luasrc/controller/diskman.lua b/package/ctcgfw/luci-app-diskman/luasrc/controller/diskman.lua index 8ce5a93ab0..1d01b21979 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/controller/diskman.lua +++ b/package/ctcgfw/luci-app-diskman/luasrc/controller/diskman.lua @@ -25,12 +25,35 @@ function index() entry({"admin", "system", "diskman", "disks"}, form("diskman/disks"), nil).leaf = true entry({"admin", "system", "diskman", "partition"}, form("diskman/partition"), nil).leaf = true entry({"admin", "system", "diskman", "btrfs"}, form("diskman/btrfs"), nil).leaf = true + entry({"admin", "system", "diskman", "format_partition"}, call("format_partition"), nil).leaf = true entry({"admin", "system", "diskman", "get_disk_info"}, call("get_disk_info"), nil).leaf = true entry({"admin", "system", "diskman", "mk_p_table"}, call("mk_p_table"), nil).leaf = true entry({"admin", "system", "diskman", "smartdetail"}, call("smart_detail"), nil).leaf = true entry({"admin", "system", "diskman", "smartattr"}, call("smart_attr"), nil).leaf = true end +function format_partition() + local partation_name = luci.http.formvalue("partation_name") + local fs = luci.http.formvalue("file_system") + if not partation_name then + luci.http.status(500, "Partition NOT found!") + luci.http.write_json("Partition NOT found!") + return + elseif not nixio.fs.access("/dev/"..partation_name) then + luci.http.status(500, "Partition NOT found!") + luci.http.write_json("Partition NOT found!") + return + elseif not fs then + luci.http.status(500, "no file system") + luci.http.write_json("no file system") + return + end + local dm = require "luci.model.diskman" + code, msg = dm.format_partition(partation_name, fs) + luci.http.status(code, msg) + luci.http.write_json({msg}) +end + function get_disk_info(dev) if not dev then luci.http.status(500, "no device") diff --git a/package/ctcgfw/luci-app-diskman/luasrc/model/cbi/diskman/partition.lua b/package/ctcgfw/luci-app-diskman/luasrc/model/cbi/diskman/partition.lua index 02db76d13b..eb6220f8c3 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/model/cbi/diskman/partition.lua +++ b/package/ctcgfw/luci-app-diskman/luasrc/model/cbi/diskman/partition.lua @@ -183,69 +183,79 @@ if not disk_info.p_table:match("Raid") then end local val_fs = s_partition_table:option(Value, "fs", translate("File System")) val_fs.forcewrite = true + val_fs.partitions = disk_info.partitions + for k, v in pairs(format_cmd) do + val_fs.format_cmd = val_fs.format_cmd and (val_fs.format_cmd .. "," .. k) or k + end + val_fs.write = function(self, section, value) disk_info.partitions[section]._fs = value end val_fs.render = function(self, section, scope) -- use listvalue when partition not mounted if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then - self.template = "cbi/value" - self:reset_values() - self.keylist = {} - self.vallist = {} - for k, v in pairs(format_cmd) do - self:value(k,k) - end + self.template = "diskman/cbi/format_button" + self.inputstyle = "reset" + self.inputtitle = disk_info.partitions[section].fs:match("^%s+$") and "Format" or disk_info.partitions[section].fs + Button.render(self, section, scope) + -- self:reset_values() + -- self.keylist = {} + -- self.vallist = {} + -- for k, v in pairs(format_cmd) do + -- self:value(k,k) + -- end -- self.default = disk_info.partitions[section].fs else - self:reset_values() - self.keylist = {} - self.vallist = {} + -- self:reset_values() + -- self.keylist = {} + -- self.vallist = {} self.template = "cbi/dvalue" - end - DummyValue.render(self, section, scope) - end - btn_format = s_partition_table:option(Button, "_format") - btn_format.render = function(self, section, scope) - if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then - self.inputtitle = translate("Format") - self.template = "diskman/cbi/disabled_button" - self.view_disabled = false - self.inputstyle = "reset" - for k, v in pairs(format_cmd) do - self:depends("val_fs", "k") - end - -- elseif disk_info.partitions[section].mount_point ~= "-" and disk_info.partitions[section].number ~= -1 then - -- self.inputtitle = "Format" - -- self.template = "diskman/cbi/disabled_button" - -- self.view_disabled = true - -- self.inputstyle = "reset" - else - self.inputtitle = "" - self.template = "cbi/dvalue" - end - Button.render(self, section, scope) - end - btn_format.forcewrite = true - btn_format.write = function(self, section, value) - local partition_name = "/dev/".. disk_info.partitions[section].name - if not nixio.fs.access(partition_name) then - m.errmessage = translate("Partition NOT found!") - return - end - local fs = disk_info.partitions[section]._fs - if not format_cmd[fs] then - m.errmessage = translate("Filesystem NOT support!") - return - end - local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name - local res = luci.util.exec(cmd .. " 2>&1") - if res and res:lower():match("error+") then - m.errmessage = luci.util.pcdata(res) - else - luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev)) + DummyValue.render(self, section, scope) end end + -- btn_format = s_partition_table:option(Button, "_format") + -- btn_format.template = "diskman/cbi/format_button" + -- btn_format.partitions = disk_info.partitions + -- btn_format.render = function(self, section, scope) + -- if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then + -- self.inputtitle = translate("Format") + -- self.template = "diskman/cbi/disabled_button" + -- self.view_disabled = false + -- self.inputstyle = "reset" + -- for k, v in pairs(format_cmd) do + -- self:depends("val_fs", "k") + -- end + -- -- elseif disk_info.partitions[section].mount_point ~= "-" and disk_info.partitions[section].number ~= -1 then + -- -- self.inputtitle = "Format" + -- -- self.template = "diskman/cbi/disabled_button" + -- -- self.view_disabled = true + -- -- self.inputstyle = "reset" + -- else + -- self.inputtitle = "" + -- self.template = "cbi/dvalue" + -- end + -- Button.render(self, section, scope) + -- end + -- btn_format.forcewrite = true + -- btn_format.write = function(self, section, value) + -- local partition_name = "/dev/".. disk_info.partitions[section].name + -- if not nixio.fs.access(partition_name) then + -- m.errmessage = translate("Partition NOT found!") + -- return + -- end + -- local fs = disk_info.partitions[section]._fs + -- if not format_cmd[fs] then + -- m.errmessage = translate("Filesystem NOT support!") + -- return + -- end + -- local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name + -- local res = luci.util.exec(cmd .. " 2>&1") + -- if res and res:lower():match("error+") then + -- m.errmessage = luci.util.pcdata(res) + -- else + -- luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev)) + -- end + -- end local btn_action = s_partition_table:option(Button, "_action") btn_action.forcewrite = true diff --git a/package/ctcgfw/luci-app-diskman/luasrc/model/diskman.lua b/package/ctcgfw/luci-app-diskman/luasrc/model/diskman.lua index ffae464433..aa13440851 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/model/diskman.lua +++ b/package/ctcgfw/luci-app-diskman/luasrc/model/diskman.lua @@ -714,4 +714,23 @@ end return subvolume end +d.format_partition = function(partition, fs) + local partition_name = "/dev/".. partition + if not nixio.fs.access(partition_name) then + return 500, translate("Partition NOT found!") + end + + local format_cmd = d.get_format_cmd() + if not format_cmd[fs] then + return 500, translate("Filesystem NOT support!") + end + local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name + local res = luci.util.exec(cmd .. " 2>&1") + if res and res:lower():match("error+") then + return 500, res + else + return 200, "OK" + end +end + return d diff --git a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/disk_info.htm b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/disk_info.htm index 42e912d521..474a320b01 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/disk_info.htm +++ b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/disk_info.htm @@ -6,7 +6,7 @@ lines.forEach((item) => { let dev = item.id.match(/cbi-disk-(.*)/)[1] if (dev == "table") { return } - XHR.get('/cgi-bin/luci/admin/system/diskman/get_disk_info/' + dev, null, (x, disk_info) => { + XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => { // handle disk info item.childNodes.forEach((cell) => { if (cell && cell.attributes) { @@ -71,7 +71,7 @@ let dev = item.id.match(/cbi-_raid-(.*)/)[1] if (dev == "table") { return } console.log(dev) - XHR.get('/cgi-bin/luci/admin/system/diskman/get_disk_info/' + dev, null, (x, disk_info) => { + XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => { // handle raid info item.childNodes.forEach((cell) => { if (cell && cell.attributes) { diff --git a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/partition_info.htm b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/partition_info.htm index 746eb199dc..87edc99fcf 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/partition_info.htm +++ b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/partition_info.htm @@ -1,7 +1,59 @@ + \ No newline at end of file diff --git a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/smart_detail.htm b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/smart_detail.htm index dfb5be7e78..56a9139f0c 100644 --- a/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/smart_detail.htm +++ b/package/ctcgfw/luci-app-diskman/luasrc/view/diskman/smart_detail.htm @@ -9,7 +9,6 @@ xhr.onload = function () { let st = JSON.parse(xhr.responseText) let tb = document.getElementById('smart_attr_table'); - console.log(st) if (st && tb) { /* clear all rows */ while (tb.rows.length > 1)