Subversion Repositories RepoView

Rev

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