Subversion Repositories RepoView

Rev

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