From 8f4758a6a9a29bee2ddb5107b147e8b3c2f541a2 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Sat, 5 Feb 2022 18:27:22 +0530 Subject: [PATCH 1/2] Add ip connection limit option Adds --ipConnectionLimit/-L option to change MHD_OPTION_PER_IP_CONNECTION_LIMIT by calling server.setIpConnectionLimit() --- src/server/kiwix-serve.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index fcb7b9a..035cff6 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -74,6 +74,7 @@ void usage() << "\t-V, --version\t\tprint software version" << std::endl << "\t-z, --nodatealiases\tcreate URL aliases for each content by removing the date" << std::endl << "\t-c, --customIndex\tadd path to custom index.html for welcome page" << std::endl + << "\t-L, --ipConnectionLimit\tLimit on the number of (concurrent) connections made to the server from the same IP address (default: infinite, recommended: >= 6)" << std::endl << std::endl << "Documentation:" << std::endl @@ -202,6 +203,7 @@ int main(int argc, char** argv) bool isVerboseFlag = false; bool monitorLibrary = false; unsigned int PPID = 0; + int ipConnectionLimit = 0; static struct option long_options[] = {{"daemon", no_argument, 0, 'd'}, @@ -220,13 +222,14 @@ int main(int argc, char** argv) {"urlRootLocation", required_argument, 0, 'r'}, {"customIndex", required_argument, 0, 'c'}, {"monitorLibrary", no_argument, 0, 'M'}, + {"ipConnectionLimit", required_argument, 0, 'L'}, {0, 0, 0, 0}}; /* Argument parsing */ while (true) { int option_index = 0; int c - = getopt_long(argc, argv, "hzmnbdvVla:p:f:t:r:i:c:M", long_options, &option_index); + = getopt_long(argc, argv, "hzmnbdvVla:p:f:t:r:i:c:ML:", long_options, &option_index); if (c != -1) { switch (c) { @@ -278,6 +281,9 @@ int main(int argc, char** argv) case 'M': monitorLibrary = true; break; + case 'L': + ipConnectionLimit = atoi(optarg); + break; } } else { if (optind < argc) { @@ -364,6 +370,7 @@ int main(int argc, char** argv) server.setTaskbar(!noSearchBarFlag, !noLibraryButtonFlag); server.setBlockExternalLinks(blockExternalLinks); server.setIndexTemplateString(indexTemplateString); + server.setIpConnectionLimit(ipConnectionLimit); if (! server.start()) { exit(1); From 0ed608f5c2587c15a7481bb15659b35a6bac0080 Mon Sep 17 00:00:00 2001 From: Emmanuel Engelhart Date: Sun, 6 Feb 2022 15:19:42 +0100 Subject: [PATCH 2/2] Cosmetic changes in kiwix-serve usage() --- src/server/kiwix-serve.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 035cff6..3bc8b4b 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -49,32 +49,32 @@ void usage() << std::endl << "Purpose:" << std::endl - << "\tDeliver ZIM file articles via HTTP" + << "\tDeliver ZIM file(s) articles via HTTP" << std::endl << std::endl << "Mandatory arguments:" << std::endl - << "\tLIBRARY_PATH\t\tis the XML library file path listing ZIM file to serve. To be used only with the --library argument." + << "\tLIBRARY_PATH\t\tXML library file path listing ZIM file to serve. To be used only with the --library argument." << std::endl - << "\tZIM_PATH\t\tis the path of a ZIM file." + << "\tZIM_PATH\t\tZIM file path(s)" << std::endl << std::endl << "Optional arguments:" << std::endl << std::endl - << "\t-h, --help\t\tprint this help" << std::endl << std::endl - << "\t-a, --attachToProcess\texit if given process id is not running anymore" << std::endl - << "\t-d, --daemon\t\tdetach the HTTP server daemon from the main process" << std::endl - << "\t-i, --address\t\tlisten only on this ip address, all available ones otherwise" << std::endl - << "\t-M, --monitorLibrary\t\tmonitor the XML library file and reload it automatically" << std::endl - << "\t-m, --nolibrarybutton\tdo not print the builtin home button in the builtin top bar overlay" << std::endl - << "\t-n, --nosearchbar\tdo not print the builtin bar overlay on the top of each served page" << std::endl - << "\t-b, --blockexternal\tprevent users from directly accessing external links" << std::endl + << "\t-h, --help\t\tPrint this help" << std::endl << std::endl + << "\t-a, --attachToProcess\tWxit if given process id is not running anymore" << std::endl + << "\t-d, --daemon\t\tDetach the HTTP server daemon from the main process" << std::endl + << "\t-i, --address\t\tListen only on this ip address, all available ones otherwise" << std::endl + << "\t-M, --monitorLibrary\tMonitor the XML library file and reload it automatically" << std::endl + << "\t-m, --nolibrarybutton\tDon't print the builtin home button in the builtin top bar overlay" << std::endl + << "\t-n, --nosearchbar\tDon't print the builtin bar overlay on the top of each served page" << std::endl + << "\t-b, --blockexternal\tPrevent users from directly accessing external links" << std::endl << "\t-p, --port\t\tTCP port on which to listen to HTTP requests (default: 80)" << std::endl << "\t-r, --urlRootLocation\tURL prefix on which the content should be made available (default: /)" << std::endl - << "\t-t, --threads\t\tnumber of threads to run in parallel (default: " << DEFAULT_THREADS << ")" << std::endl - << "\t-v, --verbose\t\tprint debug log to STDOUT" << std::endl - << "\t-V, --version\t\tprint software version" << std::endl - << "\t-z, --nodatealiases\tcreate URL aliases for each content by removing the date" << std::endl - << "\t-c, --customIndex\tadd path to custom index.html for welcome page" << std::endl - << "\t-L, --ipConnectionLimit\tLimit on the number of (concurrent) connections made to the server from the same IP address (default: infinite, recommended: >= 6)" << std::endl + << "\t-t, --threads\t\tNumber of threads to run in parallel (default: " << DEFAULT_THREADS << ")" << std::endl + << "\t-v, --verbose\t\tPrint debug log to STDOUT" << std::endl + << "\t-V, --version\t\tPrint software version" << std::endl + << "\t-z, --nodatealiases\tCreate URL aliases for each content by removing the date" << std::endl + << "\t-c, --customIndex\tAdd path to custom index.html for welcome page" << std::endl + << "\t-L, --ipConnectionLimit\tMax number of (concurrent) connections per IP (default: infinite, recommended: >= 6)" << std::endl << std::endl << "Documentation:" << std::endl