config.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package gold
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. )
  10. // ServerConfig holds a list of configuration parameters for the server
  11. type ServerConfig struct {
  12. // PortHTTP contains the HTTPS listening port number in format ":80"
  13. ListenHTTP string
  14. // PortHTTPS contains the HTTPS listening port number in format ":443"
  15. ListenHTTPS string
  16. // WebIDTLS enables/disables client cert authentication (WebID-TLS) (on by default)
  17. WebIDTLS bool
  18. // TLSCert holds the server certificate eg. cert.pem
  19. TLSCert string
  20. // TLSKey holds the server key eg. key.pem
  21. TLSKey string
  22. // Root points to the folder that will be used as root for data
  23. DataRoot string
  24. // Vhosts enables the use of virtual hosts (i.e. user.example.org)
  25. Vhosts bool
  26. // Insecure enables insecure (HTTP) operation mode only
  27. Insecure bool
  28. // NoHTTP allows to enable or disable redirects from HTTP to HTTPS
  29. NoHTTP bool
  30. // HSTS enables or disables strict security transport
  31. HSTS bool
  32. // Debug (display or hide stdout logging)
  33. Debug bool
  34. // CookieAge contains the validity duration for cookies (in hours)
  35. CookieAge int64
  36. // TokenAge contains the validity duration for recovery tokens (in minutes)
  37. TokenAge int64
  38. // METASuffix sets the default suffix for meta files (e.g. ,meta or .meta)
  39. MetaSuffix string
  40. // ACLSuffix sets the default suffix for ACL files (e.g. ,acl or .acl)
  41. ACLSuffix string
  42. // DataApp sets the default app for viewing RDF resources
  43. DataApp string
  44. // DirApp points to the app for browsing the data space
  45. DirApp string
  46. // SignUpApp points to the app used for creating new accounts
  47. SignUpApp string
  48. // ProxyTemplate is the URL of the service that handles WebID-TLS delegation
  49. ProxyTemplate string
  50. // ProxyLocal enables/disables proxying of resources on localhost
  51. ProxyLocal bool
  52. // QueryTemplate is the URL of the service that handles query request using twinql
  53. QueryTemplate string
  54. // DirIndex contains the default index file name
  55. DirIndex []string
  56. // DiskLimit is the maximum total disk (in bytes) to be allocated to a given user
  57. DiskLimit int
  58. // Agent is the WebID of the agent used for WebID-TLS delegation (and proxy)
  59. Agent string
  60. // Salt is the value used for hashing passwords
  61. Salt string
  62. // BoltPath points to the location of the Bolt db on the filesystem
  63. BoltPath string
  64. // SMTPConfig holds the settings for the remote SMTP user/server
  65. SMTPConfig EmailConfig
  66. }
  67. // NewServerConfig creates a new config object
  68. func NewServerConfig() *ServerConfig {
  69. return &ServerConfig{
  70. CookieAge: 8736, // hours (1 year)
  71. TokenAge: 5,
  72. HSTS: true,
  73. WebIDTLS: true,
  74. MetaSuffix: ".meta",
  75. ACLSuffix: ".acl",
  76. DataApp: "tabulator",
  77. DirIndex: []string{"index.html", "index.htm"},
  78. DirApp: "http://linkeddata.github.io/warp/#list/",
  79. SignUpApp: "https://solid.github.io/solid-signup/?domain=",
  80. DiskLimit: 100000000, // 100MB
  81. DataRoot: serverDefaultRoot(),
  82. BoltPath: filepath.Join(os.TempDir(), "bolt.db"),
  83. ProxyLocal: true,
  84. }
  85. }
  86. // LoadJSONFile loads server configuration
  87. func (c *ServerConfig) LoadJSONFile(filename string) error {
  88. b, err := ioutil.ReadFile(filename)
  89. if err != nil {
  90. return err
  91. }
  92. return json.Unmarshal(b, &c)
  93. }
  94. func serverDefaultRoot() string {
  95. serverRoot, err := os.Getwd()
  96. if err != nil {
  97. log.Fatalln(err)
  98. }
  99. if !strings.HasSuffix(serverRoot, "/") {
  100. serverRoot += "/"
  101. }
  102. return serverRoot
  103. }