ConfigStorage.coffee 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. return value.split("\n")
  27. if type == "boolean" and not value
  28. return false
  29. else
  30. return value
  31. createSections: ->
  32. section = @createSection("Web Interface")
  33. # Web Interface
  34. section.items.push
  35. key: "open_browser"
  36. title: "Open web browser on ZeroNet startup"
  37. type: "checkbox"
  38. # Network
  39. section = @createSection("Network")
  40. section.items.push
  41. key: "fileserver_port"
  42. title: "File server port"
  43. type: "text"
  44. valid_pattern: /[0-9]*/
  45. description: "Other peers will use this port to reach your served sites. (default: 15441)"
  46. section.items.push
  47. title: "Tor"
  48. key: "tor"
  49. type: "select"
  50. options: [
  51. {title: "Disable", value: "disable"}
  52. {title: "Enable", value: "enable"}
  53. {title: "Always", value: "always"}
  54. ]
  55. description: [
  56. "Disable: Don't connect to peers on Tor network", h("br"),
  57. "Enable: Only use Tor for Tor network peers", h("br"),
  58. "Always: Use Tor for every connections to hide your IP address (slower)"
  59. ]
  60. section.items.push
  61. title: "Use Tor bridges"
  62. key: "tor_use_bridges"
  63. type: "checkbox"
  64. description: "Use obfuscated bridge relays to avoid network level Tor block (even slower)"
  65. section.items.push
  66. title: "Trackers"
  67. key: "trackers"
  68. type: "textarea"
  69. description: "Discover new peers using these adresses"
  70. section.items.push
  71. title: "Trackers files"
  72. key: "trackers_file"
  73. type: "text"
  74. description: "Load additional list of torrent trackers dynamically, from a file"
  75. placeholder: "Eg.: data/trackers.json"
  76. value_pos: "fullwidth"
  77. section.items.push
  78. title: "Proxy for tracker connections"
  79. key: "trackers_proxy"
  80. type: "select"
  81. options: [
  82. {title: "Custom", value: ""}
  83. {title: "Tor", value: "tor"}
  84. {title: "Disable", value: "disable"}
  85. ]
  86. section.items.push
  87. title: "Custom socks proxy address for trackers"
  88. key: "trackers_proxy"
  89. type: "text"
  90. placeholder: "Eg.: 127.0.0.1:1080"
  91. value_pos: "fullwidth"
  92. valid_pattern: /.+:[0-9]+/
  93. isHidden: =>
  94. Page.values["trackers_proxy"] in ["tor", "disable"]
  95. createSection: (title) =>
  96. section = {}
  97. section.title = title
  98. section.items = []
  99. @items.push(section)
  100. return section
  101. window.ConfigStorage = ConfigStorage