Subversion Repositories RepoView

Rev

Rev 39 | Rev 43 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 42
Line 1... Line 1...
1
/* $Id: modern.c 39 2024-08-22 03:38:21Z nishi $ */
1
/* $Id: modern.c 42 2024-08-22 05:25:09Z nishi $ */
2
 
2
 
3
#include "rv_query.h"
3
#include "rv_query.h"
4
 
4
 
5
#include "rv_util.h"
5
#include "rv_util.h"
6
#include "rv_version.h"
6
#include "rv_version.h"
7
#include "rv_auth.h"
7
#include "rv_auth.h"
8
#include "rv_db.h"
8
#include "rv_db.h"
9
#include "rv_repo.h"
9
#include "rv_repo.h"
-
 
10
#include "rv_multipart.h"
10
 
11
 
11
#include "../../config.h"
12
#include "../../config.h"
12
 
13
 
13
#ifdef USE_ENSCRIPT
14
#ifdef USE_ENSCRIPT
14
#include "rv_enscript.h"
15
#include "rv_enscript.h"
Line 16... Line 17...
16
 
17
 
17
#ifdef USE_AVATAR
18
#ifdef USE_AVATAR
18
#include "rv_avatar.h"
19
#include "rv_avatar.h"
19
#endif
20
#endif
20
 
21
 
-
 
22
#ifdef USE_GRAPHICSMAGICK
-
 
23
#include "rv_magick.h"
-
 
24
#endif
-
 
25
 
21
#include <stdio.h>
26
#include <stdio.h>
22
#include <stdlib.h>
27
#include <stdlib.h>
23
#include <string.h>
28
#include <string.h>
24
#include <unistd.h>
29
#include <unistd.h>
25
 
30
 
-
 
31
extern char* nocache;
26
extern char* buffer;
32
extern char* buffer;
27
void add_data(char** data, const char* txt);
33
void add_data(char** data, const char* txt);
28
void render_stuff();
34
void render_stuff();
29
 
35
 
30
char* title = NULL;
36
char* title = NULL;
Line 287... Line 293...
287
				if(user != NULL) free(user);
293
				if(user != NULL) free(user);
288
				int i;
294
				int i;
289
				bool reject = false;
295
				bool reject = false;
290
				char* name = rv_get_query("username");
296
				char* name = rv_get_query("username");
291
				for(i = 0; name[i] != 0; i++) {
297
				for(i = 0; name[i] != 0; i++) {
292
					if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/') {
298
					if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/' || name[i] == ':' || name[i] == '\n' || name[i] == '\r') {
293
						char cbuf[2];
299
						char cbuf[2];
294
						cbuf[0] = REPO_USER_DELIM;
300
						cbuf[0] = REPO_USER_DELIM;
295
						cbuf[1] = 0;
301
						cbuf[1] = 0;
296
						add_data(&page, "Username cannot contain '<code>");
302
						add_data(&page, "Username cannot contain '<code>");
297
						add_data(&page, cbuf);
303
						add_data(&page, cbuf);
Line 386... Line 392...
386
			add_data(&page, user);
392
			add_data(&page, user);
387
			add_data(&page, ".png\"><img src=\"");
393
			add_data(&page, ".png\"><img src=\"");
388
			add_data(&page, WWW_AVATAR_ROOT);
394
			add_data(&page, WWW_AVATAR_ROOT);
389
			add_data(&page, "/");
395
			add_data(&page, "/");
390
			add_data(&page, user);
396
			add_data(&page, user);
-
 
397
			add_data(&page, ".png");
-
 
398
			add_data(&page, nocache);
391
			add_data(&page, ".png\" alt=\"Your Icon\"></a>");
399
			add_data(&page, "\" alt=\"Your Icon\" width=\"50%\"></a>");
392
			add_data(&page, "<form action=\"");
400
			add_data(&page, "<form action=\"");
393
			add_data(&page, INSTANCE_ROOT);
401
			add_data(&page, INSTANCE_ROOT);
394
			add_data(&page, "/?page=uploadpfp\" method=\"POST\" enctype=\"multipart/form-data\">\n");
402
			add_data(&page, "/?page=uploadpfp\" method=\"POST\" enctype=\"multipart/form-data\">\n");
395
			add_data(&page, "	<input type=\"file\" name=\"pfp\">\n");
403
			add_data(&page, "	<input type=\"file\" name=\"pfp\">\n");
396
			add_data(&page, "	<input type=\"submit\" value=\"Upload\">\n");
404
			add_data(&page, "	<input type=\"submit\" value=\"Upload\">\n");
397
			add_data(&page, "</form>\n");
405
			add_data(&page, "</form>\n");
398
		}
406
		}
