summaryrefslogtreecommitdiff
path: root/src/webserver
diff options
context:
space:
mode:
Diffstat (limited to 'src/webserver')
-rw-r--r--src/webserver/Changelog.txt4
-rw-r--r--src/webserver/Makefile64
-rw-r--r--src/webserver/Makefile.win70
-rw-r--r--src/webserver/WEBSER~1.layout48
-rw-r--r--src/webserver/Webserver.dev194
-rw-r--r--src/webserver/Webserver.layout76
-rw-r--r--src/webserver/conf/webserver-athena.conf72
-rw-r--r--src/webserver/main.c288
-rw-r--r--src/webserver/webserver.c272
-rw-r--r--src/webserver/webserver.h42
10 files changed, 565 insertions, 565 deletions
diff --git a/src/webserver/Changelog.txt b/src/webserver/Changelog.txt
index a3a63b35a..e4d38bac0 100644
--- a/src/webserver/Changelog.txt
+++ b/src/webserver/Changelog.txt
@@ -1,3 +1,3 @@
-Date Added
-12/3
+Date Added
+12/3
* Creation of eAthena Web Server v2 [MC Cameri] \ No newline at end of file
diff --git a/src/webserver/Makefile b/src/webserver/Makefile
index 6ceff7e20..000754036 100644
--- a/src/webserver/Makefile
+++ b/src/webserver/Makefile
@@ -1,32 +1,32 @@
-CC = gcc -pipe
-MAKE = make
-OPT = -g -O2 -ffast-math
-
-ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
-CFLAGS = $(OPT) -Wall -I../common
-else
-CFLAGS = $(OPT) -Wall -I../common
-endif
-
-OBJ = main.o webserver.o ../common/showmsg.o
-LINKOBJ = main.o webserver.o ../common/showmsg.o
-
-all: clean webserver run
-
-clean:
- rm -f *.o webserver.exe ../common/showmsg.o
-
-webserver: main.o webserver.o ../common/showmsg.o
- $(CC) $(OPT) -o "Webserver.exe" $(OBJ)
-
-main.o: main.c
- $(CC) $(OPT) -c main.c -o main.o $(CFLAGS)
-
-webserver.o: webserver.c
- $(CC) $(OPT) -c webserver.c -o webserver.o $(CFLAGS)
-
-../common/showmsg.o: ../common/showmsg.c
- $(CC) $(OPT) -c ../common/showmsg.c -o ../common/showmsg.o $(CFLAGS)
-
-run:
- ./webserver
+CC = gcc -pipe
+MAKE = make
+OPT = -g -O2 -ffast-math
+
+ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
+CFLAGS = $(OPT) -Wall -I../common
+else
+CFLAGS = $(OPT) -Wall -I../common
+endif
+
+OBJ = main.o webserver.o ../common/showmsg.o
+LINKOBJ = main.o webserver.o ../common/showmsg.o
+
+all: clean webserver run
+
+clean:
+ rm -f *.o webserver.exe ../common/showmsg.o
+
+webserver: main.o webserver.o ../common/showmsg.o
+ $(CC) $(OPT) -o "Webserver.exe" $(OBJ)
+
+main.o: main.c
+ $(CC) $(OPT) -c main.c -o main.o $(CFLAGS)
+
+webserver.o: webserver.c
+ $(CC) $(OPT) -c webserver.c -o webserver.o $(CFLAGS)
+
+../common/showmsg.o: ../common/showmsg.c
+ $(CC) $(OPT) -c ../common/showmsg.c -o ../common/showmsg.o $(CFLAGS)
+
+run:
+ ./webserver
diff --git a/src/webserver/Makefile.win b/src/webserver/Makefile.win
index ed3d57323..65cf676ad 100644
--- a/src/webserver/Makefile.win
+++ b/src/webserver/Makefile.win
@@ -1,35 +1,35 @@
-# Project: Webserver
-# Makefile created by Dev-C++ 4.9.8.0
-
-CPP = g++.exe -D__DEBUG__
-CC = gcc.exe -D__DEBUG__
-WINDRES = windres.exe
-RES =
-OBJ = main.o webserver.o ../common/showmsg.o $(RES)
-LINKOBJ = main.o webserver.o ../common/showmsg.o $(RES)
-LIBS = -L"C:/Program Files/Dev-Cpp/lib" -L"C:/cygwin/lib"
-INCS = -I"C:/Program Files/Dev-Cpp/include" -I"C:/cygwin/usr/include" -I"C:/cygwin/usr/include/mingw"
-CXXINCS = -I"C:/Program Files/Dev-Cpp/include/c++" -I"C:/Program Files/Dev-Cpp/include/c++/mingw32" -I"C:/Program Files/Dev-Cpp/include/c++/backward" -I"C:/Program Files/Dev-Cpp/include" -I"C:/cygwin/usr/include/c++/3.3.1"
-BIN = webserver.exe
-CXXFLAGS = $(CXXINCS) -pg -g3
-CFLAGS = $(INCS) -pg -g3
-
-.PHONY: all all-before all-after clean clean-custom
-
-all: all-before webserver.exe all-after
-
-
-clean: clean-custom
- rm -f $(OBJ) $(BIN)
-
-$(BIN): $(LINKOBJ)
- $(CC) $(LINKOBJ) -o "webserver.exe" $(LIBS)
-
-main.o: main.c
- $(CC) -c main.c -o main.o $(CFLAGS)
-
-webserver.o: webserver.c
- $(CC) -c webserver.c -o webserver.o $(CFLAGS)
-
-../common/showmsg.o: ../common/showmsg.c
- $(CC) -c ../common/showmsg.c -o ../common/showmsg.o $(CFLAGS)
+# Project: Webserver
+# Makefile created by Dev-C++ 4.9.8.0
+
+CPP = g++.exe -D__DEBUG__
+CC = gcc.exe -D__DEBUG__
+WINDRES = windres.exe
+RES =
+OBJ = main.o webserver.o ../common/showmsg.o $(RES)
+LINKOBJ = main.o webserver.o ../common/showmsg.o $(RES)
+LIBS = -L"C:/Program Files/Dev-Cpp/lib" -L"C:/cygwin/lib"
+INCS = -I"C:/Program Files/Dev-Cpp/include" -I"C:/cygwin/usr/include" -I"C:/cygwin/usr/include/mingw"
+CXXINCS = -I"C:/Program Files/Dev-Cpp/include/c++" -I"C:/Program Files/Dev-Cpp/include/c++/mingw32" -I"C:/Program Files/Dev-Cpp/include/c++/backward" -I"C:/Program Files/Dev-Cpp/include" -I"C:/cygwin/usr/include/c++/3.3.1"
+BIN = webserver.exe
+CXXFLAGS = $(CXXINCS) -pg -g3
+CFLAGS = $(INCS) -pg -g3
+
+.PHONY: all all-before all-after clean clean-custom
+
+all: all-before webserver.exe all-after
+
+
+clean: clean-custom
+ rm -f $(OBJ) $(BIN)
+
+$(BIN): $(LINKOBJ)
+ $(CC) $(LINKOBJ) -o "webserver.exe" $(LIBS)
+
+main.o: main.c
+ $(CC) -c main.c -o main.o $(CFLAGS)
+
+webserver.o: webserver.c
+ $(CC) -c webserver.c -o webserver.o $(CFLAGS)
+
+../common/showmsg.o: ../common/showmsg.c
+ $(CC) -c ../common/showmsg.c -o ../common/showmsg.o $(CFLAGS)
diff --git a/src/webserver/WEBSER~1.layout b/src/webserver/WEBSER~1.layout
index cbc84d563..49854196f 100644
--- a/src/webserver/WEBSER~1.layout
+++ b/src/webserver/WEBSER~1.layout
@@ -1,24 +1,24 @@
-[Editors]
-Focused=-1
-Order=-1,0
-[Editor_0]
-Open=1
-Top=0
-CursorCol=5
-CursorRow=30
-TopLine=1
-LeftChar=1
-[Editor_1]
-Open=1
-Top=0
-CursorCol=1
-CursorRow=35
-TopLine=16
-LeftChar=1
-[Editor_2]
-Open=1
-Top=1
-CursorCol=14
-CursorRow=4
-TopLine=1
-LeftChar=1
+[Editors]
+Focused=-1
+Order=-1,0
+[Editor_0]
+Open=1
+Top=0
+CursorCol=5
+CursorRow=30
+TopLine=1
+LeftChar=1
+[Editor_1]
+Open=1
+Top=0
+CursorCol=1
+CursorRow=35
+TopLine=16
+LeftChar=1
+[Editor_2]
+Open=1
+Top=1
+CursorCol=14
+CursorRow=4
+TopLine=1
+LeftChar=1
diff --git a/src/webserver/Webserver.dev b/src/webserver/Webserver.dev
index 9e100bacb..5bbb3a08c 100644
--- a/src/webserver/Webserver.dev
+++ b/src/webserver/Webserver.dev
@@ -1,97 +1,97 @@
-[Project]
-FileName=Webserver.dev
-Name=Webserver
-UnitCount=5
-Type=1
-Ver=1
-ObjFiles=
-Includes=
-Libs=
-PrivateResource=
-ResourceIncludes=
-MakeIncludes=
-Compiler=
-CppCompiler=
-Linker=
-IsCpp=0
-Icon=
-ExeOutput=
-ObjectOutput=
-OverrideOutput=1
-OverrideOutputName=webserver.exe
-HostApplication=
-Folders=common
-CommandLine=
-IncludeVersionInfo=0
-SupportXPThemes=0
-CompilerSet=1
-CompilerSettings=000000000000000000
-
-[Unit1]
-FileName=main.c
-CompileCpp=0
-Folder=
-Compile=1
-Link=1
-Priority=1000
-OverrideBuildCmd=0
-BuildCmd=$(CC) -c main.c -o main.o webserver.o $(CFLAGS)
-
-[VersionInfo]
-Major=0
-Minor=1
-Release=1
-Build=1
-LanguageID=1033
-CharsetID=1252
-CompanyName=
-FileVersion=
-FileDescription=Developed using the Dev-C++ IDE
-InternalName=
-LegalCopyright=
-LegalTrademarks=
-OriginalFilename=
-ProductName=
-ProductVersion=
-AutoIncBuildNr=0
-
-[Unit2]
-FileName=webserver.c
-CompileCpp=0
-Folder=
-Compile=1
-Link=1
-Priority=1000
-OverrideBuildCmd=1
-BuildCmd=$(CC) -c webserver.c -o webserver.o $(CFLAGS)
-
-[Unit3]
-FileName=webserver.h
-CompileCpp=0
-Folder=
-Compile=1
-Link=1
-Priority=1000
-OverrideBuildCmd=0
-BuildCmd=
-
-[Unit4]
-FileName=..\common\showmsg.c
-CompileCpp=0
-Folder=common
-Compile=1
-Link=1
-Priority=1000
-OverrideBuildCmd=0
-BuildCmd=
-
-[Unit5]
-FileName=..\common\showmsg.h
-CompileCpp=0
-Folder=common
-Compile=1
-Link=1
-Priority=1000
-OverrideBuildCmd=0
-BuildCmd=
-
+[Project]
+FileName=Webserver.dev
+Name=Webserver
+UnitCount=5
+Type=1
+Ver=1
+ObjFiles=
+Includes=
+Libs=
+PrivateResource=
+ResourceIncludes=
+MakeIncludes=
+Compiler=
+CppCompiler=
+Linker=
+IsCpp=0
+Icon=
+ExeOutput=
+ObjectOutput=
+OverrideOutput=1
+OverrideOutputName=webserver.exe
+HostApplication=
+Folders=common
+CommandLine=
+IncludeVersionInfo=0
+SupportXPThemes=0
+CompilerSet=1
+CompilerSettings=000000000000000000
+
+[Unit1]
+FileName=main.c
+CompileCpp=0
+Folder=
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=$(CC) -c main.c -o main.o webserver.o $(CFLAGS)
+
+[VersionInfo]
+Major=0
+Minor=1
+Release=1
+Build=1
+LanguageID=1033
+CharsetID=1252
+CompanyName=
+FileVersion=
+FileDescription=Developed using the Dev-C++ IDE
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=
+AutoIncBuildNr=0
+
+[Unit2]
+FileName=webserver.c
+CompileCpp=0
+Folder=
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=1
+BuildCmd=$(CC) -c webserver.c -o webserver.o $(CFLAGS)
+
+[Unit3]
+FileName=webserver.h
+CompileCpp=0
+Folder=
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=
+
+[Unit4]
+FileName=..\common\showmsg.c
+CompileCpp=0
+Folder=common
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=
+
+[Unit5]
+FileName=..\common\showmsg.h
+CompileCpp=0
+Folder=common
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=
+
diff --git a/src/webserver/Webserver.layout b/src/webserver/Webserver.layout
index b61094a58..b99312289 100644
--- a/src/webserver/Webserver.layout
+++ b/src/webserver/Webserver.layout
@@ -1,38 +1,38 @@
-[Editors]
-Focused=0
-Order=0,2,1,-1
-[Editor_0]
-Open=1
-Top=1
-CursorCol=55
-CursorRow=128
-TopLine=95
-LeftChar=1
-[Editor_1]
-Open=1
-Top=0
-CursorCol=25
-CursorRow=113
-TopLine=92
-LeftChar=1
-[Editor_2]
-Open=1
-Top=0
-CursorCol=1
-CursorRow=21
-TopLine=1
-LeftChar=1
-[Editor_3]
-Open=0
-Top=0
-CursorCol=20
-CursorRow=2
-TopLine=1
-LeftChar=1
-[Editor_4]
-Open=0
-Top=0
-CursorCol=20
-CursorRow=1
-TopLine=1
-LeftChar=1
+[Editors]
+Focused=0
+Order=0,2,1,-1
+[Editor_0]
+Open=1
+Top=1
+CursorCol=55
+CursorRow=128
+TopLine=95
+LeftChar=1
+[Editor_1]
+Open=1
+Top=0
+CursorCol=25
+CursorRow=113
+TopLine=92
+LeftChar=1
+[Editor_2]
+Open=1
+Top=0
+CursorCol=1
+CursorRow=21
+TopLine=1
+LeftChar=1
+[Editor_3]
+Open=0
+Top=0
+CursorCol=20
+CursorRow=2
+TopLine=1
+LeftChar=1
+[Editor_4]
+Open=0
+Top=0
+CursorCol=20
+CursorRow=1
+TopLine=1
+LeftChar=1
diff --git a/src/webserver/conf/webserver-athena.conf b/src/webserver/conf/webserver-athena.conf
index 003aababa..6f84aa133 100644
--- a/src/webserver/conf/webserver-athena.conf
+++ b/src/webserver/conf/webserver-athena.conf
@@ -1,36 +1,36 @@
-#############################################################
-# ______ __ __ #
-# /\ _ \/\ \__/\ \ #
-# __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
-# /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
-# /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
-# \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
-# \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
-# eAthena Web Server (Second Edition) #
-# by MC Cameri #
-# ------------------------------------------------------- #
-# -Website/Forum- #
-# http://eathena.deltaanime.net/ #
-# -Download URL- #
-# http://eathena.systeminplace.net/ #
-# -IRC Channel- #
-# irc://irc.deltaanime.net/#athena #
-#############################################################
-
-// Display the eAthena Logo at startup?
-show_title: 1
-
-//Web Server Port
-port: 81
-
-//Web Server Password
-password: juan16
-
-//Page Header
-header: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-//Document index
-document_index: index.xhtml
-
-//Send favorite icon if provided?
-favicon: yes
+#############################################################
+# ______ __ __ #
+# /\ _ \/\ \__/\ \ #
+# __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
+# /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
+# /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
+# \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
+# \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
+# eAthena Web Server (Second Edition) #
+# by MC Cameri #
+# ------------------------------------------------------- #
+# -Website/Forum- #
+# http://eathena.deltaanime.net/ #
+# -Download URL- #
+# http://eathena.systeminplace.net/ #
+# -IRC Channel- #
+# irc://irc.deltaanime.net/#athena #
+#############################################################
+
+// Display the eAthena Logo at startup?
+show_title: 1
+
+//Web Server Port
+port: 81
+
+//Web Server Password
+password: juan16
+
+//Page Header
+header: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+//Document index
+document_index: index.xhtml
+
+//Send favorite icon if provided?
+favicon: yes
diff --git a/src/webserver/main.c b/src/webserver/main.c
index 941a7a348..915d71b6d 100644
--- a/src/webserver/main.c
+++ b/src/webserver/main.c
@@ -1,144 +1,144 @@
-/******************************************************************************
- # ______ __ __ #
- # /\ _ \/\ \__/\ \ #
- # __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
- # /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
- # /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
- # \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
- # \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
- # eAthena Web Server (Second Edition) #
- # by MC Cameri #
- # ------------------------------------------------------- #
- # -Website/Forum- #
- # http://eathena.deltaanime.net/ #
- # -Download URL- #
- # http://eathena.systeminplace.net/ #
- # -IRC Channel- #
- # irc://irc.deltaanime.net/#athena #
- ******************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "../common/showmsg.h"
-#include "webserver.h"
-
-char ws_password[17];
-char ws_header[128];
-
-#define WEB_CONF "conf/webserver-athena.conf"
-#define MAX_CONNECTIONS 10
-#define HOME "home/"
-
-struct config config;
-
-int main(int argc, char *argv[])
-{
- int server_fd, client_fd;
- int sin_size;
- struct sockaddr_in server_addr;
- struct sockaddr_in client_addr;
- struct sigaction sa;
- char recvin[1024];
- char path[1024];
- char line[1024];
- int optval = 1;
- if (ws_config_read(WEB_CONF)) exit(0);
- if (config.show_title)
- ws_display_title();
- else
- printf("eAthena Web Server (Second Edition)\n");
- if (strcmpEx(ws_password,"webpass")==0)
- ShowWarning("You are using the default password (webpass), we highly "
- "recommend\n that you change it.\n");
- else if (strstr(ws_password,"webpass"))
- ShowWarning("Your password should not contain \"webpass\" in it, it is"
- " highly\n recommended that you change it.\n");
- printf("Web Server Password: %s\n",ws_password);
- printf("Web Server Port: %d\n",config.port);
-
- if ((server_fd = socket(AF_INET, SOCK_STREAM,0)) == -1) {
- ShowError("In main() -> Could not open socket.\n");
- return 1;
- }
- if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) == -1) {
- ShowError("In main() -> Could not set socket options.\n");
- return 1;
- }
- server_addr.sin_family = AF_INET;
- server_addr.sin_port = htons(config.port);
- server_addr.sin_addr.s_addr = INADDR_ANY;
- memset(&(server_addr.sin_zero), '\0', 8);
-
- if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) < 0) {
- snprintf(tmp_output,sizeof(tmp_output),"In main() -> Could not bind to port number: %d\n",config.port);
- ShowError(tmp_output);
- return 1;
- }
-
- if (listen(server_fd, MAX_CONNECTIONS) < 0) {
- snprintf(tmp_output,sizeof(tmp_output),"In main() -> Could not listen on port number: %d\n",config.port);
- ShowError(tmp_output);
- return 1;
- }
-
- sa.sa_handler = ws_sigchld_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
-
- if (sigaction(SIGCHLD, &sa, NULL) < 0) {
- ShowError("In main() -> Invalid sigaction.\n");
- return 1;
- }
- ShowInfo("eAthena Web Server is now listening for incoming connections.\n");
-
- while(1)
- {
- sin_size = sizeof(struct sockaddr_in);
- client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &sin_size);
-
- if (!fork())
- {
- close(server_fd);
- memset(recvin, 0x0, 500);
- recv(client_fd, recvin, 500, 0);
- char *html_output;
- int count = 0;
- if (sscanf(recvin,"GET %[a-zA-Z_-.+\%#@~] %*[^\n]",path)==1) {
- FILE *fp;
- strcpy(tmp_output,HOME);
- strcat(tmp_output,path);
- fp = fopen(tmp_output,"r+");
- if (fp==NULL) {
- send(client_fd,"File not found",strlen("File not found"), 0);
- close(client_fd);
- }
- memset(tmp_output,0x0,strlen(tmp_output));
- html_output = (char*)malloc(sizeof(char)*2);
- while (fgets(line,1023,fp)) {
- html_output = (char*)realloc(sizeof(html_output)+(sizeof(char)*count));
- strcat(html_output,line);
- printf(line);
- }
- send(client_fd,tmp_output,sizeof(tmp_output),0);
- fclose(fp);
- }
- // send(client_fd, ws_header, strlen(ws_header), 0);
- // generate_page(password, client_fd, get_query(recvin), inet_ntoa(client_addr.sin_addr));
- // log_visit(get_query(recvin), inet_ntoa(client_addr.sin_addr));
- close(client_fd);
- exit(0);
- }
- close(client_fd);
- }
- return 0;
-}
+/******************************************************************************
+ # ______ __ __ #
+ # /\ _ \/\ \__/\ \ #
+ # __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
+ # /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
+ # /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
+ # \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
+ # \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
+ # eAthena Web Server (Second Edition) #
+ # by MC Cameri #
+ # ------------------------------------------------------- #
+ # -Website/Forum- #
+ # http://eathena.deltaanime.net/ #
+ # -Download URL- #
+ # http://eathena.systeminplace.net/ #
+ # -IRC Channel- #
+ # irc://irc.deltaanime.net/#athena #
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "../common/showmsg.h"
+#include "webserver.h"
+
+char ws_password[17];
+char ws_header[128];
+
+#define WEB_CONF "conf/webserver-athena.conf"
+#define MAX_CONNECTIONS 10
+#define HOME "home/"
+
+struct config config;
+
+int main(int argc, char *argv[])
+{
+ int server_fd, client_fd;
+ int sin_size;
+ struct sockaddr_in server_addr;
+ struct sockaddr_in client_addr;
+ struct sigaction sa;
+ char recvin[1024];
+ char path[1024];
+ char line[1024];
+ int optval = 1;
+ if (ws_config_read(WEB_CONF)) exit(0);
+ if (config.show_title)
+ ws_display_title();
+ else
+ printf("eAthena Web Server (Second Edition)\n");
+ if (strcmpEx(ws_password,"webpass")==0)
+ ShowWarning("You are using the default password (webpass), we highly "
+ "recommend\n that you change it.\n");
+ else if (strstr(ws_password,"webpass"))
+ ShowWarning("Your password should not contain \"webpass\" in it, it is"
+ " highly\n recommended that you change it.\n");
+ printf("Web Server Password: %s\n",ws_password);
+ printf("Web Server Port: %d\n",config.port);
+
+ if ((server_fd = socket(AF_INET, SOCK_STREAM,0)) == -1) {
+ ShowError("In main() -> Could not open socket.\n");
+ return 1;
+ }
+ if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) == -1) {
+ ShowError("In main() -> Could not set socket options.\n");
+ return 1;
+ }
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = htons(config.port);
+ server_addr.sin_addr.s_addr = INADDR_ANY;
+ memset(&(server_addr.sin_zero), '\0', 8);
+
+ if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) < 0) {
+ snprintf(tmp_output,sizeof(tmp_output),"In main() -> Could not bind to port number: %d\n",config.port);
+ ShowError(tmp_output);
+ return 1;
+ }
+
+ if (listen(server_fd, MAX_CONNECTIONS) < 0) {
+ snprintf(tmp_output,sizeof(tmp_output),"In main() -> Could not listen on port number: %d\n",config.port);
+ ShowError(tmp_output);
+ return 1;
+ }
+
+ sa.sa_handler = ws_sigchld_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART;
+
+ if (sigaction(SIGCHLD, &sa, NULL) < 0) {
+ ShowError("In main() -> Invalid sigaction.\n");
+ return 1;
+ }
+ ShowInfo("eAthena Web Server is now listening for incoming connections.\n");
+
+ while(1)
+ {
+ sin_size = sizeof(struct sockaddr_in);
+ client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &sin_size);
+
+ if (!fork())
+ {
+ close(server_fd);
+ memset(recvin, 0x0, 500);
+ recv(client_fd, recvin, 500, 0);
+ char *html_output;
+ int count = 0;
+ if (sscanf(recvin,"GET %[a-zA-Z_-.+\%#@~] %*[^\n]",path)==1) {
+ FILE *fp;
+ strcpy(tmp_output,HOME);
+ strcat(tmp_output,path);
+ fp = fopen(tmp_output,"r+");
+ if (fp==NULL) {
+ send(client_fd,"File not found",strlen("File not found"), 0);
+ close(client_fd);
+ }
+ memset(tmp_output,0x0,strlen(tmp_output));
+ html_output = (char*)malloc(sizeof(char)*2);
+ while (fgets(line,1023,fp)) {
+ html_output = (char*)realloc(sizeof(html_output)+(sizeof(char)*count));
+ strcat(html_output,line);
+ printf(line);
+ }
+ send(client_fd,tmp_output,sizeof(tmp_output),0);
+ fclose(fp);
+ }
+ // send(client_fd, ws_header, strlen(ws_header), 0);
+ // generate_page(password, client_fd, get_query(recvin), inet_ntoa(client_addr.sin_addr));
+ // log_visit(get_query(recvin), inet_ntoa(client_addr.sin_addr));
+ close(client_fd);
+ exit(0);
+ }
+ close(client_fd);
+ }
+ return 0;
+}
diff --git a/src/webserver/webserver.c b/src/webserver/webserver.c
index 3a2b9b2dd..0169cd028 100644
--- a/src/webserver/webserver.c
+++ b/src/webserver/webserver.c
@@ -1,136 +1,136 @@
-/******************************************************************************
- # ______ __ __ #
- # /\ _ \/\ \__/\ \ #
- # __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
- # /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
- # /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
- # \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
- # \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
- # eAthena Web Server (Second Edition) #
- # by MC Cameri #
- # ------------------------------------------------------- #
- # -Website/Forum- #
- # http://eathena.deltaanime.net/ #
- # -Download URL- #
- # http://eathena.systeminplace.net/ #
- # -IRC Channel- #
- # irc://irc.deltaanime.net/#athena #
- ******************************************************************************/
-
-#include <stdio.h>
-#include <strings.h>
-#include "../common/showmsg.h"
-#include "webserver.h"
-
-char ws_password[17] = "pass";
-char ws_header[128] = {'\0'};
-
-/* Displays the eAthena Logo */
-void ws_display_title(void)
-{
- printf("\033[2J");
- printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1;33m (c)2004 eAthena Development Team presents \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m ______ __ __ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m /\\ _ \\/\\ \\__/\\ \\ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m __\\ \\ \\_\\ \\ \\ ,_\\ \\ \\___ __ ___ __ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m /'__`\\ \\ __ \\ \\ \\/\\ \\ _ `\\ /'__`\\/' _ `\\ /'__`\\ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m /\\ __/\\ \\ \\/\\ \\ \\ \\_\\ \\ \\ \\ \\/\\ __//\\ \\/\\ \\/\\ \\_\\.\\_ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m \\ \\____\\\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\____\\ \\_\\ \\_\\ \\__/.\\_\\ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m \\/____/ \\/_/\\/_/\\/__/ \\/_/\\/_/\\/____/\\/_/\\/_/\\/__/\\/_/ \033[0;44m)\033[K\033[0m\n");
- printf("\033[0;44m (\033[1m _ _ _ _ _ _ _ _ _ _ _ _ _ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
- printf("\033[0;44m (\033[1m / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
- printf("\033[0;44m (\033[1m ( e | n | g | l | i | s | h ) ( A | t | h | e | n | a ) \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
- printf("\033[0;44m (\033[1m \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
- printf("\033[0;44m (\033[1m \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
- printf("\033[0;44m (\033[1;33m Advanced Fusion Maps (c) 2003-2004 The Fusion Project \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
- printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n\n"); // reset color
-}
-/* Returns a boolean value given character string */
-int ws_config_switch(const char *str) {
- if (strcmpEx(str, "on") == 0 || strcmpEx(str, "yes") == 0 ||
- strcmpEx(str, "oui") == 0 || strcmpEx(str, "ja") == 0 ||
- strcmpEx(str, "si") == 0 || strcmpEx(str,"true") == 0)
- return 1;
- if (strcmpEx(str, "off") == 0 || strcmpEx(str, "no") == 0 ||
- strcmpEx(str, "non") == 0 || strcmpEx(str, "nein") == 0 ||
- strcmpEx(str, "false") == 0)
- return 0;
- return atoi(str);
-}
-
-/* Reads the eAthena Web Server's configuration file */
-int ws_config_read(const char *cfgName)
-{
- int i;
- char line[1024],w1[1024],w2[1024],temp[1024];
- FILE *fp;
-
- /* Default values */
- config.show_title=0;
- config.port=80;
-
-
- fp=fopen(cfgName,"r");
- if(fp==NULL){
- snprintf(temp,sizeof(temp),"Could not open \033[1;29m%s\033[0;0m, file not found.\n",cfgName);
- ShowMessage(temp,MSG_ERROR);
- return 1;
- }
- while(fgets(line,1020,fp)){
- const struct {
- char str[128];
- int *val;
- } data[] ={
- //List of variables
- { "show_title", &config.show_title },
- { "port", &config.port },
- };
-
- if((line[0] == '/' && line[1] == '/') || (line[0]=='#') ||
- (sscanf(line,"%1023[^:]:%1023[^\n]",w1,w2) !=2))
- continue;
- for(i=0;i<sizeof(data)/(sizeof(data[0]));i++) {
- if(strcmpEx(w1,data[i].str)==0){
- *data[i].val=ws_config_switch(w2);
- break;
- }
- }
- if(strcmpEx(w1,"import")==0) {
- ws_config_read(w2);
- continue;
- }
- if(strcmpEx(w1,"password")==0) {
- if (strlen(w2)>16) {
- ShowError("The Web Server password is too long, maximum passwor"
- "d length is 16 characters.\n");
- return 1;
- }
- strcpy(ws_password,w2);
- continue;
- }
- if(strcmpEx(w1,"header")==0) {
- if (strlen(w2)>127) {
- ShowError("The Web Server header is too long, maximum header"
- "d length is 127 characters.\n");
- return 1;
- }
- strcpy(ws_header,w2);
- continue;
- }
- }
- fclose(fp);
-
- //Correct values
- if(config.show_title < 0)
- config.show_title = 0;
- if(config.port < 1 || config.port > 65534)
- config.port=80;
-
- return 0;
-}
-
-void ws_sigchld_handler(int s)
-{
- while(wait(NULL) > 0);
-}
+/******************************************************************************
+ # ______ __ __ #
+ # /\ _ \/\ \__/\ \ #
+ # __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
+ # /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
+ # /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
+ # \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
+ # \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
+ # eAthena Web Server (Second Edition) #
+ # by MC Cameri #
+ # ------------------------------------------------------- #
+ # -Website/Forum- #
+ # http://eathena.deltaanime.net/ #
+ # -Download URL- #
+ # http://eathena.systeminplace.net/ #
+ # -IRC Channel- #
+ # irc://irc.deltaanime.net/#athena #
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <strings.h>
+#include "../common/showmsg.h"
+#include "webserver.h"
+
+char ws_password[17] = "pass";
+char ws_header[128] = {'\0'};
+
+/* Displays the eAthena Logo */
+void ws_display_title(void)
+{
+ printf("\033[2J");
+ printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1;33m (c)2004 eAthena Development Team presents \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m ______ __ __ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m /\\ _ \\/\\ \\__/\\ \\ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m __\\ \\ \\_\\ \\ \\ ,_\\ \\ \\___ __ ___ __ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m /'__`\\ \\ __ \\ \\ \\/\\ \\ _ `\\ /'__`\\/' _ `\\ /'__`\\ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m /\\ __/\\ \\ \\/\\ \\ \\ \\_\\ \\ \\ \\ \\/\\ __//\\ \\/\\ \\/\\ \\_\\.\\_ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m \\ \\____\\\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\____\\ \\_\\ \\_\\ \\__/.\\_\\ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m \\/____/ \\/_/\\/_/\\/__/ \\/_/\\/_/\\/____/\\/_/\\/_/\\/__/\\/_/ \033[0;44m)\033[K\033[0m\n");
+ printf("\033[0;44m (\033[1m _ _ _ _ _ _ _ _ _ _ _ _ _ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
+ printf("\033[0;44m (\033[1m / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
+ printf("\033[0;44m (\033[1m ( e | n | g | l | i | s | h ) ( A | t | h | e | n | a ) \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
+ printf("\033[0;44m (\033[1m \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
+ printf("\033[0;44m (\033[1m \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
+ printf("\033[0;44m (\033[1;33m Advanced Fusion Maps (c) 2003-2004 The Fusion Project \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
+ printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n\n"); // reset color
+}
+/* Returns a boolean value given character string */
+int ws_config_switch(const char *str) {
+ if (strcmpEx(str, "on") == 0 || strcmpEx(str, "yes") == 0 ||
+ strcmpEx(str, "oui") == 0 || strcmpEx(str, "ja") == 0 ||
+ strcmpEx(str, "si") == 0 || strcmpEx(str,"true") == 0)
+ return 1;
+ if (strcmpEx(str, "off") == 0 || strcmpEx(str, "no") == 0 ||
+ strcmpEx(str, "non") == 0 || strcmpEx(str, "nein") == 0 ||
+ strcmpEx(str, "false") == 0)
+ return 0;
+ return atoi(str);
+}
+
+/* Reads the eAthena Web Server's configuration file */
+int ws_config_read(const char *cfgName)
+{
+ int i;
+ char line[1024],w1[1024],w2[1024],temp[1024];
+ FILE *fp;
+
+ /* Default values */
+ config.show_title=0;
+ config.port=80;
+
+
+ fp=fopen(cfgName,"r");
+ if(fp==NULL){
+ snprintf(temp,sizeof(temp),"Could not open \033[1;29m%s\033[0;0m, file not found.\n",cfgName);
+ ShowMessage(temp,MSG_ERROR);
+ return 1;
+ }
+ while(fgets(line,1020,fp)){
+ const struct {
+ char str[128];
+ int *val;
+ } data[] ={
+ //List of variables
+ { "show_title", &config.show_title },
+ { "port", &config.port },
+ };
+
+ if((line[0] == '/' && line[1] == '/') || (line[0]=='#') ||
+ (sscanf(line,"%1023[^:]:%1023[^\n]",w1,w2) !=2))
+ continue;
+ for(i=0;i<sizeof(data)/(sizeof(data[0]));i++) {
+ if(strcmpEx(w1,data[i].str)==0){
+ *data[i].val=ws_config_switch(w2);
+ break;
+ }
+ }
+ if(strcmpEx(w1,"import")==0) {
+ ws_config_read(w2);
+ continue;
+ }
+ if(strcmpEx(w1,"password")==0) {
+ if (strlen(w2)>16) {
+ ShowError("The Web Server password is too long, maximum passwor"
+ "d length is 16 characters.\n");
+ return 1;
+ }
+ strcpy(ws_password,w2);
+ continue;
+ }
+ if(strcmpEx(w1,"header")==0) {
+ if (strlen(w2)>127) {
+ ShowError("The Web Server header is too long, maximum header"
+ "d length is 127 characters.\n");
+ return 1;
+ }
+ strcpy(ws_header,w2);
+ continue;
+ }
+ }
+ fclose(fp);
+
+ //Correct values
+ if(config.show_title < 0)
+ config.show_title = 0;
+ if(config.port < 1 || config.port > 65534)
+ config.port=80;
+
+ return 0;
+}
+
+void ws_sigchld_handler(int s)
+{
+ while(wait(NULL) > 0);
+}
diff --git a/src/webserver/webserver.h b/src/webserver/webserver.h
index 8bb84b875..84ef02b62 100644
--- a/src/webserver/webserver.h
+++ b/src/webserver/webserver.h
@@ -1,21 +1,21 @@
-#ifndef WEBSERV_H_
-#define WEBSERV_H_
-
-#define strcmpEx(x,y) (strcasecmp(x,y))
-
-extern void ws_display_title(void);
-
-extern int ws_config_read(const char *cfgName);
-
-extern struct config {
- int show_title;
- int port;
-} config;
-
-extern char ws_password[17]; //16 chars + \0
-
-extern char ws_header[128]; //!?
-
-extern void ws_sigchld_handler(int s);
-
-#endif
+#ifndef WEBSERV_H_
+#define WEBSERV_H_
+
+#define strcmpEx(x,y) (strcasecmp(x,y))
+
+extern void ws_display_title(void);
+
+extern int ws_config_read(const char *cfgName);
+
+extern struct config {
+ int show_title;
+ int port;
+} config;
+
+extern char ws_password[17]; //16 chars + \0
+
+extern char ws_header[128]; //!?
+
+extern void ws_sigchld_handler(int s);
+
+#endif