Subversion Repositories RepoView

Rev

Rev 58 | Rev 60 | 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 59 2024-08-22 06:08:54Z 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
 
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>&lt;DIR&gt;</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, "&lt;DIR&gt;");
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);
833
				add_data(&page, "</table>\n");
43 nishi 834
			} else {
835
				add_data(&page, "User does not exist.\n");
836
			}
837
		}
15 nishi 838
	} else if(strcmp(query, "sendmanrepo") == 0) {
839
		title = rv_strdup("Modifying Repository Result");
840
		page = rv_strdup("");
841
 
842
		rv_load_query('Q');
843
		if(user == NULL) {
844
			add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
845
			add_data(&page, INSTANCE_ROOT);
846
			add_data(&page, "/?page=login\">log in</a>?\n");
847
		} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
848
			add_data(&page, "Invalid Form.\n");
849
		} else if(strcmp(rv_get_query("username"), user) != 0) {
850
			add_data(&page, "You are not the owner of the repository.\n");
851
		} else {
852
			char* esc;
853
			rv_load_query('P');
854
			char* readme = rv_get_query("readme");
855
			if(readme != NULL) {
856
				rv_load_query('Q');
857
				char* name = rv_construct_repouser(rv_get_query("reponame"), rv_get_query("username"));
858
				rv_set_readme(name, readme);
859
				free(name);
860
			}
861
			rv_load_query('Q');
862
			add_data(&page, "Modified the repository successfully.<br>\n");
863
			add_data(&page, "<a href=\"");
864
			add_data(&page, INSTANCE_ROOT);
865
			add_data(&page, "?page=repo&username=");
866
			esc = url_escape(rv_get_query("username"));
867
			add_data(&page, esc);
868
			free(esc);
869
			add_data(&page, "&reponame=");
870
			esc = url_escape(rv_get_query("reponame"));
871
			add_data(&page, esc);
872
			free(esc);
873
			add_data(&page, "\">Go back to the repository</a>.\n");
874
		}
1 nishi 875
	}
876
 
877
	if(title == NULL) title = rv_strdup("");
878
	if(desc == NULL) desc = rv_strdup("");
879
	if(page == NULL) page = rv_strdup("");
10 nishi 880
	if(nav == NULL) nav = rv_strdup("");
39 nishi 881
 
882
#ifdef USE_AVATAR
883
	generate_avatar();
884
#endif
885
 
1 nishi 886
	render_stuff();
15 nishi 887
freeall:
1 nishi 888
	free(page);
889
	free(desc);
890
	free(title);
10 nishi 891
	free(nav);
46 nishi 892
	if(logopath != NULL) free(logopath);
1 nishi 893
}
894
 
3 nishi 895
char* escape(const char* str) {
1 nishi 896
	char* r = malloc(1);
897
	r[0] = 0;
898
	char cbuf[2];
899
	cbuf[1] = 0;
900
	int i;
3 nishi 901
	for(i = 0; str[i] != 0; i++) {
902
		if(str[i] == '<') {
1 nishi 903
			char* tmp = r;
904
			r = rv_strcat(tmp, "&lt;");
905
			free(tmp);
3 nishi 906
		} else if(str[i] == '>') {
1 nishi 907
			char* tmp = r;
908
			r = rv_strcat(tmp, "&gt;");
909
			free(tmp);
3 nishi 910
		} else {
1 nishi 911
			cbuf[0] = str[i];
912
			char* tmp = r;
913
			r = rv_strcat(tmp, cbuf);
914
			free(tmp);
915
		}
916
	}
917
	return r;
918
}
919
 
