summaryrefslogtreecommitdiff
path: root/src/webserver
diff options
context:
space:
mode:
Diffstat (limited to 'src/webserver')
-rw-r--r--src/webserver/Changelog.txt3
-rw-r--r--src/webserver/Makefile48
-rw-r--r--src/webserver/Makefile.win35
-rw-r--r--src/webserver/WEBSER~1.layout24
-rw-r--r--src/webserver/Webserver.dev97
-rw-r--r--src/webserver/Webserver.layout38
-rw-r--r--src/webserver/conf/webserver-athena.conf36
-rw-r--r--src/webserver/doc/API.txt50
-rw-r--r--src/webserver/doc/README11
-rw-r--r--src/webserver/generate.c38
-rw-r--r--src/webserver/htmlstyle.c51
-rw-r--r--src/webserver/logs.c8
-rw-r--r--src/webserver/main.c208
-rw-r--r--src/webserver/pages/about.c6
-rw-r--r--src/webserver/pages/notdone.c5
-rw-r--r--src/webserver/pages/sample.c24
-rw-r--r--src/webserver/parse.c135
-rw-r--r--src/webserver/webserver.c136
-rw-r--r--src/webserver/webserver.h21
19 files changed, 449 insertions, 525 deletions
diff --git a/src/webserver/Changelog.txt b/src/webserver/Changelog.txt
deleted file mode 100644
index e4d38bac0..000000000
--- a/src/webserver/Changelog.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-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 000754036..077b39980 100644
--- a/src/webserver/Makefile
+++ b/src/webserver/Makefile
@@ -1,32 +1,20 @@
-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
+all:
+ #Generate framework...
+ $(CC) -c parse.c
+ $(CC) -c generate.c
+ $(CC) -c htmlstyle.c
+ $(CC) -c logs.c
+
+ #Generate "pages"...
+ cd pages && $(CC) -c about.c && cd ..
+ cd pages && $(CC) -c sample.c && cd ..
+ cd pages && $(CC) -c notdone.c && cd ..
+
+ #Building the server...
+ $(CC) -o webserver main.c parse.o generate.o htmlstyle.o \
+ logs.o pages/about.o pages/sample.o pages/notdone.o
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
+ rm -f *.o
+ rm -f pages/*.o
+ rm -f webserver
diff --git a/src/webserver/Makefile.win b/src/webserver/Makefile.win
deleted file mode 100644
index 65cf676ad..000000000
--- a/src/webserver/Makefile.win
+++ /dev/null
@@ -1,35 +0,0 @@
-# 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
deleted file mode 100644
index 49854196f..000000000
--- a/src/webserver/WEBSER~1.layout
+++ /dev/null
@@ -1,24 +0,0 @@
-[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
deleted file mode 100644
index 5bbb3a08c..000000000
--- a/src/webserver/Webserver.dev
+++ /dev/null
@@ -1,97 +0,0 @@
-[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
deleted file mode 100644
index b99312289..000000000
--- a/src/webserver/Webserver.layout
+++ /dev/null
@@ -1,38 +0,0 @@
-[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
deleted file mode 100644
index 6f84aa133..000000000
--- a/src/webserver/conf/webserver-athena.conf
+++ /dev/null
@@ -1,36 +0,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 #
-#############################################################
-
-// 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/doc/API.txt b/src/webserver/doc/API.txt
new file mode 100644
index 000000000..c80f7bd44
--- /dev/null
+++ b/src/webserver/doc/API.txt
@@ -0,0 +1,50 @@
+Here's the webserver API, so you can work on the webserver.
+
+My personal goal is to make this interface simple, so that coding it
+will be like coding in some scripting language...
+
+
+
+char *get_param(char in_string[500], char swhat[500]);
+
+This function simply returns various data from the query string.
+ *Pass get_param NOTHING longer than 500 in length!
+
+ What do I pass where in_string is?
+ The query string.
+
+ What do I pass where swhat is?
+ One of two things...
+ Either 0 for the path of the 'page'
+ or you can pass it the param you wish to lookup.
+
+
+
+
+
+
+char *get_query(char *inquery);
+
+This function simply returns a query string from the raw server request.
+This is used once in main, I doubt you'll need it.
+
+
+
+
+
+void web_send(int sockin, char *in_data);
+
+Super easy way of sending data to a webpage!
+Simply put in the socket name and then the data.
+
+ Ex:
+ web_send(socket, "I like cheese!\n");
+
+
+
+
+char *html_header(char* title);
+Easy way to print the eAthena header for the server.
+
+ Ex:
+ web_send(sockethere, html_header("About"));
diff --git a/src/webserver/doc/README b/src/webserver/doc/README
new file mode 100644
index 000000000..0e94ff2ae
--- /dev/null
+++ b/src/webserver/doc/README
@@ -0,0 +1,11 @@
+This readme is intended for the programmers of eAthena.
+
+This webserver's apis are in API.txt.
+
+To make this simple, generate.c should handle most of the work this sever does
+in terms of what people see.
+
+When a request is made the server shoots it off to generate.c.
+
+You are welcome to create more functions used by generate.c to generate pages
+though, so don't feel limited by that one file.
diff --git a/src/webserver/generate.c b/src/webserver/generate.c
new file mode 100644
index 000000000..ad050db4c
--- /dev/null
+++ b/src/webserver/generate.c
@@ -0,0 +1,38 @@
+
+void generate_page(char password[25], int sock_in, char *query, char *ip)
+{
+ char *page = get_param(query, 0);
+ char *ppass = get_param(query, "password");
+
+
+ if ( (ppass == 0) || (strcmp(password, ppass) != 0) )
+ {
+ web_send(sock_in, html_header("Enter your password"));
+ web_send(sock_in, "<H1>NOT LOGGED IN!</H1><form action=\"/\" method=\"GET\">\n");
+ web_send(sock_in, "Enter your password:<br>\n<input type=\"text\" name=\"password\">\n");
+ web_send(sock_in, "<input type=\"submit\" value=\"Login\">\n");
+ }
+ else
+ {
+
+
+ //To make this simple, we will have a bunch of if statements
+ //that then shoot out data off into functions.
+
+
+ //The 'index'
+ if ( strcmp(page, "/") == 0 )
+ generate_notdone(sock_in, query, ip);
+
+
+ //About page:
+ if ( strcmp(page, "/about.html") == 0 )
+ generate_about(sock_in, query, ip);
+
+
+ //Test page:
+ if ( strcmp(page, "/testing/") == 0 )
+ generate_sample(sock_in, query, ip);
+
+ }
+}
diff --git a/src/webserver/htmlstyle.c b/src/webserver/htmlstyle.c
new file mode 100644
index 000000000..c3a4b927a
--- /dev/null
+++ b/src/webserver/htmlstyle.c
@@ -0,0 +1,51 @@
+char output[10000];
+
+char *html_header(char *title)
+{
+ memset(output, 0x0, 10000);
+ char *text = "<body text=\"#000000\" bgcolor=\"#939393\" link=\"#0033FF\">\n"
+ "<br><table width=\"92%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\"\n"
+ "align=\"center\" class=\"bordercolor\"><tbody><tr><td class=\"bordercolor\" width=\"100%\">\n"
+ "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n"
+ "<tbody><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#ffffff\">\n"
+ "<tbody><tr><img src=\"http://eathena.sourceforge.net/athena.jpg\" alt=\"Athena\">\n"
+ "<td bgcolor=\"#ffffff\"></td></tr></tbody></table></td></tr></tbody></table>\n"
+ "</td></tr><tr align=\"left\"><td class=\"bordercolor\"><table bgcolor=\"#c6c6c6\" width=\"100%\" cellspacing=\"0\"\n"
+ "cellpadding=\"0\" style=\"text-align: left; margin-right: auto; margin-left: 0px;\">\n";
+ "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"3\"\n"
+ "cellspacing=\"0\" bgcolor=\"#c6c6c6\" align=\"center\"><tbody><tr>"
+ "<td valign=\"middle\" bgcolor=\"#c6c6c6\" align=\"center\"><a href=\"/cgi-bin/forum/YaBB.cgi\">"
+ "<span style=\"text-decoration: underline;\"><span style=\"font-weight: bold;\">\n"
+ "To the Forum</span></span></a><br></td></tr></tbody></table></td></tr></tbody>\n"
+ "</table></td></tr><tr><td class=\"bordercolor\" align=\"center\">\n"
+ "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n"
+ "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"5\"\n"
+ "cellspacing=\"0\" bgcolor=\"#ffffff\" align=\"center\"><tbody><tr>\n"
+ "<td valign=\"middle\" bgcolor=\"#ffffff\" align=\"center\"><font size=\"2\" color=\"#6e94b7\">\n"
+ "<b>Athena</b> &laquo; Portal &raquo;</font></td></tr></tbody></table></td></tr></tbody>"
+ "</table></td></tr></tbody></table>\n";
+
+ sprintf(output, "<title>%s</title>\n%s\n", title, text);
+
+ return output;
+}
+
+
+
+char *html_start_form(char *location, char *action)
+{
+ memset(output, 0x0, 10000);
+ sprintf(output, "<form action=\"%s\" method=\"%s\">", location, action);
+ return output;
+
+
+}
+
+
+char *html_end_forum(void)
+{
+ return "</form>";
+}
+
+
+
diff --git a/src/webserver/logs.c b/src/webserver/logs.c
new file mode 100644
index 000000000..405b4882b
--- /dev/null
+++ b/src/webserver/logs.c
@@ -0,0 +1,8 @@
+#include <time.h>
+
+void log_visit(char *query, char *ip)
+{
+ time_t timer;
+ timer=time(NULL);
+ printf("%s - \"%s\" - %s", ip, query, asctime(localtime(&timer)));
+}
diff --git a/src/webserver/main.c b/src/webserver/main.c
index 915d71b6d..59362558e 100644
--- a/src/webserver/main.c
+++ b/src/webserver/main.c
@@ -1,144 +1,142 @@
-/******************************************************************************
- # ______ __ __ #
- # /\ _ \/\ \__/\ \ #
- # __\ \ \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 #
- ******************************************************************************/
+/***************************************************************************
+ description
+ -------------------
+ author : (C) 2004 by Michael J. Flickinger
+ email : mjflick@cpan.org
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.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"
+#define BLOG 10
-char ws_password[17];
-char ws_header[128];
+char *header = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
+char recvin[500], password[25];
+int s_port;
-#define WEB_CONF "conf/webserver-athena.conf"
-#define MAX_CONNECTIONS 10
-#define HOME "home/"
-
-struct config config;
+void sigchld_handler(int s)
+{
+ while(wait(NULL) > 0);
+}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
- int server_fd, client_fd;
+ if (argc < 3)
+ {
+ printf("eAthena Web Server\n");
+ printf("usage: %s [password] [port]\n", argv[0]);
+ exit(0);
+ }
+
+ s_port = atoi(argv[2]);
+
+ if ((s_port < 1) || (s_port > 65534))
+ {
+ printf("Error: The port you choose is not valid port.\n");
+ exit(0);
+ }
+
+ if (strlen(argv[1]) > 25)
+ {
+ printf("Error: Your password is too long.\n");
+ printf("It must be shorter than 25 characters.\n");
+ exit(0);
+ }
+
+ memset(password, 0x0, 25);
+ memcpy(password, argv[1], strlen(argv[1]));
+
+ int sockfd, new_fd;
+ struct sockaddr_in my_addr;
+ struct sockaddr_in their_addr;
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;
+
+ int yes=1;
+
+ if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) == -1)
+ {
+ perror("Darn, this is broken.");
+ exit(0);
}
- if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) == -1) {
- ShowError("In main() -> Could not set socket options.\n");
- return 1;
+
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
+ {
+ perror("Error... :-(");
}
- 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;
+
+ //Now we know we have a working socket. :-)
+
+ my_addr.sin_family = AF_INET;
+ my_addr.sin_port = htons(s_port);
+ my_addr.sin_addr.s_addr = INADDR_ANY;
+ memset(&(my_addr.sin_zero), '\0', 8);
+
+ if ( bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
+ {
+ perror("can not bind to this port");
+ exit(0);
}
- 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;
+ if ( listen(sockfd, BLOG) == -1)
+ {
+ perror("can not listen on port");
+ exit(0);
}
- sa.sa_handler = ws_sigchld_handler;
+ sa.sa_handler = 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;
+ if (sigaction(SIGCHLD, &sa, NULL) == -1)
+ {
+ perror("sigaction sucks");
+ exit(0);
}
- ShowInfo("eAthena Web Server is now listening for incoming connections.\n");
+
+ printf("The eAthena webserver is up and listening on port %i.\n", s_port);
while(1)
{
sin_size = sizeof(struct sockaddr_in);
- client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &sin_size);
+ new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
if (!fork())
{
- close(server_fd);
+ close(sockfd);
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);
+ recv(new_fd, recvin, 500, 0);
+ send(new_fd, header, strlen(header), 0);
+ generate_page(password, new_fd, get_query(recvin), inet_ntoa(their_addr.sin_addr));
+ log_visit(get_query(recvin), inet_ntoa(their_addr.sin_addr));
+
+ close(new_fd);
exit(0);
}
- close(client_fd);
+ close(new_fd);
}
+
return 0;
}
diff --git a/src/webserver/pages/about.c b/src/webserver/pages/about.c
new file mode 100644
index 000000000..2b0002ad8
--- /dev/null
+++ b/src/webserver/pages/about.c
@@ -0,0 +1,6 @@
+void generate_about(int sock_in, char *query, char *ip)
+{
+//printf("%s", html_header("About"));
+ web_send(sock_in, html_header("About"));
+ web_send(sock_in, "<center>eAthena Web Server!</center>\n");
+}
diff --git a/src/webserver/pages/notdone.c b/src/webserver/pages/notdone.c
new file mode 100644
index 000000000..a6492e361
--- /dev/null
+++ b/src/webserver/pages/notdone.c
@@ -0,0 +1,5 @@
+void generate_notdone(int sock_in, char *query, char *ip)
+{
+ web_send(sock_in, "<title>Not here!</title>\n");
+ web_send(sock_in, "<h2><center>This page/feature is not done yet.</center>\n</h2>");
+}
diff --git a/src/webserver/pages/sample.c b/src/webserver/pages/sample.c
new file mode 100644
index 000000000..be900a1bf
--- /dev/null
+++ b/src/webserver/pages/sample.c
@@ -0,0 +1,24 @@
+
+
+void generate_sample(int sock_in, char *query, char *ip)
+{
+
+ char *name = get_param(query, "name");
+
+ web_send(sock_in, "<title>SAMPLE</title>\n");
+
+
+ //If a name was not entered...
+ if ( name == '\0' )
+ {
+ web_send(sock_in, "<form action=\"/testing/\" method=\"GET\">\n");
+ web_send(sock_in, "<input type=\"text\" name=\"name\">\n");
+ web_send(sock_in, "<input type=\"submit\">\n");
+ }
+ else
+ {
+ web_send(sock_in, "Your name is: ");
+ web_send(sock_in, get_param(query, "name"));
+ }
+printf("OK!\n");
+}
diff --git a/src/webserver/parse.c b/src/webserver/parse.c
new file mode 100644
index 000000000..8e54a81de
--- /dev/null
+++ b/src/webserver/parse.c
@@ -0,0 +1,135 @@
+#include <stdlib.h>
+
+char filtered_query[2000];
+char rdata[500];
+char param_n[500];
+char param_d[500];
+
+
+char *get_query(char *inquery)
+{
+ memset(filtered_query, 0x0, 2000);
+ sscanf(inquery, "GET %s %[$]", filtered_query);
+ return(filtered_query);
+}
+
+void web_send(int sockin, char *in_data)
+{
+ send(sockin, in_data, strlen(in_data), 0);
+}
+
+
+//THIS IS BAD CODE BE CAREFULL WITH IT!
+//Watch out for buffer overflow...
+//When using please make sure to check the string size.
+
+//Also note:
+//I take no pride in this code, it is a really bad way of doing this...
+char *get_param(char in_string[500], char swhat[500])
+{
+ int i = 0;
+ int marker, iswitch, pint, dint;
+ char flux[500];
+ memset(flux, 0x0, 500);
+
+ //Get the path of out "page"
+ if (swhat == 0)
+ {
+ //while i is not equal to array size
+ while (i != 500)
+ {
+ //if there is a question mark, halt!
+ if (in_string[i] == '?')
+ {
+ i = 499;
+ }
+ else
+ rdata[i] = in_string[i];
+
+ i++;
+ }
+ return rdata;
+ }
+ else //so, we want a param...
+ {
+ //calculate where param begins
+ while (i != 500)
+ {
+ if (in_string[i] == '?')
+ {
+ marker = i + 1;
+ i = 499;
+ }
+ i++;
+ }
+
+ i = 0;
+
+ //keep morons from trying to crash this
+ if ((marker > 500)||(marker < 1))
+ marker = 500;
+
+ while(marker != 500)
+ {
+ if ((in_string[marker] != '&') && (in_string[marker] != '\0'))
+ {
+ flux[i] = in_string[marker];
+ i++;
+ }
+ else
+ {
+
+ //we have a param, now we must dig through it
+
+ //clear temp vars
+ memset(param_n, 0x0, 500);
+ memset(param_d, 0x0, 500);
+ iswitch = 0;
+ pint = 0;
+ dint = 0;
+ i = 0;
+
+ //split result into param_n and param_d
+ while(i != 500)
+ {
+ if ( (flux[i] != '=') && (flux[i] != '\0') )
+ {
+ if (iswitch == 0)
+ {
+ param_n[pint] = flux[i];
+ pint++;
+ }
+ else
+ {
+ param_d[dint] = flux[i];
+ dint++;
+ }
+ }
+ else
+ {
+ iswitch = 1;
+ }
+ if (flux[i] == '\0')
+ i = 499;
+
+ i++;
+ }
+
+ if ( strcmp(param_n, swhat) == 0 )
+ {
+ return param_d;
+ }
+
+ i = 0;
+ }
+
+ if (in_string[marker] == '\0')
+ {
+ marker = 499;
+ }
+ marker++;
+ }
+ return 0;
+ }
+}
+
diff --git a/src/webserver/webserver.c b/src/webserver/webserver.c
deleted file mode 100644
index 0169cd028..000000000
--- a/src/webserver/webserver.c
+++ /dev/null
@@ -1,136 +0,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
deleted file mode 100644
index 84ef02b62..000000000
--- a/src/webserver/webserver.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#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