server-config.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. -- Copyright (C) 2017 yushi studio <[email protected]>
  2. -- Licensed to the public under the GNU General Public License v3.
  3. require "luci.http"
  4. require "luci.dispatcher"
  5. require "nixio.fs"
  6. local m, s, o
  7. local sid = arg[1]
  8. local encrypt_methods = {
  9. "rc4-md5",
  10. "rc4-md5-6",
  11. "rc4",
  12. "table",
  13. "aes-128-cfb",
  14. "aes-192-cfb",
  15. "aes-256-cfb",
  16. "aes-128-ctr",
  17. "aes-192-ctr",
  18. "aes-256-ctr",
  19. "bf-cfb",
  20. "camellia-128-cfb",
  21. "camellia-192-cfb",
  22. "camellia-256-cfb",
  23. "cast5-cfb",
  24. "des-cfb",
  25. "idea-cfb",
  26. "rc2-cfb",
  27. "seed-cfb",
  28. "salsa20",
  29. "chacha20",
  30. "chacha20-ietf"
  31. }
  32. local encrypt_methods_ss = {
  33. -- aead
  34. "aes-128-gcm",
  35. "aes-192-gcm",
  36. "aes-256-gcm",
  37. "chacha20-ietf-poly1305",
  38. "xchacha20-ietf-poly1305"
  39. --[[ stream
  40. "table",
  41. "rc4",
  42. "rc4-md5",
  43. "aes-128-cfb",
  44. "aes-192-cfb",
  45. "aes-256-cfb",
  46. "aes-128-ctr",
  47. "aes-192-ctr",
  48. "aes-256-ctr",
  49. "bf-cfb",
  50. "camellia-128-cfb",
  51. "camellia-192-cfb",
  52. "camellia-256-cfb",
  53. "salsa20",
  54. "chacha20",
  55. "chacha20-ietf" ]]
  56. }
  57. local protocol = {"origin"}
  58. obfs = {"plain", "http_simple", "http_post"}
  59. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  60. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/server")
  61. if m.uci:get("shadowsocksr", sid) ~= "server_config" then
  62. luci.http.redirect(m.redirect)
  63. return
  64. end
  65. -- [[ Server Setting ]]--
  66. s = m:section(NamedSection, sid, "server_config")
  67. s.anonymous = true
  68. s.addremove = false
  69. o = s:option(Flag, "enable", translate("Enable"))
  70. o.default = 1
  71. o.rmempty = false
  72. o = s:option(ListValue, "type", translate("Server Type"))
  73. o:value("socks5", translate("Socks5"))
  74. if nixio.fs.access("/usr/bin/ssserver") or nixio.fs.access("/usr/bin/ss-server") then
  75. o:value("ss", translate("Shadowsocks"))
  76. end
  77. if nixio.fs.access("/usr/bin/ssr-server") then
  78. o:value("ssr", translate("ShadowsocksR"))
  79. end
  80. o.default = "socks5"
  81. o = s:option(Value, "server_port", translate("Server Port"))
  82. o.datatype = "port"
  83. math.randomseed(tostring(os.time()):reverse():sub(1, 7))
  84. o.default = math.random(10240, 20480)
  85. o.rmempty = false
  86. o.description = translate("warning! Please do not reuse the port!")
  87. o = s:option(Value, "timeout", translate("Connection Timeout"))
  88. o.datatype = "uinteger"
  89. o.default = 60
  90. o.rmempty = false
  91. o:depends("type", "ss")
  92. o:depends("type", "ssr")
  93. o = s:option(Value, "username", translate("Username"))
  94. o.rmempty = false
  95. o:depends("type", "socks5")
  96. o = s:option(Value, "password", translate("Password"))
  97. o.password = true
  98. o.rmempty = false
  99. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  100. for _, v in ipairs(encrypt_methods) do
  101. o:value(v)
  102. end
  103. o.rmempty = false
  104. o:depends("type", "ssr")
  105. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  106. for _, v in ipairs(encrypt_methods_ss) do
  107. o:value(v)
  108. end
  109. o.rmempty = false
  110. o:depends("type", "ss")
  111. o = s:option(ListValue, "protocol", translate("Protocol"))
  112. for _, v in ipairs(protocol) do
  113. o:value(v)
  114. end
  115. o.rmempty = false
  116. o:depends("type", "ssr")
  117. o = s:option(ListValue, "obfs", translate("Obfs"))
  118. for _, v in ipairs(obfs) do
  119. o:value(v)
  120. end
  121. o.rmempty = false
  122. o:depends("type", "ssr")
  123. o = s:option(Value, "obfs_param", translate("Obfs param(optional)"))
  124. o:depends("type", "ssr")
  125. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  126. o.rmempty = false
  127. o:depends("type", "ss")
  128. o:depends("type", "ssr")
  129. return m