1 |
nishi |
1 |
/* $Id: modern.c 60 2024-08-22 06:13:26Z 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"
|
42 |
nishi |
10 |
#include "rv_multipart.h"
|
1 |
nishi |
11 |
|
|
|
12 |
#include "../../config.h"
|
|
|
13 |
|
13 |
nishi |
14 |
#ifdef USE_ENSCRIPT
|
|
|
15 |
#include "rv_enscript.h"
|
|
|
16 |
#endif
|
|
|
17 |
|
39 |
nishi |
18 |
#ifdef USE_AVATAR
|
|
|
19 |
#include "rv_avatar.h"
|
|
|
20 |
#endif
|
|
|
21 |
|
42 |
nishi |
22 |
#ifdef USE_GRAPHICSMAGICK
|
|
|
23 |
#include "rv_magick.h"
|
|
|
24 |
#endif
|
|
|
25 |
|
43 |
nishi |
26 |
#include <sys/stat.h>
|
7 |
nishi |
27 |
#include <stdio.h>
|
1 |
nishi |
28 |
#include <stdlib.h>
|
|
|
29 |
#include <string.h>
|
39 |
nishi |
30 |
#include <unistd.h>
|
1 |
nishi |
31 |
|
42 |
nishi |
32 |
extern char* nocache;
|
1 |
nishi |
33 |
extern char* buffer;
|
|
|
34 |
void add_data(char** data, const char* txt);
|
|
|
35 |
void render_stuff();
|
|
|
36 |
|
|
|
37 |
char* title = NULL;
|
|
|
38 |
char* desc = NULL;
|
|
|
39 |
char* page = NULL;
|
10 |
nishi |
40 |
char* nav = NULL;
|
46 |
nishi |
41 |
char* logopath = NULL;
|
11 |
nishi |
42 |
char* grepouser;
|
6 |
nishi |
43 |
extern char* user;
|
1 |
nishi |
44 |
|
43 |
nishi |
45 |
bool invalid_char(char c) {
|
|
|
46 |
if(c >= '0' && c <= '9') return false;
|
|
|
47 |
if(c >= 'a' && c <= 'z') return false;
|
|
|
48 |
if(c >= 'A' && c <= 'Z') return false;
|
|
|
49 |
if(c == '_' && c == '-' && c == '.') return false;
|
44 |
nishi |
50 |
return true;
|
43 |
nishi |
51 |
}
|
|
|
52 |
|
11 |
nishi |
53 |
char* url_escape(const char* input) {
|
|
|
54 |
const char hex[] = "0123456789ABCDEF";
|
|
|
55 |
char* r = malloc(1);
|
|
|
56 |
r[0] = 0;
|
|
|
57 |
char cbuf[2];
|
|
|
58 |
cbuf[1] = 0;
|
|
|
59 |
int i;
|
|
|
60 |
for(i = 0; input[i] != 0; i++) {
|
|
|
61 |
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) {
|
|
|
62 |
add_data(&r, "%");
|
|
|
63 |
cbuf[0] = hex[(input[i] >> 4) & 0xf];
|
|
|
64 |
add_data(&r, cbuf);
|
|
|
65 |
cbuf[0] = hex[input[i] & 0xf];
|
|
|
66 |
add_data(&r, cbuf);
|
|
|
67 |
} else {
|
|
|
68 |
cbuf[0] = input[i];
|
|
|
69 |
add_data(&r, cbuf);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
return r;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
char* html_escape(const char* input) {
|
|
|
76 |
char* r = malloc(1);
|
|
|
77 |
r[0] = 0;
|
|
|
78 |
char cbuf[2];
|
|
|
79 |
cbuf[1] = 0;
|
|
|
80 |
int i;
|
|
|
81 |
for(i = 0; input[i] != 0; i++) {
|
|
|
82 |
if(input[i] == '<') {
|
|
|
83 |
add_data(&r, "<");
|
|
|
84 |
} else if(input[i] == '>') {
|
|
|
85 |
add_data(&r, ">");
|
|
|
86 |
} else {
|
|
|
87 |
cbuf[0] = input[i];
|
|
|
88 |
add_data(&r, cbuf);
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
return r;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
char* html_escape_nl_to_br(const char* input) {
|
|
|
95 |
char* r = malloc(1);
|
|
|
96 |
r[0] = 0;
|
|
|
97 |
char cbuf[2];
|
|
|
98 |
cbuf[1] = 0;
|
|
|
99 |
int i;
|
|
|
100 |
for(i = 0; input[i] != 0; i++) {
|
|
|
101 |
if(input[i] == '<') {
|
|
|
102 |
add_data(&r, "<");
|
|
|
103 |
} else if(input[i] == '>') {
|
|
|
104 |
add_data(&r, ">");
|
|
|
105 |
} else if(input[i] == '\n') {
|
|
|
106 |
add_data(&r, "<br>");
|
|
|
107 |
} else {
|
|
|
108 |
cbuf[0] = input[i];
|
|
|
109 |
add_data(&r, cbuf);
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
return r;
|
|
|
113 |
}
|
|
|
114 |
|
54 |
nishi |
115 |
int fcounter = 0;
|
56 |
nishi |
116 |
char* instead_username = NULL;
|
11 |
nishi |
117 |
void list_repo(const char* name, const char* rev) {
|
|
|
118 |
char* showname = html_escape(name);
|
56 |
nishi |
119 |
char* urluser = url_escape(instead_username == NULL ? user : instead_username);
|
11 |
nishi |
120 |
char* urlrepo = url_escape(name);
|
53 |
nishi |
121 |
add_data(&page, "<tr style=\"background-color: #");
|
|
|
122 |
if((fcounter % 2) == 0) {
|
|
|
123 |
add_data(&page, "D2E1C0");
|
|
|
124 |
} else {
|
|
|
125 |
add_data(&page, "FFFFFF");
|
|
|
126 |
}
|
|
|
127 |
fcounter++;
|
|
|
128 |
add_data(&page, "\"><td><a href=\"");
|
11 |
nishi |
129 |
add_data(&page, INSTANCE_ROOT);
|
|
|
130 |
add_data(&page, "/?page=repo&reponame=");
|
|
|
131 |
add_data(&page, urlrepo);
|
|
|
132 |
add_data(&page, "&username=");
|
|
|
133 |
add_data(&page, urluser);
|
|
|
134 |
add_data(&page, "\">");
|
|
|
135 |
add_data(&page, showname);
|
|
|
136 |
add_data(&page, "</a></td>");
|
|
|
137 |
add_data(&page, "<td>");
|
|
|
138 |
add_data(&page, rev);
|
|
|
139 |
add_data(&page, "</td>");
|
|
|
140 |
add_data(&page, "</tr>");
|
|
|
141 |
free(showname);
|
|
|
142 |
free(urluser);
|
|
|
143 |
free(urlrepo);
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
void list_files(const char* pathname) {
|
|
|
147 |
if(fcounter == 0) {
|
|
|
148 |
add_data(&nav, "<li><a href=\"#filelist\">File List</a></li>\n");
|
|
|
149 |
add_data(&page, "<h2 id=\"filelist\">File List</h2>\n");
|
|
|
150 |
add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Name</th><th>Size</th></tr>\n");
|
12 |
nishi |
151 |
char* path = rv_get_query("path");
|
|
|
152 |
if(path == NULL) path = "/";
|
|
|
153 |
if(strcmp(path, "/") != 0) {
|
|
|
154 |
char* query = rv_strdup("?page=repo&reponame=");
|
|
|
155 |
char* esc;
|
|
|
156 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
157 |
add_data(&query, esc);
|
|
|
158 |
free(esc);
|
|
|
159 |
add_data(&query, "&username=");
|
15 |
nishi |
160 |
esc = url_escape(rv_get_query("username"));
|
12 |
nishi |
161 |
add_data(&query, esc);
|
|
|
162 |
free(esc);
|
|
|
163 |
add_data(&query, "&path=");
|
|
|
164 |
|
|
|
165 |
char* urlpath = rv_strdup(path);
|
|
|
166 |
int i;
|
|
|
167 |
int counter = 0;
|
|
|
168 |
int rep = urlpath[strlen(urlpath) - 1] == '/' ? 2 : 1;
|
|
|
169 |
for(i = strlen(urlpath) - 1; i >= 0; i--) {
|
|
|
170 |
char oldc = urlpath[i];
|
|
|
171 |
urlpath[i] = 0;
|
|
|
172 |
if(oldc == '/') {
|
|
|
173 |
counter++;
|
|
|
174 |
if(counter == 2) {
|
|
|
175 |
break;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
if(strlen(urlpath) == 0) {
|
|
|
181 |
free(urlpath);
|
|
|
182 |
urlpath = rv_strdup("/");
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
esc = url_escape(urlpath);
|
|
|
186 |
add_data(&query, esc);
|
|
|
187 |
free(esc);
|
|
|
188 |
|
|
|
189 |
add_data(&page, "<tr><td><a href=\"");
|
|
|
190 |
add_data(&page, query);
|
|
|
191 |
add_data(&page, "\">../</a></td><td><DIR></td></tr>\n");
|
|
|
192 |
fcounter++;
|
|
|
193 |
free(query);
|
|
|
194 |
}
|
11 |
nishi |
195 |
}
|
|
|
196 |
fcounter++;
|
|
|
197 |
add_data(&page, "<tr style=\"background-color: #");
|
|
|
198 |
if((fcounter % 2) == 0) {
|
|
|
199 |
add_data(&page, "D2E1C0");
|
|
|
200 |
} else {
|
|
|
201 |
add_data(&page, "FFFFFF");
|
|
|
202 |
}
|
|
|
203 |
char* path = rv_get_query("path");
|
|
|
204 |
if(path == NULL) path = "/";
|
|
|
205 |
char* query = rv_strdup("?page=repo&reponame=");
|
|
|
206 |
char* esc;
|
|
|
207 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
208 |
add_data(&query, esc);
|
|
|
209 |
free(esc);
|
|
|
210 |
add_data(&query, "&username=");
|
15 |
nishi |
211 |
esc = url_escape(rv_get_query("username"));
|
11 |
nishi |
212 |
add_data(&query, esc);
|
|
|
213 |
free(esc);
|
|
|
214 |
add_data(&query, "&path=");
|
13 |
nishi |
215 |
char* urlpath = rv_strcat3(path, "/", pathname);
|
11 |
nishi |
216 |
esc = url_escape(urlpath);
|
|
|
217 |
add_data(&query, esc);
|
|
|
218 |
free(esc);
|
|
|
219 |
char* sz = malloc(128);
|
|
|
220 |
sprintf(sz, "%lld", rv_get_filesize(grepouser, urlpath));
|
|
|
221 |
add_data(&page, "\"><td><a href=\"");
|
|
|
222 |
add_data(&page, query);
|
|
|
223 |
add_data(&page, "\">");
|
|
|
224 |
add_data(&page, pathname);
|
|
|
225 |
add_data(&page, "</a></td>\n");
|
|
|
226 |
add_data(&page, "<td>\n");
|
|
|
227 |
if(strcmp(sz, "-1") != 0) {
|
|
|
228 |
add_data(&page, sz);
|
|
|
229 |
} else {
|
|
|
230 |
add_data(&page, "<DIR>");
|
|
|
231 |
}
|
|
|
232 |
add_data(&page, "</td>\n");
|
|
|
233 |
free(sz);
|
|
|
234 |
add_data(&page, "</tr>\n");
|
|
|
235 |
free(query);
|
|
|
236 |
free(urlpath);
|
|
|
237 |
}
|
|
|
238 |
|
39 |
nishi |
239 |
void generate_avatar(void) {
|
|
|
240 |
if(user != NULL) {
|
|
|
241 |
char* tmp = rv_strcat3(AVATAR_ROOT, "/", user);
|
|
|
242 |
char* path = rv_strcat(tmp, ".png");
|
|
|
243 |
free(tmp);
|
|
|
244 |
if(access(path, F_OK) != 0) {
|
|
|
245 |
rv_avatar_generate(path, user);
|
|
|
246 |
}
|
|
|
247 |
free(path);
|
|
|
248 |
}
|
49 |
nishi |
249 |
if(rv_get_query("username") != NULL) {
|
|
|
250 |
char* un = rv_get_query("username");
|
|
|
251 |
char* tmp = rv_strcat3(AVATAR_ROOT, "/", un);
|
|
|
252 |
char* path = rv_strcat(tmp, ".png");
|
|
|
253 |
free(tmp);
|
|
|
254 |
if(access(path, F_OK) != 0) {
|
|
|
255 |
rv_avatar_generate(path, un);
|
|
|
256 |
}
|
|
|
257 |
free(path);
|
|
|
258 |
}
|
39 |
nishi |
259 |
}
|
|
|
260 |
|
3 |
nishi |
261 |
void render_page(void) {
|
1 |
nishi |
262 |
rv_load_query('Q');
|
|
|
263 |
char* query = rv_get_query("page");
|
|
|
264 |
if(query == NULL) query = "welcome";
|
|
|
265 |
|
39 |
nishi |
266 |
#ifdef USE_AVATAR
|
|
|
267 |
generate_avatar();
|
|
|
268 |
#endif
|
|
|
269 |
|
3 |
nishi |
270 |
if(strcmp(query, "welcome") == 0) {
|
1 |
nishi |
271 |
title = rv_strdup("Welcome");
|
|
|
272 |
desc = rv_strdup("Welcome to " INSTANCE_NAME ".");
|
|
|
273 |
page = rv_strcat3("Welcome to " INSTANCE_NAME ".<br>This instance is running RepoView version ", rv_get_version(), ".");
|
13 |
nishi |
274 |
#ifdef ALLOW_SIGNUP
|
|
|
275 |
} else if(strcmp(query, "signup") == 0) {
|
|
|
276 |
title = rv_strdup("Signup");
|
|
|
277 |
desc = rv_strdup("You can create your account here.");
|
|
|
278 |
page = rv_strdup("");
|
|
|
279 |
|
|
|
280 |
add_data(&page, "<form action=\"");
|
|
|
281 |
add_data(&page, INSTANCE_ROOT);
|
|
|
282 |
add_data(&page, "/?page=sendsignup\" method=\"POST\">\n");
|
|
|
283 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
284 |
add_data(&page, " <tr>\n");
|
|
|
285 |
add_data(&page, " <th>Username</th>\n");
|
|
|
286 |
add_data(&page, " <td>\n");
|
|
|
287 |
add_data(&page, " <input name=\"username\">\n");
|
|
|
288 |
add_data(&page, " </td>\n");
|
|
|
289 |
add_data(&page, " </tr>\n");
|
|
|
290 |
add_data(&page, " <tr>\n");
|
|
|
291 |
add_data(&page, " <th>Password</th>\n");
|
|
|
292 |
add_data(&page, " <td>\n");
|
|
|
293 |
add_data(&page, " <input name=\"password\" type=\"password\">\n");
|
|
|
294 |
add_data(&page, " </td>\n");
|
|
|
295 |
add_data(&page, " </tr>\n");
|
|
|
296 |
add_data(&page, " </table>\n");
|
|
|
297 |
char cbuf[2];
|
|
|
298 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
299 |
cbuf[1] = 0;
|
|
|
300 |
add_data(&page, "Username cannot contain '<code>");
|
|
|
301 |
add_data(&page, cbuf);
|
43 |
nishi |
302 |
add_data(&page, "</code>'.<br>");
|
13 |
nishi |
303 |
add_data(&page, " <input type=\"submit\" value=\"Signup\">\n");
|
|
|
304 |
add_data(&page, "</form>\n");
|
|
|
305 |
} else if(strcmp(query, "sendsignup") == 0) {
|
|
|
306 |
title = rv_strdup("Signup Result");
|
|
|
307 |
page = rv_strdup("");
|
|
|
308 |
|
|
|
309 |
rv_load_query('P');
|
|
|
310 |
if(user != NULL) {
|
|
|
311 |
page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
|
|
|
312 |
add_data(&page, INSTANCE_ROOT);
|
|
|
313 |
add_data(&page, "/?page=logout\">log out</a>?\n");
|
|
|
314 |
} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
|
|
|
315 |
add_data(&page, "Invalid form.\n");
|
|
|
316 |
} else {
|
|
|
317 |
if(rv_has_user(rv_get_query("username"))) {
|
|
|
318 |
add_data(&page, "User already exists.");
|
|
|
319 |
} else {
|
|
|
320 |
if(user != NULL) free(user);
|
|
|
321 |
int i;
|
|
|
322 |
bool reject = false;
|
|
|
323 |
char* name = rv_get_query("username");
|
|
|
324 |
for(i = 0; name[i] != 0; i++) {
|
43 |
nishi |
325 |
if(name[i] == REPO_USER_DELIM || invalid_char(name[i])) {
|
13 |
nishi |
326 |
char cbuf[2];
|
|
|
327 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
328 |
cbuf[1] = 0;
|
|
|
329 |
add_data(&page, "Username cannot contain '<code>");
|
|
|
330 |
add_data(&page, cbuf);
|
|
|
331 |
add_data(&page, "</code>'.");
|
|
|
332 |
reject = true;
|
|
|
333 |
break;
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
if(!reject) {
|
|
|
337 |
rv_create_user(rv_get_query("username"), rv_get_query("password"));
|
|
|
338 |
user = rv_strdup(rv_get_query("username"));
|
|
|
339 |
add_data(&page, "Welcome.\n");
|
|
|
340 |
rv_save_login(rv_get_query("username"));
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
}
|
|
|
344 |
#endif
|
3 |
nishi |
345 |
} else if(strcmp(query, "login") == 0) {
|
1 |
nishi |
346 |
title = rv_strdup("Login");
|
|
|
347 |
desc = rv_strdup("You can log in to your account here.");
|
|
|
348 |
page = rv_strdup("");
|
|
|
349 |
|
|
|
350 |
add_data(&page, "<form action=\"");
|
|
|
351 |
add_data(&page, INSTANCE_ROOT);
|
|
|
352 |
add_data(&page, "/?page=sendlogin\" method=\"POST\">\n");
|
|
|
353 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
354 |
add_data(&page, " <tr>\n");
|
|
|
355 |
add_data(&page, " <th>Username</th>\n");
|
|
|
356 |
add_data(&page, " <td>\n");
|
|
|
357 |
add_data(&page, " <input name=\"username\">\n");
|
|
|
358 |
add_data(&page, " </td>\n");
|
|
|
359 |
add_data(&page, " </tr>\n");
|
|
|
360 |
add_data(&page, " <tr>\n");
|
|
|
361 |
add_data(&page, " <th>Password</th>\n");
|
|
|
362 |
add_data(&page, " <td>\n");
|
|
|
363 |
add_data(&page, " <input name=\"password\" type=\"password\">\n");
|
|
|
364 |
add_data(&page, " </td>\n");
|
|
|
365 |
add_data(&page, " </tr>\n");
|
|
|
366 |
add_data(&page, " </table>\n");
|
|
|
367 |
add_data(&page, " <input type=\"submit\" value=\"Login\">\n");
|
|
|
368 |
add_data(&page, "</form>\n");
|
3 |
nishi |
369 |
} else if(strcmp(query, "sendlogin") == 0) {
|
1 |
nishi |
370 |
title = rv_strdup("Login Result");
|
|
|
371 |
page = rv_strdup("");
|
|
|
372 |
|
|
|
373 |
rv_load_query('P');
|
11 |
nishi |
374 |
if(user != NULL) {
|
|
|
375 |
page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
|
|
|
376 |
add_data(&page, INSTANCE_ROOT);
|
13 |
nishi |
377 |
add_data(&page, "/?page=logout\">log out</a>?\n");
|
11 |
nishi |
378 |
} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
|
5 |
nishi |
379 |
add_data(&page, "Invalid form.\n");
|
3 |
nishi |
380 |
} else {
|
|
|
381 |
if(rv_has_user(rv_get_query("username"))) {
|
5 |
nishi |
382 |
if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
|
6 |
nishi |
383 |
if(user != NULL) free(user);
|
|
|
384 |
user = rv_strdup(rv_get_query("username"));
|
5 |
nishi |
385 |
add_data(&page, "Welcome back.\n");
|
|
|
386 |
rv_save_login(rv_get_query("username"));
|
|
|
387 |
} else {
|
|
|
388 |
add_data(&page, "Invalid password.");
|
|
|
389 |
}
|
3 |
nishi |
390 |
} else {
|
5 |
nishi |
391 |
add_data(&page, "User does not exist.");
|
1 |
nishi |
392 |
}
|
|
|
393 |
}
|
7 |
nishi |
394 |
} else if(strcmp(query, "sendlogout") == 0) {
|
|
|
395 |
title = rv_strdup("Logout Result");
|
|
|
396 |
page = rv_strdup("");
|
|
|
397 |
if(user == NULL) {
|
|
|
398 |
add_data(&page, "You were not logged in.\n");
|
|
|
399 |
} else {
|
|
|
400 |
rv_logout();
|
|
|
401 |
add_data(&page, "Goodbye.\n");
|
|
|
402 |
free(user);
|
|
|
403 |
user = NULL;
|
|
|
404 |
}
|
27 |
nishi |
405 |
#ifdef USE_MYPAGE
|
6 |
nishi |
406 |
} else if(strcmp(query, "mypage") == 0) {
|
|
|
407 |
title = rv_strdup("My Page");
|
|
|
408 |
desc = rv_strdup("You manage your information here.");
|
|
|
409 |
if(user == NULL) {
|
|
|
410 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
411 |
add_data(&page, INSTANCE_ROOT);
|
|
|
412 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
39 |
nishi |
413 |
} else {
|
|
|
414 |
page = rv_strdup("");
|
43 |
nishi |
415 |
nav = rv_strdup("");
|
|
|
416 |
add_data(&nav, "<li><a href=\"#youricon\">Your Icon</a></li>\n");
|
|
|
417 |
add_data(&nav, "<li><a href=\"#bio\">Bio</a></li>\n");
|
|
|
418 |
add_data(&page, "<form action=\"");
|
|
|
419 |
add_data(&page, INSTANCE_ROOT);
|
|
|
420 |
add_data(&page, "/?page=upload\" method=\"POST\" enctype=\"multipart/form-data\">\n");
|
|
|
421 |
add_data(&page, " <h2 id=\"youricon\">Your Icon</h2>\n");
|
|
|
422 |
add_data(&page, " <a href=\"");
|
39 |
nishi |
423 |
add_data(&page, WWW_AVATAR_ROOT);
|
|
|
424 |
add_data(&page, "/");
|
|
|
425 |
add_data(&page, user);
|
|
|
426 |
add_data(&page, ".png\"><img src=\"");
|
|
|
427 |
add_data(&page, WWW_AVATAR_ROOT);
|
|
|
428 |
add_data(&page, "/");
|
|
|
429 |
add_data(&page, user);
|
42 |
nishi |
430 |
add_data(&page, ".png");
|
43 |
nishi |
431 |
add_data(&page, "\" alt=\"Your Icon\" width=\"50%\"></a><br>");
|
39 |
nishi |
432 |
add_data(&page, " <input type=\"file\" name=\"pfp\">\n");
|
43 |
nishi |
433 |
add_data(&page, " <h2 id=\"bio\">Bio</h2>\n");
|
|
|
434 |
add_data(&page, " <textarea name=\"bio\" style=\"width: 100%;resize: none;height: 128px;\">\n");
|
|
|
435 |
char* path = rv_strcat3(BIO_ROOT, "/", user);
|
|
|
436 |
FILE* f = fopen(path, "r");
|
|
|
437 |
if(f != NULL) {
|
|
|
438 |
struct stat s;
|
|
|
439 |
stat(path, &s);
|
|
|
440 |
char* biobuf = malloc(s.st_size + 1);
|
|
|
441 |
fread(biobuf, 1, s.st_size, f);
|
|
|
442 |
biobuf[s.st_size] = 0;
|
|
|
443 |
|
|
|
444 |
char* esc = html_escape(biobuf);
|
|
|
445 |
add_data(&page, esc);
|
|
|
446 |
free(esc);
|
|
|
447 |
|
|
|
448 |
free(biobuf);
|
|
|
449 |
fclose(f);
|
|
|
450 |
}
|
|
|
451 |
free(path);
|
|
|
452 |
add_data(&page, "</textarea>\n");
|
|
|
453 |
add_data(&page, " <input type=\"submit\" value=\"Send\">\n");
|
39 |
nishi |
454 |
add_data(&page, "</form>\n");
|
6 |
nishi |
455 |
}
|
27 |
nishi |
456 |
#endif
|
42 |
nishi |
457 |
#ifdef USE_AVATAR
|
43 |
nishi |
458 |
} else if(strcmp(query, "upload") == 0) {
|
|
|
459 |
title = rv_strdup("Uploading My Page Result");
|
42 |
nishi |
460 |
page = rv_strdup("");
|
|
|
461 |
if(user == NULL) {
|
|
|
462 |
add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
463 |
add_data(&page, INSTANCE_ROOT);
|
|
|
464 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
465 |
} else {
|
|
|
466 |
struct multipart_entry* entry = rv_get_multipart("pfp");
|
43 |
nishi |
467 |
if(entry != NULL && entry->length > 0) {
|
|
|
468 |
char* tmp = rv_strcat3(AVATAR_ROOT, "/", user);
|
|
|
469 |
char* path = rv_strcat(tmp, ".tmp");
|
|
|
470 |
char* outpath = rv_strcat(tmp, ".png");
|
|
|
471 |
free(tmp);
|
|
|
472 |
FILE* f = fopen(path, "wb");
|
|
|
473 |
fwrite(entry->data, 1, entry->length, f);
|
|
|
474 |
fclose(f);
|
|
|
475 |
char* reason;
|
|
|
476 |
if(rv_resize_picture(path, outpath, &reason)) {
|
50 |
nishi |
477 |
add_data(&page, "Uploaded the profile picture successfully.<br>\n");
|
43 |
nishi |
478 |
} else {
|
|
|
479 |
add_data(&page, "Failed to upload the profile picture.<br><code>\n");
|
|
|
480 |
char* esc = html_escape(reason);
|
|
|
481 |
add_data(&page, esc);
|
|
|
482 |
free(esc);
|
|
|
483 |
add_data(&page, "</code>\n");
|
|
|
484 |
free(reason);
|
|
|
485 |
}
|
|
|
486 |
free(path);
|
|
|
487 |
free(outpath);
|
42 |
nishi |
488 |
}
|
43 |
nishi |
489 |
entry = rv_get_multipart("bio");
|
|
|
490 |
if(entry != NULL) {
|
|
|
491 |
char* path = rv_strcat3(BIO_ROOT, "/", user);
|
|
|
492 |
FILE* f = fopen(path, "w");
|
|
|
493 |
fwrite(entry->data, 1, entry->length, f);
|
|
|
494 |
fclose(f);
|
|
|
495 |
free(path);
|
50 |
nishi |
496 |
add_data(&page, "Uploaded the bio successfully.<br>\n");
|
43 |
nishi |
497 |
}
|
42 |
nishi |
498 |
}
|
|
|
499 |
#endif
|
9 |
nishi |
500 |
} else if(strcmp(query, "myrepo") == 0) {
|
|
|
501 |
title = rv_strdup("My Repositories");
|
|
|
502 |
desc = rv_strdup("You manage your repositories here.");
|
|
|
503 |
if(user == NULL) {
|
|
|
504 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
505 |
add_data(&page, INSTANCE_ROOT);
|
|
|
506 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
10 |
nishi |
507 |
} else {
|
11 |
nishi |
508 |
char cbuf[2];
|
|
|
509 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
510 |
cbuf[1] = 0;
|
10 |
nishi |
511 |
nav = rv_strdup("");
|
|
|
512 |
add_data(&nav, "<li><a href=\"#createrepo\">Create a repository</a></li>\n");
|
|
|
513 |
add_data(&nav, "<li><a href=\"#repolist\">Repository List</a></li>\n");
|
|
|
514 |
page = rv_strdup("");
|
|
|
515 |
add_data(&page, "<h2 id=\"createrepo\">Create a repository</h2>\n");
|
|
|
516 |
add_data(&page, "<form action=\"");
|
|
|
517 |
add_data(&page, INSTANCE_ROOT);
|
|
|
518 |
add_data(&page, "/?page=createrepo\" method=\"POST\">\n");
|
|
|
519 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
520 |
add_data(&page, " <tr>\n");
|
|
|
521 |
add_data(&page, " <th>Repository name</th>\n");
|
|
|
522 |
add_data(&page, " <td>\n");
|
|
|
523 |
add_data(&page, " <input name=\"name\">\n");
|
|
|
524 |
add_data(&page, " </td>\n");
|
|
|
525 |
add_data(&page, " <td><input type=\"submit\" value=\"Create\"></td>\n");
|
|
|
526 |
add_data(&page, " </tr>\n");
|
|
|
527 |
add_data(&page, " </table>\n");
|
11 |
nishi |
528 |
add_data(&page, "Repository name cannot contain '<code>");
|
|
|
529 |
add_data(&page, cbuf);
|
43 |
nishi |
530 |
add_data(&page, "</code>'.");
|
10 |
nishi |
531 |
add_data(&page, "</form>\n");
|
|
|
532 |
add_data(&page, "<h2 id=\"repolist\">Repository List</h2>\n");
|
57 |
nishi |
533 |
add_data(&page, "<table border=\"0\" style=\"width: 100%;\">\n");
|
53 |
nishi |
534 |
add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Repository name</th><th>Revision</th></tr>\n");
|
|
|
535 |
fcounter = 0;
|
11 |
nishi |
536 |
rv_repo_list(user, list_repo);
|
|
|
537 |
add_data(&page, "</table>\n");
|
9 |
nishi |
538 |
}
|
11 |
nishi |
539 |
} else if(strcmp(query, "createrepo") == 0) {
|
|
|
540 |
title = rv_strdup("Creating Repository Result");
|
|
|
541 |
page = rv_strdup("");
|
|
|
542 |
|
|
|
543 |
rv_load_query('P');
|
|
|
544 |
if(user == NULL) {
|
|
|
545 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
546 |
add_data(&page, INSTANCE_ROOT);
|
|
|
547 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
548 |
} else if(rv_get_query("name") == NULL) {
|
|
|
549 |
add_data(&page, "Invalid form.\n");
|
|
|
550 |
} else {
|
|
|
551 |
int i;
|
|
|
552 |
bool reject = false;
|
|
|
553 |
char* name = rv_get_query("name");
|
|
|
554 |
for(i = 0; name[i] != 0; i++) {
|
43 |
nishi |
555 |
if(name[i] == REPO_USER_DELIM || invalid_char(name[i])) {
|
11 |
nishi |
556 |
char cbuf[2];
|
|
|
557 |
cbuf[0] = REPO_USER_DELIM;
|
|
|
558 |
cbuf[1] = 0;
|
|
|
559 |
add_data(&page, "Repository name cannot contain '<code>");
|
|
|
560 |
add_data(&page, cbuf);
|
|
|
561 |
add_data(&page, "</code>'.");
|
|
|
562 |
reject = true;
|
|
|
563 |
break;
|
|
|
564 |
}
|
|
|
565 |
}
|
|
|
566 |
if(!reject) {
|
|
|
567 |
char* ru = rv_construct_repouser(name, user);
|
|
|
568 |
if(rv_repo_exists(ru)) {
|
|
|
569 |
add_data(&page, "Repository already exists.");
|
|
|
570 |
} else {
|
|
|
571 |
char* esc;
|
|
|
572 |
rv_create_repo(ru);
|
|
|
573 |
add_data(&page, "Repository has been created.<br>\n");
|
|
|
574 |
add_data(&page, "<a href=\"");
|
|
|
575 |
add_data(&page, INSTANCE_ROOT);
|
|
|
576 |
esc = url_escape(name);
|
|
|
577 |
add_data(&page, "/?page=repo&reponame=");
|
|
|
578 |
add_data(&page, esc);
|
|
|
579 |
free(esc);
|
|
|
580 |
esc = url_escape(user);
|
|
|
581 |
add_data(&page, "&username=");
|
|
|
582 |
add_data(&page, esc);
|
|
|
583 |
free(esc);
|
|
|
584 |
add_data(&page, "\">Go to the repository</a>.\n");
|
|
|
585 |
}
|
|
|
586 |
free(ru);
|
|
|
587 |
}
|
|
|
588 |
}
|
7 |
nishi |
589 |
} else if(strcmp(query, "logout") == 0) {
|
|
|
590 |
title = rv_strdup("Logout");
|
|
|
591 |
desc = rv_strdup("You can log out from your account here.");
|
|
|
592 |
if(user == NULL) {
|
|
|
593 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
594 |
add_data(&page, INSTANCE_ROOT);
|
|
|
595 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
596 |
} else {
|
|
|
597 |
page = rv_strdup("");
|
|
|
598 |
add_data(&page, "Are you sure you want to log out?\n");
|
|
|
599 |
add_data(&page, "<form method=\"POST\" action=\"");
|
|
|
600 |
add_data(&page, INSTANCE_ROOT);
|
|
|
601 |
add_data(&page, "/?page=sendlogout\">\n");
|
|
|
602 |
add_data(&page, " <input type=\"submit\" value=\"Yes\">\n");
|
|
|
603 |
add_data(&page, "</form>\n");
|
|
|
604 |
}
|
11 |
nishi |
605 |
} else if(strcmp(query, "repo") == 0) {
|
|
|
606 |
title = rv_strdup("Repository");
|
|
|
607 |
desc = rv_strdup("");
|
|
|
608 |
page = rv_strdup("");
|
|
|
609 |
nav = rv_strdup("");
|
15 |
nishi |
610 |
rv_load_query('Q');
|
11 |
nishi |
611 |
if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
|
|
|
612 |
add_data(&page, "Required parameters not set.");
|
|
|
613 |
} else {
|
15 |
nishi |
614 |
char* ruser = rv_get_query("username");
|
11 |
nishi |
615 |
char* repo = rv_get_query("reponame");
|
15 |
nishi |
616 |
char* repouser = rv_construct_repouser(repo, ruser);
|
11 |
nishi |
617 |
grepouser = repouser;
|
|
|
618 |
if(rv_repo_exists(repouser)) {
|
15 |
nishi |
619 |
char* showuser = html_escape(ruser);
|
11 |
nishi |
620 |
char* showrepo = html_escape(repo);
|
|
|
621 |
char* showreadme = rv_get_readme(repouser);
|
|
|
622 |
desc = html_escape_nl_to_br(showreadme);
|
|
|
623 |
add_data(&title, " - ");
|
32 |
nishi |
624 |
add_data(&title, showuser);
|
|
|
625 |
add_data(&title, "/");
|
11 |
nishi |
626 |
add_data(&title, showrepo);
|
|
|
627 |
free(showuser);
|
|
|
628 |
free(showrepo);
|
|
|
629 |
free(showreadme);
|
15 |
nishi |
630 |
#ifdef WWW_SVN_ROOT
|
16 |
nishi |
631 |
add_data(&nav, "<li><a href=\"#repoinfo\">Info</a></li>\n");
|
15 |
nishi |
632 |
add_data(&page, "<h2 id=\"repoinfo\">Info</h2>\n");
|
|
|
633 |
add_data(&page, "<a href=\"");
|
|
|
634 |
add_data(&page, WWW_SVN_ROOT);
|
|
|
635 |
add_data(&page, "/");
|
|
|
636 |
char* escru = url_escape(repouser);
|
|
|
637 |
add_data(&page, escru);
|
|
|
638 |
free(escru);
|
|
|
639 |
add_data(&page, "\">Raw repository</a>");
|
|
|
640 |
#endif
|
11 |
nishi |
641 |
|
|
|
642 |
int isdir;
|
|
|
643 |
char* path = rv_get_query("path");
|
|
|
644 |
if(path == NULL) path = "/";
|
|
|
645 |
fcounter = 0;
|
|
|
646 |
add_data(&page, "<table border=\"0\" style=\"width: 100%;\">");
|
15 |
nishi |
647 |
bool rej = false;
|
11 |
nishi |
648 |
if(!rv_get_list(repouser, path, list_files, &isdir)) {
|
|
|
649 |
add_data(&page, "<tr><td>Path not found.</td></tr>\n");
|
15 |
nishi |
650 |
rej = true;
|
11 |
nishi |
651 |
}
|
|
|
652 |
add_data(&page, "</table>");
|
15 |
nishi |
653 |
if(isdir == 0 && !rej) {
|
11 |
nishi |
654 |
add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
|
|
|
655 |
add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
|
|
|
656 |
add_data(&page, "<pre class=\"codeblock\"><code>");
|
13 |
nishi |
657 |
#ifdef USE_ENSCRIPT
|
|
|
658 |
int i;
|
|
|
659 |
char* ext = NULL;
|
|
|
660 |
for(i = strlen(path) - 1; i >= 0; i--) {
|
|
|
661 |
if(path[i] == '.') {
|
|
|
662 |
ext = path + i + 1;
|
|
|
663 |
break;
|
|
|
664 |
}
|
|
|
665 |
}
|
|
|
666 |
char* data = rv_enscript(repouser, path, ext);
|
|
|
667 |
if(data != NULL) {
|
|
|
668 |
add_data(&page, data);
|
|
|
669 |
free(data);
|
|
|
670 |
} else {
|
|
|
671 |
data = rv_read_file(repouser, path);
|
|
|
672 |
if(data != NULL) {
|
|
|
673 |
char* esc = html_escape_nl_to_br(data);
|
|
|
674 |
add_data(&page, esc);
|
|
|
675 |
free(esc);
|
|
|
676 |
free(data);
|
|
|
677 |
} else {
|
|
|
678 |
add_data(&page, "Cannot open the file.\n");
|
|
|
679 |
}
|
|
|
680 |
}
|
|
|
681 |
#else
|
11 |
nishi |
682 |
char* data = rv_read_file(repouser, path);
|
12 |
nishi |
683 |
if(data != NULL) {
|
|
|
684 |
char* esc = html_escape_nl_to_br(data);
|
|
|
685 |
add_data(&page, esc);
|
|
|
686 |
free(esc);
|
|
|
687 |
free(data);
|
|
|
688 |
} else {
|
|
|
689 |
add_data(&page, "Cannot open the file.\n");
|
|
|
690 |
}
|
13 |
nishi |
691 |
#endif
|
11 |
nishi |
692 |
add_data(&page, "</code></pre>");
|
|
|
693 |
}
|
15 |
nishi |
694 |
if(user != NULL && strcmp(user, ruser) == 0) {
|
|
|
695 |
char* esc;
|
|
|
696 |
add_data(&nav, "<li><a href=\"#managerepo\">Manage The Repository</a></li>\n");
|
|
|
697 |
add_data(&page, "<h2 id=\"managerepo\">Manage The Repository</h2>\n");
|
|
|
698 |
add_data(&page, "<form action=\"");
|
|
|
699 |
add_data(&page, INSTANCE_ROOT);
|
|
|
700 |
add_data(&page, "/?page=sendmanrepo&username=");
|
|
|
701 |
esc = url_escape(ruser);
|
|
|
702 |
add_data(&page, esc);
|
|
|
703 |
free(esc);
|
|
|
704 |
add_data(&page, "&reponame=");
|
21 |
nishi |
705 |
esc = url_escape(repo);
|
15 |
nishi |
706 |
add_data(&page, esc);
|
|
|
707 |
free(esc);
|
|
|
708 |
add_data(&page, "\" method=\"POST\">\n");
|
|
|
709 |
add_data(&page, "<table border=\"0\" style=\"width: 100%;\">\n");
|
|
|
710 |
add_data(&page, " <tr>\n");
|
|
|
711 |
add_data(&page, " <th>README</th>\n");
|
|
|
712 |
add_data(&page, " <td>\n");
|
|
|
713 |
add_data(&page, " <textarea name=\"readme\" style=\"width: 100%;resize: none;height: 128px;\">\n");
|
|
|
714 |
char* readme = rv_get_readme(repouser);
|
|
|
715 |
esc = html_escape(readme);
|
|
|
716 |
add_data(&page, esc);
|
|
|
717 |
free(esc);
|
|
|
718 |
free(readme);
|
43 |
nishi |
719 |
add_data(&page, "</textarea>\n");
|
15 |
nishi |
720 |
add_data(&page, " </td>\n");
|
|
|
721 |
add_data(&page, " </tr>\n");
|
|
|
722 |
add_data(&page, "</table>\n");
|
|
|
723 |
add_data(&page, "<input type=\"submit\" value=\"Send\">\n");
|
|
|
724 |
add_data(&page, "</form>\n");
|
|
|
725 |
add_data(&page, "<a href=\"");
|
|
|
726 |
add_data(&page, INSTANCE_ROOT);
|
|
|
727 |
add_data(&page, "/?page=deleterepo&username=");
|
|
|
728 |
esc = url_escape(ruser);
|
|
|
729 |
add_data(&page, esc);
|
|
|
730 |
free(esc);
|
|
|
731 |
add_data(&page, "&reponame=");
|
|
|
732 |
esc = url_escape(ruser);
|
|
|
733 |
add_data(&page, esc);
|
|
|
734 |
free(esc);
|
|
|
735 |
add_data(&page, "\">\n");
|
|
|
736 |
add_data(&page, "Delete repository\n");
|
|
|
737 |
add_data(&page, "</a>\n");
|
|
|
738 |
}
|
11 |
nishi |
739 |
} else {
|
|
|
740 |
add_data(&page, "Repository does not exist.\n");
|
|
|
741 |
}
|
|
|
742 |
free(repouser);
|
|
|
743 |
}
|
15 |
nishi |
744 |
} else if(strcmp(query, "deleterepo") == 0) {
|
|
|
745 |
title = rv_strdup("Delete The Repository");
|
|
|
746 |
page = rv_strdup("");
|
|
|
747 |
|
|
|
748 |
rv_load_query('Q');
|
|
|
749 |
if(user == NULL) {
|
|
|
750 |
add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
751 |
add_data(&page, INSTANCE_ROOT);
|
|
|
752 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
753 |
} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
|
|
|
754 |
add_data(&page, "Invalid Form.\n");
|
|
|
755 |
} else {
|
|
|
756 |
char* esc;
|
|
|
757 |
add_data(&page, "Are you sure you want to delete the repository?\n");
|
|
|
758 |
add_data(&page, "<form method=\"POST\" action=\"");
|
|
|
759 |
add_data(&page, INSTANCE_ROOT);
|
|
|
760 |
add_data(&page, "/?page=senddeleterepo&username=");
|
|
|
761 |
esc = url_escape(rv_get_query("username"));
|
|
|
762 |
add_data(&page, esc);
|
|
|
763 |
free(esc);
|
|
|
764 |
add_data(&page, "&reponame=");
|
|
|
765 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
766 |
add_data(&page, esc);
|
|
|
767 |
free(esc);
|
|
|
768 |
add_data(&page, "\">");
|
|
|
769 |
add_data(&page, " <input type=\"submit\" value=\"Yes\">\n");
|
|
|
770 |
add_data(&page, "</form>\n");
|
|
|
771 |
}
|
|
|
772 |
} else if(strcmp(query, "senddeleterepo") == 0) {
|
|
|
773 |
title = rv_strdup("Deleting Repository Result");
|
|
|
774 |
page = rv_strdup("");
|
|
|
775 |
|
|
|
776 |
rv_load_query('Q');
|
|
|
777 |
if(user == NULL) {
|
|
|
778 |
add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
779 |
add_data(&page, INSTANCE_ROOT);
|
|
|
780 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
781 |
} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
|
|
|
782 |
add_data(&page, "Invalid Form.\n");
|
|
|
783 |
} else if(strcmp(rv_get_query("username"), user) != 0) {
|
|
|
784 |
add_data(&page, "You are not the owner of the repository.\n");
|
|
|
785 |
} else {
|
|
|
786 |
char* repouser = rv_construct_repouser(rv_get_query("reponame"), rv_get_query("username"));
|
|
|
787 |
if(rv_repo_exists(repouser)) {
|
|
|
788 |
rv_remove_repo(repouser);
|
|
|
789 |
add_data(&page, "Deleted the repository successfully.<br>\n");
|
|
|
790 |
} else {
|
|
|
791 |
add_data(&page, "Repository does not exist.<br>\n");
|
|
|
792 |
}
|
|
|
793 |
}
|
43 |
nishi |
794 |
} else if(strcmp(query, "person") == 0) {
|
|
|
795 |
title = rv_strdup("Person");
|
|
|
796 |
page = rv_strdup("");
|
58 |
nishi |
797 |
nav = rv_strdup("");
|
43 |
nishi |
798 |
|
|
|
799 |
rv_load_query('Q');
|
|
|
800 |
if(rv_get_query("username") == NULL) {
|
|
|
801 |
add_data(&page, "Invalid Form.\n");
|
|
|
802 |
} else {
|
|
|
803 |
if(rv_has_user(rv_get_query("username"))) {
|
59 |
nishi |
804 |
add_data(&nav, "<li><a href=\"#repolist\">Repository List</a></li>");
|
43 |
nishi |
805 |
add_data(&title, " - ");
|
|
|
806 |
add_data(&title, rv_get_query("username"));
|
|
|
807 |
char* path = rv_strcat3(BIO_ROOT, "/", rv_get_query("username"));
|
|
|
808 |
FILE* f = fopen(path, "r");
|
|
|
809 |
if(f != NULL) {
|
|
|
810 |
struct stat s;
|
|
|
811 |
stat(path, &s);
|
|
|
812 |
char* buf = malloc(s.st_size + 1);
|
|
|
813 |
fread(buf, 1, s.st_size, f);
|
|
|
814 |
buf[s.st_size] = 0;
|
|
|
815 |
|
|
|
816 |
desc = html_escape_nl_to_br(buf);
|
|
|
817 |
|
|
|
818 |
fclose(f);
|
|
|
819 |
}
|
48 |
nishi |
820 |
|
|
|
821 |
char* tmp = rv_strcat3(WWW_AVATAR_ROOT, "/", rv_get_query("username"));
|
|
|
822 |
logopath = rv_strcat(tmp, ".png");
|
|
|
823 |
free(tmp);
|
|
|
824 |
|
43 |
nishi |
825 |
free(path);
|
52 |
nishi |
826 |
|
|
|
827 |
add_data(&page, "<h2 id=\"repolist\">Repository List</h2>\n");
|
57 |
nishi |
828 |
add_data(&page, "<table border=\"0\" style=\"width: 100%;\">\n");
|
53 |
nishi |
829 |
add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Repository name</th><th>Revision</th></tr>\n");
|
55 |
nishi |
830 |
fcounter = 0;
|
56 |
nishi |
831 |
instead_username = rv_get_query("username");
|
52 |
nishi |
832 |
rv_repo_list(rv_get_query("username"), list_repo);
|
60 |
nishi |
833 |
instead_username = NULL;
|
52 |
nishi |
834 |
add_data(&page, "</table>\n");
|
43 |
nishi |
835 |
} else {
|
|
|
836 |
add_data(&page, "User does not exist.\n");
|
|
|
837 |
}
|
|
|
838 |
}
|
15 |
nishi |
839 |
} else if(strcmp(query, "sendmanrepo") == 0) {
|
|
|
840 |
title = rv_strdup("Modifying Repository Result");
|
|
|
841 |
page = rv_strdup("");
|
|
|
842 |
|
|
|
843 |
rv_load_query('Q');
|
|
|
844 |
if(user == NULL) {
|
|
|
845 |
add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
846 |
add_data(&page, INSTANCE_ROOT);
|
|
|
847 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
848 |
} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
|
|
|
849 |
add_data(&page, "Invalid Form.\n");
|
|
|
850 |
} else if(strcmp(rv_get_query("username"), user) != 0) {
|
|
|
851 |
add_data(&page, "You are not the owner of the repository.\n");
|
|
|
852 |
} else {
|
|
|
853 |
char* esc;
|
|
|
854 |
rv_load_query('P');
|
|
|
855 |
char* readme = rv_get_query("readme");
|
|
|
856 |
if(readme != NULL) {
|
|
|
857 |
rv_load_query('Q');
|
|
|
858 |
char* name = rv_construct_repouser(rv_get_query("reponame"), rv_get_query("username"));
|
|
|
859 |
rv_set_readme(name, readme);
|
|
|
860 |
free(name);
|
|
|
861 |
}
|
|
|
862 |
rv_load_query('Q');
|
|
|
863 |
add_data(&page, "Modified the repository successfully.<br>\n");
|
|
|
864 |
add_data(&page, "<a href=\"");
|
|
|
865 |
add_data(&page, INSTANCE_ROOT);
|
|
|
866 |
add_data(&page, "?page=repo&username=");
|
|
|
867 |
esc = url_escape(rv_get_query("username"));
|
|
|
868 |
add_data(&page, esc);
|
|
|
869 |
free(esc);
|
|
|
870 |
add_data(&page, "&reponame=");
|
|
|
871 |
esc = url_escape(rv_get_query("reponame"));
|
|
|
872 |
add_data(&page, esc);
|
|
|
873 |
free(esc);
|
|
|
874 |
add_data(&page, "\">Go back to the repository</a>.\n");
|
|
|
875 |
}
|
1 |
nishi |
876 |
}
|
|
|
877 |
|
|
|
878 |
if(title == NULL) title = rv_strdup("");
|
|
|
879 |
if(desc == NULL) desc = rv_strdup("");
|
|
|
880 |
if(page == NULL) page = rv_strdup("");
|
10 |
nishi |
881 |
if(nav == NULL) nav = rv_strdup("");
|
39 |
nishi |
882 |
|
|
|
883 |
#ifdef USE_AVATAR
|
|
|
884 |
generate_avatar();
|
|
|
885 |
#endif
|
|
|
886 |
|
1 |
nishi |
887 |
render_stuff();
|
15 |
nishi |
888 |
freeall:
|
1 |
nishi |
889 |
free(page);
|
|
|
890 |
free(desc);
|
|
|
891 |
free(title);
|
10 |
nishi |
892 |
free(nav);
|
46 |
nishi |
893 |
if(logopath != NULL) free(logopath);
|
1 |
nishi |
894 |
}
|
|
|
895 |
|
3 |
nishi |
896 |
char* escape(const char* str) {
|
1 |
nishi |
897 |
char* r = malloc(1);
|
|
|
898 |
r[0] = 0;
|
|
|
899 |
char cbuf[2];
|
|
|
900 |
cbuf[1] = 0;
|
|
|
901 |
int i;
|
3 |
nishi |
902 |
for(i = 0; str[i] != 0; i++) {
|
|
|
903 |
if(str[i] == '<') {
|
1 |
nishi |
904 |
char* tmp = r;
|
|
|
905 |
r = rv_strcat(tmp, "<");
|
|
|
906 |
free(tmp);
|
3 |
nishi |
907 |
} else if(str[i] == '>') {
|
1 |
nishi |
908 |
char* tmp = r;
|
|
|
909 |
r = rv_strcat(tmp, ">");
|
|
|
910 |
free(tmp);
|
3 |
nishi |
911 |
} else {
|
1 |
nishi |
912 |
cbuf[0] = str[i];
|
|
|
913 |
char* tmp = r;
|
|
|
914 |
r = rv_strcat(tmp, cbuf);
|
|
|
915 |
free(tmp);
|
|
|
916 |
}
|
|
|
917 |
}
|
|
|
918 |
return r;
|
|
|
919 |
}
|
|
|
920 |
|
3 |
nishi |
921 |
void render_stuff(void) {
|
1 |
nishi |
922 |
char* escaped;
|
|
|
923 |
add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
|
|
924 |
add_data(&buffer, "<html>\n");
|
|
|
925 |
add_data(&buffer, " <head>\n");
|
|
|
926 |
add_data(&buffer, " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
|
|
|
927 |
add_data(&buffer, " <title>");
|
|
|
928 |
add_data(&buffer, INSTANCE_NAME);
|
|
|
929 |
add_data(&buffer, " - ");
|
|
|
930 |
add_data(&buffer, title);
|
|
|
931 |
add_data(&buffer, "</title>\n");
|
|
|
932 |
add_data(&buffer, " <style type=\"text/css\">\n");
|
|
|
933 |
add_data(&buffer, "* {\n");
|
|
|
934 |
add_data(&buffer, " padding: 0;\n");
|
|
|
935 |
add_data(&buffer, " margin: 0;\n");
|
|
|
936 |
add_data(&buffer, "}\n");
|
|
|
937 |
add_data(&buffer, "li {\n");
|
|
|
938 |
add_data(&buffer, " list-style: outside;\n");
|
|
|
939 |
add_data(&buffer, " margin-left: 1.25em;\n");
|
|
|
940 |
add_data(&buffer, "}\n");
|
|
|
941 |
add_data(&buffer, "a {\n");
|
|
|
942 |
add_data(&buffer, " text-decoration: none;\n");
|
|
|
943 |
add_data(&buffer, "}\n");
|
|
|
944 |
add_data(&buffer, "#nav div {\n");
|
|
|
945 |
add_data(&buffer, " float: left;\n");
|
|
|
946 |
add_data(&buffer, " margin: 0 0;\n");
|
|
|
947 |
add_data(&buffer, " padding-left: 0;\n");
|
9 |
nishi |
948 |
add_data(&buffer, " padding-right: 25px;\n");
|
1 |
nishi |
949 |
add_data(&buffer, " padding-top: 7px;\n");
|
|
|
950 |
add_data(&buffer, "}\n");
|
11 |
nishi |
951 |
add_data(&buffer, "th,td {\n");
|
|
|
952 |
add_data(&buffer, " padding: 2px;\n");
|
|
|
953 |
add_data(&buffer, "}\n");
|
1 |
nishi |
954 |
add_data(&buffer, "body {\n");
|
|
|
955 |
add_data(&buffer, " background-color: #1F4677;\n");
|
|
|
956 |
add_data(&buffer, " width: 940px;\n");
|
|
|
957 |
add_data(&buffer, " margin: 5px auto;\n");
|
|
|
958 |
add_data(&buffer, " font-family: sans-serif;\n");
|
|
|
959 |
add_data(&buffer, "}\n");
|
|
|
960 |
add_data(&buffer, "#nav {\n");
|
|
|
961 |
add_data(&buffer, " background-color: white;\n");
|
6 |
nishi |
962 |
add_data(&buffer, " background-image: url('");
|
|
|
963 |
add_data(&buffer, INSTANCE_NAVBAR);
|
|
|
964 |
add_data(&buffer, "');\n");
|
1 |
nishi |
965 |
add_data(&buffer, " height: 44px;\n");
|
|
|
966 |
add_data(&buffer, " padding: 8px;\n");
|
|
|
967 |
add_data(&buffer, " padding-left: 32px;\n");
|
|
|
968 |
add_data(&buffer, " font-size: 22px;\n");
|
|
|
969 |
add_data(&buffer, " font-weight: bold;\n");
|
|
|
970 |
add_data(&buffer, "}\n");
|
11 |
nishi |
971 |
add_data(&buffer, "pre {\n");
|
|
|
972 |
add_data(&buffer, " background-color: #dddddd;\n");
|
|
|
973 |
add_data(&buffer, " border: solid 2px #bbbbbb;\n");
|
12 |
nishi |
974 |
add_data(&buffer, " padding: 8px;\n");
|
|
|
975 |
add_data(&buffer, " overflow: scroll;\n");
|
11 |
nishi |
976 |
add_data(&buffer, "}\n");
|
1 |
nishi |
977 |
add_data(&buffer, "#index {\n");
|
|
|
978 |
add_data(&buffer, " list-style: none;\n");
|
|
|
979 |
add_data(&buffer, " line-height: normal;\n");
|
|
|
980 |
add_data(&buffer, " margin: auto 0;\n");
|
|
|
981 |
add_data(&buffer, " padding-left: 0;\n");
|
|
|
982 |
add_data(&buffer, "}\n");
|
|
|
983 |
add_data(&buffer, "#desc {\n");
|
|
|
984 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
985 |
add_data(&buffer, " margin: 9px auto;\n");
|
|
|
986 |
add_data(&buffer, " height: 128px;\n");
|
|
|
987 |
add_data(&buffer, " padding: 24px;\n");
|
|
|
988 |
add_data(&buffer, "}\n");
|
|
|
989 |
add_data(&buffer, "#descinside {\n");
|
|
|
990 |
add_data(&buffer, " float: left;\n");
|
11 |
nishi |
991 |
add_data(&buffer, " width: 700px;\n");
|
|
|
992 |
add_data(&buffer, " overflow-y: scroll;\n");
|
|
|
993 |
add_data(&buffer, " max-height: 128px;\n");
|
1 |
nishi |
994 |
add_data(&buffer, "}\n");
|
|
|
995 |
add_data(&buffer, "#logo {\n");
|
|
|
996 |
add_data(&buffer, " float: right;\n");
|
|
|
997 |
add_data(&buffer, "}\n");
|
|
|
998 |
add_data(&buffer, "#content {\n");
|
|
|
999 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
1000 |
add_data(&buffer, " margin: -10px auto;\n");
|
|
|
1001 |
add_data(&buffer, " padding: 8px 24px 24px;\n");
|
|
|
1002 |
add_data(&buffer, "}\n");
|
|
|
1003 |
add_data(&buffer, "#pageindex {\n");
|
|
|
1004 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
1005 |
add_data(&buffer, " padding-right: 24px;\n");
|
|
|
1006 |
add_data(&buffer, " padding-bottom: 24px;\n");
|
|
|
1007 |
add_data(&buffer, " float: left;\n");
|
|
|
1008 |
add_data(&buffer, " border-right: 4px #1F4677 solid;\n");
|
|
|
1009 |
add_data(&buffer, " width: 150px;\n");
|
|
|
1010 |
add_data(&buffer, "}\n");
|
|
|
1011 |
add_data(&buffer, "#pagecontent {\n");
|
|
|
1012 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
1013 |
add_data(&buffer, " width: 670px;\n");
|
|
|
1014 |
add_data(&buffer, " float: right;\n");
|
|
|
1015 |
add_data(&buffer, " padding-left: 24px;\n");
|
|
|
1016 |
add_data(&buffer, "}\n");
|
|
|
1017 |
add_data(&buffer, "#footer {\n");
|
|
|
1018 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
1019 |
add_data(&buffer, " padding: 8px 8px 48px;\n");
|
|
|
1020 |
add_data(&buffer, " margin: 8px auto;\n");
|
|
|
1021 |
add_data(&buffer, " font-size: 15px;\n");
|
|
|
1022 |
add_data(&buffer, " height: 32px;\n");
|
|
|
1023 |
add_data(&buffer, "}\n");
|
|
|
1024 |
add_data(&buffer, ".fixfloat {\n");
|
|
|
1025 |
add_data(&buffer, " clear: both;\n");
|
|
|
1026 |
add_data(&buffer, "}\n");
|
|
|
1027 |
add_data(&buffer, "#copyright {\n");
|
|
|
1028 |
add_data(&buffer, " float: right;\n");
|
|
|
1029 |
add_data(&buffer, " font-size: 10px;\n");
|
|
|
1030 |
add_data(&buffer, " margin-top: 16px;\n");
|
|
|
1031 |
add_data(&buffer, "}\n");
|
|
|
1032 |
add_data(&buffer, "#gotop {\n");
|
|
|
1033 |
add_data(&buffer, " position: absolute;\n");
|
|
|
1034 |
add_data(&buffer, "}\n");
|
|
|
1035 |
add_data(&buffer, "h2, h3 {\n");
|
|
|
1036 |
add_data(&buffer, " padding-top: 8px;\n");
|
|
|
1037 |
add_data(&buffer, " padding-bottom: 8px;\n");
|
|
|
1038 |
add_data(&buffer, "}\n");
|
|
|
1039 |
add_data(&buffer, "img {\n");
|
|
|
1040 |
add_data(&buffer, " border: none;\n");
|
|
|
1041 |
add_data(&buffer, "}\n");
|
|
|
1042 |
add_data(&buffer, " </style>\n");
|
|
|
1043 |
add_data(&buffer, " </head>\n");
|
|
|
1044 |
add_data(&buffer, " <body>\n");
|
|
|
1045 |
add_data(&buffer, " <div id=\"nav\">\n");
|
|
|
1046 |
add_data(&buffer, " <div>\n");
|
|
|
1047 |
add_data(&buffer, " <a href=\"");
|
|
|
1048 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
1049 |
add_data(&buffer, "/\">Home</a>\n");
|
|
|
1050 |
add_data(&buffer, " </div>\n");
|
5 |
nishi |
1051 |
if(user == NULL) {
|
|
|
1052 |
add_data(&buffer, " <div>\n");
|
|
|
1053 |
add_data(&buffer, " <a href=\"");
|
|
|
1054 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
1055 |
add_data(&buffer, "/?page=login\">Login</a>\n");
|
|
|
1056 |
add_data(&buffer, " </div>\n");
|
13 |
nishi |
1057 |
#ifdef ALLOW_SIGNUP
|
|
|
1058 |
add_data(&buffer, " <div>\n");
|
|
|
1059 |
add_data(&buffer, " <a href=\"");
|
|
|
1060 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
1061 |
add_data(&buffer, "/?page=signup\">Signup</a>\n");
|
|
|
1062 |
add_data(&buffer, " </div>\n");
|
|
|
1063 |
#endif
|
7 |
nishi |
1064 |
} else {
|
27 |
nishi |
1065 |
#ifdef USE_MYPAGE
|
7 |
nishi |
1066 |
add_data(&buffer, " <div>\n");
|
|
|
1067 |
add_data(&buffer, " <a href=\"");
|
|
|
1068 |
add_data(&buffer, INSTANCE_ROOT);
|
9 |
nishi |
1069 |
add_data(&buffer, "/?page=mypage\">My Page</a>\n");
|
|
|
1070 |
add_data(&buffer, " </div>\n");
|
27 |
nishi |
1071 |
#endif
|
9 |
nishi |
1072 |
|
|
|
1073 |
add_data(&buffer, " <div>\n");
|
|
|
1074 |
add_data(&buffer, " <a href=\"");
|
|
|
1075 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
1076 |
add_data(&buffer, "/?page=myrepo\">My Repositories</a>\n");
|
|
|
1077 |
add_data(&buffer, " </div>\n");
|
|
|
1078 |
|
|
|
1079 |
add_data(&buffer, " <div>\n");
|
|
|
1080 |
add_data(&buffer, " <a href=\"");
|
|
|
1081 |
add_data(&buffer, INSTANCE_ROOT);
|
7 |
nishi |
1082 |
add_data(&buffer, "/?page=logout\">Logout</a>\n");
|
|
|
1083 |
add_data(&buffer, " </div>\n");
|
5 |
nishi |
1084 |
}
|
6 |
nishi |
1085 |
if(user != NULL) {
|
43 |
nishi |
1086 |
#ifdef USE_AVATAR
|
|
|
1087 |
#ifdef USE_MYPAGE
|
|
|
1088 |
add_data(&buffer, "<a href=\"");
|
6 |
nishi |
1089 |
add_data(&buffer, INSTANCE_ROOT);
|
43 |
nishi |
1090 |
add_data(&buffer, "/?page=person&username=");
|
|
|
1091 |
add_data(&buffer, user);
|
|
|
1092 |
add_data(&buffer, "\">");
|
|
|
1093 |
#endif
|
|
|
1094 |
add_data(&buffer, "<img src=\"");
|
|
|
1095 |
add_data(&buffer, WWW_AVATAR_ROOT);
|
|
|
1096 |
add_data(&buffer, "/");
|
|
|
1097 |
add_data(&buffer, user);
|
|
|
1098 |
add_data(&buffer, ".png\" alt=\"Your Icon\" style=\"float: right;height: 32px;\">");
|
|
|
1099 |
#ifdef USE_MYPAGE
|
|
|
1100 |
add_data(&buffer, "</a>");
|
|
|
1101 |
#endif
|
|
|
1102 |
#endif
|
|
|
1103 |
add_data(&buffer, "<div style=\"clear: both;float: right;font-size: 10px;padding-right: 0;font-style: italic;\">You have logged in as <a href=\"");
|
|
|
1104 |
add_data(&buffer, INSTANCE_ROOT);
|
6 |
nishi |
1105 |
add_data(&buffer, "/?page=mypage\">");
|
|
|
1106 |
add_data(&buffer, user);
|
|
|
1107 |
add_data(&buffer, "</a></div>");
|
|
|
1108 |
}
|
1 |
nishi |
1109 |
add_data(&buffer, " </div>\n");
|
|
|
1110 |
add_data(&buffer, " <div id=\"desc\">\n");
|
|
|
1111 |
add_data(&buffer, " <div id=\"descinside\">\n");
|
|
|
1112 |
add_data(&buffer, " <h1>");
|
|
|
1113 |
add_data(&buffer, title);
|
|
|
1114 |
add_data(&buffer, "</h1>\n");
|
|
|
1115 |
add_data(&buffer, " <p>\n");
|
|
|
1116 |
add_data(&buffer, desc);
|
|
|
1117 |
add_data(&buffer, " </p>\n");
|
|
|
1118 |
add_data(&buffer, " </div>\n");
|
|
|
1119 |
add_data(&buffer, " <img id=\"logo\" src=\"");
|
46 |
nishi |
1120 |
if(logopath != NULL) {
|
|
|
1121 |
add_data(&buffer, logopath);
|
43 |
nishi |
1122 |
} else {
|
|
|
1123 |
add_data(&buffer, INSTANCE_LOGO);
|
|
|
1124 |
}
|
1 |
nishi |
1125 |
add_data(&buffer, "\" height=\"128px\" alt=\"logo\">\n");
|
|
|
1126 |
add_data(&buffer, " </div>\n");
|
|
|
1127 |
add_data(&buffer, " <div id=\"content\">\n");
|
|
|
1128 |
add_data(&buffer, " <div id=\"pageindex\">\n");
|
|
|
1129 |
add_data(&buffer, " <h3>Page Menu</h3>\n");
|
|
|
1130 |
add_data(&buffer, " <ul>\n");
|
10 |
nishi |
1131 |
add_data(&buffer, nav);
|
1 |
nishi |
1132 |
add_data(&buffer, " </ul>\n");
|
|
|
1133 |
add_data(&buffer, " </div>\n");
|
|
|
1134 |
add_data(&buffer, " <div id=\"pagecontent\">\n");
|
|
|
1135 |
add_data(&buffer, page);
|
|
|
1136 |
add_data(&buffer, " </div>\n");
|
11 |
nishi |
1137 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
1 |
nishi |
1138 |
add_data(&buffer, " </div>\n");
|
|
|
1139 |
add_data(&buffer, " <div id=\"footer\">\n");
|
|
|
1140 |
add_data(&buffer, " <div id=\"gotop\">\n");
|
|
|
1141 |
add_data(&buffer, " <a href=\"#top\">Top</a>\n");
|
|
|
1142 |
add_data(&buffer, " </div>\n");
|
|
|
1143 |
add_data(&buffer, " <div id=\"copyright\">\n");
|
|
|
1144 |
add_data(&buffer, " ");
|
|
|
1145 |
escaped = escape(INSTANCE_ADMIN);
|
|
|
1146 |
add_data(&buffer, escaped);
|
|
|
1147 |
free(escaped);
|
|
|
1148 |
add_data(&buffer, "\n");
|
|
|
1149 |
add_data(&buffer, " </div>\n");
|
|
|
1150 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
15 |
nishi |
1151 |
#ifdef INSTANCE_BANNERS
|
|
|
1152 |
add_data(&buffer, " <div id=\"banners\" style=\"clear: both;\">\n");
|
|
|
1153 |
add_data(&buffer, INSTANCE_BANNERS);
|
|
|
1154 |
add_data(&buffer, " </div>\n");
|
|
|
1155 |
#else
|
|
|
1156 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
|
|
1157 |
#endif
|
1 |
nishi |
1158 |
add_data(&buffer, " </div>\n");
|
|
|
1159 |
add_data(&buffer, " </body>\n");
|
|
|
1160 |
add_data(&buffer, "</html>\n");
|
5 |
nishi |
1161 |
if(user != NULL) free(user);
|
1 |
nishi |
1162 |
}
|