1 |
nishi |
1 |
/* $Id: modern.c 12 2024-08-21 05:05:19Z nishi $ */
|
|
|
2 |
|
|
|
3 |
#include "rv_query.h"
|
|
|
4 |
|
|
|
5 |
#include "rv_util.h"
|
|
|
6 |
#include "rv_version.h"
|
3 |
nishi |
7 |
#include "rv_auth.h"
|
1 |
nishi |
8 |
#include "rv_db.h"
|
11 |
nishi |
9 |
#include "rv_repo.h"
|
1 |
nishi |
10 |
|
|
|
11 |
#include "../../config.h"
|
|
|
12 |
|
7 |
nishi |
13 |
#include <stdio.h>
|
1 |
nishi |
14 |
#include <stdlib.h>
|
|
|
15 |
#include <string.h>
|
|
|
16 |
|
|
|
17 |
extern char* buffer;
|
|
|
18 |
void add_data(char** data, const char* txt);
|
|
|
19 |
void render_stuff();
|
|
|
20 |
|
|
|
21 |
char* title = NULL;
|
|
|
22 |
char* desc = NULL;
|
|
|
23 |
char* page = NULL;
|
10 |
nishi |
24 |
char* nav = NULL;
|
11 |
nishi |
25 |
char* grepouser;
|
6 |
nishi |
26 |
extern char* user;
|
1 |
nishi |
27 |
|
11 |
nishi |
28 |
char* url_escape(const char* input) {
|
|
|
29 |
const char hex[] = "0123456789ABCDEF";
|
|
|
30 |
char* r = malloc(1);
|
|
|
31 |
r[0] = 0;
|
|
|
32 |
char cbuf[2];
|
|
|
33 |
cbuf[1] = 0;
|
|
|
34 |
int i;
|
|
|
35 |
for(i = 0; input[i] != 0; i++) {
|
|
|
36 |
if(input[i] == 0x20 || input[i] == 0x22 || input[i] == 0x25 || input[i] == 0x2d || input[i] == 0x2e || input[i] == 0x3c || input[i] == 0x3e || input[i] == 0x5c || input[i] == 0x5e || input[i] == 0x5f || input[i] == 0x60 || input[i] == 0x7b || input[i] == 0x7c || input[i] == 0x7d || input[i] == 0x7e || input[i] == 0x21 || input[i] == 0x23 || input[i] == 0x24 || input[i] == 0x26 || input[i] == 0x27 || input[i] == 0x28 || input[i] == 0x29 || input[i] == 0x2a || input[i] == 0x2b || input[i] == 0x2c || input[i] == 0x2f || input[i] == 0x3a || input[i] == 0x3b || input[i] == 0x3d || input[i] == 0x3f || input[i] == 0x40 || input[i] == 0x5b || input[i] == 0x5d) {
|
|
|
37 |
add_data(&r, "%");
|
|
|
38 |
cbuf[0] = hex[(input[i] >> 4) & 0xf];
|
|
|
39 |
add_data(&r, cbuf);
|
|
|
40 |
cbuf[0] = hex[input[i] & 0xf];
|
|
|
41 |
add_data(&r, cbuf);
|
|
|
42 |
} else {
|
|
|
43 |
cbuf[0] = input[i];
|
|
|
44 |
add_data(&r, cbuf);
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
return r;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
char* html_escape(const char* input) {
|
|
|
51 |
char* r = malloc(1);
|
|
|
52 |
r[0] = 0;
|
|
|
53 |
char cbuf[2];
|
|
|
54 |
cbuf[1] = 0;
|
|
|
55 |
int i;
|
|
|
56 |
for(i = 0; input[i] != 0; i++) {
|
|
|
57 |
if(input[i] == '<') {
|
|
|
58 |
add_data(&r, "<");
|
|
|
59 |
} else if(input[i] == '>') {
|
|
|
60 |
add_data(&r, ">");
|
|
|
61 |
} else {
|
|
|
62 |
cbuf[0] = input[i];
|
|
|
63 |
add_data(&r, cbuf);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
return r;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
char* html_escape_nl_to_br(const char* input) {
|
|
|
70 |
char* r = malloc(1);
|
|
|
71 |
r[0] = 0;
|
|
|
72 |
char cbuf[2];
|
|
|
73 |
cbuf[1] = 0;
|
|
|
74 |
int i;
|
|
|
75 |
for(i = 0; input[i] != 0; i++) {
|
|
|
76 |
if(input[i] == '<') {
|
|
|
77 |
add_data(&r, "<");
|
|
|
78 |
} else if(input[i] == '>') {
|
|
|
79 |
add_data(&r, ">");
|
|
|
80 |
} else if(input[i] == '\n') {
|
|
|
81 |
add_data(&r, "<br>");
|
|
|
82 |
} else {
|
|
|
83 |
cbuf[0] = input[i];
|
|
|
84 |
add_data(&r, cbuf);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
return r;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
void list_repo(const char* name, const char* rev) {
|
|
|
91 |
char* showname = html_escape(name);
|
|
|
92 |
char* urluser = url_escape(user);
|
|
|
93 |
char* urlrepo = url_escape(name);
|
|
|
94 |
add_data(&page, "<tr>");
|
|
|
95 |
add_data(&page, "<td><a href=\"");
|
|
|
96 |
add_data(&page, INSTANCE_ROOT);
|
|
|
97 |
add_data(&page, "/?page=repo&reponame=");
|
|
|
98 |
add_data(&page, urlrepo);
|
|
|
99 |
add_data(&page, "&username=");
|
|
|
100 |
add_data(&page, urluser);
|
|
|
101 |
add_data(&page, "\">");
|
|
|
102 |
add_data(&page, showname);
|
|
|
103 |
add_data(&page, "</a></td>");
|
|
|
104 |
add_data(&page, "<td>");
|
|
|
105 |
add_data(&page, rev);
|
|
|
106 |
add_data(&page, "</td>");
|
|
|
107 |
add_data(&page, "</tr>");
|
|
|
108 |
free(showname);
|
|
|
109 |
free(urluser);
|
|
|
110 |
free(urlrepo);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
int fcounter = 0;
|
|
|
114 |
void list_files(const char* pathname) {
|
|
|
115 |
if(fcounter == 0) {
|
|
|
116 |
add_data(&nav, "<li><a href=\"#filelist\">File List</a></li>\n");
|
|
|
117 |
add_data(&page, "<h2 id=\"filelist\">File List</h2>\n");
|
|
|
118 |
add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Name</th><th>Size</th></tr>\n");
|
12 |
nishi |
119 |
char* path = rv_get_query("path");
|
|
|
120 |
if(path == NULL) path = "/";
|
|
|
121 |
if(strcmp(path, "/") != 0) {
|
|
|
122 |
char* query = rv_strdup("?page=repo&reponame=");
|
|
|
123 |
char* esc;
|
|
|
124 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
125 |
add_data(&query, esc);
|
|
|
126 |
free(esc);
|
|
|
127 |
add_data(&query, "&username=");
|
|
|
128 |
esc = url_escape(user);
|
|
|
129 |
add_data(&query, esc);
|
|
|
130 |
free(esc);
|
|
|
131 |
add_data(&query, "&path=");
|
|
|
132 |
|
|
|
133 |
char* urlpath = rv_strdup(path);
|
|
|
134 |
int i;
|
|
|
135 |
int counter = 0;
|
|
|
136 |
int rep = urlpath[strlen(urlpath) - 1] == '/' ? 2 : 1;
|
|
|
137 |
for(i = strlen(urlpath) - 1; i >= 0; i--) {
|
|
|
138 |
char oldc = urlpath[i];
|
|
|
139 |
urlpath[i] = 0;
|
|
|
140 |
if(oldc == '/') {
|
|
|
141 |
counter++;
|
|
|
142 |
if(counter == 2) {
|
|
|
143 |
break;
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
if(strlen(urlpath) == 0) {
|
|
|
149 |
free(urlpath);
|
|
|
150 |
urlpath = rv_strdup("/");
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
esc = url_escape(urlpath);
|
|
|
154 |
add_data(&query, esc);
|
|
|
155 |
free(esc);
|
|
|
156 |
|
|
|
157 |
add_data(&page, "<tr><td><a href=\"");
|
|
|
158 |
add_data(&page, query);
|
|
|
159 |
add_data(&page, "\">../</a></td><td><DIR></td></tr>\n");
|
|
|
160 |
fcounter++;
|
|
|
161 |
free(query);
|
|
|
162 |
}
|
11 |
nishi |
163 |
}
|
|
|
164 |
fcounter++;
|
|
|
165 |
add_data(&page, "<tr style=\"background-color: #");
|
|
|
166 |
if((fcounter % 2) == 0) {
|
|
|
167 |
add_data(&page, "D2E1C0");
|
|
|
168 |
} else {
|
|
|
169 |
add_data(&page, "FFFFFF");
|
|
|
170 |
}
|
|
|
171 |
char* path = rv_get_query("path");
|
|
|
172 |
if(path == NULL) path = "/";
|
|
|
173 |
char* query = rv_strdup("?page=repo&reponame=");
|
|
|
174 |
char* esc;
|
|
|
175 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
176 |
add_data(&query, esc);
|
|
|
177 |
free(esc);
|
|
|
178 |
add_data(&query, "&username=");
|
|
|
179 |
esc = url_escape(user);
|
|
|
180 |
add_data(&query, esc);
|
|
|
181 |
free(esc);
|
|
|
182 |
add_data(&query, "&path=");
|
|
|
183 |
char* urlpath = rv_strcat(path, pathname);
|
|
|
184 |
esc = url_escape(urlpath);
|
|
|
185 |
add_data(&query, esc);
|
|
|
186 |
free(esc);
|
|
|
187 |
char* sz = malloc(128);
|
|
|
188 |
sprintf(sz, "%lld", rv_get_filesize(grepouser, urlpath));
|
|
|
189 |
add_data(&page, "\"><td><a href=\"");
|
|
|
190 |
add_data(&page, query);
|
|
|
191 |
add_data(&page, "\">");
|
|
|
192 |
add_data(&page, pathname);
|
|
|
193 |
add_data(&page, "</a></td>\n");
|
|
|
194 |
add_data(&page, "<td>\n");
|
|
|
195 |
if(strcmp(sz, "-1") != 0) {
|
|
|
196 |
add_data(&page, sz);
|
|
|
197 |
} else {
|
|
|
198 |
add_data(&page, "<DIR>");
|
|
|
199 |
}
|
|
|
200 |
add_data(&page, "</td>\n");
|
|
|
201 |
free(sz);
|
|
|
202 |
add_data(&page, "</tr>\n");
|
|
|
203 |
free(query);
|
|
|
204 |
free(urlpath);
|
|
|
205 |
}
|
|
|
206 |
|
3 |
nishi |
207 |
void render_page(void) {
|
1 |
nishi |
208 |
rv_load_query('Q');
|
|
|
209 |
char* query = rv_get_query("page");
|
|
|
210 |
if(query == NULL) query = "welcome";
|
|
|
211 |
|
3 |
nishi |
212 |
if(strcmp(query, "welcome") == 0) {
|
1 |
nishi |
213 |
title = rv_strdup("Welcome");
|
|
|
214 |
desc = rv_strdup("Welcome to " INSTANCE_NAME ".");
|
|
|
215 |
page = rv_strcat3("Welcome to " INSTANCE_NAME ".<br>This instance is running RepoView version ", rv_get_version(), ".");
|
3 |
nishi |
216 |
} else if(strcmp(query, "login") == 0) {
|
1 |
nishi |
217 |
title = rv_strdup("Login");
|
|
|
218 |
desc = rv_strdup("You can log in to your account here.");
|
|
|
219 |
page = rv_strdup("");
|
|
|
220 |
|
|
|
221 |
add_data(&page, "<form action=\"");
|
|
|
222 |
add_data(&page, INSTANCE_ROOT);
|
|
|
223 |
add_data(&page, "/?page=sendlogin\" method=\"POST\">\n");
|
|
|
224 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
225 |
add_data(&page, " <tr>\n");
|
|
|
226 |
add_data(&page, " <th>Username</th>\n");
|
|
|
227 |
add_data(&page, " <td>\n");
|
|
|
228 |
add_data(&page, " <input name=\"username\">\n");
|
|
|
229 |
add_data(&page, " </td>\n");
|
|
|
230 |
add_data(&page, " </tr>\n");
|
|
|
231 |
add_data(&page, " <tr>\n");
|
|
|
232 |
add_data(&page, " <th>Password</th>\n");
|
|
|
233 |
add_data(&page, " <td>\n");
|
|
|
234 |
add_data(&page, " <input name=\"password\" type=\"password\">\n");
|
|
|
235 |
add_data(&page, " </td>\n");
|
|
|
236 |
add_data(&page, " </tr>\n");
|
|
|
237 |
add_data(&page, " </table>\n");
|
|
|
238 |
add_data(&page, " <input type=\"submit\" value=\"Login\">\n");
|
|
|
239 |
add_data(&page, "</form>\n");
|
3 |
nishi |
240 |
} else if(strcmp(query, "sendlogin") == 0) {
|
1 |
nishi |
241 |
title = rv_strdup("Login Result");
|
|
|
242 |
page = rv_strdup("");
|
|
|
243 |
|
|
|
244 |
rv_load_query('P');
|
11 |
nishi |
245 |
if(user != NULL) {
|
|
|
246 |
page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
|
|
|
247 |
add_data(&page, INSTANCE_ROOT);
|
|
|
248 |
add_data(&page, "/?page=login\">log out</a>?\n");
|
|
|
249 |
} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
|
5 |
nishi |
250 |
add_data(&page, "Invalid form.\n");
|
3 |
nishi |
251 |
} else {
|
|
|
252 |
if(rv_has_user(rv_get_query("username"))) {
|
5 |
nishi |
253 |
if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
|
6 |
nishi |
254 |
if(user != NULL) free(user);
|
|
|
255 |
user = rv_strdup(rv_get_query("username"));
|
5 |
nishi |
256 |
add_data(&page, "Welcome back.\n");
|
|
|
257 |
rv_save_login(rv_get_query("username"));
|
|
|
258 |
} else {
|
|
|
259 |
add_data(&page, "Invalid password.");
|
|
|
260 |
}
|
3 |
nishi |
261 |
} else {
|
5 |
nishi |
262 |
add_data(&page, "User does not exist.");
|
1 |
nishi |
263 |
}
|
|
|
264 |
}
|
7 |
nishi |
265 |
} else if(strcmp(query, "sendlogout") == 0) {
|
|
|
266 |
title = rv_strdup("Logout Result");
|
|
|
267 |
page = rv_strdup("");
|
|
|
268 |
if(user == NULL) {
|
|
|
269 |
add_data(&page, "You were not logged in.\n");
|
|
|
270 |
} else {
|
|
|
271 |
rv_logout();
|
|
|
272 |
add_data(&page, "Goodbye.\n");
|
|
|
273 |
free(user);
|
|
|
274 |
user = NULL;
|
|
|
275 |
}
|
6 |
nishi |
276 |
} else if(strcmp(query, "mypage") == 0) {
|
|
|
277 |
title = rv_strdup("My Page");
|
|
|
278 |
desc = rv_strdup("You manage your information here.");
|
|
|
279 |
if(user == NULL) {
|
|
|
280 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
281 |
add_data(&page, INSTANCE_ROOT);
|
|
|
282 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
283 |
}
|
9 |
nishi |
284 |
} else if(strcmp(query, "myrepo") == 0) {
|
|
|
285 |
title = rv_strdup("My Repositories");
|
|
|
286 |
desc = rv_strdup("You manage your repositories here.");
|
|
|
287 |
if(user == NULL) {
|
|
|
288 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
289 |
add_data(&page, INSTANCE_ROOT);
|
|
|
290 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
10 |
nishi |
291 |
} else {
|
11 |
nishi |
292 |
char cbuf[2];
|
|
|
293 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
294 |
cbuf[1] = 0;
|
10 |
nishi |
295 |
nav = rv_strdup("");
|
|
|
296 |
add_data(&nav, "<li><a href=\"#createrepo\">Create a repository</a></li>\n");
|
|
|
297 |
add_data(&nav, "<li><a href=\"#repolist\">Repository List</a></li>\n");
|
|
|
298 |
page = rv_strdup("");
|
|
|
299 |
add_data(&page, "<h2 id=\"createrepo\">Create a repository</h2>\n");
|
|
|
300 |
add_data(&page, "<form action=\"");
|
|
|
301 |
add_data(&page, INSTANCE_ROOT);
|
|
|
302 |
add_data(&page, "/?page=createrepo\" method=\"POST\">\n");
|
|
|
303 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
304 |
add_data(&page, " <tr>\n");
|
|
|
305 |
add_data(&page, " <th>Repository name</th>\n");
|
|
|
306 |
add_data(&page, " <td>\n");
|
|
|
307 |
add_data(&page, " <input name=\"name\">\n");
|
|
|
308 |
add_data(&page, " </td>\n");
|
|
|
309 |
add_data(&page, " <td><input type=\"submit\" value=\"Create\"></td>\n");
|
|
|
310 |
add_data(&page, " </tr>\n");
|
|
|
311 |
add_data(&page, " </table>\n");
|
11 |
nishi |
312 |
add_data(&page, "Repository name cannot contain '<code>");
|
|
|
313 |
add_data(&page, cbuf);
|
|
|
314 |
add_data(&page, "</code>'.");
|
10 |
nishi |
315 |
add_data(&page, "</form>\n");
|
|
|
316 |
add_data(&page, "<h2 id=\"repolist\">Repository List</h2>\n");
|
11 |
nishi |
317 |
add_data(&page, "<table border=\"0\">\n");
|
|
|
318 |
add_data(&page, "<tr><th>Repository name</th><th>Revision</th></tr>\n");
|
|
|
319 |
rv_repo_list(user, list_repo);
|
|
|
320 |
add_data(&page, "</table>\n");
|
9 |
nishi |
321 |
}
|
11 |
nishi |
322 |
} else if(strcmp(query, "createrepo") == 0) {
|
|
|
323 |
title = rv_strdup("Creating Repository Result");
|
|
|
324 |
page = rv_strdup("");
|
|
|
325 |
|
|
|
326 |
rv_load_query('P');
|
|
|
327 |
if(user == NULL) {
|
|
|
328 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
329 |
add_data(&page, INSTANCE_ROOT);
|
|
|
330 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
331 |
} else if(rv_get_query("name") == NULL) {
|
|
|
332 |
add_data(&page, "Invalid form.\n");
|
|
|
333 |
} else {
|
|
|
334 |
int i;
|
|
|
335 |
bool reject = false;
|
|
|
336 |
char* name = rv_get_query("name");
|
|
|
337 |
for(i = 0; name[i] != 0; i++) {
|
|
|
338 |
if(name[i] == REPO_USER_DELIM) {
|
|
|
339 |
char cbuf[2];
|
|
|
340 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
341 |
cbuf[1] = 0;
|
|
|
342 |
add_data(&page, "Repository name cannot contain '<code>");
|
|
|
343 |
add_data(&page, cbuf);
|
|
|
344 |
add_data(&page, "</code>'.");
|
|
|
345 |
reject = true;
|
|
|
346 |
break;
|
|
|
347 |
}
|
|
|
348 |
}
|
|
|
349 |
if(!reject) {
|
|
|
350 |
char* ru = rv_construct_repouser(name, user);
|
|
|
351 |
if(rv_repo_exists(ru)) {
|
|
|
352 |
add_data(&page, "Repository already exists.");
|
|
|
353 |
} else {
|
|
|
354 |
char* esc;
|
|
|
355 |
rv_create_repo(ru);
|
|
|
356 |
add_data(&page, "Repository has been created.<br>\n");
|
|
|
357 |
add_data(&page, "<a href=\"");
|
|
|
358 |
add_data(&page, INSTANCE_ROOT);
|
|
|
359 |
esc = url_escape(name);
|
|
|
360 |
add_data(&page, "/?page=repo&reponame=");
|
|
|
361 |
add_data(&page, esc);
|
|
|
362 |
free(esc);
|
|
|
363 |
esc = url_escape(user);
|
|
|
364 |
add_data(&page, "&username=");
|
|
|
365 |
add_data(&page, esc);
|
|
|
366 |
free(esc);
|
|
|
367 |
add_data(&page, "\">Go to the repository</a>.\n");
|
|
|
368 |
}
|
|
|
369 |
free(ru);
|
|
|
370 |
}
|
|
|
371 |
}
|
7 |
nishi |
372 |
} else if(strcmp(query, "logout") == 0) {
|
|
|
373 |
title = rv_strdup("Logout");
|
|
|
374 |
desc = rv_strdup("You can log out from your account here.");
|
|
|
375 |
if(user == NULL) {
|
|
|
376 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
377 |
add_data(&page, INSTANCE_ROOT);
|
|
|
378 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
379 |
} else {
|
|
|
380 |
page = rv_strdup("");
|
|
|
381 |
add_data(&page, "Are you sure you want to log out?\n");
|
|
|
382 |
add_data(&page, "<form method=\"POST\" action=\"");
|
|
|
383 |
add_data(&page, INSTANCE_ROOT);
|
|
|
384 |
add_data(&page, "/?page=sendlogout\">\n");
|
|
|
385 |
add_data(&page, " <input type=\"submit\" value=\"Yes\">\n");
|
|
|
386 |
add_data(&page, "</form>\n");
|
|
|
387 |
}
|
11 |
nishi |
388 |
} else if(strcmp(query, "repo") == 0) {
|
|
|
389 |
title = rv_strdup("Repository");
|
|
|
390 |
desc = rv_strdup("");
|
|
|
391 |
page = rv_strdup("");
|
|
|
392 |
nav = rv_strdup("");
|
|
|
393 |
if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
|
|
|
394 |
add_data(&page, "Required parameters not set.");
|
|
|
395 |
} else {
|
|
|
396 |
char* user = rv_get_query("username");
|
|
|
397 |
char* repo = rv_get_query("reponame");
|
|
|
398 |
char* repouser = rv_construct_repouser(repo, user);
|
|
|
399 |
grepouser = repouser;
|
|
|
400 |
if(rv_repo_exists(repouser)) {
|
|
|
401 |
char* showuser = html_escape(user);
|
|
|
402 |
char* showrepo = html_escape(repo);
|
|
|
403 |
char* showreadme = rv_get_readme(repouser);
|
|
|
404 |
desc = html_escape_nl_to_br(showreadme);
|
|
|
405 |
add_data(&title, " - ");
|
|
|
406 |
add_data(&title, showrepo);
|
|
|
407 |
add_data(&title, "/");
|
|
|
408 |
add_data(&title, showuser);
|
|
|
409 |
free(showuser);
|
|
|
410 |
free(showrepo);
|
|
|
411 |
free(showreadme);
|
|
|
412 |
|
|
|
413 |
int isdir;
|
|
|
414 |
char* path = rv_get_query("path");
|
|
|
415 |
if(path == NULL) path = "/";
|
|
|
416 |
fcounter = 0;
|
|
|
417 |
add_data(&page, "<table border=\"0\" style=\"width: 100%;\">");
|
|
|
418 |
if(!rv_get_list(repouser, path, list_files, &isdir)) {
|
|
|
419 |
add_data(&page, "<tr><td>Path not found.</td></tr>\n");
|
|
|
420 |
}
|
|
|
421 |
add_data(&page, "</table>");
|
|
|
422 |
if(isdir == 0) {
|
|
|
423 |
add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
|
|
|
424 |
add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
|
|
|
425 |
add_data(&page, "<pre class=\"codeblock\"><code>");
|
|
|
426 |
char* data = rv_read_file(repouser, path);
|
12 |
nishi |
427 |
if(data != NULL) {
|
|
|
428 |
char* esc = html_escape_nl_to_br(data);
|
|
|
429 |
add_data(&page, esc);
|
|
|
430 |
free(esc);
|
|
|
431 |
free(data);
|
|
|
432 |
} else {
|
|
|
433 |
add_data(&page, "Cannot open the file.\n");
|
|
|
434 |
}
|
11 |
nishi |
435 |
add_data(&page, "</code></pre>");
|
|
|
436 |
}
|
|
|
437 |
} else {
|
|
|
438 |
add_data(&page, "Repository does not exist.\n");
|
|
|
439 |
}
|
|
|
440 |
free(repouser);
|
|
|
441 |
}
|
1 |
nishi |
442 |
}
|
|
|
443 |
|
|
|
444 |
if(title == NULL) title = rv_strdup("");
|
|
|
445 |
if(desc == NULL) desc = rv_strdup("");
|
|
|
446 |
if(page == NULL) page = rv_strdup("");
|
10 |
nishi |
447 |
if(nav == NULL) nav = rv_strdup("");
|
1 |
nishi |
448 |
render_stuff();
|
|
|
449 |
free(page);
|
|
|
450 |
free(desc);
|
|
|
451 |
free(title);
|
10 |
nishi |
452 |
free(nav);
|
1 |
nishi |
453 |
}
|
|
|
454 |
|
3 |
nishi |
455 |
char* escape(const char* str) {
|
1 |
nishi |
456 |
char* r = malloc(1);
|
|
|
457 |
r[0] = 0;
|
|
|
458 |
char cbuf[2];
|
|
|
459 |
cbuf[1] = 0;
|
|
|
460 |
int i;
|
3 |
nishi |
461 |
for(i = 0; str[i] != 0; i++) {
|
|
|
462 |
if(str[i] == '<') {
|
1 |
nishi |
463 |
char* tmp = r;
|
|
|
464 |
r = rv_strcat(tmp, "<");
|
|
|
465 |
free(tmp);
|
3 |
nishi |
466 |
} else if(str[i] == '>') {
|
1 |
nishi |
467 |
char* tmp = r;
|
|
|
468 |
r = rv_strcat(tmp, ">");
|
|
|
469 |
free(tmp);
|
3 |
nishi |
470 |
} else {
|
1 |
nishi |
471 |
cbuf[0] = str[i];
|
|
|
472 |
char* tmp = r;
|
|
|
473 |
r = rv_strcat(tmp, cbuf);
|
|
|
474 |
free(tmp);
|
|
|
475 |
}
|
|
|
476 |
}
|
|
|
477 |
return r;
|
|
|
478 |
}
|
|
|
479 |
|
3 |
nishi |
480 |
void render_stuff(void) {
|
1 |
nishi |
481 |
char* escaped;
|
|
|
482 |
add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
|
|
483 |
add_data(&buffer, "<html>\n");
|
|
|
484 |
add_data(&buffer, " <head>\n");
|
|
|
485 |
add_data(&buffer, " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
|
|
|
486 |
add_data(&buffer, " <title>");
|
|
|
487 |
add_data(&buffer, INSTANCE_NAME);
|
|
|
488 |
add_data(&buffer, " - ");
|
|
|
489 |
add_data(&buffer, title);
|
|
|
490 |
add_data(&buffer, "</title>\n");
|
|
|
491 |
add_data(&buffer, " <style type=\"text/css\">\n");
|
|
|
492 |
add_data(&buffer, "* {\n");
|
|
|
493 |
add_data(&buffer, " padding: 0;\n");
|
|
|
494 |
add_data(&buffer, " margin: 0;\n");
|
|
|
495 |
add_data(&buffer, "}\n");
|
|
|
496 |
add_data(&buffer, "li {\n");
|
|
|
497 |
add_data(&buffer, " list-style: outside;\n");
|
|
|
498 |
add_data(&buffer, " margin-left: 1.25em;\n");
|
|
|
499 |
add_data(&buffer, "}\n");
|
|
|
500 |
add_data(&buffer, "a {\n");
|
|
|
501 |
add_data(&buffer, " text-decoration: none;\n");
|
|
|
502 |
add_data(&buffer, "}\n");
|
|
|
503 |
add_data(&buffer, "#nav div {\n");
|
|
|
504 |
add_data(&buffer, " float: left;\n");
|
|
|
505 |
add_data(&buffer, " margin: 0 0;\n");
|
|
|
506 |
add_data(&buffer, " padding-left: 0;\n");
|
9 |
nishi |
507 |
add_data(&buffer, " padding-right: 25px;\n");
|
1 |
nishi |
508 |
add_data(&buffer, " padding-top: 7px;\n");
|
|
|
509 |
add_data(&buffer, "}\n");
|
11 |
nishi |
510 |
add_data(&buffer, "th,td {\n");
|
|
|
511 |
add_data(&buffer, " padding: 2px;\n");
|
|
|
512 |
add_data(&buffer, "}\n");
|
1 |
nishi |
513 |
add_data(&buffer, "body {\n");
|
|
|
514 |
add_data(&buffer, " background-color: #1F4677;\n");
|
|
|
515 |
add_data(&buffer, " width: 940px;\n");
|
|
|
516 |
add_data(&buffer, " margin: 5px auto;\n");
|
|
|
517 |
add_data(&buffer, " font-family: sans-serif;\n");
|
|
|
518 |
add_data(&buffer, "}\n");
|
|
|
519 |
add_data(&buffer, "#nav {\n");
|
|
|
520 |
add_data(&buffer, " background-color: white;\n");
|
6 |
nishi |
521 |
add_data(&buffer, " background-image: url('");
|
|
|
522 |
add_data(&buffer, INSTANCE_NAVBAR);
|
|
|
523 |
add_data(&buffer, "');\n");
|
1 |
nishi |
524 |
add_data(&buffer, " height: 44px;\n");
|
|
|
525 |
add_data(&buffer, " padding: 8px;\n");
|
|
|
526 |
add_data(&buffer, " padding-left: 32px;\n");
|
|
|
527 |
add_data(&buffer, " font-size: 22px;\n");
|
|
|
528 |
add_data(&buffer, " font-weight: bold;\n");
|
|
|
529 |
add_data(&buffer, "}\n");
|
11 |
nishi |
530 |
add_data(&buffer, "pre {\n");
|
|
|
531 |
add_data(&buffer, " background-color: #dddddd;\n");
|
|
|
532 |
add_data(&buffer, " border: solid 2px #bbbbbb;\n");
|
12 |
nishi |
533 |
add_data(&buffer, " padding: 8px;\n");
|
|
|
534 |
add_data(&buffer, " overflow: scroll;\n");
|
11 |
nishi |
535 |
add_data(&buffer, "}\n");
|
1 |
nishi |
536 |
add_data(&buffer, "#index {\n");
|
|
|
537 |
add_data(&buffer, " list-style: none;\n");
|
|
|
538 |
add_data(&buffer, " line-height: normal;\n");
|
|
|
539 |
add_data(&buffer, " margin: auto 0;\n");
|
|
|
540 |
add_data(&buffer, " padding-left: 0;\n");
|
|
|
541 |
add_data(&buffer, "}\n");
|
|
|
542 |
add_data(&buffer, "#desc {\n");
|
|
|
543 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
544 |
add_data(&buffer, " margin: 9px auto;\n");
|
|
|
545 |
add_data(&buffer, " height: 128px;\n");
|
|
|
546 |
add_data(&buffer, " padding: 24px;\n");
|
|
|
547 |
add_data(&buffer, "}\n");
|
|
|
548 |
add_data(&buffer, "#descinside {\n");
|
|
|
549 |
add_data(&buffer, " float: left;\n");
|
11 |
nishi |
550 |
add_data(&buffer, " width: 700px;\n");
|
|
|
551 |
add_data(&buffer, " overflow-y: scroll;\n");
|
|
|
552 |
add_data(&buffer, " max-height: 128px;\n");
|
1 |
nishi |
553 |
add_data(&buffer, "}\n");
|
|
|
554 |
add_data(&buffer, "#logo {\n");
|
|
|
555 |
add_data(&buffer, " float: right;\n");
|
|
|
556 |
add_data(&buffer, "}\n");
|
|
|
557 |
add_data(&buffer, "#content {\n");
|
|
|
558 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
559 |
add_data(&buffer, " margin: -10px auto;\n");
|
|
|
560 |
add_data(&buffer, " padding: 8px 24px 24px;\n");
|
|
|
561 |
add_data(&buffer, "}\n");
|
|
|
562 |
add_data(&buffer, "#pageindex {\n");
|
|
|
563 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
564 |
add_data(&buffer, " padding-right: 24px;\n");
|
|
|
565 |
add_data(&buffer, " padding-bottom: 24px;\n");
|
|
|
566 |
add_data(&buffer, " float: left;\n");
|
|
|
567 |
add_data(&buffer, " border-right: 4px #1F4677 solid;\n");
|
|
|
568 |
add_data(&buffer, " width: 150px;\n");
|
|
|
569 |
add_data(&buffer, "}\n");
|
|
|
570 |
add_data(&buffer, "#pagecontent {\n");
|
|
|
571 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
572 |
add_data(&buffer, " width: 670px;\n");
|
|
|
573 |
add_data(&buffer, " float: right;\n");
|
|
|
574 |
add_data(&buffer, " padding-left: 24px;\n");
|
|
|
575 |
add_data(&buffer, "}\n");
|
|
|
576 |
add_data(&buffer, "#footer {\n");
|
|
|
577 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
578 |
add_data(&buffer, " padding: 8px 8px 48px;\n");
|
|
|
579 |
add_data(&buffer, " margin: 8px auto;\n");
|
|
|
580 |
add_data(&buffer, " font-size: 15px;\n");
|
|
|
581 |
add_data(&buffer, " height: 32px;\n");
|
|
|
582 |
add_data(&buffer, "}\n");
|
|
|
583 |
add_data(&buffer, ".fixfloat {\n");
|
|
|
584 |
add_data(&buffer, " clear: both;\n");
|
|
|
585 |
add_data(&buffer, "}\n");
|
|
|
586 |
add_data(&buffer, "#copyright {\n");
|
|
|
587 |
add_data(&buffer, " float: right;\n");
|
|
|
588 |
add_data(&buffer, " font-size: 10px;\n");
|
|
|
589 |
add_data(&buffer, " margin-top: 16px;\n");
|
|
|
590 |
add_data(&buffer, "}\n");
|
|
|
591 |
add_data(&buffer, "#gotop {\n");
|
|
|
592 |
add_data(&buffer, " position: absolute;\n");
|
|
|
593 |
add_data(&buffer, "}\n");
|
|
|
594 |
add_data(&buffer, "h2, h3 {\n");
|
|
|
595 |
add_data(&buffer, " padding-top: 8px;\n");
|
|
|
596 |
add_data(&buffer, " padding-bottom: 8px;\n");
|
|
|
597 |
add_data(&buffer, "}\n");
|
|
|
598 |
add_data(&buffer, "img {\n");
|
|
|
599 |
add_data(&buffer, " border: none;\n");
|
|
|
600 |
add_data(&buffer, "}\n");
|
|
|
601 |
add_data(&buffer, " </style>\n");
|
|
|
602 |
add_data(&buffer, " </head>\n");
|
|
|
603 |
add_data(&buffer, " <body>\n");
|
|
|
604 |
add_data(&buffer, " <div id=\"nav\">\n");
|
|
|
605 |
add_data(&buffer, " <div>\n");
|
|
|
606 |
add_data(&buffer, " <a href=\"");
|
|
|
607 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
608 |
add_data(&buffer, "/\">Home</a>\n");
|
|
|
609 |
add_data(&buffer, " </div>\n");
|
5 |
nishi |
610 |
if(user == NULL) {
|
|
|
611 |
add_data(&buffer, " <div>\n");
|
|
|
612 |
add_data(&buffer, " <a href=\"");
|
|
|
613 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
614 |
add_data(&buffer, "/?page=login\">Login</a>\n");
|
|
|
615 |
add_data(&buffer, " </div>\n");
|
7 |
nishi |
616 |
} else {
|
|
|
617 |
add_data(&buffer, " <div>\n");
|
|
|
618 |
add_data(&buffer, " <a href=\"");
|
|
|
619 |
add_data(&buffer, INSTANCE_ROOT);
|
9 |
nishi |
620 |
add_data(&buffer, "/?page=mypage\">My Page</a>\n");
|
|
|
621 |
add_data(&buffer, " </div>\n");
|
|
|
622 |
|
|
|
623 |
add_data(&buffer, " <div>\n");
|
|
|
624 |
add_data(&buffer, " <a href=\"");
|
|
|
625 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
626 |
add_data(&buffer, "/?page=myrepo\">My Repositories</a>\n");
|
|
|
627 |
add_data(&buffer, " </div>\n");
|
|
|
628 |
|
|
|
629 |
add_data(&buffer, " <div>\n");
|
|
|
630 |
add_data(&buffer, " <a href=\"");
|
|
|
631 |
add_data(&buffer, INSTANCE_ROOT);
|
7 |
nishi |
632 |
add_data(&buffer, "/?page=logout\">Logout</a>\n");
|
|
|
633 |
add_data(&buffer, " </div>\n");
|
5 |
nishi |
634 |
}
|
6 |
nishi |
635 |
if(user != NULL) {
|
|
|
636 |
add_data(&buffer, "<div style=\"float: right;font-size: 10px;padding-top: 36px;padding-right: 0;font-style: italic;\">You have logged in as <a href=\"");
|
|
|
637 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
638 |
add_data(&buffer, "/?page=mypage\">");
|
|
|
639 |
add_data(&buffer, user);
|
|
|
640 |
add_data(&buffer, "</a></div>");
|
|
|
641 |
}
|
1 |
nishi |
642 |
add_data(&buffer, " </div>\n");
|
|
|
643 |
add_data(&buffer, " <div id=\"desc\">\n");
|
|
|
644 |
add_data(&buffer, " <div id=\"descinside\">\n");
|
|
|
645 |
add_data(&buffer, " <h1>");
|
|
|
646 |
add_data(&buffer, title);
|
|
|
647 |
add_data(&buffer, "</h1>\n");
|
|
|
648 |
add_data(&buffer, " <p>\n");
|
|
|
649 |
add_data(&buffer, desc);
|
|
|
650 |
add_data(&buffer, " </p>\n");
|
|
|
651 |
add_data(&buffer, " </div>\n");
|
|
|
652 |
add_data(&buffer, " <img id=\"logo\" src=\"");
|
|
|
653 |
add_data(&buffer, INSTANCE_LOGO);
|
|
|
654 |
add_data(&buffer, "\" height=\"128px\" alt=\"logo\">\n");
|
|
|
655 |
add_data(&buffer, " </div>\n");
|
|
|
656 |
add_data(&buffer, " <div id=\"content\">\n");
|
|
|
657 |
add_data(&buffer, " <div id=\"pageindex\">\n");
|
|
|
658 |
add_data(&buffer, " <h3>Page Menu</h3>\n");
|
|
|
659 |
add_data(&buffer, " <ul>\n");
|
10 |
nishi |
660 |
add_data(&buffer, nav);
|
1 |
nishi |
661 |
add_data(&buffer, " </ul>\n");
|
|
|
662 |
add_data(&buffer, " </div>\n");
|
|
|
663 |
add_data(&buffer, " <div id=\"pagecontent\">\n");
|
|
|
664 |
add_data(&buffer, page);
|
|
|
665 |
add_data(&buffer, " </div>\n");
|
11 |
nishi |
666 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
1 |
nishi |
667 |
add_data(&buffer, " </div>\n");
|
|
|
668 |
add_data(&buffer, " <div id=\"footer\">\n");
|
|
|
669 |
add_data(&buffer, " <div id=\"gotop\">\n");
|
|
|
670 |
add_data(&buffer, " <a href=\"#top\">Top</a>\n");
|
|
|
671 |
add_data(&buffer, " </div>\n");
|
|
|
672 |
add_data(&buffer, " <div id=\"copyright\">\n");
|
|
|
673 |
add_data(&buffer, " ");
|
|
|
674 |
escaped = escape(INSTANCE_ADMIN);
|
|
|
675 |
add_data(&buffer, escaped);
|
|
|
676 |
free(escaped);
|
|
|
677 |
add_data(&buffer, "\n");
|
|
|
678 |
add_data(&buffer, " </div>\n");
|
|
|
679 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
|
|
680 |
add_data(&buffer, " </div>\n");
|
|
|
681 |
add_data(&buffer, " </body>\n");
|
|
|
682 |
add_data(&buffer, "</html>\n");
|
5 |
nishi |
683 |
if(user != NULL) free(user);
|
1 |
nishi |
684 |
}
|