diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | config.cpp | 35 | ||||
-rw-r--r-- | config.h | 21 | ||||
-rw-r--r-- | webserver.conf | 40 | ||||
-rw-r--r-- | webserver.cpp | 36 |
5 files changed, 139 insertions, 1 deletions
@@ -56,6 +56,7 @@ LIBS+= \ endif PROGSRC=\ + config.cpp \ http.cpp \ http_debian10.cpp @@ -69,6 +70,7 @@ SRC=$(PROGSRC) webserver.cpp all: test-$(PROJECTNAME) $(PROJECTNAME) ./test-$(PROJECTNAME) + ./webserver -c webserver.conf # testsuite ---------------------------------------------- test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) @@ -96,6 +98,12 @@ install: mkdir -p $(DESTDIR)/usr/bin cp webserver $(DESTDIR)/usr/bin + mkdir -p $(DESTDIR)/usr/lib/webserver/plugins + mkdir -p $(DESTDIR)/usr/local/lib/webserver/plugins + + mkdir -p $(DESTDIR)/etc + cp webserver.conf $(DESTDIR)/etc/webserver.conf + # misc --------------------------------------------------- deb: # build binary deb package diff --git a/config.cpp b/config.cpp new file mode 100644 index 0000000..edbe3c4 --- /dev/null +++ b/config.cpp @@ -0,0 +1,35 @@ +#include "config.h" + +#include <boost/property_tree/ptree.hpp> +#include <boost/property_tree/xml_parser.hpp> + +namespace pt = boost::property_tree; + +void Config::readConfigfile(std::string filename) +{ + if (filename == "") { + filename = default_filename; + } + + pt::ptree tree; + + pt::read_xml(filename, tree); + + m_user = tree.get<std::string>("webserver.user"); + m_group = tree.get<std::string>("webserver.group1"); +} + +Config::Config(const std::string& filename) +{ + readConfigfile(filename); +} + +std::string Config::User() const +{ + return m_user; +} + +std::string Config::Group() const +{ + return m_group; +} diff --git a/config.h b/config.h new file mode 100644 index 0000000..b1f17a3 --- /dev/null +++ b/config.h @@ -0,0 +1,21 @@ +#pragma once + +#include <string> + +class Config +{ + const std::string default_filename{"/etc/webserver.conf"}; + + void readConfigfile(std::string filename); + + std::string m_user; + std::string m_group; + + public: + Config(const std::string& filename); + + // Data getters + std::string User() const; + std::string Group() const; +}; + diff --git a/webserver.conf b/webserver.conf new file mode 100644 index 0000000..c3580c8 --- /dev/null +++ b/webserver.conf @@ -0,0 +1,40 @@ +<webserver> + <user>www-data<user> + <group>www-data</group> + <plugin-directory>/usr/lib/webserver/plugins</plugin-directory> + <plugin-directory>/usr/local/lib/webserver/plugins</plugin-directory> + <sites> + <site> + <name>antcom.de</name> + <host>antcom.de</host> + <path requested="/" type="files">/var/www/antcom.de</path> + <path requested="/webbox" type="plugin">webbox</path> + </site> + <!-- + <site> + <name>reichwein.it</name> + <host>reichwein.it</host> + </site> + danielareichwein.de + rolandreichwein.de + kneipenband.com + --> + </sites> + <sockets> + <socket> + <address>127.0.0.1</address> + <port>80</port> + <protocol>http</protocol> + <!-- + <site>antcom.de</site> + <site>reichwein.it</site> + --> + </socket> + <socket> + <address>127.0.0.1</address> + <port>443</port> + <protocol>https</protocol> + </socket> + </sockets> +</webserver> + diff --git a/webserver.cpp b/webserver.cpp index 4b6a89c..b079707 100644 --- a/webserver.cpp +++ b/webserver.cpp @@ -1,6 +1,40 @@ +#include "config.h" #include "http.h" +#include <exception> +#include <iostream> +#include <string> + +using namespace std::string_literals; + +void usage() +{ + std::cout << "usage: webserver [-c <configuration-filename>]" << std::endl; +} + int main(int argc, char* argv[]) { - return http_server(argc, argv); + std::string config_filename; + + if (!(argc == 1 || argc == 3)) { + usage(); + return 1; + } + + if (argc == 3) { + if (argv[1] != "-c"s) { + usage(); + return 1; + } + + config_filename = argv[2]; + } + + try { + Config config{config_filename}; + return http_server(argc, argv); + } catch (const std::exception& ex) { + std::cout << "Error: " << ex.what() << std::endl; + return 1; + } } |