From 140dab4725da9c19aad33e6bdbbd94ec28b9f4c0 Mon Sep 17 00:00:00 2001 From: Wander Nauta Date: Sun, 24 May 2026 11:50:57 +0200 Subject: [PATCH 1/3] use argparse for port number and root directory --- tkserv.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tkserv.cc b/tkserv.cc index 7385247..3d56978 100644 --- a/tkserv.cc +++ b/tkserv.cc @@ -397,6 +397,8 @@ int main(int argc, char** argv) argparse::ArgumentParser args("tkserv", "0.0"); + args.add_argument("port").help("Port number to use").default_value(8089); + args.add_argument("root").help("Directory containing static assets").default_value("./html/"); args.add_argument("--rnd-admin-password").help("Create admin user if necessary, and set a random password").default_value(string("")); args.add_argument("--insecure-cookie").help("Use an insecure cookie, for non-https operations").default_value(string("")); try { @@ -2441,13 +2443,9 @@ int main(int argc, char** argv) sws.d_svr.set_payload_max_length(1024 * 1024); // 1MB - string root = "./html/"; - if(argc > 2) - root = argv[2]; + string root = args.get("root"); sws.d_svr.set_mount_point("/", root); - int port = 8089; - if(argc > 1) - port = atoi(argv[1]); + int port = args.get("port"); fmt::print("Listening on port {} serving html from {}, using {} threads\n", port, root, CPPHTTPLIB_THREAD_POOL_COUNT); From 8e66d58a15e3776ba337a510cee4a606a869abed Mon Sep 17 00:00:00 2001 From: Wander Nauta Date: Sun, 24 May 2026 12:22:40 +0200 Subject: [PATCH 2/3] increase SQLite logging if --dev flag is given This logs all SQLite errors to stdout. This necessarily duplicates logging somewhat: if we (actually SQLiteWriter) convert the error into an exception, and that exception is logged, it is now logged twice. If we drop the exception, intending to quietly ignore it, that is now no longer quiet. Therefore, put this behind a runtime flag. The logging callback also serves as a convenient place for a debugger breakpoint. See https://sqlite.org/errlog.html for the possible messages. --- tkserv.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tkserv.cc b/tkserv.cc index 3d56978..1cf6936 100644 --- a/tkserv.cc +++ b/tkserv.cc @@ -18,6 +18,7 @@ #include "thingpool.hh" #include "sws.hh" #include "search.hh" +#include using namespace std; void addTkUserManagement(SimpleWebSystem& sws, const std::string& mailserver, @@ -401,6 +402,7 @@ int main(int argc, char** argv) args.add_argument("root").help("Directory containing static assets").default_value("./html/"); args.add_argument("--rnd-admin-password").help("Create admin user if necessary, and set a random password").default_value(string("")); args.add_argument("--insecure-cookie").help("Use an insecure cookie, for non-https operations").default_value(string("")); + args.add_argument("--dev").help("Increase SQLite log verbosity").flag(); try { args.parse_args(argc, argv); } @@ -409,7 +411,12 @@ int main(int argc, char** argv) std::exit(1); } - + if (args["--dev"] == true) { + sqlite3_config(SQLITE_CONFIG_LOG, +[](void *, int iErrCode, const char *zMsg) { + std::cout << "SQLite: " << zMsg << " (" << iErrCode << ")" << std::endl; + }, nullptr); + } + ThingPool tp("tk.sqlite3", SQLWFlag::ReadOnly); tp.setInit([](SQLiteWriter& sqlw) { sqlw.query("ATTACH DATABASE 'oo.sqlite3' as oo"); From 2096f828e01b552ab4a91b00acda5a172b7b99be Mon Sep 17 00:00:00 2001 From: Wander Nauta Date: Sun, 24 May 2026 16:53:10 +0200 Subject: [PATCH 3/3] add smtp-server, sender-email, base-url args The --insecure-cookie flag is removed. --- tkserv.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tkserv.cc b/tkserv.cc index 1cf6936..a79f637 100644 --- a/tkserv.cc +++ b/tkserv.cc @@ -401,7 +401,9 @@ int main(int argc, char** argv) args.add_argument("port").help("Port number to use").default_value(8089); args.add_argument("root").help("Directory containing static assets").default_value("./html/"); args.add_argument("--rnd-admin-password").help("Create admin user if necessary, and set a random password").default_value(string("")); - args.add_argument("--insecure-cookie").help("Use an insecure cookie, for non-https operations").default_value(string("")); + args.add_argument("--smtp-server").help("IP address or address:port of SMTP smart host").default_value("10.0.0.2"); + args.add_argument("--sender-email").help("From address of email we send").default_value("opentk@hubertnet.nl"); + args.add_argument("--base-url").help("URL of this instance without trailing slash, for use in email").default_value("https://berthub.eu/tkconv"); args.add_argument("--dev").help("Increase SQLite log verbosity").flag(); try { args.parse_args(argc, argv); @@ -445,8 +447,7 @@ int main(int argc, char** argv) sws.d_svr.set_keep_alive_max_count(1); sws.d_svr.set_keep_alive_timeout(1); sws.standardFunctions(); - addTkUserManagement(sws, "10.0.0.2", "opentk@hubertnet.nl", "https://berthub.eu/tkconv"); - // addTkUserManagement(sws, "10.0.0.2", "opentk@hubertnet.nl", "http://127.0.0.1:8089"); + addTkUserManagement(sws, args.get("--smtp-server"), args.get("--sender-email"), args.get("--base-url")); if(args.is_used("--rnd-admin-password")) {