2 LuCI - Lua Configuration Interface - Aria2 support
4 Copyright 2014-2016 nanpuyue <nanpuyue@gmail.com>
5 Modified by maz-1 <ohmygod19993@gmail.com>
6 Modified by kuoruan <kuoruan@gmail.com>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
15 local sys = require "luci.sys"
16 local util = require "luci.util"
17 local uci = require "luci.model.uci".cursor()
19 local cfgbtn = "<input type=\"button\" value=\"" .. translate("Generate Randomly") .. "\" onclick=\"randomSecret(32);\" />"
20 local sessionbtn = "<input class=\"cbi-button mar-10\" type=\"button\" value=\"" .. translate("View Json-RPC URL") .. "\" onclick=\"showRPCURL();\" />"
21 local aria2rpctxt = "<input class=\"mar-10\" id=\"aria2rpcpath\" onmouseover=\"obj=document.getElementById(this.id);obj.focus();obj.select()\" />"
22 local use_websocket = "<input id=\"use_websocket\" type=\"checkbox\" /><label for=\"use_websocket\">" .. translate("Use WebSocket") .. "</label>"
24 function ipkg_ver(pkg)
26 local control = io.open("/usr/lib/opkg/info/%s.control" % pkg, "r")
30 ln = control:read("*l")
31 if ln and ln:match("^Version: ") then
32 version = ln:gsub("^Version: ", ""):gsub("-%d", "")
41 function ipkg_ver_lined(pkg)
42 return ipkg_ver(pkg):gsub("%.", "-")
45 m = Map("aria2", translate("Aria2"), translate("Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings."))
47 m:section(SimpleSection).template = "aria2/web_script"
49 s = m:section(TypedSection, "aria2", translate("Aria2 Settings"))
53 s:tab("general", translate("General Settings"))
54 s:tab("file", translate("Files and Locations"))
55 s:tab("task", translate("Task Settings"))
56 s:tab("bittorrent", translate("BitTorrent Settings"))
58 o = s:taboption("general", Flag, "enabled", translate("Enabled"))
61 user = s:taboption("general", ListValue, "user", translate("Run daemon as user"))
63 for _, p_user in util.vspairs(util.split(sys.exec("cat /etc/passwd | cut -f 1 -d :"))) do
67 o = s:taboption("general", Value, "rpc_listen_port", translate("RPC port"))
69 o.placeholder = "6800"
71 rpc_auth_method = s:taboption("general", ListValue, "rpc_auth_method", translate("RPC authentication method"))
72 rpc_auth_method:value("none", translate("No Authentication"))
73 rpc_auth_method:value("user_pass", translate("Username & Password"))
74 rpc_auth_method:value("token", translate("Token"))
76 o = s:taboption("general", Value, "rpc_user", translate("RPC username"))
77 o:depends("rpc_auth_method", "user_pass")
80 o = s:taboption("general", Value, "rpc_passwd", translate("RPC password"))
81 o:depends("rpc_auth_method", "user_pass")
85 o = s:taboption("general", Value, "rpc_secret", translate("RPC Token"), "<br/>" .. cfgbtn)
86 o:depends("rpc_auth_method", "token")
89 o = s:taboption("file", Value, "config_dir", translate("Config file directory"))
90 o.placeholder = "/var/etc/aria2"
92 o = s:taboption("file", Value, "dir", translate("Default download directory"))
95 s:taboption("file", Value, "disk_cache", translate("Disk cache"), translate("in bytes, You can append K or M."))
97 o = s:taboption("file", ListValue, "file_allocation", translate("Preallocation"), translate("\"Falloc\" is not available in all cases."))
98 o:value("none", translate("Off"))
99 o:value("prealloc", translate("Prealloc"))
100 o:value("trunc", translate("Trunc"))
101 o:value("falloc", translate("Falloc"))
103 overall_speed_limit = s:taboption("task", Flag, "overall_speed_limit", translate("Overall speed limit enabled"))
105 o = s:taboption("task", Value, "max_overall_download_limit", translate("Overall download limit"), translate("in bytes/sec, You can append K or M."))
106 o:depends("overall_speed_limit", "1")
108 o = s:taboption("task", Value, "max_overall_upload_limit", translate("Overall upload limit"), translate("in bytes/sec, You can append K or M."))
109 o:depends("overall_speed_limit", "1")
111 task_speed_limit = s:taboption("task", Flag, "task_speed_limit", translate("Per task speed limit enabled"))
113 o = s:taboption("task", Value, "max_download_limit", translate("Per task download limit"), translate("in bytes/sec, You can append K or M."))
114 o:depends("task_speed_limit", "1")
116 o = s:taboption("task", Value, "max_upload_limit", translate("Per task upload limit"), translate("in bytes/sec, You can append K or M."))
117 o:depends("task_speed_limit", "1")
119 o = s:taboption("task", Value, "max_concurrent_downloads", translate("Max concurrent downloads"))
122 o = s:taboption("task", Value, "max_connection_per_server", translate("Max connection per server"), "1-16")
123 o.datetype = "range(1, 16)"
126 o = s:taboption("task", Value, "min_split_size", translate("Min split size"), "1M-1024M")
127 o.placeholder = "20M"
129 o = s:taboption("task", Value, "split", translate("Max number of split"))
132 o = s:taboption("task", Value, "save_session_interval", translate("Autosave session interval"), translate("Sec"))
135 o = s:taboption("task", Value, "user_agent", translate("User agent value"))
136 o.placeholder = "aria2/" .. ipkg_ver("aria2")
138 o = s:taboption("bittorrent", Flag, "enable_dht", translate("<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled"))
142 o = s:taboption("bittorrent", Flag, "bt_enable_lpd", translate("<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled"))
146 o = s:taboption("bittorrent", Flag, "follow_torrent", translate("Follow torrent"))
150 o = s:taboption("bittorrent", Value, "listen_port", translate("BitTorrent listen port"))
151 o.placeholder = "6881-6999"
153 o = s:taboption("bittorrent", Value, "bt_max_peers", translate("Max number of peers per torrent"))
156 bt_tracker_enable = s:taboption("bittorrent", Flag, "bt_tracker_enable", translate("Additional Bt tracker enabled"))
157 bt_tracker = s:taboption("bittorrent", DynamicList, "bt_tracker", translate("List of additional Bt tracker"))
158 bt_tracker:depends("bt_tracker_enable", "1")
159 bt_tracker.rmempty = true
161 function bt_tracker.cfgvalue(self, section)
163 local val = Value.cfgvalue(self, section)
164 if type(val) == "table" then
165 val = table.concat(val, ",")
169 for v in val:gmatch("[^,%s]+") do
175 function bt_tracker.write(self, section, value)
177 for v in util.imatch(value) do
180 Value.write(self, section, table.concat(rv, ","))
183 o = s:taboption("bittorrent", Value, "peer_id_prefix", translate("Prefix of peer ID"))
184 o.placeholder = "A2-" .. ipkg_ver_lined("aria2") .. "-"
186 s = m:section(TypedSection, "aria2", translate("Extra Settings"))
190 o = s:option(DynamicList, "extra_settings", translate("List of extra settings"))
191 o.placeholder = "option=value"
194 m:section(SimpleSection, nil, sessionbtn .. use_websocket .. aria2rpctxt)