3 e7e5fa49 2022-12-30 thomas * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 e7e5fa49 2022-12-30 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
6 e7e5fa49 2022-12-30 thomas * Permission to use, copy, modify, and distribute this software for any
7 e7e5fa49 2022-12-30 thomas * purpose with or without fee is hereby granted, provided that the above
8 e7e5fa49 2022-12-30 thomas * copyright notice and this permission notice appear in all copies.
10 e7e5fa49 2022-12-30 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 e7e5fa49 2022-12-30 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 e7e5fa49 2022-12-30 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 e7e5fa49 2022-12-30 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 e7e5fa49 2022-12-30 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 e7e5fa49 2022-12-30 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 e7e5fa49 2022-12-30 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 e7e5fa49 2022-12-30 thomas #include <sys/types.h>
20 e7e5fa49 2022-12-30 thomas #include <sys/queue.h>
22 e7e5fa49 2022-12-30 thomas #include <event.h>
23 e7e5fa49 2022-12-30 thomas #include <stdint.h>
24 e7e5fa49 2022-12-30 thomas #include <stdlib.h>
25 e7e5fa49 2022-12-30 thomas #include <string.h>
26 e7e5fa49 2022-12-30 thomas #include <imsg.h>
28 e7e5fa49 2022-12-30 thomas #include "proc.h"
30 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
31 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
33 e7e5fa49 2022-12-30 thomas static int
34 e7e5fa49 2022-12-30 thomas gotweb_render_age(struct template *tp, time_t time, int ref_tm)
36 e7e5fa49 2022-12-30 thomas const struct got_error *err;
37 e7e5fa49 2022-12-30 thomas char *age;
40 e7e5fa49 2022-12-30 thomas err = gotweb_get_time_str(&age, time, ref_tm);
43 e7e5fa49 2022-12-30 thomas r = tp->tp_puts(tp, age);
44 e7e5fa49 2022-12-30 thomas free(age);
50 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_header(struct template *tp) }}
52 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
53 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
54 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
55 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
56 e7e5fa49 2022-12-30 thomas const char *prfx = c->script_name;
57 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
59 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
60 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
61 e7e5fa49 2022-12-30 thomas u_path.page = -1;
62 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
64 e7e5fa49 2022-12-30 thomas <!doctype html>
67 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
68 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
69 e7e5fa49 2022-12-30 thomas <meta name="viewport" content="initial-scale=.75" />
70 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
71 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
72 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
73 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
74 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
75 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
76 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
77 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
80 e7e5fa49 2022-12-30 thomas <div id="gw_body">
81 e7e5fa49 2022-12-30 thomas <div id="header">
82 e7e5fa49 2022-12-30 thomas <div id="got_link">
83 e7e5fa49 2022-12-30 thomas <a href="{{ srv->logo_url }}" target="_blank">
84 e7e5fa49 2022-12-30 thomas <img src="{{ prfx }}{{ srv->logo }}" />
88 e7e5fa49 2022-12-30 thomas <div id="site_path">
89 e7e5fa49 2022-12-30 thomas <div id="site_link">
90 e7e5fa49 2022-12-30 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
91 e7e5fa49 2022-12-30 thomas {{ srv->site_link }}
93 e7e5fa49 2022-12-30 thomas {{ if qs->path }}
94 e7e5fa49 2022-12-30 thomas {! u_path.path = qs->path; !}
95 e7e5fa49 2022-12-30 thomas {{ " / " }}
96 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
97 e7e5fa49 2022-12-30 thomas {{ qs->path }}
100 e7e5fa49 2022-12-30 thomas {{ if qs->action != INDEX }}
101 e7e5fa49 2022-12-30 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
102 e7e5fa49 2022-12-30 thomas {{ end }}
105 e7e5fa49 2022-12-30 thomas <div id="content">
106 e7e5fa49 2022-12-30 thomas {{ end }}
108 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_footer(struct template *tp) }}
110 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
111 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
113 e7e5fa49 2022-12-30 thomas <div id="site_owner_wrapper">
114 e7e5fa49 2022-12-30 thomas <div id="site_owner">
115 e7e5fa49 2022-12-30 thomas {{ if srv->show_site_owner }}
116 e7e5fa49 2022-12-30 thomas {{ srv->site_owner }}
117 e7e5fa49 2022-12-30 thomas {{ end }}
124 e7e5fa49 2022-12-30 thomas {{ end }}
126 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
128 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
129 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
131 e7e5fa49 2022-12-30 thomas <div id="index_header">
132 e7e5fa49 2022-12-30 thomas <div id="index_header_project">
135 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
136 e7e5fa49 2022-12-30 thomas <div id="index_header_description">
137 e7e5fa49 2022-12-30 thomas Description
139 e7e5fa49 2022-12-30 thomas {{ end }}
140 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
141 e7e5fa49 2022-12-30 thomas <div id="index_header_owner">
144 e7e5fa49 2022-12-30 thomas {{ end }}
145 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
146 e7e5fa49 2022-12-30 thomas <div id="index_header_age">
147 e7e5fa49 2022-12-30 thomas Last Change
149 e7e5fa49 2022-12-30 thomas {{ end }}
151 e7e5fa49 2022-12-30 thomas {{ end }}
153 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
155 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
156 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
157 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
158 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
159 e7e5fa49 2022-12-30 thomas .index_page = -1,
160 e7e5fa49 2022-12-30 thomas .page = -1,
161 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
162 e7e5fa49 2022-12-30 thomas }, briefs = {
163 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
164 e7e5fa49 2022-12-30 thomas .index_page = -1,
165 e7e5fa49 2022-12-30 thomas .page = -1,
166 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
167 e7e5fa49 2022-12-30 thomas }, commits = {
168 e7e5fa49 2022-12-30 thomas .action = COMMITS,
169 e7e5fa49 2022-12-30 thomas .index_page = -1,
170 e7e5fa49 2022-12-30 thomas .page = -1,
171 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
172 e7e5fa49 2022-12-30 thomas }, tags = {
173 e7e5fa49 2022-12-30 thomas .action = TAGS,
174 e7e5fa49 2022-12-30 thomas .index_page = -1,
175 e7e5fa49 2022-12-30 thomas .page = -1,
176 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
177 e7e5fa49 2022-12-30 thomas }, tree = {
178 e7e5fa49 2022-12-30 thomas .action = TREE,
179 e7e5fa49 2022-12-30 thomas .index_page = -1,
180 e7e5fa49 2022-12-30 thomas .page = -1,
181 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
184 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
185 e7e5fa49 2022-12-30 thomas <div class="index_project">
186 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
188 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
189 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
190 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
192 e7e5fa49 2022-12-30 thomas {{ end }}
193 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
194 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
195 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
197 e7e5fa49 2022-12-30 thomas {{ end }}
198 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
199 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
200 e7e5fa49 2022-12-30 thomas {{ repo_dir->age }}
202 e7e5fa49 2022-12-30 thomas {{ end }}
203 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
204 e7e5fa49 2022-12-30 thomas <div class="navs">
205 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
206 e7e5fa49 2022-12-30 thomas {{ " | " }}
207 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
208 e7e5fa49 2022-12-30 thomas {{ " | " }}
209 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
210 e7e5fa49 2022-12-30 thomas {{ " | " }}
211 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
212 e7e5fa49 2022-12-30 thomas {{ " | " }}
213 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
215 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
218 e7e5fa49 2022-12-30 thomas {{ end }}
220 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
222 e7e5fa49 2022-12-30 thomas const struct got_error *error;
223 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
224 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
225 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
226 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
227 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
228 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
229 e7e5fa49 2022-12-30 thomas struct gotweb_url diff_url, tree_url;
230 e7e5fa49 2022-12-30 thomas char *tmp;
232 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
233 e7e5fa49 2022-12-30 thomas .action = DIFF,
234 e7e5fa49 2022-12-30 thomas .index_page = -1,
235 e7e5fa49 2022-12-30 thomas .page = -1,
236 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
237 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
239 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
240 e7e5fa49 2022-12-30 thomas .action = TREE,
241 e7e5fa49 2022-12-30 thomas .index_page = -1,
242 e7e5fa49 2022-12-30 thomas .page = -1,
243 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
244 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
247 e7e5fa49 2022-12-30 thomas if (qs->action == SUMMARY) {
248 e7e5fa49 2022-12-30 thomas qs->action = BRIEFS;
249 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
251 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, srv->max_commits_display);
252 e7e5fa49 2022-12-30 thomas if (error)
253 e7e5fa49 2022-12-30 thomas return -1;
255 e7e5fa49 2022-12-30 thomas <div id="briefs_title_wrapper">
256 e7e5fa49 2022-12-30 thomas <div id="briefs_title">Commit Briefs</div>
258 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
259 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
261 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
262 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
264 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->author, '<');
266 e7e5fa49 2022-12-30 thomas *tmp = '\0';
268 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
270 e7e5fa49 2022-12-30 thomas *tmp = '\0';
272 e7e5fa49 2022-12-30 thomas <div class="briefs_age">
273 e7e5fa49 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
275 e7e5fa49 2022-12-30 thomas <div class="briefs_author">
276 e7e5fa49 2022-12-30 thomas {{ rc->author }}
278 e7e5fa49 2022-12-30 thomas <div class="briefs_log">
279 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
280 e7e5fa49 2022-12-30 thomas {{ rc->commit_msg }}
282 e7e5fa49 2022-12-30 thomas {{ if rc->refs_str }}
283 e7e5fa49 2022-12-30 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
284 e7e5fa49 2022-12-30 thomas {{ end }}
287 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
288 e7e5fa49 2022-12-30 thomas <div class="navs">
289 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
290 e7e5fa49 2022-12-30 thomas {{ " | " }}
291 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
294 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
295 e7e5fa49 2022-12-30 thomas {{ end }}
296 e7e5fa49 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
297 2f4f0731 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
298 e7e5fa49 2022-12-30 thomas {{ end }}
300 2f4f0731 2022-12-30 thomas {{ end }}
302 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
304 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
305 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
306 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
307 2f4f0731 2022-12-30 thomas int have_prev, have_next;
309 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
311 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
312 2f4f0731 2022-12-30 thomas <div id="nav_prev">
313 2f4f0731 2022-12-30 thomas {{ if have_prev }}
314 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
317 2f4f0731 2022-12-30 thomas {{ end }}
319 2f4f0731 2022-12-30 thomas <div id="nav_next">
320 2f4f0731 2022-12-30 thomas {{ if have_next }}
321 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
324 2f4f0731 2022-12-30 thomas {{ end }}
327 2f4f0731 2022-12-30 thomas {{ finally }}
329 2f4f0731 2022-12-30 thomas free(t->next_id);
330 2f4f0731 2022-12-30 thomas t->next_id = NULL;
331 2f4f0731 2022-12-30 thomas free(t->prev_id);
332 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
334 e7e5fa49 2022-12-30 thomas {{ end }}
336 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
338 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
339 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
340 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
341 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
342 7ade8b27 2022-12-30 thomas struct gotweb_url diff, tree;
344 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
345 7ade8b27 2022-12-30 thomas .action = DIFF,
346 7ade8b27 2022-12-30 thomas .index_page = -1,
347 7ade8b27 2022-12-30 thomas .page = -1,
348 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
350 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
351 7ade8b27 2022-12-30 thomas .action = TREE,
352 7ade8b27 2022-12-30 thomas .index_page = -1,
353 7ade8b27 2022-12-30 thomas .page = -1,
354 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
357 7ade8b27 2022-12-30 thomas <div class="commits_title_wrapper">
358 7ade8b27 2022-12-30 thomas <div class="commits_title">Commits</div>
360 7ade8b27 2022-12-30 thomas <div class="commits_content">
361 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
363 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
364 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
366 7ade8b27 2022-12-30 thomas <div class="commits_header_wrapper">
367 7ade8b27 2022-12-30 thomas <div class="commits_header">
368 7ade8b27 2022-12-30 thomas <div class="header_commit_title">Commit:</div>
369 7ade8b27 2022-12-30 thomas <div class="header_commit">{{ rc->commit_id }}</div>
370 7ade8b27 2022-12-30 thomas <div class="header_author_title">Author:</div>
371 7ade8b27 2022-12-30 thomas <div class="header_author">{{ rc->author }}</div>
372 7ade8b27 2022-12-30 thomas <div class="header_age_title">Date:</div>
373 7ade8b27 2022-12-30 thomas <div class="header_age">
374 7ade8b27 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
378 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
379 7ade8b27 2022-12-30 thomas <div class="navs">
380 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
381 7ade8b27 2022-12-30 thomas {{ " | " }}
382 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
385 7ade8b27 2022-12-30 thomas <div class="dotted_line"></div>
386 7ade8b27 2022-12-30 thomas {{ end }}
387 7ade8b27 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
388 7ade8b27 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
389 7ade8b27 2022-12-30 thomas {{ end }}
391 7ade8b27 2022-12-30 thomas {{ end }}