~ubuntu-branches/ubuntu/utopic/hockeypuck/utopic-proposed

« back to all changes in this revision

Viewing changes to hkp/templates.go

  • Committer: Package Import Robot
  • Author(s): Casey Marshall
  • Date: 2014-04-13 20:06:01 UTC
  • Revision ID: package-import@ubuntu.com-20140413200601-oxdlqn1gy0x8m55u
Tags: 1.0~rel20140413+7a1892a~trusty
Hockeypuck 1.0 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Hockeypuck - OpenPGP key server
 
3
   Copyright (C) 2012-2014  Casey Marshall
 
4
 
 
5
   This program is free software: you can redistribute it and/or modify
 
6
   it under the terms of the GNU Affero General Public License as published by
 
7
   the Free Software Foundation, version 3.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU Affero General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Affero General Public License
 
15
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
package hkp
 
19
 
 
20
import (
 
21
        "html/template"
 
22
        "strings"
 
23
        "time"
 
24
)
 
25
 
 
26
const footerTmplSrc = `
 
27
{{define "page_footer"}}
 
28
<div id="footer">
 
29
<div id="copyright"><a href="http://hockeypuck.github.io/">Hockeypuck OpenPGP Key Server</a> - Copyright (C) 2012 <a href="/pks/lookup?op=vindex&search=0x44A2D1DB">Casey Marshall</a> and Hockeypuck contributors.</div>
 
30
<div id="copyleft">This program is free software: you can redistribute it and/or modify
 
31
  it under the terms of the
 
32
  <a href="https://www.gnu.org/licenses/agpl-3.0.html">GNU Affero General Public License</a>
 
33
  as published by the Free Software Foundation, version 3.</div>
 
34
</div>
 
35
{{end}}`
 
36
 
 
37
const headTmplSrc = `
 
38
{{define "head"}}
 
39
<link rel="stylesheet" href="/css/reset.css" />
 
40
<link rel="stylesheet" href="/css/hkp.css" />
 
41
{{end}}`
 
42
 
 
43
const headerTmplSrc = `
 
44
{{define "page_header"}}
 
45
<div id="header">
 
46
<h1><a id="logo" href="/">Hockeypuck</a></h1>
 
47
<div id="topmenu">
 
48
        <ul>
 
49
                <li><span class="menu-label">OpenPGP:</span></li>
 
50
                <li><a href="/openpgp/lookup">Search</a></li>
 
51
                <li><a href="/openpgp/add">Add</a></li>
 
52
                <li><a href="/pks/lookup?op=stats">Stats</a></li>
 
53
                <li><span class="menu-label">Machines:</span></li>
 
54
                <li><span class="todo-link">SSH</span></li>
 
55
                <li><span class="todo-link">SSL/TLS</span></li>
 
56
                <li class="about"><a href="http://hockeypuck.github.io/">Project Home</a></li>
 
57
        </ul>
 
58
</div>
 
59
</div>
 
60
{{end}}`
 
61
 
 
62
const layoutTmplSrc = `
 
63
{{define "top"}}
 
64
<!DOCTYPE html>
 
65
<html>
 
66
<head>
 
67
<meta charset="utf-8" />
 
68
<title>{{template "title"}}</title>
 
69
{{template "head"}}
 
70
</head>
 
71
<body>
 
72
<div id="container">
 
73
{{template "page_header"}}
 
74
<div id="main">
 
75
{{end}}
 
76
 
 
77
{{define "bottom"}}
 
78
</div><!-- main -->
 
79
</div><!-- container -->
 
80
{{template "page_footer"}}
 
81
</body>
 
82
</html>
 
83
{{end}}
 
84
 
 
85
{{define "layout"}}
 
86
{{template "top" .}}
 
87
{{template "page_content" .}}
 
88
{{template "bottom" .}}
 
89
{{end}}`
 
90
 
 
91
const addFormTmplSrc = `
 
92
{{define "title"}}Hockeypuck | Add Public Key{{end}}
 
93
 
 
94
{{define "page_content"}}
 
95
<h2 class="pks-add">Add Public Key</h2>
 
96
<p>Paste the ASCII-armored public key block into the form below.</p>
 
97
<form class="pks-add" action="/pks/add" method="post">
 
98
        <div>
 
99
                <textarea name="keytext" cols="66" rows="20"></textarea>
 
100
        </div>
 
101
        <div>
 
102
                <input id="add_submit" type="submit" value="Add Public Key"></input>
 
103
        </div>
 
104
</form>
 
105
{{end}}`
 
106
 
 
107
const addResultTmplSrc = `
 
108
{{define "title"}}Hockeypuck | Updated Public Keys{{end}}
 
109
 
 
110
{{define "page_content"}}
 
111
<h2>Updated Public Keys</h2>
 
112
{{range .Changes}}
 
113
<p><a href="/pks/lookup?op=index&search=0x{{.Fingerprint}}">{{.}}</a></p>
 
114
{{end}}
 
115
{{end}}`
 
