1
0

aria2.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. --[[
  2. LuCI - Lua Configuration Interface - Aria2 support
  3. Copyright 2014-2016 nanpuyue <nanpuyue@gmail.com>
  4. Modified by maz-1 <ohmygod19993@gmail.com>
  5. Modified by kuoruan <kuoruan@gmail.com>
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. ]]--
  11. local sys = require "luci.sys"
  12. local util = require "luci.util"
  13. local uci = require "luci.model.uci".cursor()
  14. local cfgbtn = "<input type=\"button\" value=\"" .. translate("Generate Randomly") .. "\" onclick=\"randomSecret(32);\" />"
  15. local sessionbtn = "<input class=\"cbi-button mar-10\" type=\"button\" value=\"" .. translate("View Json-RPC URL") .. "\" onclick=\"showRPCURL();\" />"
  16. local aria2rpctxt = "<input class=\"mar-10\" id=\"aria2rpcpath\" onmouseover=\"obj=document.getElementById(this.id);obj.focus();obj.select()\" />"
  17. local use_websocket = "<input id=\"use_websocket\" type=\"checkbox\" /><label for=\"use_websocket\">" .. translate("Use WebSocket") .. "</label>"
  18. function ipkg_ver(pkg)
  19. local version = nil
  20. local control = io.open("/usr/lib/opkg/info/%s.control" % pkg, "r")
  21. if control then
  22. local ln
  23. repeat
  24. ln = control:read("*l")
  25. if ln and ln:match("^Version: ") then
  26. version = ln:gsub("^Version: ", ""):gsub("-%d", "")
  27. break
  28. end
  29. until not ln
  30. control:close()
  31. end
  32. return version
  33. end
  34. function ipkg_ver_lined(pkg)
  35. return ipkg_ver(pkg):gsub("%.", "-")
  36. end
  37. m = Map("aria2", translate("Aria2"), translate("Aria2 is a multi-protocol &amp; multi-source download utility, here you can configure the settings."))
  38. m:section(SimpleSection).template = "aria2/overview_status"
  39. s = m:section(TypedSection, "aria2", translate("Aria2 Settings"))
  40. s.addremove = false
  41. s.anonymous = true
  42. s:tab("general", translate("General Settings"))
  43. s:tab("file", translate("Files and Locations"))
  44. s:tab("task", translate("Task Settings"))
  45. s:tab("bittorrent", translate("BitTorrent Settings"))
  46. o = s:taboption("general", Flag, "enabled", translate("Enabled"))
  47. o.rmempty = false
  48. user = s:taboption("general", ListValue, "user", translate("Run daemon as user"))
  49. local p_user
  50. for _, p_user in util.vspairs(util.split(sys.exec("cat /etc/passwd | cut -f 1 -d :"))) do
  51. user:value(p_user)
  52. end
  53. o = s:taboption("general", Value, "rpc_listen_port", translate("RPC port"))
  54. o.datatype = "port"
  55. o.placeholder = "6800"
  56. rpc_auth_method = s:taboption("general", ListValue, "rpc_auth_method", translate("RPC authentication method"))
  57. rpc_auth_method:value("none", translate("No Authentication"))
  58. rpc_auth_method:value("user_pass", translate("Username & Password"))
  59. rpc_auth_method:value("token", translate("Token"))
  60. o = s:taboption("general", Value, "rpc_user", translate("RPC username"))
  61. o:depends("rpc_auth_method", "user_pass")
  62. o.rmempty = false
  63. o = s:taboption("general", Value, "rpc_passwd", translate("RPC password"))
  64. o:depends("rpc_auth_method", "user_pass")
  65. o.password = true
  66. o.rmempty = true
  67. o = s:taboption("general", Value, "rpc_secret", translate("RPC Token"), "<br/>" .. cfgbtn)
  68. o:depends("rpc_auth_method", "token")
  69. o.rmempty = true
  70. o = s:taboption("file", Value, "config_dir", translate("Config file directory"))
  71. o.placeholder = "/var/etc/aria2"
  72. o = s:taboption("file", Flag, "enable_log", translate("Enable log"), translate("Log file is in the config file dir."))
  73. o.enabled = "true"
  74. o.disabled = "false"
  75. o = s:taboption("file", ListValue, "log_level", translate("Log level"))
  76. o:depends("enable_log", "true")
  77. o:value("debug", translate("Debug"))
  78. o:value("info", translate("Info"))
  79. o:value("notice", translate("Notice"))
  80. o:value("warn", translate("Warn"))
  81. o:value("error", translate("Error"))
  82. o = s:taboption("file", Value, "dir", translate("Default download directory"))
  83. o.rmempty = false
  84. o = s:taboption("file", Value, "disk_cache", translate("Disk cache"), translate("in bytes, You can append K or M."))
  85. o.rmempty = true
  86. o = s:taboption("file", ListValue, "file_allocation", translate("Preallocation"), translate("\"Falloc\" is not available in all cases."))
  87. o:value("none", translate("Off"))
  88. o:value("prealloc", translate("Prealloc"))
  89. o:value("trunc", translate("Trunc"))
  90. o:value("falloc", translate("Falloc"))
  91. overall_speed_limit = s:taboption("task", Flag, "overall_speed_limit", translate("Overall speed limit enabled"))
  92. overall_speed_limit.rmempty = true
  93. o = s:taboption("task", Value, "max_overall_download_limit", translate("Overall download limit"), translate("in bytes/sec, You can append K or M."))
  94. o:depends("overall_speed_limit", "1")
  95. o = s:taboption("task", Value, "max_overall_upload_limit", translate("Overall upload limit"), translate("in bytes/sec, You can append K or M."))
  96. o:depends("overall_speed_limit", "1")
  97. task_speed_limit = s:taboption("task", Flag, "task_speed_limit", translate("Per task speed limit enabled"))
  98. task_speed_limit.rmempty = true
  99. o = s:taboption("task", Value, "max_download_limit", translate("Per task download limit"), translate("in bytes/sec, You can append K or M."))
  100. o:depends("task_speed_limit", "1")
  101. o = s:taboption("task", Value, "max_upload_limit", translate("Per task upload limit"), translate("in bytes/sec, You can append K or M."))
  102. o:depends("task_speed_limit", "1")
  103. o = s:taboption("task", Value, "max_concurrent_downloads", translate("Max concurrent downloads"))
  104. o.placeholder = "5"
  105. o = s:taboption("task", Value, "max_connection_per_server", translate("Max connection per server"), "1-16")
  106. o.datetype = "range(1, 16)"
  107. o.placeholder = "1"
  108. o = s:taboption("task", Value, "min_split_size", translate("Min split size"), "1M-1024M")
  109. o.placeholder = "20M"
  110. o = s:taboption("task", Value, "split", translate("Max number of split"))
  111. o.placeholder = "5"
  112. o = s:taboption("task", Value, "save_session_interval", translate("Autosave session interval"), translate("Sec"))
  113. o.default = "30"
  114. o = s:taboption("task", Value, "user_agent", translate("User agent value"))
  115. o.placeholder = "aria2/" .. ipkg_ver("aria2")
  116. o = s:taboption("bittorrent", Flag, "enable_dht", translate("<abbr title=\"Distributed Hash Table\">DHT</abbr> enabled"))
  117. o.enabled = "true"
  118. o.disabled = "false"
  119. o = s:taboption("bittorrent", Flag, "bt_enable_lpd", translate("<abbr title=\"Local Peer Discovery\">LPD</abbr> enabled"))
  120. o.enabled = "true"
  121. o.disabled = "false"
  122. o = s:taboption("bittorrent", Flag, "follow_torrent", translate("Follow torrent"))
  123. o.enabled = "true"
  124. o.disabled = "false"
  125. o = s:taboption("bittorrent", Value, "listen_port", translate("BitTorrent listen port"))
  126. o.placeholder = "6881-6999"
  127. o = s:taboption("bittorrent", Value, "bt_max_peers", translate("Max number of peers per torrent"))
  128. o.placeholder = "55"
  129. bt_tracker_enable = s:taboption("bittorrent", Flag, "bt_tracker_enable", translate("Additional Bt tracker enabled"))
  130. bt_tracker = s:taboption("bittorrent", DynamicList, "bt_tracker", translate("List of additional Bt tracker"))
  131. bt_tracker:depends("bt_tracker_enable", "1")
  132. bt_tracker.rmempty = true
  133. function bt_tracker.cfgvalue(self, section)
  134. local rv = {}
  135. local val = Value.cfgvalue(self, section)
  136. if type(val) == "table" then
  137. val = table.concat(val, ",")
  138. elseif not val then
  139. val = ""
  140. end
  141. for v in val:gmatch("[^,%s]+") do
  142. rv[#rv+1] = v
  143. end
  144. return rv
  145. end
  146. function bt_tracker.write(self, section, value)
  147. local rv = {}
  148. for v in util.imatch(value) do
  149. rv[#rv+1] = v
  150. end
  151. Value.write(self, section, table.concat(rv, ","))
  152. end
  153. o = s:taboption("bittorrent", Value, "peer_id_prefix", translate("Prefix of peer ID"))
  154. o.placeholder = "A2-" .. ipkg_ver_lined("aria2") .. "-"
  155. s = m:section(TypedSection, "aria2", translate("Extra Settings"))
  156. s.addremove = false
  157. s.anonymous = true
  158. o = s:option(DynamicList, "extra_settings", translate("List of extra settings"))
  159. o.placeholder = "option=value"
  160. o.rmempty = true
  161. m:section(SimpleSection, nil, sessionbtn .. use_websocket .. aria2rpctxt)
  162. return m