summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-aria2/luasrc/controller
diff options
context:
space:
mode:
authorXingwang Liao <kuoruan@gmail.com>2019-03-29 17:09:37 +0800
committerXingwang Liao <kuoruan@gmail.com>2019-07-01 14:28:54 +0800
commitf90de782a758ad1c702e2ae9403e415d8592eac5 (patch)
tree0412c837b306840342f9aff8f85b3c33c2c9cb14 /applications/luci-app-aria2/luasrc/controller
parent9a979e6db5de1c268dfd35099e58187439919df9 (diff)
luci-app-aria2: Refactor, new views and more options
This commit contains: * Refactor package code. * Add options for RPC, HTTP/HTTPS and BT. * Improve descriptions for some options. * New views for config files and log files. * Also updated translation for simplified Chinese. Signed-off-by: Xingwang Liao <kuoruan@gmail.com>
Diffstat (limited to 'applications/luci-app-aria2/luasrc/controller')
-rw-r--r--applications/luci-app-aria2/luasrc/controller/aria2.lua66
1 files changed, 42 insertions, 24 deletions
diff --git a/applications/luci-app-aria2/luasrc/controller/aria2.lua b/applications/luci-app-aria2/luasrc/controller/aria2.lua
index 56172ec1dd..4891727a08 100644
--- a/applications/luci-app-aria2/luasrc/controller/aria2.lua
+++ b/applications/luci-app-aria2/luasrc/controller/aria2.lua
@@ -1,15 +1,11 @@
---[[
-LuCI - Lua Configuration Interface - aria2 support
+-- Copyright 2016-2019 Xingwang Liao <kuoruan@gmail.com>
+-- Licensed to the public under the MIT License.
-Copyright 2014-2015 nanpuyue <nanpuyue@gmail.com>
-Modified by kuoruan <kuoruan@gmail.com>
-
-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
-]]--
+local fs = require "nixio.fs"
+local sys = require "luci.sys"
+local http = require "luci.http"
+local util = require "luci.util"
+local uci = require "luci.model.uci".cursor()
module("luci.controller.aria2", package.seeall)
@@ -18,26 +14,48 @@ function index()
return
end
- local page = entry({"admin", "services", "aria2"}, cbi("aria2"), _("Aria2 Settings"))
- page.dependent = true
+ entry({"admin", "services", "aria2"},
+ firstchild(), _("Aria2")).dependent = false
- entry({"admin", "services", "aria2", "status"}, call("status")).leaf = true
+ entry({"admin", "services", "aria2", "config"},
+ cbi("aria2/config"), _("Configuration"), 1)
-end
+ entry({"admin", "services", "aria2", "file"},
+ form("aria2/files"), _("Files"), 2)
+
+ entry({"admin", "services", "aria2", "log"},
+ firstchild(), _("Log"), 3)
-function status()
- local sys = require "luci.sys"
- local ipkg = require "luci.model.ipkg"
- local http = require "luci.http"
- local uci = require "luci.model.uci".cursor()
+ entry({"admin", "services", "aria2", "log", "view"},
+ template("aria2/log_template"))
+
+ entry({"admin", "services", "aria2", "log", "read"},
+ call("action_log_read"))
+
+ entry({"admin", "services", "aria2", "status"},
+ call("action_status"))
+
+end
+function action_status()
local status = {
- running = (sys.call("pidof aria2c > /dev/null") == 0),
- yaaw = ipkg.installed("yaaw"),
- webui = ipkg.installed("webui-aria2"),
- ariang = (ipkg.installed("ariang") or ipkg.installed("ariang-nginx"))
+ running = (sys.call("pidof aria2c >/dev/null") == 0)
}
http.prepare_content("application/json")
http.write_json(status)
end
+
+function action_log_read()
+ local data = { log = "", syslog = "" }
+
+ local log_file = uci:get("aria2", "main", "log") or "/var/log/aria2.log"
+ if fs.access(log_file) then
+ data.log = util.trim(sys.exec("tail -n 50 %s | sed 'x;1!H;$!d;x'" % log_file))
+ end
+
+ data.syslog = util.trim(sys.exec("logread | grep aria2 | tail -n 50 | sed 'x;1!H;$!d;x'"))
+
+ http.prepare_content("application/json")
+ http.write_json(data)
+end