Keine Ahnung
This commit is contained in:
		@@ -118,7 +118,7 @@ URI::URI(string webroot, string reqpath) {
 | 
				
			|||||||
		if (relpath[relpath.length() - 1] == '/') {
 | 
							if (relpath[relpath.length() - 1] == '/') {
 | 
				
			||||||
			relpath.erase(relpath.length() - 1);
 | 
								relpath.erase(relpath.length() - 1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		newpath = relpath + info;
 | 
							newpath = relpath + '/' + info;
 | 
				
			||||||
		filepath = "";
 | 
							filepath = "";
 | 
				
			||||||
	} else if (relpath != reqpath) {
 | 
						} else if (relpath != reqpath) {
 | 
				
			||||||
		if (!info.empty()) {
 | 
							if (!info.empty()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,7 @@
 | 
				
			|||||||
 | 
					#include <utility>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <utility>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Necronda Web Server 3.0
 | 
					 * Necronda Web Server 3.0
 | 
				
			||||||
 * client.cpp - Client and Connection handler
 | 
					 * client.cpp - Client and Connection handler
 | 
				
			||||||
@@ -37,6 +41,17 @@ typedef struct {
 | 
				
			|||||||
} IpAddressInfo;
 | 
					} IpAddressInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void log_to_file(const char *prefix, const string &str, string host) {
 | 
				
			||||||
 | 
					    //FILE *file = fopen((getWebRoot(std::move(host)) + ".access.log").c_str(), "a");
 | 
				
			||||||
 | 
					    //fprintf(file, "%s%s\r\n", prefix, str.c_str());
 | 
				
			||||||
 | 
					    //fflush(file);
 | 
				
			||||||
 | 
					    //fclose(file);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void log_error_to_file(const char *prefix, const string &str, string host) {
 | 
				
			||||||
 | 
					    log_to_file(prefix, "\x1B[1;31m" + str + "\x1B[0m", std::move(host));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Writes log messages to the console
 | 
					 * Writes log messages to the console
 | 
				
			||||||
 * @param prefix The connection prefix
 | 
					 * @param prefix The connection prefix
 | 
				
			||||||
@@ -203,10 +218,12 @@ bool connection_handler(const char *preprefix, const char *col1, const char *col
 | 
				
			|||||||
				error = true;
 | 
									error = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								string host = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (!req.isExistingField("Host")) {
 | 
								if (!req.isExistingField("Host")) {
 | 
				
			||||||
				req.respond(400);
 | 
									req.respond(400);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				string host = req.getField("Host");
 | 
									host = req.getField("Host");
 | 
				
			||||||
				long pos = host.find(':');
 | 
									long pos = host.find(':');
 | 
				
			||||||
				if (pos != string::npos) {
 | 
									if (pos != string::npos) {
 | 
				
			||||||
					host.erase(pos, host.length() - pos);
 | 
										host.erase(pos, host.length() - pos);
 | 
				
			||||||
@@ -227,6 +244,7 @@ bool connection_handler(const char *preprefix, const char *col1, const char *col
 | 
				
			|||||||
				prefix = buffer;
 | 
									prefix = buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				log(prefix, "\x1B[1m" + req.getMethod() + " " + req.getPath() + "\x1B[0m");
 | 
									log(prefix, "\x1B[1m" + req.getMethod() + " " + req.getPath() + "\x1B[0m");
 | 
				
			||||||
 | 
									log_to_file(prefix, "\x1B[1m" + req.getMethod() + " " + req.getPath() + "\x1B[0m", host);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				bool noRedirect = req.getPath().find("/.well-known/acme-challenge/") == 0;
 | 
									bool noRedirect = req.getPath().find("/.well-known/acme-challenge/") == 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -445,19 +463,21 @@ bool connection_handler(const char *preprefix, const char *col1, const char *col
 | 
				
			|||||||
				color = "\x1B[1;31m"; // Server Error: Red
 | 
									color = "\x1B[1;31m"; // Server Error: Red
 | 
				
			||||||
				//comment = " -> " + req.getPath();
 | 
									//comment = " -> " + req.getPath();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			log(prefix,
 | 
								string msg = color + to_string(status.code) + " " + status.message + comment + " (" + formatTime(req.getDuration()) + ")\x1B[0m";
 | 
				
			||||||
				color + to_string(status.code) + " " + status.message + comment + " (" + formatTime(req.getDuration()) +
 | 
								log(prefix, msg);
 | 
				
			||||||
				")\x1B[0m");
 | 
								if (!host.empty()) {
 | 
				
			||||||
 | 
					                log_to_file(prefix, msg, host);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
		} catch (char *msg) {
 | 
							} catch (char *msg) {
 | 
				
			||||||
			HttpStatusCode status = req.getStatusCode();
 | 
								HttpStatusCode status = req.getStatusCode();
 | 
				
			||||||
			log(prefix, to_string(status.code) + " " + status.message + " (" + formatTime(req.getDuration()) + ")");
 | 
								log(prefix, to_string(status.code) + " " + status.message + " (" + formatTime(req.getDuration()) + ")");
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				if (msg == "timeout") {
 | 
									if (strncmp(msg, "timeout", strlen(msg)) == 0) {
 | 
				
			||||||
					log(prefix, "Timeout!");
 | 
										log(prefix, "Timeout!");
 | 
				
			||||||
					req.setField("Connection", "close");
 | 
										req.setField("Connection", "close");
 | 
				
			||||||
					req.respond(408);
 | 
										req.respond(408);
 | 
				
			||||||
					error = true;
 | 
										error = true;
 | 
				
			||||||
				} else if (msg == "Invalid path") {
 | 
									} else if (strncmp(msg, "Invalid path", strlen(msg)) == 0) {
 | 
				
			||||||
					log(prefix, "Timeout!");
 | 
										log(prefix, "Timeout!");
 | 
				
			||||||
					req.setField("Connection", "close");
 | 
										req.setField("Connection", "close");
 | 
				
			||||||
					req.respond(400);
 | 
										req.respond(400);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user