Subversion Repositories RepoView

Rev

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

Rev 12 Rev 13
Line 1... Line 1...
1
/* $Id: modern.c 12 2024-08-21 05:05:19Z nishi $ */
1
/* $Id: modern.c 13 2024-08-21 12:31:40Z 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 8... Line 8...
8
#include "rv_db.h"
8
#include "rv_db.h"
9
#include "rv_repo.h"
9
#include "rv_repo.h"
10
 
10
 
11
#include "../../config.h"
11
#include "../../config.h"
12
 
12
 
-
 
13
#ifdef USE_ENSCRIPT
-
 
14
#include "rv_enscript.h"
-
 
15
#endif
-
 
16
 
13
#include <stdio.h>
17
#include <stdio.h>
14
#include <stdlib.h>
18
#include <stdlib.h>
15
#include <string.h>
19
#include <string.h>
16
 
20
 
17
extern char* buffer;
21
extern char* buffer;
Line 178... Line 182...
178
	add_data(&query, "&username=");
182
	add_data(&query, "&username=");
179
	esc = url_escape(user);
183
	esc = url_escape(user);
180
	add_data(&query, esc);
184
	add_data(&query, esc);
181
	free(esc);
185
	free(esc);
182
	add_data(&query, "&path=");
186
	add_data(&query, "&path=");
183
	char* urlpath = rv_strcat(path, pathname);
187
	char* urlpath = rv_strcat3(path, "/", pathname);
184
	esc = url_escape(urlpath);
188
	esc = url_escape(urlpath);
185
	add_data(&query, esc);
189
	add_data(&query, esc);
186
	free(esc);
190
	free(esc);
187
	char* sz = malloc(128);
191
	char* sz = malloc(128);
188
	sprintf(sz, "%lld", rv_get_filesize(grepouser, urlpath));
192
	sprintf(sz, "%lld", rv_get_filesize(grepouser, urlpath));
Line 211... Line 215...
211
 
215
 
212
	if(strcmp(query, "welcome") == 0) {
216
	if(strcmp(query, "welcome") == 0) {
213
		title = rv_strdup("Welcome");
217
		title = rv_strdup("Welcome");
214
		desc = rv_strdup("Welcome to " INSTANCE_NAME ".");
218
		desc = rv_strdup("Welcome to " INSTANCE_NAME ".");
215
		page = rv_strcat3("Welcome to " INSTANCE_NAME ".<br>This instance is running RepoView version ", rv_get_version(), ".");
219
		page = rv_strcat3("Welcome to " INSTANCE_NAME ".<br>This instance is running RepoView version ", rv_get_version(), ".");
-
 
220
#ifdef ALLOW_SIGNUP
-
 
221
	} else if(strcmp(query, "signup") == 0) {
-
 
222
		title = rv_strdup("Signup");
-
 
223
		desc = rv_strdup("You can create your account here.");
-
 
224
		page = rv_strdup("");
-
 
225
 
-
 
226
		add_data(&page, "<form action=\"");
-
 
227
		add_data(&page, INSTANCE_ROOT);
-
 
228
		add_data(&page, "/?page=sendsignup\" method=\"POST\">\n");
-
 
229
		add_data(&page, "	<table border=\"0\">\n");
-
 
230
		add_data(&page, "		<tr>\n");
-
 
231
		add_data(&page, "			<th>Username</th>\n");
-
 
232
		add_data(&page, "			<td>\n");
-
 
233
		add_data(&page, "				<input name=\"username\">\n");
-
 
234
		add_data(&page, "			</td>\n");
-
 
235
		add_data(&page, "		</tr>\n");
-
 
236
		add_data(&page, "		<tr>\n");
-
 
237
		add_data(&page, "			<th>Password</th>\n");
-
 
238
		add_data(&page, "			<td>\n");
-
 
239
		add_data(&page, "				<input name=\"password\" type=\"password\">\n");
-
 
240
		add_data(&page, "			</td>\n");
-
 
241
		add_data(&page, "		</tr>\n");
-
 
242
		add_data(&page, "	</table>\n");
-
 
243
		char cbuf[2];
-
 
244
		cbuf[0] = REPO_USER_DELIM;
-
 
245
		cbuf[1] = 0;
-
 
246
		add_data(&page, "Username cannot contain '<code>");
-
 
247
		add_data(&page, cbuf);
-
 
248
		add_data(&page, "</code>'.<br>");
-
 
249
		add_data(&page, "	<input type=\"submit\" value=\"Signup\">\n");
-
 
250
		add_data(&page, "</form>\n");
-
 
251
	} else if(strcmp(query, "sendsignup") == 0) {
-
 
252
		title = rv_strdup("Signup Result");
-
 
253
		page = rv_strdup("");
-
 
254
 
-
 
255
		rv_load_query('P');
-
 
256
		if(user != NULL) {
-
 
257
			page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
-
 
258
			add_data(&page, INSTANCE_ROOT);
-
 
259
			add_data(&page, "/?page=logout\">log out</a>?\n");
-
 
260
		} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
-
 
261
			add_data(&page, "Invalid form.\n");
-
 
262
		} else {
-
 
263
			if(rv_has_user(rv_get_query("username"))) {
-
 
264
				add_data(&page, "User already exists.");
-
 
265
			} else {
-
 
266
				if(user != NULL) free(user);
-
 
267
				int i;
-
 
268
				bool reject = false;
-
 
269
				char* name = rv_get_query("username");
-
 
270
				for(i = 0; name[i] != 0; i++) {
-
 
271
					if(name[i] == REPO_USER_DELIM) {
-
 
272
						char cbuf[2];
-
 
273
						cbuf[0] = REPO_USER_DELIM;
-
 
274
						cbuf[1] = 0;
-
 
275
						add_data(&page, "Username cannot contain '<code>");
-
 
276
						add_data(&page, cbuf);
-
 
277
						add_data(&page, "</code>'.");
-
 
278
						reject = true;
-
 
279
						break;
-
 
280
					}
-
 
281
				}
-
 
282
				if(!reject) {
-
 
283
					rv_create_user(rv_get_query("username"), rv_get_query("password"));
-
 
284
					user = rv_strdup(rv_get_query("username"));
-
 
285
					add_data(&page, "Welcome.\n");
-
 
286
					rv_save_login(rv_get_query("username"));
-
 
287
				}
-
 
288
			}
-
 
289
		}
-
 
290
#endif
216
	} else if(strcmp(query, "login") == 0) {
291
	} else if(strcmp(query, "login") == 0) {
217
		title = rv_strdup("Login");
292
		title = rv_strdup("Login");
218
		desc = rv_strdup("You can log in to your account here.");
293
		desc = rv_strdup("You can log in to your account here.");
219
		page = rv_strdup("");
294
		page = rv_strdup("");
220
 
295
 
Line 243... Line 318...
243
 
318
 
244
		rv_load_query('P');
319
		rv_load_query('P');
245
		if(user != NULL) {
320
		if(user != NULL) {
246
			page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
321
			page = rv_strdup("It looks like you are already logged in.<br>Want to <a href=\"");
247
			add_data(&page, INSTANCE_ROOT);
322
			add_data(&page, INSTANCE_ROOT);
248
			add_data(&page, "/?page=login\">log out</a>?\n");
323
			add_data(&page, "/?page=logout\">log out</a>?\n");
249
		} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
324
		} else if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
250
			add_data(&page, "Invalid form.\n");
325
			add_data(&page, "Invalid form.\n");
251
		} else {
326
		} else {
252
			if(rv_has_user(rv_get_query("username"))) {
327
			if(rv_has_user(rv_get_query("username"))) {
253
				if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
328
				if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
Line 421... Line 496...
421
				add_data(&page, "</table>");
496
				add_data(&page, "</table>");
422
				if(isdir == 0) {
497
				if(isdir == 0) {
423
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
498
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
424
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
499
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
425
					add_data(&page, "<pre class=\"codeblock\"><code>");
500
					add_data(&page, "<pre class=\"codeblock\"><code>");
-
 
501
#ifdef USE_ENSCRIPT
-
 
502
					int i;
-
 
503
					char* ext = NULL;
-
 
504
					for(i = strlen(path) - 1; i >= 0; i--) {
-
 
505
						if(path[i] == '.') {
-
 
506
							ext = path + i + 1;
-
 
507
							break;
-
 
508
						}
-
 
509
					}
-
 
510
					char* data = rv_enscript(repouser, path, ext);
-
 
511
					if(data != NULL) {
-
 
512
						add_data(&page, data);
-
 
513
						free(data);
-
 
514
					} else {
-
 
515
						data = rv_read_file(repouser, path);
-
 
516
						if(data != NULL) {
-
 
517
							char* esc = html_escape_nl_to_br(data);
-
 
518
							add_data(&page, esc);
-
 
519
							free(esc);
-
 
520
							free(data);
-
 
521
						} else {
-
 
522
							add_data(&page, "Cannot open the file.\n");
-
 
523
						}
-
 
524
					}
-
 
525
#else
426
					char* data = rv_read_file(repouser, path);
526
					char* data = rv_read_file(repouser, path);
427
					if(data != NULL) {
527
					if(data != NULL) {
428
						char* esc = html_escape_nl_to_br(data);
528
						char* esc = html_escape_nl_to_br(data);
429
						add_data(&page, esc);
529
						add_data(&page, esc);
430
						free(esc);
530
						free(esc);
431
						free(data);
531
						free(data);
432
					} else {
532
					} else {
433
						add_data(&page, "Cannot open the file.\n");
533
						add_data(&page, "Cannot open the file.\n");
434
					}
534
					}
-
 
535
#endif
435
					add_data(&page, "</code></pre>");
536
					add_data(&page, "</code></pre>");
436
				}
537
				}
437
			} else {
538
			} else {
438
				add_data(&page, "Repository does not exist.\n");
539
				add_data(&page, "Repository does not exist.\n");
439
			}
540
			}
Line 611... Line 712...
611
		add_data(&buffer, "			<div>\n");
712
		add_data(&buffer, "			<div>\n");
612
		add_data(&buffer, "				<a href=\"");
713
		add_data(&buffer, "				<a href=\"");
613
		add_data(&buffer, INSTANCE_ROOT);
714
		add_data(&buffer, INSTANCE_ROOT);
614
		add_data(&buffer, "/?page=login\">Login</a>\n");
715
		add_data(&buffer, "/?page=login\">Login</a>\n");
615
		add_data(&buffer, "			</div>\n");
716
		add_data(&buffer, "			</div>\n");
-
 
717
#ifdef ALLOW_SIGNUP
-
 
718
		add_data(&buffer, "			<div>\n");
-
 
719
		add_data(&buffer, "				<a href=\"");
-
 
720
		add_data(&buffer, INSTANCE_ROOT);
-
 
721
		add_data(&buffer, "/?page=signup\">Signup</a>\n");
-
 
722
		add_data(&buffer, "			</div>\n");
-
 
723
#endif
616
	} else {
724
	} else {
617
		add_data(&buffer, "			<div>\n");
725
		add_data(&buffer, "			<div>\n");
618
		add_data(&buffer, "				<a href=\"");
726
		add_data(&buffer, "				<a href=\"");
619
		add_data(&buffer, INSTANCE_ROOT);
727
		add_data(&buffer, INSTANCE_ROOT);
620
		add_data(&buffer, "/?page=mypage\">My Page</a>\n");
728
		add_data(&buffer, "/?page=mypage\">My Page</a>\n");