forked from ponzu-cms/ponzu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
185 lines (173 loc) · 5.48 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package entities
import (
"github.com/fanky5g/ponzu/config"
"github.com/fanky5g/ponzu/content/editor"
"github.com/fanky5g/ponzu/content/item"
)
// Config represents the configurable options of the system
type Config struct {
item.Item
Name string `json:"name"`
Domain string `json:"domain"`
BindAddress string `json:"bind_addr"`
HTTPPort string `json:"http_port"`
HTTPSPort string `json:"https_port"`
AdminEmail string `json:"admin_email"`
ClientSecret string `json:"client_secret"`
Etag string `json:"etag"`
DisableCORS bool `json:"cors_disabled"`
DisableGZIP bool `json:"gzip_disabled"`
DisableHTTPCache bool `json:"cache_disabled"`
CacheMaxAge int64 `json:"cache_max_age"`
CacheInvalidate []string `json:"cache"`
BackupBasicAuthUser string `json:"backup_basic_auth_user"`
BackupBasicAuthPassword string `json:"backup_basic_auth_password"`
}
// String partially implements item.Identifiable and overrides Item's String()
func (c *Config) String() string { return c.Name }
// MarshalEditor writes a buffer of templates to edit a Post and partially implements editor.Editable
func (c *Config) MarshalEditor(paths config.Paths) ([]byte, error) {
view, err := editor.Form(c,
paths,
editor.Field{
View: editor.Input("Name", c, map[string]string{
"label": "Site Name",
"placeholder": "Add a name to this site (internal use only)",
}, nil),
},
editor.Field{
View: editor.Input("Domain", c, map[string]string{
"label": "Domain Name (required for SSL certificate)",
"placeholder": "e.g. www.example.com or example.com",
}, nil),
},
editor.Field{
View: editor.Input("BindAddress", c, map[string]string{
"type": "hidden",
}, nil),
},
editor.Field{
View: editor.Input("HTTPPort", c, map[string]string{
"type": "hidden",
}, nil),
},
editor.Field{
View: editor.Input("HTTPSPort", c, map[string]string{
"type": "hidden",
}, nil),
},
editor.Field{
View: editor.Input("AdminEmail", c, map[string]string{
"label": "Administrator Email (notified of internal system information)",
}, nil),
},
editor.Field{
View: editor.Input("ClientSecret", c, map[string]string{
"label": "Client Secret (used to validate requests, DO NOT SHARE)",
"disabled": "true",
}, nil),
},
editor.Field{
View: editor.Input("ClientSecret", c, map[string]string{
"type": "hidden",
}, nil),
},
editor.Field{
View: editor.Input("Etag", c, map[string]string{
"label": "Etag Header (used to cache resources)",
"disabled": "true",
}, nil),
},
editor.Field{
View: editor.Input("Etag", c, map[string]string{
"type": "hidden",
}, nil),
},
editor.Field{
View: editor.Checkbox("DisableCORS", c, map[string]string{
"label": "Disable CORS (so only " + c.Domain + " can fetch your data)",
}, map[string]string{
"true": "Disable CORS",
}),
},
editor.Field{
View: editor.Checkbox("DisableGZIP", c, map[string]string{
"label": "Disable GZIP (will increase server speed, but also bandwidth)",
}, map[string]string{
"true": "Disable GZIP",
}),
},
editor.Field{
View: editor.Checkbox("DisableHTTPCache", c, map[string]string{
"label": "Disable HTTP Cache (overrides 'Cache-Control' header)",
}, map[string]string{
"true": "Disable HTTP Cache",
}),
},
editor.Field{
View: editor.Input("CacheMaxAge", c, map[string]string{
"label": "Max-Age value for HTTP caching (in seconds, 0 = 2592000)",
"type": "text",
}, nil),
},
editor.Field{
View: editor.Checkbox("CacheInvalidate", c, map[string]string{
"label": "Invalidate cache on save",
}, map[string]string{
"invalidate": "Invalidate Cache",
}),
},
editor.Field{
View: editor.Input("BackupBasicAuthUser", c, map[string]string{
"label": "HTTP Basic Auth GetUserByEmail",
"placeholder": "Enter a user name for Basic Auth access",
"type": "text",
}, nil),
},
editor.Field{
View: editor.Input("BackupBasicAuthPassword", c, map[string]string{
"label": "HTTP Basic Auth Password",
"placeholder": "Enter a password for Basic Auth access",
"type": "password",
}, nil),
},
)
if err != nil {
return nil, err
}
openingTag := []byte(`
<div class="card">
<div class="card-content">
<div class="card-title">System Configuration</div>
</div>
<form action="` + paths.PublicPath + `/configure" method="post">
`)
closingTag := []byte(`</form></div>`)
script := []byte(`
<script>
$(function() {
// hide default fields & labels unnecessary for the config
var fields = $('.default-fields');
fields.css('position', 'relative');
fields.find('input:not([type=submit])').remove();
fields.find('label').remove();
fields.find('button').css({
position: 'absolute',
top: '-10px',
right: '0px'
});
var contentOnly = $('.entities-only.__ponzu');
contentOnly.hide();
contentOnly.find('input, textarea, select').attr('name', '');
// adjust layout of td so save button is in same location as usual
fields.find('td').css('float', 'right');
// stop some fixed config settings from being modified
fields.find('input[name=client_secret]').attr('name', '');
});
</script>
`)
view = append(openingTag, view...)
view = append(view, closingTag...)
view = append(view, script...)
return view, nil
}