399
#endif
407
#endif
-
 
408
#ifdef USE_AVATAR
-
 
409
	} else if(strcmp(query, "uploadpfp") == 0) {
-
 
410
		title = rv_strdup("Uploading Profile Picture Result");
-
 
411
		page = rv_strdup("");
-
 
412
		if(user == NULL) {
-
 
413
			add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
-
 
414
			add_data(&page, INSTANCE_ROOT);
-
 
415
			add_data(&page, "/?page=login\">log in</a>?\n");
-
 
416
		} else if(rv_get_multipart("pfp") == NULL) {
-
 
417
			add_data(&page, "Invalid Form.");
-
 
418
		} else {
-
 
419
			struct multipart_entry* entry = rv_get_multipart("pfp");
-
 
420
			char* tmp = rv_strcat3(AVATAR_ROOT, "/", user);
-
 
421
			char* path = rv_strcat(tmp, ".tmp");
-
 
422
			char* outpath = rv_strcat(tmp, ".png");
-
 
423
			free(tmp);
-
 
424
			FILE* f = fopen(path, "wb");
-
 
425
			fwrite(entry->data, 1, entry->length, f);
-
 
426
			fclose(f);
-
 
427
			char* reason;
-
 
428
			if(rv_resize_picture(path, outpath, &reason)) {
-
 
429
				add_data(&page, "Uploaded the profile picture successfully.\n");
-
 
430
			} else {
-
 
431
				add_data(&page, "Failed to upload the profile picture.<br><code>\n");
-
 
432
				char* esc = html_escape(reason);
-
 
433
				add_data(&page, esc);
-
 
434
				free(esc);
-
 
435
				add_data(&page, "</code>\n");
-
 
436
				free(reason);
-
 
437
			}
-
 
438
			free(path);
-
 
439
			free(outpath);
-
 
440
		}
-
 
441
#endif
400
	} else if(strcmp(query, "myrepo") == 0) {
442
	} else if(strcmp(query, "myrepo") == 0) {
401
		title = rv_strdup("My Repositories");
443
		title = rv_strdup("My Repositories");
402
		desc = rv_strdup("You manage your repositories here.");
444
		desc = rv_strdup("You manage your repositories here.");
403
		if(user == NULL) {
445
		if(user == NULL) {
404
			page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
446
			page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
Line 449... Line 491...
449
		} else {
491
		} else {
450
			int i;
492
			int i;
451
			bool reject = false;
493
			bool reject = false;
452
			char* name = rv_get_query("name");
494
			char* name = rv_get_query("name");
453
			for(i = 0; name[i] != 0; i++) {
495
			for(i = 0; name[i] != 0; i++) {
454
				if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/') {
496
				if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/' || name[i] == ':' || name[i] == '\n' || name[i] == '\r') {
455
					char cbuf[2];
497
					char cbuf[2];
456
					cbuf[0] = REPO_USER_DELIM;
498
					cbuf[0] = REPO_USER_DELIM;
457
					cbuf[1] = 0;
499
					cbuf[1] = 0;
458
					add_data(&page, "Repository name cannot contain '<code>");
500
					add_data(&page, "Repository name cannot contain '<code>");
459
					add_data(&page, cbuf);
501
					add_data(&page, cbuf);