Subversion Repositories RepoView

Rev

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