ConfigStorage.coffee 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. class ConfigStorage extends Class
  2. constructor: (@config) ->
  3. @items = []
  4. @createSections()
  5. @setValues(@config)
  6. setValues: (values) ->
  7. for section in @items
  8. for item in section.items
  9. if not values[item.key]
  10. continue
  11. item.value = @formatValue(values[item.key].value)
  12. item.default = @formatValue(values[item.key].default)
  13. item.pending = values[item.key].pending
  14. values[item.key].item = item
  15. formatValue: (value) ->
  16. if not value
  17. return false
  18. else if typeof(value) == "object"
  19. return value.join("\n")
  20. else if typeof(value) == "number"
  21. return value.toString()
  22. else
  23. return value
  24. deformatValue: (value, type) ->
  25. if type == "object" and typeof(value) == "string"
  26. if not value.length
  27. return value = null
  28. else
  29. return value.split("\n")
  30. if type == "boolean" and not value
  31. return false
  32. else if type == "number"
  33. if typeof(value) == "number"
  34. return value.toString()
  35. else if not value
  36. return "0"
  37. else
  38. return value
  39. else
  40. return value
  41. createSections: ->
  42. # Web Interface
  43. section = @createSection("Web Interface")
  44. section.items.push
  45. key: "open_browser"
  46. title: "Open web browser on ZeroNet startup"
  47. type: "checkbox"
  48. # Network
  49. section = @createSection("Network")
  50. section.items.push
  51. key: "offline"
  52. title: "Offline mode"
  53. type: "checkbox"
  54. description: "Disable network communication."
  55. section.items.push
  56. key: "fileserver_ip_type"
  57. title: "File server network"
  58. type: "select"
  59. options: [
  60. {title: "IPv4", value: "ipv4"}
  61. {title: "IPv6", value: "ipv6"}
  62. {title: "Dual (IPv4 & IPv6)", value: "dual"}
  63. ]
  64. description: "Accept incoming peers using IPv4 or IPv6 address. (default: dual)"
  65. section.items.push
  66. key: "fileserver_port"
  67. title: "File server port"
  68. type: "text"
  69. valid_pattern: /[0-9]*/
  70. description: "Other peers will use this port to reach your served sites. (default: randomize)"
  71. section.items.push
  72. key: "ip_external"
  73. title: "File server external ip"
  74. type: "textarea"
  75. placeholder: "Detect automatically"
  76. description: "Your file server is accessible on these ips. (default: detect automatically)"
  77. section.items.push
  78. title: "Tor"
  79. key: "tor"
  80. type: "select"
  81. options: [
  82. {title: "Disable", value: "disable"}
  83. {title: "Enable", value: "enable"}
  84. {title: "Always", value: "always"}
  85. ]
  86. description: [
  87. "Disable: Don't connect to peers on Tor network", h("br"),
  88. "Enable: Only use Tor for Tor network peers", h("br"),
  89. "Always: Use Tor for every connections to hide your IP address (slower)"
  90. ]
  91. section.items.push
  92. title: "Use Tor bridges"
  93. key: "tor_use_bridges"
  94. type: "checkbox"
  95. description: "Use obfuscated bridge relays to avoid network level Tor block (even slower)"
  96. isHidden: ->
  97. return not Page.server_info.tor_has_meek_bridges
  98. section.items.push
  99. title: "Trackers"
  100. key: "trackers"
  101. type: "textarea"
  102. description: "Discover new peers using these adresses"
  103. section.items.push
  104. title: "Trackers files"
  105. key: "trackers_file"
  106. type: "textarea"
  107. description: "Load additional list of torrent trackers dynamically, from a file"
  108. placeholder: "Eg.: {data_dir}/trackers.json"
  109. value_pos: "fullwidth"
  110. section.items.push
  111. title: "Proxy for tracker connections"
  112. key: "trackers_proxy"
  113. type: "select"
  114. options: [
  115. {title: "Custom", value: ""}
  116. {title: "Tor", value: "tor"}
  117. {title: "Disable", value: "disable"}
  118. ]
  119. isHidden: ->
  120. Page.values["tor"] == "always"
  121. section.items.push
  122. title: "Custom socks proxy address for trackers"
  123. key: "trackers_proxy"
  124. type: "text"
  125. placeholder: "Eg.: 127.0.0.1:1080"
  126. value_pos: "fullwidth"
  127. valid_pattern: /.+:[0-9]+/
  128. isHidden: =>
  129. Page.values["trackers_proxy"] in ["tor", "disable"]
  130. # Performance
  131. section = @createSection("Performance")
  132. section.items.push
  133. key: "log_level"
  134. title: "Level of logging to file"
  135. type: "select"
  136. options: [
  137. {title: "Everything", value: "DEBUG"}
  138. {title: "Only important messages", value: "INFO"}
  139. {title: "Only errors", value: "ERROR"}
  140. ]
  141. section.items.push
  142. key: "threads_fs_read"
  143. title: "Threads for async file system reads"
  144. type: "select"
  145. options: [
  146. {title: "Sync read", value: 0}
  147. {title: "1 thread", value: 1}
  148. {title: "2 threads", value: 2}
  149. {title: "3 threads", value: 3}
  150. {title: "4 threads", value: 4}
  151. {title: "5 threads", value: 5}
  152. {title: "10 threads", value: 10}
  153. ]
  154. section.items.push
  155. key: "threads_fs_write"
  156. title: "Threads for async file system writes"
  157. type: "select"
  158. options: [
  159. {title: "Sync write", value: 0}
  160. {title: "1 thread", value: 1}
  161. {title: "2 threads", value: 2}
  162. {title: "3 threads", value: 3}
  163. {title: "4 threads", value: 4}
  164. {title: "5 threads", value: 5}
  165. {title: "10 threads", value: 10}
  166. ]
  167. section.items.push
  168. key: "threads_crypt"
  169. title: "Threads for cryptographic functions"
  170. type: "select"
  171. options: [
  172. {title: "Sync execution", value: 0}
  173. {title: "1 thread", value: 1}
  174. {title: "2 threads", value: 2}
  175. {title: "3 threads", value: 3}
  176. {title: "4 threads", value: 4}
  177. {title: "5 threads", value: 5}
  178. {title: "10 threads", value: 10}
  179. ]
  180. section.items.push
  181. key: "threads_db"
  182. title: "Threads for database operations"
  183. type: "select"
  184. options: [
  185. {title: "Sync execution", value: 0}
  186. {title: "1 thread", value: 1}
  187. {title: "2 threads", value: 2}
  188. {title: "3 threads", value: 3}
  189. {title: "4 threads", value: 4}
  190. {title: "5 threads", value: 5}
  191. {title: "10 threads", value: 10}
  192. ]
  193. createSection: (title) =>
  194. section = {}
  195. section.title = title
  196. section.items = []
  197. @items.push(section)
  198. return section
  199. window.ConfigStorage = ConfigStorage