#include "auth.h" #include "config.h" #include "server.h" #include "plugin.h" #include #include #include #include using namespace std::string_literals; void usage() { std::cout << "usage: webserver [-c | -p ] " << std::endl; std::cout << " webserver [-c ] - start server with specified configuration\n" " file or default /etc/webserver.conf" << std::endl; std::cout << " webserver -p - encrypt password for basic HTTP AUTH,\n" " suitable for config file, and exit" << std::endl; } void initlocale() { if (setenv("LC_ALL", "UTF-8", 1)) { exit(1); } } int webserver(int argc, char* argv[]) { try { //initlocale(); // TODO: breaks plugins std::filesystem::path config_filename; if (!(argc == 1 || argc == 3)) { usage(); return 1; } if (argc == 3) { // normal run with configuration file specified if (argv[1] == "-c"s) { config_filename = argv[2]; } else if (argv[1] == "-p"s) { // generate crypted password std::cout << Auth::generate(argv[2]) << std::endl; return 0; } else { usage(); return 1; } } Config config{config_filename}; PluginLoader plugin_loader(config); plugin_loader.load_plugins(); if (!plugin_loader.validate_config()) throw std::runtime_error("Config validation error."); return run_server(config, plugin_loader.get_plugins()); } catch (const std::exception& ex) { std::cout << "Error: " << ex.what() << std::endl; return 1; } }