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