Subversion Repositories RepoView

Rev

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