Subversion Repositories IRC-Archiver

Rev

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

Rev 14 Rev 18
Line 1... Line 1...
1
/* $Id: html.c 14 2024-08-30 07:49:29Z nishi $ */
1
/* $Id: html.c 18 2024-08-30 08:29:19Z nishi $ */
2
 
2
 
3
#include "web_html.h"
3
#include "web_html.h"
4
 
4
 
5
#include "web_db.h"
5
#include "web_db.h"
6
 
6
 
Line 73... Line 73...
73
		char* tmp = fmtmsg; \
73
		char* tmp = fmtmsg; \
74
		fmtmsg = ia_strcat(tmp, "</" tagname ">"); \
74
		fmtmsg = ia_strcat(tmp, "</" tagname ">"); \
75
		free(tmp); \
75
		free(tmp); \
76
	}
76
	}
77
 
77
 
78
int mtimesort(const struct dirent** d1_, const struct dirent** d2_){
78
int mtimesort(const struct dirent** d1_, const struct dirent** d2_) {
79
	struct dirent* d1 = (struct dirent*)d1_;
79
	struct dirent* d1 = (struct dirent*)d1_;
80
	struct dirent* d2 = (struct dirent*)d2_;
80
	struct dirent* d2 = (struct dirent*)d2_;
81
	char* d1_path = ia_strcat3(webroot, "/", d1->d_name);
81
	char* d1_path = ia_strcat3(webroot, "/", d1->d_name);
82
	char* d2_path = ia_strcat3(webroot, "/", d2->d_name);
82
	char* d2_path = ia_strcat3(webroot, "/", d2->d_name);
83
	struct stat s1;
83
	struct stat s1;
Line 259... Line 259...
259
		free(title);
259
		free(title);
260
	}
260
	}
261
	free(path);
261
	free(path);
262
	path = ia_strcat(webroot, "/index.html");
262
	path = ia_strcat(webroot, "/index.html");
263
	f = fopen(path, "w");
263
	f = fopen(path, "w");
264
	if(f != NULL){
264
	if(f != NULL) {
265
		char* title = ia_strdup("Index");
265
		char* title = ia_strdup("Index");
266
		struct dirent **namelist;
266
		struct dirent** namelist;
267
		int n = scandir(webroot, &namelist, NULL, mtimesort);
267
		int n = scandir(webroot, &namelist, NULL, mtimesort);
268
		fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
268
		fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
269
		fprintf(f, "<html>\n");
269
		fprintf(f, "<html>\n");
270
		fprintf(f, "	<head>\n");
270
		fprintf(f, "	<head>\n");
271
		fprintf(f, "		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n");
271
		fprintf(f, "		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n");
Line 281... Line 281...
281
		fprintf(f, "		<table border=\"1\" style=\"width: 100%%;\">\n");
281
		fprintf(f, "		<table border=\"1\" style=\"width: 100%%;\">\n");
282
		fprintf(f, "			<tr>\n");
282
		fprintf(f, "			<tr>\n");
283
		fprintf(f, "				<th>Name</th><th style=\"width: 250px;\">Archived at</th><th style=\"width: 100px;\">Link</th>");
283
		fprintf(f, "				<th>Name</th><th style=\"width: 250px;\">Archived at</th><th style=\"width: 100px;\">Link</th>");
284
		fprintf(f, "			</tr>\n");
284
		fprintf(f, "			</tr>\n");
285
		int i;
285
		int i;
286
		for(i = 0; i < n; i++){
286
		for(i = 0; i < n; i++) {
287
			if(strcmp(namelist[i]->d_name, "..") != 0 && strcmp(namelist[i]->d_name, ".") != 0 && strcmp(namelist[i]->d_name, "index.html") != 0){
287
			if(strcmp(namelist[i]->d_name, "..") != 0 && strcmp(namelist[i]->d_name, ".") != 0 && strcmp(namelist[i]->d_name, "index.html") != 0) {
288
				struct stat s;
288
				struct stat s;
289
				char* np = ia_strcat3(webroot, "/", namelist[i]->d_name);
289
				char* np = ia_strcat3(webroot, "/", namelist[i]->d_name);
290
				stat(np, &s);
290
				stat(np, &s);
291
				struct tm* tm = gmtime(&s.st_mtime);
291
				struct tm* tm = gmtime(&s.st_mtime);
292
				char date[512];
292
				char date[512];
293
				strftime(date, 512, "%Y/%m/%d %H:%M:%S UTC", tm);
293
				strftime(date, 512, "%Y/%m/%d %H:%M:%S UTC", tm);
294
				char* name = ia_strdup(namelist[i]->d_name);
294
				char* name = ia_strdup(namelist[i]->d_name);
295
				int j;
295
				int j;
296
				for(j = strlen(name) - 1; j >= 0; j--){
296
				for(j = strlen(name) - 1; j >= 0; j--) {
297
					if(name[j] == '.'){
297
					if(name[j] == '.') {
298
						name[j] = 0;
298
						name[j] = 0;
299
						break;
299
						break;
300
					}
300
					}
301
				}
301
				}
302
				char* esc = web_html_escape(name);
302
				char* esc = web_html_escape(name);