Subversion Repositories RepoView

Rev

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

Rev 14 Rev 15
Line 1... Line 1...
1
/* $Id: modern.c 14 2024-08-21 14:24:05Z nishi $ */
1
/* $Id: modern.c 15 2024-08-21 15:36:37Z 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"
Line 127... Line 127...
127
			char* esc;
127
			char* esc;
128
			esc = url_escape(rv_get_query("reponame"));
128
			esc = url_escape(rv_get_query("reponame"));
129
			add_data(&query, esc);
129
			add_data(&query, esc);
130
			free(esc);
130
			free(esc);
131
			add_data(&query, "&username=");
131
			add_data(&query, "&username=");
132
			esc = url_escape(user);
132
			esc = url_escape(rv_get_query("username"));
133
			add_data(&query, esc);
133
			add_data(&query, esc);
134
			free(esc);
134
			free(esc);
135
			add_data(&query, "&path=");
135
			add_data(&query, "&path=");
136
 
136
 
137
			char* urlpath = rv_strdup(path);
137
			char* urlpath = rv_strdup(path);
Line 178... Line 178...
178
	char* esc;
178
	char* esc;
179
	esc = url_escape(rv_get_query("reponame"));
179
	esc = url_escape(rv_get_query("reponame"));
180
	add_data(&query, esc);
180
	add_data(&query, esc);
181
	free(esc);
181
	free(esc);
182
	add_data(&query, "&username=");
182
	add_data(&query, "&username=");
183
	esc = url_escape(user);
183
	esc = url_escape(rv_get_query("username"));
184
	add_data(&query, esc);
184
	add_data(&query, esc);
185
	free(esc);
185
	free(esc);
186
	add_data(&query, "&path=");
186
	add_data(&query, "&path=");
187
	char* urlpath = rv_strcat3(path, "/", pathname);
187
	char* urlpath = rv_strcat3(path, "/", pathname);
188
	esc = url_escape(urlpath);
188
	esc = url_escape(urlpath);
Line 463... Line 463...
463
	} else if(strcmp(query, "repo") == 0) {
463
	} else if(strcmp(query, "repo") == 0) {
464
		title = rv_strdup("Repository");
464
		title = rv_strdup("Repository");
465
		desc = rv_strdup("");
465
		desc = rv_strdup("");
466
		page = rv_strdup("");
466
		page = rv_strdup("");
467
		nav = rv_strdup("");
467
		nav = rv_strdup("");
-
 
468
		rv_load_query('Q');
468
		if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
469
		if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
469
			add_data(&page, "Required parameters not set.");
470
			add_data(&page, "Required parameters not set.");
470
		} else {
471
		} else {
471
			char* user = rv_get_query("username");
472
			char* ruser = rv_get_query("username");
472
			char* repo = rv_get_query("reponame");
473
			char* repo = rv_get_query("reponame");
473
			char* repouser = rv_construct_repouser(repo, user);
474
			char* repouser = rv_construct_repouser(repo, ruser);
474
			grepouser = repouser;
475
			grepouser = repouser;
475
			if(rv_repo_exists(repouser)) {
476
			if(rv_repo_exists(repouser)) {
476
				char* showuser = html_escape(user);
477
				char* showuser = html_escape(ruser);
477
				char* showrepo = html_escape(repo);
478
				char* showrepo = html_escape(repo);
478
				char* showreadme = rv_get_readme(repouser);
479
				char* showreadme = rv_get_readme(repouser);
479
				desc = html_escape_nl_to_br(showreadme);
480
				desc = html_escape_nl_to_br(showreadme);
480
				add_data(&title, " - ");
481
				add_data(&title, " - ");
481
				add_data(&title, showrepo);
482
				add_data(&title, showrepo);
482
				add_data(&title, "/");
483
				add_data(&title, "/");
483
				add_data(&title, showuser);
484
				add_data(&title, showuser);
484
				free(showuser);
485
				free(showuser);
485
				free(showrepo);
486
				free(showrepo);
486
				free(showreadme);
487
				free(showreadme);
-
 
488
#ifdef WWW_SVN_ROOT
-
 
489
				add_data(&page, "<h2 id=\"repoinfo\">Info</h2>\n");
-
 
490
				add_data(&page, "<a href=\"");
-
 
491
				add_data(&page, WWW_SVN_ROOT);
-
 
492
				add_data(&page, "/");
-
 
493
				char* escru = url_escape(repouser);
-
 
494
				add_data(&page, escru);
-
 
495
				free(escru);
-
 
496
				add_data(&page, "\">Raw repository</a>");
-
 
497
#endif
487
 
498
 
488
				int isdir;
499
				int isdir;
489
				char* path = rv_get_query("path");
500
				char* path = rv_get_query("path");
490
				if(path == NULL) path = "/";
501
				if(path == NULL) path = "/";
491
				fcounter = 0;
502
				fcounter = 0;
492
				add_data(&page, "<table border=\"0\" style=\"width: 100%;\">");
503
				add_data(&page, "<table border=\"0\" style=\"width: 100%;\">");
-
 
504
				bool rej = false;
493
				if(!rv_get_list(repouser, path, list_files, &isdir)) {
505
				if(!rv_get_list(repouser, path, list_files, &isdir)) {
494
					add_data(&page, "<tr><td>Path not found.</td></tr>\n");
506
					add_data(&page, "<tr><td>Path not found.</td></tr>\n");
-
 
507
					rej = true;
495
				}
508
				}
496
				add_data(&page, "</table>");
509
				add_data(&page, "</table>");
497
				if(isdir == 0) {
510
				if(isdir == 0 && !rej) {
498
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
511
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
499
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
512
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
500
					add_data(&page, "<pre class=\"codeblock\"><code>");
513
					add_data(&page, "<pre class=\"codeblock\"><code>");
501
#ifdef USE_ENSCRIPT
514
#ifdef USE_ENSCRIPT
502
					int i;
515
					int i;
Line 533... Line 546...
533
						add_data(&page, "Cannot open the file.\n");
546
						add_data(&page, "Cannot open the file.\n");
534
					}
547
					}
535
#endif
548
#endif
536
					add_data(&page, "</code></pre>");
549
					add_data(&page, "</code></pre>");
537
				}
550
				}
-
 
551
				if(user != NULL && strcmp(user, ruser) == 0) {
-
 
552
					char* esc;
-
 
553
					add_data(&nav, "<li><a href=\"#managerepo\">Manage The Repository</a></li>\n");
-
 
554
					add_data(&page, "<h2 id=\"managerepo\">Manage The Repository</h2>\n");
-
 
555
					add_data(&page, "<form action=\"");
-
 
556
					add_data(&page, INSTANCE_ROOT);
-
 
557
					add_data(&page, "/?page=sendmanrepo&username=");
-
 
558
					esc = url_escape(ruser);
-
 
559
					add_data(&page, esc);
-
 
560
					free(esc);
-
 
561
					add_data(&page, "&reponame=");
-
 
562
					esc = url_escape(ruser);
-
 
563
					add_data(&page, esc);
-
 
564
					free(esc);
-
 
565
					add_data(&page, "\" method=\"POST\">\n");
-
 
566
					add_data(&page, "<table border=\"0\" style=\"width: 100%;\">\n");
-
 
567
					add_data(&page, "	<tr>\n");
-
 
568
					add_data(&page, "		<th>README</th>\n");
-
 
569
					add_data(&page, "		<td>\n");
-
 
570
					add_data(&page, "			<textarea name=\"readme\" style=\"width: 100%;resize: none;height: 128px;\">\n");
-
 
571
					char* readme = rv_get_readme(repouser);
-
 
572
					esc = html_escape(readme);
-
 
573
					add_data(&page, esc);
-
 
574
					free(esc);
-
 
575
					free(readme);
-
 
576
					add_data(&page, "			</textarea>\n");
-
 
577
					add_data(&page, "		</td>\n");
-
 
578
					add_data(&page, "	</tr>\n");
-
 
579
					add_data(&page, "</table>\n");
-
 
580
					add_data(&page, "<input type=\"submit\" value=\"Send\">\n");
-
 
581
					add_data(&page, "</form>\n");
-
 
582
					add_data(&page, "<a href=\"");
-
 
583
					add_data(&page, INSTANCE_ROOT);
-
 
584
					add_data(&page, "/?page=deleterepo&username=");
-
 
585
					esc = url_escape(ruser);
-
 
586
					add_data(&page, esc);
-
 
587
					free(esc);
-
 
588
					add_data(&page, "&reponame=");
-
 
589
					esc = url_escape(ruser);
-
 
590
					add_data(&page, esc);
-
 
591
					free(esc);
-
 
592
					add_data(&page, "\">\n");
-
 
593
					add_data(&page, "Delete repository\n");
-
 
594
					add_data(&page, "</a>\n");
-
 
595
				}
538
			} else {
596
			} else {
539
				add_data(&page, "Repository does not exist.\n");
597
				add_data(&page, "Repository does not exist.\n");
540
			}
598
			}
541
			free(repouser);
599
			free(repouser);
542
		}
600
		}
-
 
601
	} else if(strcmp(query, "deleterepo") == 0) {
-
 
602
		title = rv_strdup("Delete The Repository");
-
 
603
		page = rv_strdup("");
-
 
604
 
-
 
605
		rv_load_query('Q');
-
 
606
		if(user == NULL) {
-
 
607
			add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
-
 
608
			add_data(&page, INSTANCE_ROOT);
-
 
609
			add_data(&page, "/?page=login\">log in</a>?\n");
-
 
610
		} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
-
 
611
			add_data(&page, "Invalid Form.\n");
-
 
612
		} else {
-
 
613
			char* esc;
-
 
614
			add_data(&page, "Are you sure you want to delete the repository?\n");
-
 
615
			add_data(&page, "<form method=\"POST\" action=\"");
-
 
616
			add_data(&page, INSTANCE_ROOT);
-
 
617
			add_data(&page, "/?page=senddeleterepo&username=");
-
 
618
			esc = url_escape(rv_get_query("username"));
-
 
619
			add_data(&page, esc);
-
 
620
			free(esc);
-
 
621
			add_data(&page, "&reponame=");
-
 
622
			esc = url_escape(rv_get_query("reponame"));
-
 
623
			add_data(&page, esc);
-
 
624
			free(esc);
-
 
625
			add_data(&page, "\">");
-
 
626
			add_data(&page, "	<input type=\"submit\" value=\"Yes\">\n");
-
 
627
			add_data(&page, "</form>\n");
-
 
628
		}
-
 
629
	} else if(strcmp(query, "senddeleterepo") == 0) {
-
 
630
		title = rv_strdup("Deleting Repository Result");
-
 
631
		page = rv_strdup("");
-
 
632
 
-
 
633
		rv_load_query('Q');
-
 
634
		if(user == NULL) {
-
 
635
			add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
-
 
636
			add_data(&page, INSTANCE_ROOT);
-
 
637
			add_data(&page, "/?page=login\">log in</a>?\n");
-
 
638
		} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
-
 
639
			add_data(&page, "Invalid Form.\n");
-
 
640
		} else if(strcmp(rv_get_query("username"), user) != 0) {
-
 
641
			add_data(&page, "You are not the owner of the repository.\n");
-
 
642
		} else {
-
 
643
			char* repouser = rv_construct_repouser(rv_get_query("reponame"), rv_get_query("username"));
-
 
644
			if(rv_repo_exists(repouser)) {
-
 
645
				rv_remove_repo(repouser);
-
 
646
				add_data(&page, "Deleted the repository successfully.<br>\n");
-
 
647
			} else {
-
 
648
				add_data(&page, "Repository does not exist.<br>\n");
-
 
649
			}
-
 
650
		}
-
 
651
	} else if(strcmp(query, "sendmanrepo") == 0) {
-
 
652
		title = rv_strdup("Modifying Repository Result");
-
 
653
		page = rv_strdup("");
-
 
654
 
-
 
655
		rv_load_query('Q');
-
 
656
		if(user == NULL) {
-
 
657
			add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
-
 
658
			add_data(&page, INSTANCE_ROOT);
-
 
659
			add_data(&page, "/?page=login\">log in</a>?\n");
-
 
660
		} else if(rv_get_query("username") == NULL || rv_get_query("reponame") == NULL) {
-
 
661
			add_data(&page, "Invalid Form.\n");
-
 
662
		} else if(strcmp(rv_get_query("username"), user) != 0) {
-
 
663
			add_data(&page, "You are not the owner of the repository.\n");
-
 
664
		} else {
-
 
665
			char* esc;
-
 
666
			rv_load_query('P');
-
 
667
			char* readme = rv_get_query("readme");
-
 
668
			if(readme != NULL) {
-
 
669
				rv_load_query('Q');
-
 
670
				char* name = rv_construct_repouser(rv_get_query("reponame"), rv_get_query("username"));
-
 
671
				rv_set_readme(name, readme);
-
 
672
				free(name);
-
 
673
			}
-
 
674
			rv_load_query('Q');
-
 
675
			add_data(&page, "Modified the repository successfully.<br>\n");
-
 
676
			add_data(&page, "<a href=\"");
-
 
677
			add_data(&page, INSTANCE_ROOT);
-
 
678
			add_data(&page, "?page=repo&username=");
-
 
679
			esc = url_escape(rv_get_query("username"));
-
 
680
			add_data(&page, esc);
-
 
681
			free(esc);
-
 
682
			add_data(&page, "&reponame=");
-
 
683
			esc = url_escape(rv_get_query("reponame"));
-
 
684
			add_data(&page, esc);
-
 
685
			free(esc);
-
 
686
			add_data(&page, "\">Go back to the repository</a>.\n");
-
 
687
		}
543
	}
688
	}
544
 
689
 
545
	if(title == NULL) title = rv_strdup("");
690
	if(title == NULL) title = rv_strdup("");
546
	if(desc == NULL) desc = rv_strdup("");
691
	if(desc == NULL) desc = rv_strdup("");
547
	if(page == NULL) page = rv_strdup("");
692
	if(page == NULL) page = rv_strdup("");
548
	if(nav == NULL) nav = rv_strdup("");
693
	if(nav == NULL) nav = rv_strdup("");
549
	render_stuff();
694
	render_stuff();
-
 
695
freeall:
550
	free(page);
696
	free(page);
551
	free(desc);
697
	free(desc);
552
	free(title);
698
	free(title);
553
	free(nav);
699
	free(nav);
554
}
700
}
Line 783... Line 929...
783
	add_data(&buffer, escaped);
929
	add_data(&buffer, escaped);
784
	free(escaped);
930
	free(escaped);
785
	add_data(&buffer, "\n");
931
	add_data(&buffer, "\n");
786
	add_data(&buffer, "			</div>\n");
932
	add_data(&buffer, "			</div>\n");
787
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
933
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
-
 
934
#ifdef INSTANCE_BANNERS
-
 
935
	add_data(&buffer, "			<div id=\"banners\" style=\"clear: both;\">\n");
-
 
936
	add_data(&buffer, INSTANCE_BANNERS);
-
 
937
	add_data(&buffer, "			</div>\n");
-
 
938
#else
-
 
939
	add_data(&buffer, "			<div class=\"fixfloat\"></div>\n");
-
 
940
#endif
788
	add_data(&buffer, "		</div>\n");
941
	add_data(&buffer, "		</div>\n");
789
	add_data(&buffer, "	</body>\n");
942
	add_data(&buffer, "	</body>\n");
790
	add_data(&buffer, "</html>\n");
943
	add_data(&buffer, "</html>\n");
791
	if(user != NULL) free(user);
944
	if(user != NULL) free(user);
792
}
945
}