116
 
 
117
const searchFormTmplSrc = `
 
118
{{define "title"}}Hockeypuck | Search OpenPGP Public Keys{{end}}
 
119
 
 
120
{{define "page_content"}}
 
121
<h2 class="pks-search">OpenPGP Search</h2>
 
122
<form class="pks-search" method="post">
 
123
        <div>
 
124
                <input name="search" type="search"></input>
 
125
        </div>
 
126
        <div>
 
127
                <input id="search_submit" formaction="/pks/lookup?op=index" type="submit" value="Public Key Search"></input>
 
128
                <input id="get_submit" formaction="/pks/lookup?op=get" type="submit" value="I'm Feeling Lucky"></input>
 
129
        </div>
 
130
</form>
 
131
{{end}}`
 
132
 
 
133
const statsTmplSrc = `
 
134
{{define "title"}}Hockeypuck | Server Status{{end}}
 
135
 
 
136
{{define "page_content"}}
 
137
<h2>Server Status</h2>
 
138
<table>
 
139
<tr><th>Hostname:</th><td>{{.Hostname}}</td></tr>
 
140
<tr><th>Port:</th><td>{{.Port}}</td></tr>
 
141
<tr><th>Version:</th><td>{{.Version}}</td></tr>
 
142
</table>
 
143
{{if .PksPeers}}
 
144
<h2>Outgoing Mailsync Peers</h2>
 
145
<table>
 
146
<tr><th>Email Address</th><th>Last Synchronized</th></tr>
 
147
{{range .PksPeers}}
 
148
<tr><td>{{.Addr}}</td><td>{{timef .LastSync}}</td></tr>
 
149
{{end}}
 
150
</table>
 
151
{{end}}
 
152
<h2>Statistics</h2>
 
153
<table>
 
154
<tr><th>Total number of keys:</th><td>{{.TotalKeys}}</td></tr>
 
155
</table>
 
156
{{if .KeyStatsHourly}}
 
157
<h3>Keys loaded in the last 24 hours</h3>
 
158
<table>
 
159
<tr><th>Hour</th><th>New</th><th>Updated</th></tr>
 
160
{{range .KeyStatsHourly}}
 
161
<tr><td>{{.Hour}}</td><td>{{.Created}}</td><td>{{.Modified}}</td></tr>
 
162
{{end}}
 
163
</table>
 
164
{{end}}
 
165
{{if .KeyStatsDaily}}
 
166
<h3>Keys loaded in the last 7 days</h3>
 
167
<table>
 
168
<tr><th>Day</th><th>New</th><th>Updated</th></tr>
 
169
{{range .KeyStatsDaily}}
 
170
<tr><td>{{.Day}}</td><td>{{.Created}}</td><td>{{.Modified}}</td></tr>
 
171
{{end}}
 
172
</table>
 
173
{{end}}
 
174
{{end}}`
 
175
 
 
176
// baseTmplSrcs contains common templates that need to be defined
 
177
// for all Hockeypuck HKP templates.
 
178
var BaseTemplateSrcs = []string{
 
179
        headTmplSrc, headerTmplSrc, footerTmplSrc,
 
180
        layoutTmplSrc}
 
181
 
 
182
// SearchFormTemplate is used to render the default search form at '/'
 
183
var SearchFormTemplate *template.Template
 
184
 
 
185
// AddFormTemplate is used to render the form to add a key.
 
186
var AddFormTemplate *template.Template
 
187
 
 
188
// AddResultTemplate displays the fingerprints of updated keys.
 
189
var AddResultTemplate *template.Template
 
190
 
 
191
// PksIndexTemplate is used to render the op=index and op=vindex
 
192
// responses when not in machine readable mode.
 
193
var PksIndexTemplate *template.Template
 
194
 
 
195
// StatsTemplate renders the op=stats page
 
196
var StatsTemplate *template.Template
 
197
 
 
198
func mustParseHkpTemplate(src string) *template.Template {
 
199
        return template.Must(template.New("placeholder").Parse(strings.Join(
 
200
                append(BaseTemplateSrcs, src), "")))
 
201
}
 
202
 
 
203
func init() {
 
204
        SearchFormTemplate = mustParseHkpTemplate(searchFormTmplSrc)
 
205
        AddFormTemplate = mustParseHkpTemplate(addFormTmplSrc)
 
206
        AddResultTemplate = mustParseHkpTemplate(addResultTmplSrc)
 
207
        StatsTemplate = template.Must(template.New("placeholder").Funcs(
 
208
                template.FuncMap{"timef": func(ts int64) string {
 
209
                        tm := time.Unix(0, ts)
 
210
                        return tm.Format(time.RFC3339)
 
211
                }}).Parse(strings.Join(append(BaseTemplateSrcs, statsTmplSrc), "")))
 
212
}