Blame


1 ed619ca0 2022-12-14 op {!
2 ed619ca0 2022-12-14 op /*
3 ed619ca0 2022-12-14 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 ed619ca0 2022-12-14 op * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 ed619ca0 2022-12-14 op *
6 ed619ca0 2022-12-14 op * Permission to use, copy, modify, and distribute this software for any
7 ed619ca0 2022-12-14 op * purpose with or without fee is hereby granted, provided that the above
8 ed619ca0 2022-12-14 op * copyright notice and this permission notice appear in all copies.
9 ed619ca0 2022-12-14 op *
10 ed619ca0 2022-12-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 ed619ca0 2022-12-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 ed619ca0 2022-12-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ed619ca0 2022-12-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 ed619ca0 2022-12-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ed619ca0 2022-12-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 ed619ca0 2022-12-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ed619ca0 2022-12-14 op */
18 ed619ca0 2022-12-14 op
19 ed619ca0 2022-12-14 op #include <sys/types.h>
20 ed619ca0 2022-12-14 op #include <sys/queue.h>
21 ed619ca0 2022-12-14 op
22 ed619ca0 2022-12-14 op #include <event.h>
23 ed619ca0 2022-12-14 op #include <stdint.h>
24 ed619ca0 2022-12-14 op #include <stdlib.h>
25 ed619ca0 2022-12-14 op #include <string.h>
26 ed619ca0 2022-12-14 op #include <imsg.h>
27 ed619ca0 2022-12-14 op
28 ed619ca0 2022-12-14 op #include "proc.h"
29 ed619ca0 2022-12-14 op
30 ed619ca0 2022-12-14 op #include "gotwebd.h"
31 ed619ca0 2022-12-14 op #include "tmpl.h"
32 ed619ca0 2022-12-14 op
33 ed619ca0 2022-12-14 op const struct got_error *gotweb_render_navs(struct request *);
34 ed619ca0 2022-12-14 op
35 ed619ca0 2022-12-14 op static int
36 ed619ca0 2022-12-14 op gotweb_render_age(struct template *tp, time_t time, int ref_tm)
37 ed619ca0 2022-12-14 op {
38 ed619ca0 2022-12-14 op const struct got_error *err;
39 ed619ca0 2022-12-14 op char *age;
40 ed619ca0 2022-12-14 op int r;
41 ed619ca0 2022-12-14 op
42 ed619ca0 2022-12-14 op err = gotweb_get_time_str(&age, time, ref_tm);
43 ed619ca0 2022-12-14 op if (err)
44 ed619ca0 2022-12-14 op return 0;
45 ed619ca0 2022-12-14 op r = tp->tp_puts(tp, age);
46 ed619ca0 2022-12-14 op free(age);
47 ed619ca0 2022-12-14 op return r;
48 ed619ca0 2022-12-14 op }
49 ed619ca0 2022-12-14 op
50 ed619ca0 2022-12-14 op !}
51 ed619ca0 2022-12-14 op
52 ed619ca0 2022-12-14 op {{ define gotweb_render_header(struct template *tp) }}
53 ed619ca0 2022-12-14 op {!
54 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
55 ed619ca0 2022-12-14 op struct server *srv = c->srv;
56 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
57 ed619ca0 2022-12-14 op struct gotweb_url u_path;
58 ed619ca0 2022-12-14 op const char *prfx = c->script_name;
59 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
60 ed619ca0 2022-12-14 op
61 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
62 ed619ca0 2022-12-14 op u_path.index_page = -1;
63 ed619ca0 2022-12-14 op u_path.page = -1;
64 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
65 ed619ca0 2022-12-14 op !}
66 ed619ca0 2022-12-14 op <!doctype html>
67 ed619ca0 2022-12-14 op <html>
68 ed619ca0 2022-12-14 op <head>
69 ed619ca0 2022-12-14 op <meta charset="utf-8" />
70 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
71 ed619ca0 2022-12-14 op <meta name="viewport" content="initial-scale=.75" />
72 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
73 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
74 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
75 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
76 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
77 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
78 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
79 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
80 ed619ca0 2022-12-14 op </head>
81 ed619ca0 2022-12-14 op <body>
82 ed619ca0 2022-12-14 op <div id="gw_body">
83 ed619ca0 2022-12-14 op <div id="header">
84 ed619ca0 2022-12-14 op <div id="got_link">
85 ed619ca0 2022-12-14 op <a href="{{ srv->logo_url }}" target="_blank">
86 ed619ca0 2022-12-14 op <img src="{{ prfx }}{{ srv->logo }}" />
87 ed619ca0 2022-12-14 op </a>
88 ed619ca0 2022-12-14 op </div>
89 ed619ca0 2022-12-14 op </div>
90 ed619ca0 2022-12-14 op <div id="site_path">
91 ed619ca0 2022-12-14 op <div id="site_link">
92 ed619ca0 2022-12-14 op <a href="?index_page={{ printf "%d", qs->index_page }}">
93 ed619ca0 2022-12-14 op {{ srv->site_link }}
94 ed619ca0 2022-12-14 op </a>
95 ed619ca0 2022-12-14 op {{ if qs->path }}
96 ed619ca0 2022-12-14 op {! u_path.path = qs->path; !}
97 ed619ca0 2022-12-14 op {{ " / " }}
98 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
99 ed619ca0 2022-12-14 op {{ qs->path }}
100 ed619ca0 2022-12-14 op </a>
101 ed619ca0 2022-12-14 op {{ end }}
102 ed619ca0 2022-12-14 op {{ if qs->action != INDEX }}
103 ed619ca0 2022-12-14 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
104 ed619ca0 2022-12-14 op {{ end }}
105 ed619ca0 2022-12-14 op </div>
106 ed619ca0 2022-12-14 op </div>
107 ed619ca0 2022-12-14 op <div id="content">
108 ed619ca0 2022-12-14 op {{ end }}
109 ed619ca0 2022-12-14 op
110 ed619ca0 2022-12-14 op {{ define gotweb_render_footer(struct template *tp) }}
111 ed619ca0 2022-12-14 op {!
112 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
113 ed619ca0 2022-12-14 op struct server *srv = c->srv;
114 ed619ca0 2022-12-14 op !}
115 ed619ca0 2022-12-14 op <div id="site_owner_wrapper">
116 ed619ca0 2022-12-14 op <div id="site_owner">
117 ed619ca0 2022-12-14 op {{ if srv->show_site_owner }}
118 ed619ca0 2022-12-14 op {{ srv->site_owner }}
119 ed619ca0 2022-12-14 op {{ end }}
120 ed619ca0 2022-12-14 op </div>
121 ed619ca0 2022-12-14 op </div>
122 ed619ca0 2022-12-14 op </div>
123 ed619ca0 2022-12-14 op </div>
124 ed619ca0 2022-12-14 op </body>
125 ed619ca0 2022-12-14 op </html>
126 ed619ca0 2022-12-14 op {{ end }}
127 ed619ca0 2022-12-14 op
128 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
129 ed619ca0 2022-12-14 op {!
130 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
131 ed619ca0 2022-12-14 op struct server *srv = c->srv;
132 ed619ca0 2022-12-14 op !}
133 ed619ca0 2022-12-14 op <div id="index_header">
134 ed619ca0 2022-12-14 op <div id="index_header_project">
135 ed619ca0 2022-12-14 op Project
136 ed619ca0 2022-12-14 op </div>
137 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
138 ed619ca0 2022-12-14 op <div id="index_header_description">
139 ed619ca0 2022-12-14 op Description
140 ed619ca0 2022-12-14 op </div>
141 ed619ca0 2022-12-14 op {{ end }}
142 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
143 ed619ca0 2022-12-14 op <div id="index_header_owner">
144 ed619ca0 2022-12-14 op Owner
145 ed619ca0 2022-12-14 op </div>
146 ed619ca0 2022-12-14 op {{ end }}
147 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
148 ed619ca0 2022-12-14 op <div id="index_header_age">
149 ed619ca0 2022-12-14 op Last Change
150 ed619ca0 2022-12-14 op </div>
151 ed619ca0 2022-12-14 op {{ end }}
152 ed619ca0 2022-12-14 op </div>
153 ed619ca0 2022-12-14 op {{ end }}
154 ed619ca0 2022-12-14 op
155 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
156 ed619ca0 2022-12-14 op {!
157 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
158 ed619ca0 2022-12-14 op struct server *srv = c->srv;
159 ed619ca0 2022-12-14 op struct gotweb_url summary = {
160 ed619ca0 2022-12-14 op .action = SUMMARY,
161 ed619ca0 2022-12-14 op .index_page = -1,
162 ed619ca0 2022-12-14 op .page = -1,
163 ed619ca0 2022-12-14 op .path = repo_dir->name,
164 ed619ca0 2022-12-14 op }, briefs = {
165 ed619ca0 2022-12-14 op .action = BRIEFS,
166 ed619ca0 2022-12-14 op .index_page = -1,
167 ed619ca0 2022-12-14 op .page = -1,
168 ed619ca0 2022-12-14 op .path = repo_dir->name,
169 ed619ca0 2022-12-14 op }, commits = {
170 ed619ca0 2022-12-14 op .action = COMMITS,
171 ed619ca0 2022-12-14 op .index_page = -1,
172 ed619ca0 2022-12-14 op .page = -1,
173 ed619ca0 2022-12-14 op .path = repo_dir->name,
174 ed619ca0 2022-12-14 op }, tags = {
175 ed619ca0 2022-12-14 op .action = TAGS,
176 ed619ca0 2022-12-14 op .index_page = -1,
177 ed619ca0 2022-12-14 op .page = -1,
178 ed619ca0 2022-12-14 op .path = repo_dir->name,
179 ed619ca0 2022-12-14 op }, tree = {
180 ed619ca0 2022-12-14 op .action = TREE,
181 ed619ca0 2022-12-14 op .index_page = -1,
182 ed619ca0 2022-12-14 op .page = -1,
183 ed619ca0 2022-12-14 op .path = repo_dir->name,
184 ed619ca0 2022-12-14 op };
185 ed619ca0 2022-12-14 op !}
186 ed619ca0 2022-12-14 op <div class="index_wrapper">
187 ed619ca0 2022-12-14 op <div class="index_project">
188 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
189 ed619ca0 2022-12-14 op </div>
190 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
191 ed619ca0 2022-12-14 op <div class="index_project_description">
192 ed619ca0 2022-12-14 op {{ repo_dir->description }}
193 ed619ca0 2022-12-14 op </div>
194 ed619ca0 2022-12-14 op {{ end }}
195 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
196 ed619ca0 2022-12-14 op <div class="index_project_owner">
197 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
198 ed619ca0 2022-12-14 op </div>
199 ed619ca0 2022-12-14 op {{ end }}
200 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
201 ed619ca0 2022-12-14 op <div class="index_project_age">
202 ed619ca0 2022-12-14 op {{ repo_dir->age }}
203 ed619ca0 2022-12-14 op </div>
204 ed619ca0 2022-12-14 op {{ end }}
205 ed619ca0 2022-12-14 op <div class="navs_wrapper">
206 ed619ca0 2022-12-14 op <div class="navs">
207 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
208 ed619ca0 2022-12-14 op {{ " | " }}
209 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
210 ed619ca0 2022-12-14 op {{ " | " }}
211 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
212 ed619ca0 2022-12-14 op {{ " | " }}
213 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
214 ed619ca0 2022-12-14 op {{ " | " }}
215 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
216 ed619ca0 2022-12-14 op </div>
217 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
218 ed619ca0 2022-12-14 op </div>
219 ed619ca0 2022-12-14 op </div>
220 ed619ca0 2022-12-14 op {{ end }}
221 ed619ca0 2022-12-14 op
222 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
223 ed619ca0 2022-12-14 op {!
224 ed619ca0 2022-12-14 op const struct got_error *error;
225 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
226 ed619ca0 2022-12-14 op struct server *srv = c->srv;
227 ed619ca0 2022-12-14 op struct transport *t = c->t;
228 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
229 ed619ca0 2022-12-14 op struct repo_commit *rc;
230 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
231 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
232 ed619ca0 2022-12-14 op char *tmp;
233 ed619ca0 2022-12-14 op
234 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
235 ed619ca0 2022-12-14 op .action = DIFF,
236 ed619ca0 2022-12-14 op .index_page = -1,
237 ed619ca0 2022-12-14 op .page = -1,
238 ed619ca0 2022-12-14 op .path = repo_dir->name,
239 ed619ca0 2022-12-14 op .headref = qs->headref,
240 ed619ca0 2022-12-14 op };
241 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
242 ed619ca0 2022-12-14 op .action = TREE,
243 ed619ca0 2022-12-14 op .index_page = -1,
244 ed619ca0 2022-12-14 op .page = -1,
245 ed619ca0 2022-12-14 op .path = repo_dir->name,
246 ed619ca0 2022-12-14 op .headref = qs->headref,
247 ed619ca0 2022-12-14 op };
248 ed619ca0 2022-12-14 op
249 ed619ca0 2022-12-14 op if (qs->action == SUMMARY) {
250 ed619ca0 2022-12-14 op qs->action = BRIEFS;
251 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
252 ed619ca0 2022-12-14 op } else
253 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, srv->max_commits_display);
254 ed619ca0 2022-12-14 op if (error)
255 ed619ca0 2022-12-14 op return -1;
256 ed619ca0 2022-12-14 op !}
257 ed619ca0 2022-12-14 op <div id="briefs_title_wrapper">
258 ed619ca0 2022-12-14 op <div id="briefs_title">Commit Briefs</div>
259 ed619ca0 2022-12-14 op </div>
260 ed619ca0 2022-12-14 op <div id="briefs_content">
261 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
262 ed619ca0 2022-12-14 op {!
263 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
264 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
265 ed619ca0 2022-12-14 op
266 ed619ca0 2022-12-14 op tmp = strchr(rc->author, '<');
267 ed619ca0 2022-12-14 op if (tmp)
268 ed619ca0 2022-12-14 op *tmp = '\0';
269 ed619ca0 2022-12-14 op
270 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
271 ed619ca0 2022-12-14 op if (tmp)
272 ed619ca0 2022-12-14 op *tmp = '\0';
273 ed619ca0 2022-12-14 op !}
274 ed619ca0 2022-12-14 op <div class="briefs_age">
275 ed619ca0 2022-12-14 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
276 ed619ca0 2022-12-14 op </div>
277 ed619ca0 2022-12-14 op <div class="briefs_author">
278 ed619ca0 2022-12-14 op {{ rc->author }}
279 ed619ca0 2022-12-14 op </div>
280 ed619ca0 2022-12-14 op <div class="briefs_log">
281 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
282 ed619ca0 2022-12-14 op {{ rc->commit_msg }}
283 ed619ca0 2022-12-14 op </a>
284 ed619ca0 2022-12-14 op {{ if rc->refs_str }}
285 ed619ca0 2022-12-14 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
286 ed619ca0 2022-12-14 op {{ end }}
287 ed619ca0 2022-12-14 op </a>
288 ed619ca0 2022-12-14 op </div>
289 ed619ca0 2022-12-14 op <div class="navs_wrapper">
290 ed619ca0 2022-12-14 op <div class="navs">
291 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
292 ed619ca0 2022-12-14 op {{ " | " }}
293 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
294 ed619ca0 2022-12-14 op </div>
295 ed619ca0 2022-12-14 op </div>
296 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
297 ed619ca0 2022-12-14 op {{ end }}
298 ed619ca0 2022-12-14 op {{ if t->next_id || t->prev_id }}
299 ed619ca0 2022-12-14 op {! gotweb_render_navs(c); !}
300 ed619ca0 2022-12-14 op {{ end }}
301 ed619ca0 2022-12-14 op </div>
302 ed619ca0 2022-12-14 op {{ end }}