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/overview_status"
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", Flag, "enable_log", translate("Enable log"), translate("Log file is in the config file dir."))
96 o = s:taboption("file", ListValue, "log_level", translate("Log level"))
97 o:depends("enable_log", "true")
98 o:value("debug", translate("Debug"))
99 o:value("info", translate("Info"))
100 o:value("notice", translate("Notice"))
101 o:value("warn", translate("Warn"))
102 o:value("error", translate("Error"))
104 o = s:taboption("file", Value, "dir", translate("Default download directory"))
107 o = s:taboption("file", Value, "disk_cache", translate("Disk cache"), translate("in bytes, You can append K or M."))
110 o = s:taboption("file", ListValue, "file_allocation", translate("Preallocation"), translate("\"Falloc\" is not available in all cases."))
111 o:value("none", translate("Off"))
112 o:value("prealloc", translate("Prealloc"))
113 o:value("trunc", translate("Trunc"))
114 o:value("falloc", translate("Falloc"))
116 overall_speed_limit = s:taboption("task", Flag, "overall_speed_limit", translate("Overall speed limit enabled"))
117 overall_speed_limit.rmempty = true
119 o = s:taboption("task", Value, "max_overall_download_limit", translate("Overall download limit"), translate("in bytes/sec, You can append K or M."))
120 o:depends("overall_speed_limit", "1")
122 o = s:taboption("task", Value, "max_overall_upload_limit", translate("Overall upload limit"), translate("in bytes/sec, You can append K or M."))
123 o:depends("overall_speed_limit", "1")
125 task_speed_limit = s:taboption("task", Flag, "task_speed_limit", translate("Per task speed limit enabled"))
126 task_speed_limit.rmempty = true
128 o = s:taboption("task", Value, "max_download_limit", translate("Per task download limit"), translate("in bytes/sec, You can append K or M."))
129 o:depends("task_speed_limit", "1")
131 o = s:taboption("task", Value, "max_upload_limit", translate("Per task upload limit"), translate("in bytes/sec, You can append K or M."))
132 o:depends("task_speed_limit", "1")
134 o = s:taboption("task", Value, "max_concurrent_downloads", translate("Max concurrent downloads"))
137 o = s:taboption("task", Value, "max_connection_per_server", translate("Max connection per server"), "1-16")
138 o.datetype = "range(1, 16)"
141 o = s:taboption("task", Value, "min_split_size", translate("Min split size"), "1M-1024M")
142 o.placeholder = "20M"
144 o = s:taboption("task", Value, "split", translate("Max number of split"))
147 o = s:taboption("task", Value, "save_session_interval", translate("Autosave session interval"), translate("Sec"))
150 o = s:taboption("task", Value, "user_agent", translate("User agent value"))
151 o.placeholder = "aria2/" .. ipkg_ver("aria2")
153 o = s:taboption("bittorrent", Flag, "enable_dht", translate("<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled"))
157 o = s:taboption("bittorrent", Flag, "bt_enable_lpd", translate("<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled"))
161 o = s:taboption("bittorrent", Flag, "follow_torrent", translate("Follow torrent"))
165 o = s:taboption("bittorrent", Value, "listen_port", translate("BitTorrent listen port"))
166 o.placeholder = "6881-6999"
168 o = s:taboption("bittorrent", Value, "bt_max_peers", translate("Max number of peers per torrent"))
171 bt_tracker_enable = s:taboption("bittorrent", Flag, "bt_tracker_enable", translate("Additional Bt tracker enabled"))
172 bt_tracker = s:taboption("bittorrent", DynamicList, "bt_tracker", translate("List of additional Bt tracker"))
173 bt_tracker:depends("bt_tracker_enable", "1")
174 bt_tracker.rmempty = true
176 function bt_tracker.cfgvalue(self, section)
178 local val = Value.cfgvalue(self, section)
179 if type(val) == "table" then
180 val = table.concat(val, ",")
184 for v in val:gmatch("[^,%s]+") do
190 function bt_tracker.write(self, section, value)
192 for v in util.imatch(value) do
195 Value.write(self, section, table.concat(rv, ","))
198 o = s:taboption("bittorrent", Value, "peer_id_prefix", translate("Prefix of peer ID"))
199 o.placeholder = "A2-" .. ipkg_ver_lined("aria2") .. "-"
201 s = m:section(TypedSection, "aria2", translate("Extra Settings"))
205 o = s:option(DynamicList, "extra_settings", translate("List of extra settings"))
206 o.placeholder = "option=value"
209 m:section(SimpleSection, nil, sessionbtn .. use_websocket .. aria2rpctxt)