3 nishi 920
void render_stuff(void) {
1 nishi 921
	char* escaped;
922
	add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
923
	add_data(&buffer, "<html>\n");
924
	add_data(&buffer, "	<head>\n");
925
	add_data(&buffer, "		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
926
	add_data(&buffer, "		<title>");
927
	add_data(&buffer, INSTANCE_NAME);
928
	add_data(&buffer, " - ");
929
	add_data(&buffer, title);
930
	add_data(&buffer, "</title>\n");
931
	add_data(&buffer, "		<style type=\"text/css\">\n");
932
	add_data(&buffer, "* {\n");
933
	add_data(&buffer, "	padding: 0;\n");
934
	add_data(&buffer, "	margin: 0;\n");
935
	add_data(&buffer, "}\n");
936
	add_data(&buffer, "li {\n");
937
	add_data(&buffer, "	list-style: outside;\n");
938
	add_data(&buffer, "	margin-left: 1.25em;\n");
939
	add_data(&buffer, "}\n");
940
	add_data(&buffer, "a {\n");
941
	add_data(&buffer, "	text-decoration: none;\n");
942
	add_data(&buffer, "}\n");
943
	add_data(&buffer, "#nav div {\n");
944
	add_data(&buffer, "	float: left;\n");
945
	add_data(&buffer, "	margin: 0 0;\n");
946
	add_data(&buffer, "	padding-left: 0;\n");
9 nishi 947
	add_data(&buffer, "	padding-right: 25px;\n");
1 nishi 948
	add_data(&buffer, "	padding-top: 7px;\n");
949
	add_data(&buffer, "}\n");
11 nishi 950
	add_data(&buffer, "th,td {\n");
951
	add_data(&buffer, "	padding: 2px;\n");
952
	add_data(&buffer, "}\n");
1 nishi 953
	add_data(&buffer, "body {\n");
954
	add_data(&buffer, "	background-color: #1F4677;\n");
955
	add_data(&buffer, "	width: 940px;\n");
956
	add_data(&buffer, "	margin: 5px auto;\n");
957
	add_data(&buffer, "	font-family: sans-serif;\n");
958
	add_data(&buffer, "}\n");
959
	add_data(&buffer, "#nav {\n");
960
	add_data(&buffer, "	background-color: white;\n");
6 nishi 961
	add_data(&buffer, "	background-image: url('");
962
	add_data(&buffer, INSTANCE_NAVBAR);
963
	add_data(&buffer, "');\n");
1 nishi 964
	add_data(&buffer, "	height: 44px;\n");
965
	add_data(&buffer, "	padding: 8px;\n");
966
	add_data(&buffer, "	padding-left: 32px;\n");
967
	add_data(&buffer, "	font-size: 22px;\n");
968
	add_data(&buffer, "	font-weight: bold;\n");
969
	add_data(&buffer, "}\n");
11 nishi 970
	add_data(&buffer, "pre {\n");
971
	add_data(&buffer, "	background-color: #dddddd;\n");
972
	add_data(&buffer, "	border: solid 2px #bbbbbb;\n");
12 nishi 973
	add_data(&buffer, "	padding: 8px;\n");
974
	add_data(&buffer, "	overflow: scroll;\n");
11 nishi 975
	add_data(&buffer, "}\n");
1 nishi 976
	add_data(&buffer, "#index {\n");
977
	add_data(&buffer, "	list-style: none;\n");
978
	add_data(&buffer, "	line-height: normal;\n");
979
	add_data(&buffer, "	margin: auto 0;\n");
980
	add_data(&buffer, "	padding-left: 0;\n");
981
	add_data(&buffer, "}\n");
982
	add_data(&buffer, "#desc {\n");
983
	add_data(&buffer, "	background-color: #D2E1F6;\n");
984
	add_data(&buffer, "	margin: 9px auto;\n");
985
	add_data(&buffer, "	height: 128px;\n");
986
	add_data(&buffer, "	padding: 24px;\n");
987
	add_data(&buffer, "}\n");
988
	add_data(&buffer, "#descinside {\n");
989
	add_data(&buffer, "	float: left;\n");
11 nishi 990
	add_data(&buffer, "	width: 700px;\n");
991
	add_data(&buffer, "	overflow-y: scroll;\n");
992
	add_data(&buffer, "	max-height: 128px;\n");
1 nishi 993
	add_data(&buffer, "}\n");
994
	add_data(&buffer, "#logo {\n");
995
	add_data(&buffer, "	float: right;\n");
996
	add_data(&buffer, "}\n");
997
	add_data(&buffer, "#content {\n");
998
	add_data(&buffer, "	background-color: #FFFFFF;\n");
999
	add_data(&buffer, "	margin: -10px auto;\n");
1000
	add_data(&buffer, "	padding: 8px 24px 24px;\n");
1001
	add_data(&buffer, "}\n");
1002
	add_data(&buffer, "#pageindex {\n");
1003
	add_data(&buffer, "	background-color: #FFFFFF;\n");
1004
	add_data(&buffer, "	padding-right: 24px;\n");
1005
	add_data(&buffer, "	padding-bottom: 24px;\n");
1006
	add_data(&buffer, "	float: left;\n");
1007
	add_data(&buffer, "	border-right: 4px #1F4677 solid;\n");
1008
	add_data(&buffer, "	width: 150px;\n");
1009
	add_data(&buffer, "}\n");
1010
	add_data(&buffer, "#pagecontent {\n");
1011
	add_data(&buffer, "	background-color: #FFFFFF;\n");
1012
	add_data(&buffer, "	width: 670px;\n");
1013
	add_data(&buffer, "	float: right;\n");
1014
	add_data(&buffer, "	padding-left: 24px;\n");
1015
	add_data(&buffer, "}\n");
1016
	add_data(&buffer, "#footer {\n");
1017
	add_data(&buffer, "	background-color: #D2E1F6;\n");
1018
	add_data(&buffer, "	padding: 8px 8px 48px;\n");
1019
	add_data(&buffer, "	margin: 8px auto;\n");
1020
	add_data(&buffer, "	font-size: 15px;\n");
1021
	add_data(&buffer, "	height: 32px;\n");
1022
	add_data(&buffer, "}\n");
1023
	add_data(&buffer, ".fixfloat {\n");
1024
	add_data(&buffer, "	clear: both;\n");
1025
	add_data(&buffer, "}\n");
1026
	add_data(&buffer, "#copyright {\n");
1027
	add_data(&buffer, "	float: right;\n");
1028
	add_data(&buffer, "	font-size: 10px;\n");
1029
	add_data(&buffer, "	margin-top: 16px;\n");
1030
	add_data(&buffer, "}\n");
1031
	add_data(&buffer, "#gotop {\n");
1032
	add_data(&buffer, "	position: absolute;\n");
1033
	add_data(&buffer, "}\n");
1034
	add_data(&buffer, "h2, h3 {\n");
1035
	add_data(&buffer, "	padding-top: 8px;\n");
1036
	add_data(&buffer, "	padding-bottom: 8px;\n");
1037
	add_data(&buffer, "}\n");
1038
	add_data(&buffer, "img {\n");
1039
	add_data(&buffer, "	border: none;\n");
1040
	add_data(&buffer, "}\n");
1041
	add_data(&buffer, "		</style>\n");
1042
	add_data(&buffer, "	</head>\n");
1043
	add_data(&buffer, "	<body>\n");
1044
	add_data(&buffer, "		<div id=\"nav\">\n");
1045
	add_data(&buffer, "			<div>\n");
1046
	add_data(&buffer, "				<a href=\"");
1047
	add_data(&buffer, INSTANCE_ROOT);
1048
	add_data(&buffer, "/\">Home</a>\n");
1049
	add_data(&buffer, "			</div>\n");
5 nishi 1050
	if(user == NULL) {
1051
		add_data(&buffer, "			<div>\n");
1052
		add_data(&buffer, "				<a href=\"");
1053
		add_data(&buffer, INSTANCE_ROOT);
1054
		add_data(&buffer, "/?page=login\">Login</a>\n");
1055
		add_data(&buffer, "			</div>\n");
13 nishi 1056
#ifdef ALLOW_SIGNUP
1057
		add_data(&buffer, "			<div>\n");
1058
		add_data(&buffer, "				<a href=\"");
1059
		add_data(&buffer, INSTANCE_ROOT);
1060
		add_data(&buffer, "/?page=signup\">Signup</a>\n");
1061
		add_data(&buffer, "			</div>\n");
1062
#endif
7 nishi 1063
	} else {
27 nishi 1064
#ifdef USE_MYPAGE
7 nishi 1065
		add_data(&buffer, "			<div>\n");
1066
		add_data(&buffer, "				<a href=\"");
1067
		add_data(&buffer, INSTANCE_ROOT);
9 nishi 1068
		add_data(&buffer, "/?page=mypage\">My Page</a>\n");
1069
		add_data(&buffer, "			</div>\n");
27 nishi 1070
#endif
9 nishi 1071
 
1072
		add_data(&buffer, "			<div>\n");
1073
		add_data(&buffer, "				<a href=\"");
1074
		add_data(&buffer, INSTANCE_ROOT);
1075
		add_data(&buffer, "/?page=myrepo\">My Repositories</a>\n");
1076
		add_data(&buffer, "			</div>\n");
1077
 
1078
		add_data(&buffer, "			<div>\n");
1079
		add_data(&buffer, "				<a href=\"");
1080
		add_data(&buffer, INSTANCE_ROOT);
7 nishi 1081
		add_data(&buffer, "/?page=logout\">Logout</a>\n");
1082
		add_data(&buffer, "			</div>\n");
5 nishi 1083
	}
6 nishi 1084
	if(user != NULL) {
43 nishi 1085
#ifdef USE_AVATAR
1086
#ifdef USE_MYPAGE
1087
		add_data(&buffer, "<a href=\"");
6 nishi 1088
		add_data(&buffer, INSTANCE_ROOT);
43 nishi 1089
		add_data(&buffer, "/?page=person&username=");
1090
		add_data(&buffer, user);
1091
		add_data(&buffer, "\">");
1092
#endif
1093
		add_data(&buffer, "<img src=\"");
1094
		add_data(&buffer, WWW_AVATAR_ROOT);
1095
		add_data(&buffer, "/");
1096
		add_data(&buffer, user);
1097
		add_data(&buffer, ".png\" alt=\"Your Icon\" style=\"float: right;height: 32px;\">");
1098
#ifdef USE_MYPAGE
1099
		add_data(&buffer, "</a>");
1100
#endif
1101
#endif
1102
		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=\"");
1103
		add_data(&buffer, INSTANCE_ROOT);
6 nishi 1104
		add_data(&buffer, "/?page=mypage\">");
1105
		add_data(&buffer, user);
1106
		add_data(&buffer, "</a></div>");
1107
	}
1 nishi 1108
	add_data(&buffer, "		</div>\n");
1109
	add_data(&buffer, "		<div id=\"desc\">\n");
1110
	add_data(&buffer, "			<div id=\"descinside\">\n");
1111
	add_data(&buffer, "				<h1>");
1112
	add_data(&buffer, title);
1113
	add_data(&buffer, "</h1>\n");
1114
	add_data(&buffer, "				<p>\n");
1115
	add_data(&buffer, desc);
1116
	add_data(&buffer, "				</p>\n");
1117
	add_data(&buffer, "			</div>\n");
1118
	add_data(&buffer, "			<img id=\"logo\" src=\"");
46 nishi 1119
	if(logopath != NULL) {
1120
		add_data(&buffer, logopath);
43 nishi 1121
	} else {
1122
		add_data(&buffer, INSTANCE_LOGO);
1123
	}
1 nishi 1124
	add_data(&buffer, "\" height=\"128px\" alt=\"logo\">\n");
1125
	add_data(&buffer, "		</div>\n");
1126
	add_data(&buffer, "		<div id=\"content\">\n");
1127
	add_data(&buffer, "			<div id=\"pageindex\">\n");
1128
	add_data(&buffer, "				<h3>Page Menu</h3>\n");
1129
	add_data(&buffer, "				<ul>\n");
10 nishi 1130
	add_data(&buffer, nav);
1 nishi 1131
	add_data(&buffer, "				</ul>\n");
1132
	add_data(&buffer, "			</div>\n");
1133
	add_data(&buffer, "			<div id=\"pagecontent\">\n");
1134
	add_data(&buffer, page);
1135
	add_data(&buffer, "			</div>\n");
11 nishi 1136
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
1 nishi 1137
	add_data(&buffer, "		</div>\n");
1138
	add_data(&buffer, "		<div id=\"footer\">\n");
1139
	add_data(&buffer, "			<div id=\"gotop\">\n");
1140
	add_data(&buffer, "				<a href=\"#top\">Top</a>\n");
1141
	add_data(&buffer, "			</div>\n");
1142
	add_data(&buffer, "			<div id=\"copyright\">\n");
1143
	add_data(&buffer, "				");
1144
	escaped = escape(INSTANCE_ADMIN);
1145
	add_data(&buffer, escaped);
1146
	free(escaped);
1147
	add_data(&buffer, "\n");
1148
	add_data(&buffer, "			</div>\n");
1149
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
15 nishi 1150
#ifdef INSTANCE_BANNERS
1151
	add_data(&buffer, "			<div id=\"banners\" style=\"clear: both;\">\n");
1152
	add_data(&buffer, INSTANCE_BANNERS);
1153
	add_data(&buffer, "			</div>\n");
1154
#else
1155
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
1156
#endif
1 nishi 1157
	add_data(&buffer, "		</div>\n");
1158
	add_data(&buffer, "	</body>\n");
1159
	add_data(&buffer, "</html>\n");
5 nishi 1160
	if(user != NULL) free(user);
1 nishi 1161
}