Subversion Repositories RepoView

Rev

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