From 2b440db3cd5c7b6605227a8863fb90d2ec9abb68 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Mon, 18 Feb 2008 21:52:02 +0000 Subject: [PATCH] Improved debugging output SVN revision: 2051 --- NT/elogd.sln | 1 - NT/elogd.vcproj | 2 +- src/elogd.c | 158 +++++++++++++++++++++++++++++++++--------------- 3 files changed, 109 insertions(+), 52 deletions(-) diff --git a/NT/elogd.sln b/NT/elogd.sln index f3aea9d9..2fcfe4a8 100755 --- a/NT/elogd.sln +++ b/NT/elogd.sln @@ -17,7 +17,6 @@ Global {8D6EBED8-48F3-4719-907E-7BE46A3C0FA4}.Debug|Win32.ActiveCfg = Debug|Win32 {8D6EBED8-48F3-4719-907E-7BE46A3C0FA4}.Release|Win32.ActiveCfg = Release|Win32 {FD6FCAF3-A94B-40FA-AE52-07705DE2E519}.Debug|Win32.ActiveCfg = Debug|Win32 - {FD6FCAF3-A94B-40FA-AE52-07705DE2E519}.Debug|Win32.Build.0 = Debug|Win32 {FD6FCAF3-A94B-40FA-AE52-07705DE2E519}.Release|Win32.ActiveCfg = Release|Win32 {CB6EB7FE-CC3D-4548-B8B8-8DDA05916759}.Debug|Win32.ActiveCfg = Debug|Win32 {CB6EB7FE-CC3D-4548-B8B8-8DDA05916759}.Debug|Win32.Build.0 = Debug|Win32 diff --git a/NT/elogd.vcproj b/NT/elogd.vcproj index b240b873..c3629cf8 100755 --- a/NT/elogd.vcproj +++ b/NT/elogd.vcproj @@ -44,7 +44,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="\mxml;\openssl\include;" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_SSL1" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_SSL" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" diff --git a/src/elogd.c b/src/elogd.c index 9cf0efd4..dd1950e2 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -132,7 +132,7 @@ char pidfile[256]; /* Pidfile name #include "strlcpy.h" BOOL running_as_daemon; /* Running as a daemon/service? */ -int elog_tcp_port = (int) DEFAULT_PORT; /* Server's TCP port */ +int elog_tcp_port; /* Server's TCP port */ static void (*printf_handler) (const char *); /* Handler to printf for logging */ static void (*fputs_handler) (const char *); /* Handler to fputs for logging */ @@ -6162,9 +6162,12 @@ void rsputs_elcode(LOGBOOK * lbs, BOOL email_notify, const char *str) else sprintf(hattrib, "%s", attrib + 5); - } else if (strstr(attrib, "://") == 0 && attrib[0] != '#') /* add http:// if missing */ - sprintf(hattrib, "http://%s", attrib); - else + } else if (strstr(attrib, "://") == 0 && attrib[0] != '#') { /* add http:// if missing */ + if (_ssl_flag) + sprintf(hattrib, "https://%s", attrib); + else + sprintf(hattrib, "http://%s", attrib); + } else strlcpy(hattrib, attrib, sizeof(hattrib)); strextract(str + i, '[', value, sizeof(value)); @@ -6213,11 +6216,15 @@ void rsputs_elcode(LOGBOOK * lbs, BOOL email_notify, const char *str) } /* add http:// if missing */ - else if (!strnieq(attrib, "http://", 7) && + else if ((!strnieq(attrib, "http://", 7) && !strnieq(attrib, "https://", 8)) && strstr(pattern_list[l].subst, "mailto") == NULL && strstr(pattern_list[l].subst, "img") == NULL && - strncmp(pattern_list[l].subst, "http://midas.psi.ch/elog/config.html\n"); + rsprintf("https://midas.psi.ch/elog/config.html\">https://midas.psi.ch/elog/config.html\n"); rsprintf(".\n"); rsprintf("\n\n"); rsprintf("
\n"); rsprintf("
\n"); - rsprintf("S. Ritt, 18 October 2001"); + rsprintf("S. Ritt, 18 October 2001"); rsprintf("
"); show_bottom_text(lbs); rsprintf("\r\n"); @@ -7825,7 +7841,7 @@ void show_bottom_text(LOGBOOK * lbs) } else /* add little logo */ rsprintf - ("
ELOG V%s-%d
", + ("
ELOG V%s-%d
", loc("Goto ELOG home page"), VERSION, atoi(svn_revision + 13)); } @@ -7875,7 +7891,7 @@ void show_bottom_text_login(LOGBOOK * lbs) } else /* add little logo */ rsprintf - ("
ELOG V%s-%d
", + ("
ELOG V%s-%d
", loc("Goto ELOG home page"), VERSION, atoi(svn_revision + 13)); } @@ -11787,7 +11803,7 @@ void show_admin_page(LOGBOOK * lbs, char *top_group) rsprintf("\n"); /* put link for config page */ - rsprintf("
Syntax Help"); + rsprintf("
Syntax Help"); rsprintf("\n"); @@ -12505,10 +12521,17 @@ int save_user_config(LOGBOOK * lbs, char *user, BOOL new_user, BOOL activate) if (referer[0]) strcpy(url, referer); else { - if (elog_tcp_port == 80) - sprintf(url, "http://%s/", http_host); - else - sprintf(url, "http://%s:%d/", http_host, elog_tcp_port); + if (elog_tcp_port == 80) { + if (_ssl_flag) + sprintf(url, "https://%s/", http_host); + else + sprintf(url, "http://%s/", http_host); + } else { + if (_ssl_flag) + sprintf(url, "https://%s:%d/", http_host, elog_tcp_port); + else + sprintf(url, "http://%s:%d/", http_host, elog_tcp_port); + } if (lbs) { strlcat(url, lbs->name_enc, sizeof(url)); strlcat(url, "/", sizeof(url)); @@ -12990,10 +13013,17 @@ void show_forgot_pwd_page(LOGBOOK * lbs) if (referer[0]) strcpy(url, referer); else { - if (elog_tcp_port == 80) - sprintf(url, "http://%s/", http_host); - else - sprintf(url, "http://%s:%d/", http_host, elog_tcp_port); + if (elog_tcp_port == 80) { + if (_ssl_flag) + sprintf(url, "https://%s/", http_host); + else + sprintf(url, "http://%s/", http_host); + } else { + if (_ssl_flag) + sprintf(url, "https://%s:%d/", http_host, elog_tcp_port); + else + sprintf(url, "http://%s:%d/", http_host, elog_tcp_port); + } } } else { if (url[strlen(url) - 1] != '/') @@ -18338,7 +18368,10 @@ void show_rss_feed(LOGBOOK * lbs) /* if HTTP request comes from localhost, use localhost as absolute link (needed if running on DSL at home) */ if (!url[0] && strstr(http_host, "localhost")) { - strcpy(url, "http://localhost"); + if (_ssl_flag) + strcpy(url, "https://localhost"); + else + strcpy(url, "http://localhost"); if (elog_tcp_port != 80) sprintf(url + strlen(url), ":%d", elog_tcp_port); strcat(url, "/"); @@ -18346,7 +18379,10 @@ void show_rss_feed(LOGBOOK * lbs) if (!url[0]) { /* assemble absolute path from host name and port */ - sprintf(url, "http://%s", host_name); + if (_ssl_flag) + sprintf(url, "https://%s", host_name); + else + sprintf(url, "http://%s", host_name); if (elog_tcp_port != 80) sprintf(url + strlen(url), ":%d", elog_tcp_port); strcat(url, "/"); @@ -25465,7 +25501,7 @@ void interprete(char *lbook, char *path) if (getcfg(lbs->name, "Help URL", str, sizeof(str))) { /* if URL is given, redirect */ - if (strstr(str, "http://")) { + if (strstr(str, "http://") || strstr(str, "https://")) { redirect(lbs, str); return; } @@ -25500,7 +25536,7 @@ void interprete(char *lbook, char *path) strlcat(file_name, ".html", sizeof(file_name)); f = fopen(file_name, "r"); if (f == NULL) - redirect(lbs, "http://midas.psi.ch/elog/eloghelp_english.html"); + redirect(lbs, "https://midas.psi.ch/elog/eloghelp_english.html"); else { fclose(f); send_file_direct(file_name); @@ -25523,7 +25559,7 @@ void interprete(char *lbook, char *path) strlcat(file_name, ".html", sizeof(file_name)); f = fopen(file_name, "r"); if (f == NULL) - redirect(lbs, "http://midas.psi.ch/elog/elcode_english.html"); + redirect(lbs, "https://midas.psi.ch/elog/elcode_english.html"); else { fclose(f); send_file_direct(file_name); @@ -26081,7 +26117,7 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b if (file_name[0] && (p - string) == 0) { /* check for URL */ - if (stristr(file_name, "http://")) { + if (stristr(file_name, "http://") || stristr(file_name, "https://")) { size = retrieve_url(file_name, &buffer, NULL); if (size <= 0) { strencode2(str2, file_name, sizeof(str2)); @@ -26786,10 +26822,21 @@ void send_return(int _sock, const char *net_buffer) send(_sock, header_buffer, strlen(header_buffer), 0); send(_sock, p + 4, length, 0); #endif - if (verbose > 1) { + if (verbose == 1) { + eprintf("Returned %d bytes\n", length); + } else if (verbose == 2) { + if (strrchr(net_buffer, '/')) + strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); + else + str[0] = 0; eprintf("==== Return ================================\n"); eputs(header_buffer); - eputs(p + 2); + if (chkext(net_buffer, ".gif") || chkext(net_buffer, ".jpg") + || chkext(net_buffer, ".png") || chkext(net_buffer, ".ico") + || chkext(net_buffer, ".pdf") || return_length > 10000) + eprintf("\n<%d bytes of %s>\n\n", length, str); + else + eputs(p+4); eprintf("\n"); } } else { @@ -26805,7 +26852,9 @@ void send_return(int _sock, const char *net_buffer) #else send(_sock, return_buffer, return_length, 0); #endif - if (verbose > 1) { + if (verbose == 1) { + eprintf("Returned %d bytes\n", return_length); + } else if (verbose == 2) { if (strrchr(net_buffer, '/')) strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); else @@ -27023,6 +27072,23 @@ void server_loop(void) else _logging_level = 2; + /* initialize SSL if requested */ + _ssl_flag = 0; + if (getcfg("global", "SSL", str, sizeof(str)) && + atoi(str) == 1) { +#ifdef HAVE_SSL + ssl_ctx = init_ssl(); + if (ssl_ctx == NULL) { + eprintf("Cannot initialize SSL\n"); + exit(EXIT_FAILURE); + } + _ssl_flag = 1; +#else + eprintf("SLL support not compiled into elogd\n"); + exit(EXIT_FAILURE); +#endif + } + /* create a new socket */ lsock = socket(AF_INET, SOCK_STREAM, 0); if (lsock == -1) { @@ -27079,23 +27145,6 @@ void server_loop(void) /* open configuration file */ getcfg("dummy", "dummy", str, sizeof(str)); - /* initialize SSL if requested */ - _ssl_flag = 0; - if (getcfg("global", "SSL", str, sizeof(str)) && - atoi(str) == 1) { -#ifdef HAVE_SSL - ssl_ctx = init_ssl(); - if (ssl_ctx == NULL) { - eprintf("Cannot initialize SSL\n"); - exit(EXIT_FAILURE); - } - _ssl_flag = 1; -#else - eprintf("SLL support not compiled into elogd\n"); - exit(EXIT_FAILURE); -#endif - } - /* now, initiate daemon/service */ if (running_as_daemon) { /* Redirect all messages handled with eprintf/efputs to syslog */ @@ -27235,7 +27284,10 @@ void server_loop(void) exit(EXIT_FAILURE); } - sprintf(str, "Server listening on port %d ...\n", elog_tcp_port); + if (_ssl_flag) + sprintf(str, "SSLServer listening on port %d ...\n", elog_tcp_port); + else + sprintf(str, "Server listening on port %d ...\n", elog_tcp_port); eprintf("%s", str); if (_logging_level > 0) write_logfile(NULL, str); @@ -28551,6 +28603,12 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); } + /* get default port */ + if (getcfg("global", "SSL", str, sizeof(str)) && atoi(str) == 1) + elog_tcp_port = 443; + else + elog_tcp_port = 80; + /* get port from configuration file */ if (tcp_port_cl != 0) elog_tcp_port = tcp_port_cl;