Subversion Repositories RepoView

Rev

Rev 52 | Rev 54 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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