Subversion Repositories RepoView

Rev

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