luci-app-aria2: Refactor, new views and more options
[project/luci.git] / applications / luci-app-aria2 / luasrc / model / cbi / aria2 / files.lua
1 -- Copyright 2017-2019 Xingwang Liao <kuoruan@gmail.com>
2 -- Licensed to the public under the MIT License.
3
4 local m, s, o
5
6 local fs = require "nixio.fs"
7 local util = require "luci.util"
8 local uci = require "luci.model.uci".cursor()
9
10 local config_dir = uci:get("aria2", "main", "config_dir") or "/var/etc/aria2"
11 local config_file = "%s/aria2.conf.main" % config_dir
12 local session_file = "%s/aria2.session.main" % config_dir
13
14 m = SimpleForm("aria2", "%s - %s" % { translate("Aria2"), translate("Files") },
15 translate("Here shows the files used by aria2."))
16 m.reset = false
17 m.submit = false
18
19 s = m:section(SimpleSection, nil, translatef("Content of config file: <code>%s</code>", config_file))
20
21 o = s:option(TextValue, "_config")
22 o.rows = 20
23 o.readonly = true
24 o.cfgvalue = function()
25 local v = fs.readfile(config_file) or translate("File does not exist.")
26 return util.trim(v) ~= "" and v or translate("Empty file.")
27 end
28
29 s = m:section(SimpleSection, nil, translatef("Content of session file: <code>%s</code>", session_file))
30
31 o = s:option(TextValue, "_session")
32 o.rows = 20
33 o.readonly = true
34 o.cfgvalue = function()
35 local v = fs.readfile(session_file) or translate("File does not exist.")
36 return util.trim(v) ~= "" and v or translate("Empty file.")
37 end
38
39 return m