diff options
author | Hsing-Wang Liao <kuoruan@gmail.com> | 2016-05-30 14:30:47 +0800 |
---|---|---|
committer | Hsing-Wang Liao <kuoruan@gmail.com> | 2016-05-30 21:27:22 +0800 |
commit | c88aea6277ce7242217eda6115a44f6fedb49e56 (patch) | |
tree | 1a26880f21f79573ed9f96f44e00b69ad9adc6b4 /applications/luci-app-aria2 | |
parent | c46963613f7f1312dac62e507346777ba6f8d8a6 (diff) |
luci-app-aria2: Add package
LuCI Support for Aria2
Signed-off-by: Hsing-Wang Liao <kuoruan@gmail.com>
Diffstat (limited to 'applications/luci-app-aria2')
-rw-r--r-- | applications/luci-app-aria2/Makefile | 15 | ||||
-rw-r--r-- | applications/luci-app-aria2/luasrc/controller/aria2.lua | 42 | ||||
-rw-r--r-- | applications/luci-app-aria2/luasrc/model/cbi/aria2.lua | 196 | ||||
-rw-r--r-- | applications/luci-app-aria2/luasrc/view/aria2/web_script.htm | 77 | ||||
-rw-r--r-- | applications/luci-app-aria2/po/templates/aria2.po | 176 | ||||
-rw-r--r-- | applications/luci-app-aria2/po/zh-cn/aria2.po | 176 | ||||
-rwxr-xr-x | applications/luci-app-aria2/root/etc/uci-defaults/40_luci-aria2 | 11 |
7 files changed, 693 insertions, 0 deletions
diff --git a/applications/luci-app-aria2/Makefile b/applications/luci-app-aria2/Makefile new file mode 100644 index 000000000..0179f04f4 --- /dev/null +++ b/applications/luci-app-aria2/Makefile @@ -0,0 +1,15 @@ +# +# Copyright (C) 2016 Openwrt.org +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI Support for Aria2 +LUCI_DEPENDS:=+aria2 + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/applications/luci-app-aria2/luasrc/controller/aria2.lua b/applications/luci-app-aria2/luasrc/controller/aria2.lua new file mode 100644 index 000000000..17289305d --- /dev/null +++ b/applications/luci-app-aria2/luasrc/controller/aria2.lua @@ -0,0 +1,42 @@ +--[[ +LuCI - Lua Configuration Interface - aria2 support + +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 +]]-- + +module("luci.controller.aria2", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/aria2") then + return + end + + local page = entry({"admin", "services", "aria2"}, cbi("aria2"), _("Aria2 Settings")) + page.dependent = true + + entry({"admin", "services", "aria2", "status"}, call("status")).leaf = true + +end + +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() + + local status = { + running = (sys.call("pidof aria2c > /dev/null") == 0), + yaaw = ipkg.installed("yaaw"), + webui = ipkg.installed("webui-aria2") + } + + http.prepare_content("application/json") + http.write_json(status) +end diff --git a/applications/luci-app-aria2/luasrc/model/cbi/aria2.lua b/applications/luci-app-aria2/luasrc/model/cbi/aria2.lua new file mode 100644 index 000000000..780aea33d --- /dev/null +++ b/applications/luci-app-aria2/luasrc/model/cbi/aria2.lua @@ -0,0 +1,196 @@ +--[[ +LuCI - Lua Configuration Interface - Aria2 support + +Copyright 2014-2016 nanpuyue <nanpuyue@gmail.com> +Modified by maz-1 <ohmygod19993@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 sys = require "luci.sys" +local util = require "luci.util" +local uci = require "luci.model.uci".cursor() + +local cfgbtn = "<input type=\"button\" value=\"" .. translate("Generate Randomly") .. "\" onclick=\"randomSecret(32);\" />" +local sessionbtn = "<input class=\"cbi-button mar-10\" type=\"button\" value=\"" .. translate("View Json-RPC URL") .. "\" onclick=\"showRPCURL();\" />" +local aria2rpctxt = "<input class=\"mar-10\" id=\"aria2rpcpath\" onmouseover=\"obj=document.getElementById(this.id);obj.focus();obj.select()\" />" +local use_websocket = "<input id=\"use_websocket\" type=\"checkbox\" /><label for=\"use_websocket\">" .. translate("Use WebSocket") .. "</label>" + +function ipkg_ver(pkg) + local version = nil + local control = io.open("/usr/lib/opkg/info/%s.control" % pkg, "r") + if control then + local ln + repeat + ln = control:read("*l") + if ln and ln:match("^Version: ") then + version = ln:gsub("^Version: ", ""):gsub("-%d", "") + break + end + until not ln + control:close() + end + return version +end + +function ipkg_ver_lined(pkg) + return ipkg_ver(pkg):gsub("%.", "-") +end + +m = Map("aria2", translate("Aria2"), translate("Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings.")) + +m:section(SimpleSection).template = "aria2/web_script" + +s = m:section(TypedSection, "aria2", translate("Aria2 Settings")) +s.addremove = false +s.anonymous = true + +s:tab("general", translate("General Settings")) +s:tab("file", translate("Files and Locations")) +s:tab("task", translate("Task Settings")) +s:tab("bittorrent", translate("BitTorrent Settings")) + +o = s:taboption("general", Flag, "enabled", translate("Enabled")) +o.rmempty = false + +user = s:taboption("general", ListValue, "user", translate("Run daemon as user")) +local p_user +for _, p_user in util.vspairs(util.split(sys.exec("cat /etc/passwd | cut -f 1 -d :"))) do + user:value(p_user) +end + +o = s:taboption("general", Value, "rpc_listen_port", translate("RPC port")) +o.datatype = "port" +o.placeholder = "6800" + +rpc_auth_method = s:taboption("general", ListValue, "rpc_auth_method", translate("RPC authentication method")) +rpc_auth_method:value("none", translate("No Authentication")) +rpc_auth_method:value("user_pass", translate("Username & Password")) +rpc_auth_method:value("token", translate("Token")) + +o = s:taboption("general", Value, "rpc_user", translate("RPC username")) +o:depends("rpc_auth_method", "user_pass") +o.rmempty = false + +o = s:taboption("general", Value, "rpc_passwd", translate("RPC password")) +o:depends("rpc_auth_method", "user_pass") +o.password = true +o.rmempty = false + +o = s:taboption("general", Value, "rpc_secret", translate("RPC Token"), "<br/>" .. cfgbtn) +o:depends("rpc_auth_method", "token") +o.rmempty = false + +o = s:taboption("file", Value, "config_dir", translate("Config file directory")) +o.placeholder = "/var/etc/aria2" + +o = s:taboption("file", Value, "dir", translate("Default download directory")) +o.rmempty = false + +s:taboption("file", Value, "disk_cache", translate("Disk cache"), translate("in bytes, You can append K or M.")) + +o = s:taboption("file", ListValue, "file_allocation", translate("Preallocation"), translate("\"Falloc\" is not available in all cases.")) +o:value("none", translate("Off")) +o:value("prealloc", translate("Prealloc")) +o:value("trunc", translate("Trunc")) +o:value("falloc", translate("Falloc")) + +overall_speed_limit = s:taboption("task", Flag, "overall_speed_limit", translate("Overall speed limit enabled")) + +o = s:taboption("task", Value, "max_overall_download_limit", translate("Overall download limit"), translate("in bytes/sec, You can append K or M.")) +o:depends("overall_speed_limit", "1") + +o = s:taboption("task", Value, "max_overall_upload_limit", translate("Overall upload limit"), translate("in bytes/sec, You can append K or M.")) +o:depends("overall_speed_limit", "1") + +task_speed_limit = s:taboption("task", Flag, "task_speed_limit", translate("Per task speed limit enabled")) + +o = s:taboption("task", Value, "max_download_limit", translate("Per task download limit"), translate("in bytes/sec, You can append K or M.")) +o:depends("task_speed_limit", "1") + +o = s:taboption("task", Value, "max_upload_limit", translate("Per task upload limit"), translate("in bytes/sec, You can append K or M.")) +o:depends("task_speed_limit", "1") + +o = s:taboption("task", Value, "max_concurrent_downloads", translate("Max concurrent downloads")) +o.placeholder = "5" + +o = s:taboption("task", Value, "max_connection_per_server", translate("Max connection per server"), "1-16") +o.datetype = "range(1, 16)" +o.placeholder = "1" + +o = s:taboption("task", Value, "min_split_size", translate("Min split size"), "1M-1024M") +o.placeholder = "20M" + +o = s:taboption("task", Value, "split", translate("Max number of split")) +o.placeholder = "5" + +o = s:taboption("task", Value, "save_session_interval", translate("Autosave session interval"), translate("Sec")) +o.default = "30" + +o = s:taboption("task", Value, "user_agent", translate("User agent value")) +o.placeholder = "aria2/" .. ipkg_ver("aria2") + +o = s:taboption("bittorrent", Flag, "enable_dht", translate("<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled")) +o.enabled = "true" +o.disabled = "false" + +o = s:taboption("bittorrent", Flag, "bt_enable_lpd", translate("<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled")) +o.enabled = "true" +o.disabled = "false" + +o = s:taboption("bittorrent", Flag, "follow_torrent", translate("Follow torrent")) +o.enabled = "true" +o.disabled = "false" + +o = s:taboption("bittorrent", Value, "listen_port", translate("BitTorrent listen port")) +o.placeholder = "6881-6999" + +o = s:taboption("bittorrent", Value, "bt_max_peers", translate("Max number of peers per torrent")) +o.placeholder = "55" + +bt_tracker_enable = s:taboption("bittorrent", Flag, "bt_tracker_enable", translate("Additional Bt tracker enabled")) +bt_tracker = s:taboption("bittorrent", DynamicList, "bt_tracker", translate("List of additional Bt tracker")) +bt_tracker:depends("bt_tracker_enable", "1") +bt_tracker.rmempty = true + +function bt_tracker.cfgvalue(self, section) + local rv = {} + local val = Value.cfgvalue(self, section) + if type(val) == "table" then + val = table.concat(val, ",") + elseif not val then + val = "" + end + for v in val:gmatch("[^,%s]+") do + rv[#rv+1] = v + end + return rv +end + +function bt_tracker.write(self, section, value) + local rv = {} + for v in util.imatch(value) do + rv[#rv+1] = v + end + Value.write(self, section, table.concat(rv, ",")) +end + +o = s:taboption("bittorrent", Value, "peer_id_prefix", translate("Prefix of peer ID")) +o.placeholder = "A2-" .. ipkg_ver_lined("aria2") .. "-" + +s = m:section(TypedSection, "aria2", translate("Extra Settings")) +s.addremove = false +s.anonymous = true + +o = s:option(DynamicList, "extra_settings", translate("List of extra settings")) +o.placeholder = "option=value" +o.rmempty = true + +m:section(SimpleSection, nil, sessionbtn .. use_websocket .. aria2rpctxt) + +return m diff --git a/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm b/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm new file mode 100644 index 000000000..933c6af70 --- /dev/null +++ b/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm @@ -0,0 +1,77 @@ +<script type="text/javascript">//<![CDATA[ +XHR.poll(5, '<%=url([[admin]], [[services]], [[aria2]], [[status]])%>', null, + function(x, data) { + var tb = document.getElementById('aria2_status'); + if (data && tb) { + if (data.running) { + var links = '<em><%:The Aria2 service is running.%></em>'; + if (data.yaaw) { + links += '<input class="cbi-button mar-10" type="button" value="<%:Open YAAW%>" onclick="openWebUI(\'yaaw\');" />'; + } + if (data.webui) { + links += '<input class="cbi-button mar-10" type="button" value="<%:Open WebUI-Aria2%>" onclick="openWebUI(\'webui-aria2\');" />'; + } + tb.innerHTML = links; + } else { + tb.innerHTML = '<em><%:The Aria2 service is not running.%></em>'; + } + } + } +); + +function randomString(len) { + len = len || 32; + var $chars = 'abcdefghijklmnopqrstuvwxyz1234567890'; + var maxPos = $chars.length; + var pwd = ''; + for (i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +}; + +function randomSecret() { + var Token = document.getElementById("cbid.aria2.main.rpc_secret"); + Token.value = randomString(32); +}; + +function showRPCURL() { + var websocket = document.getElementById("use_websocket"); + var protocol = (websocket.checked) ? "ws" : "http"; + var newTextNode = document.getElementById("aria2rpcpath"); + var auth_method = document.getElementById("cbid.aria2.main.rpc_auth_method"); + var auth_port = document.getElementById("cbid.aria2.main.rpc_listen_port"); + if (auth_port.value == "") { + auth_port_value = "6800" + } else { + auth_port_value = auth_port.value + }; + if (auth_method.value == "token") { + var auth_token = document.getElementById("cbid.aria2.main.rpc_secret"); + newTextNode.value = protocol + "://token:" + auth_token.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc"; + } else if (auth_method.value == "user_pass") { + var auth_user = document.getElementById("cbid.aria2.main.rpc_user"); + var auth_passwd = document.getElementById("cbid.aria2.main.rpc_passwd"); + newTextNode.value = protocol + "://" + auth_user.value + ":" + auth_passwd.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc"; + } else { + newTextNode.value = protocol + "://" + document.domain + ":" + auth_port_value + "/jsonrpc"; + } +}; + +function openWebUI(path) { + var curWwwPath = window.document.location.href; + var pathName = window.document.location.pathname; + var pos = curWwwPath.indexOf(pathName); + var localhostPath = curWwwPath.substring(0, pos); + var url = "http:" + localhostPath.substring(window.location.protocol.length) + "/" + path; + window.open(url) +}; +//]]> +</script> +<style>.mar-10 {margin-left: 10px; margin-right: 10px;}</style> +<fieldset class="cbi-section"> + <legend><%:Aria2 Status%></legend> + <p id="aria2_status"> + <em><%:Collecting data...%></em> + </p> +</fieldset> diff --git a/applications/luci-app-aria2/po/templates/aria2.po b/applications/luci-app-aria2/po/templates/aria2.po new file mode 100644 index 000000000..353d48ece --- /dev/null +++ b/applications/luci-app-aria2/po/templates/aria2.po @@ -0,0 +1,176 @@ +msgid "Aria2" +msgstr "" + +msgid "Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings." +msgstr "" + +msgid "Aria2 Status" +msgstr "" + +msgid "Open YAAW" +msgstr "" + +msgid "Open WebUI-Aria2" +msgstr "" + +msgid "The Aria2 service is running." +msgstr "" + +msgid "The Aria2 service is not running." +msgstr "" + +msgid "Aria2 Settings" +msgstr "" + +msgid "General settings" +msgstr "" + +msgid "Files and Locations" +msgstr "" + +msgid "Enabled" +msgstr "" + +msgid "Task Settings" +msgstr "" + +msgid "BitTorrent Settings" +msgstr "" + +msgid "Run daemon as user" +msgstr "" + +msgid "RPC port" +msgstr "" + +msgid "RPC authentication method" +msgstr "" + +msgid "No Authentication" +msgstr "" + +msgid "Username & Password" +msgstr "" + +msgid "Token" +msgstr "" + +msgid "RPC username" +msgstr "" + +msgid "RPC password" +msgstr "" + +msgid "RPC Token" +msgstr "" + +msgid "Generate Randomly" +msgstr "" + +msgid "Config file directory" +msgstr "" + +msgid "Default download directory" +msgstr "" + +msgid "Disk cache" +msgstr "" + +msgid "in bytes, You can append K or M." +msgstr "" + +msgid "Preallocation" +msgstr "" + +msgid "Off" +msgstr "" + +msgid "Prealloc" +msgstr "" + +msgid "Trunc" +msgstr "" + +msgid "Falloc" +msgstr "" + +msgid "\"Falloc\" is not available in all cases." +msgstr "" + +msgid "Overall speed limit enabled" +msgstr "" + +msgid "Overall download limit" +msgstr "" + +msgid "in bytes/sec, You can append K or M." +msgstr "" + +msgid "Overall upload limit" +msgstr "" + +msgid "Per task speed limit enabled" +msgstr "" + +msgid "Per task download limit" +msgstr "" + +msgid "Per task upload limit" +msgstr "" + +msgid "Max concurrent downloads" +msgstr "" + +msgid "Max connection per server" +msgstr "" + +msgid "Min split size" +msgstr "" + +msgid "Max number of split" +msgstr "" + +msgid "Autosave session interval" +msgstr "" + +msgid "Sec" +msgstr "" + +msgid "User agent value" +msgstr "" + +msgid "<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled" +msgstr "" + +msgid "<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled" +msgstr "" + +msgid "Follow torrent" +msgstr "" + +msgid "BitTorrent listen port" +msgstr "" + +msgid "Max number of peers per torrent" +msgstr "" + +msgid "Additional Bt tracker enabled" +msgstr "" + +msgid "List of additional Bt tracker" +msgstr "" + +msgid "Prefix of peer ID" +msgstr "" + +msgid "Extra Settings" +msgstr "" + +msgid "List of extra settings" +msgstr "" + +msgid "View Json-RPC URL" +msgstr "" + +msgid "Use WebSocket" +msgstr "" diff --git a/applications/luci-app-aria2/po/zh-cn/aria2.po b/applications/luci-app-aria2/po/zh-cn/aria2.po new file mode 100644 index 000000000..9b7d7bcc2 --- /dev/null +++ b/applications/luci-app-aria2/po/zh-cn/aria2.po @@ -0,0 +1,176 @@ +msgid "Aria2" +msgstr "" + +msgid "Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings." +msgstr "Aria2 是一个支持多协议多线程的下载器, 你可以在这里对其进行配置." + +msgid "Aria2 Status" +msgstr "Aria2 状态" + +msgid "Open YAAW" +msgstr "打开YAAW" + +msgid "Open WebUI-Aria2" +msgstr "打开WebUI-Aria2" + +msgid "The Aria2 service is running." +msgstr "Aria2 正在运行" + +msgid "The Aria2 service is not running." +msgstr "Aria2 未运行" + +msgid "Aria2 Settings" +msgstr "Aria2 配置" + +msgid "General settings" +msgstr "一般设置" + +msgid "Files and Locations" +msgstr "文件和目录" + +msgid "Enabled" +msgstr "启用" + +msgid "Task Settings" +msgstr "任务设置" + +msgid "BitTorrent Settings" +msgstr "BT设置" + +msgid "Run daemon as user" +msgstr "以此用户权限运行" + +msgid "RPC port" +msgstr "RPC端口" + +msgid "RPC authentication method" +msgstr "RPC认证方式" + +msgid "No Authentication" +msgstr "无认证" + +msgid "Username & Password" +msgstr "用户名与密码" + +msgid "Token" +msgstr "令牌" + +msgid "RPC username" +msgstr "RPC用户名" + +msgid "RPC password" +msgstr "RPC密码" + +msgid "RPC Token" +msgstr "RPC令牌" + +msgid "Generate Randomly" +msgstr "随机生成" + +msgid "Config file directory" +msgstr "配置文件目录" + +msgid "Default download directory" +msgstr "默认下载目录" + +msgid "Disk cache" +msgstr "磁盘缓存" + +msgid "in bytes, You can append K or M." +msgstr "单位 B, 你可以在数字后跟上 K 或 M." + +msgid "Preallocation" +msgstr "磁盘预分配" + +msgid "Off" +msgstr "关闭" + +msgid "Prealloc" +msgstr "" + +msgid "Trunc" +msgstr "" + +msgid "Falloc" +msgstr "" + +msgid "\"Falloc\" is not available in all cases." +msgstr "\"Falloc\" 并不是在所有情况下都可用." + +msgid "Overall speed limit enabled" +msgstr "启用全局限速" + +msgid "Overall download limit" +msgstr "全局下载限速" + +msgid "in bytes/sec, You can append K or M." +msgstr "单位 B/s, 你可以在数字后跟上 K 或 M." + +msgid "Overall upload limit" +msgstr "全局上传限速" + +msgid "Per task speed limit enabled" +msgstr "启用单任务限速" + +msgid "Per task download limit" +msgstr "单任务下载限速" + +msgid "Per task upload limit" +msgstr "单任务上传限速" + +msgid "Max concurrent downloads" +msgstr "最大同时下载任务数" + +msgid "Max connection per server" +msgstr "单服务器最大连接数" + +msgid "Min split size" +msgstr "最小文件分片大小" + +msgid "Max number of split" +msgstr "单文件最大线程数" + +msgid "Autosave session interval" +msgstr "定时保存会话间隔" + +msgid "Sec" +msgstr "秒" + +msgid "User agent value" +msgstr "用户代理(UA)" + +msgid "<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled" +msgstr "启用<abbr title=\"分布式哈希表\">DHT</abbr>" + +msgid "<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled" +msgstr "启用<abbr title=\"本地节点发现\">LPD</abbr>" + +msgid "Follow torrent" +msgstr "自动添加下载的种子" + +msgid "BitTorrent listen port" +msgstr "BT监听端口" + +msgid "Max number of peers per torrent" +msgstr "单个种子最大连接数" + +msgid "Additional Bt tracker enabled" +msgstr "添加额外的Tracker" + +msgid "List of additional Bt tracker" +msgstr "附加Tracker列表" + +msgid "Prefix of peer ID" +msgstr "Peer ID前缀" + +msgid "Extra Settings" +msgstr "附加选项" + +msgid "List of extra settings" +msgstr "附加选项列表" + +msgid "View Json-RPC URL" +msgstr "查看 Json-RPC URL" + +msgid "Use WebSocket" +msgstr "使用WebSocket" diff --git a/applications/luci-app-aria2/root/etc/uci-defaults/40_luci-aria2 b/applications/luci-app-aria2/root/etc/uci-defaults/40_luci-aria2 new file mode 100755 index 000000000..3a9ba5b29 --- /dev/null +++ b/applications/luci-app-aria2/root/etc/uci-defaults/40_luci-aria2 @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@aria2[-1] + add ucitrack aria2 + set ucitrack.@aria2[-1].init=aria2 + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 |