diff --git a/elogd.c b/elogd.c index 89fb6950..b5a072eb 100755 --- a/elogd.c +++ b/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.23 2002/05/31 12:51:58 midas + First version with truely relative paths + Revision 1.22 2002/05/13 20:50:53 midas Fixed problem with daylight savings time @@ -74,7 +77,7 @@ \********************************************************************/ /* Version of ELOG */ -#define VERSION "1.3.5" +#define VERSION "1.3.6" #include #include @@ -498,6 +501,14 @@ struct tm *ts; recv_string(s, str, sizeof(str), 10000); if (verbose) puts(str); + /* drain server messages */ + do + { + str[0] = 0; + recv_string(s, str, sizeof(str), 300); + if (verbose) puts(str); + } while (str[0]); + snprintf(str, sizeof(str) - 1, "HELO %s\r\n", host_name); send(s, str, strlen(str), 0); if (verbose) puts(str); @@ -2583,7 +2594,7 @@ void redirect(char *path) rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } - rsprintf("Location: /%s/%s\r\n\r\nredir\r\n", logbook_enc, path); + rsprintf("Location: %s\r\n\r\nredir\r\n", path); } void redirect2(char *path) @@ -2808,14 +2819,14 @@ void show_standard_header(char *title, char *path) rsprintf("%s\n", title); if (*gt("BGImage")) - rsprintf("\n", logbook_enc, gt("BGImage")); + rsprintf("\n", gt("BGImage")); else rsprintf("\n"); if (path) - rsprintf("
\n\n", logbook_enc, path); + rsprintf("\n\n", path); else - rsprintf("\n\n", logbook_enc); + rsprintf("\n\n"); } /*------------------------------------------------------------------*/ @@ -2843,7 +2854,7 @@ int i; if (getcfg("global", "main tab", str)) { - rsprintf("%s\n", str); + rsprintf("%s\n", str); rsprintf(" \n"); } @@ -2861,7 +2872,7 @@ int i; if (equal_ustring(str, logbook)) rsprintf("%s\n", gt("Title BGColor"), gt("Title fontcolor"), str); else - rsprintf("%s\n", ref, str); + rsprintf("%s\n", ref, str); rsprintf(" \n"); } rsprintf(" \n"); @@ -2895,7 +2906,7 @@ int i; /* right cell */ rsprintf("", gt("Title BGColor")); if (*gt("Title image")) - rsprintf("", logbook_enc, gt("Title image")); + rsprintf("", gt("Title image")); else rsprintf("ELOG V%s  ", gt("Title fontcolor"), VERSION); @@ -3245,13 +3256,16 @@ struct tm *gmt; } /* get optional expriation from configuration file */ - exp = 24; + exp = 0; if (getcfg(logbook, "Login expiration", str)) exp = atof(str); if (exp == 0) { - rsprintf("Set-Cookie: upwd=%s; path=/%s\r\n", new_pwd, logbook_enc); + if (getcfg("global", "Password file", str)) + rsprintf("Set-Cookie: upwd=%s; path=/\r\n", new_pwd); + else + rsprintf("Set-Cookie: upwd=%s\r\n", new_pwd); } else { @@ -3260,11 +3274,13 @@ struct tm *gmt; gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%Y %H:%M:%S GMT", gmt); - rsprintf("Set-Cookie: upwd=%s; path=/%s; expires=%s\r\n", new_pwd, logbook_enc, str); + if (getcfg("global", "Password file", str)) + rsprintf("Set-Cookie: upwd=%s; path=/; expires=%s\r\n", new_pwd, str); + else + rsprintf("Set-Cookie: upwd=%s; expires=%s\r\n", new_pwd, str); } - sprintf(str, "/%s/", logbook_enc); - rsprintf("Location: %s\r\n\r\nredir\r\n", str); + rsprintf("Location: .\r\n\r\nredir\r\n"); return; } } @@ -3442,8 +3458,7 @@ time_t now; rsprintf("Content-Type: text/html\r\n\r\n"); rsprintf("ELOG\n"); - rsprintf("\n", - logbook_enc); + rsprintf("\n"); /*---- title row ----*/ @@ -3626,7 +3641,7 @@ time_t now; else rsprintf("", attr_list[index], attr_options[index][i]); - rsprintf(" \n", logbook_enc, attr_options[index][i]); + rsprintf(" \n", attr_options[index][i]); } rsprintf("\n"); @@ -4000,7 +4015,7 @@ char str[256]; for (j=0 ; j", attr_list[i], attr_options[i][j]); - rsprintf(" \n", logbook_enc, attr_options[i][j]); + rsprintf(" \n", attr_options[i][j]); } } @@ -4047,8 +4062,7 @@ char *buffer; rsprintf("Content-Type: text/html\r\n\r\n"); rsprintf("ELOG config\n"); - rsprintf("\n", - logbook_enc); + rsprintf("\n"); /*---- title ----*/ @@ -4328,13 +4342,13 @@ FILE *f; if (past_n) { sprintf(str, loc("Last %d days"), past_n*2); - rsprintf(" %s |\n", logbook_enc, past_n*2, str); + rsprintf(" %s |\n", past_n*2, str); } if (last_n) { sprintf(str, loc("Last %d entries"), last_n*2); - rsprintf(" %s |\n", logbook_enc, last_n*2, str); + rsprintf(" %s |\n", last_n*2, str); } } else @@ -4343,9 +4357,9 @@ FILE *f; url_encode(str); if (i < n-1) - rsprintf(" %s |\n", logbook_enc, str, loc(menu_item[i])); + rsprintf(" %s |\n", str, loc(menu_item[i])); else - rsprintf(" %s \n", logbook_enc, str, loc(menu_item[i])); + rsprintf(" %s \n", str, loc(menu_item[i])); } } @@ -4378,17 +4392,17 @@ FILE *f; if (past_n) { sprintf(str, loc("Last %d days"), past_n*2); - rsprintf(" %s |\n", logbook_enc, past_n*2, str); + rsprintf(" %s |\n", past_n*2, str); } if (last_n) { sprintf(str, loc("Last %d entries"), last_n*2); - rsprintf(" %s |\n", logbook_enc, last_n*2, str); + rsprintf(" %s |\n", last_n*2, str); } - rsprintf(" %s |\n", logbook_enc, loc("Find"), loc("Find")); - rsprintf(" %s \n", logbook_enc, loc("Back"), loc("Back")); + rsprintf(" %s |\n", loc("Find"), loc("Find")); + rsprintf(" %s \n", loc("Back"), loc("Back")); rsprintf("\n"); } @@ -4892,7 +4906,7 @@ FILE *f; strcpy(lb_enc, logbook_list[lindex]); url_encode(lb_enc); - sprintf(ref, "/%s/%s", lb_enc, str); + sprintf(ref, "../%s/%s", lb_enc, str); if (full) { @@ -4902,7 +4916,8 @@ FILE *f; size = printable ? 2 : 3; nowrap = printable ? "" : "nowrap"; - rsprintf("  %d  ", col, size, ref, n_found); + rsprintf("  %d  ", + col, size, ref, n_found); if (search_all) rsprintf("%s", nowrap, col, size, logbook_list[lindex]); @@ -4953,7 +4968,7 @@ FILE *f; { rsprintf("", col); if (attrib[i][0]) - rsprintf("", logbook_enc, attrib[i]); + rsprintf("", attrib[i]); rsprintf(" "); } @@ -5004,7 +5019,7 @@ FILE *f; { strcpy(str, attachment[index]); str[13] = 0; - sprintf(ref, "/%s/%s/%s", logbook_list[lindex], str, attachment[index]+14); + sprintf(ref, "../%s/%s/%s", logbook_list[lindex], str, attachment[index]+14); for (i=0 ; i<(int)strlen(attachment[index]) ; i++) str[i] = toupper(attachment[index][i]); @@ -5080,7 +5095,8 @@ FILE *f; size = printable ? 2 : 3; nowrap = printable ? "" : "nowrap"; - rsprintf("  %d  ", col, size, ref, n_found); + rsprintf("  %d  ", + col, size, ref, n_found); if (search_all) rsprintf("%s", nowrap, col, logbook_list[lindex]); @@ -5131,7 +5147,7 @@ FILE *f; { rsprintf("", col); if (attrib[i][0]) - rsprintf("", logbook_enc, attrib[i]); + rsprintf("", attrib[i]); rsprintf(" "); } @@ -5493,8 +5509,8 @@ int i, j, n, missing, first, index, n_attr, n_mail, suppress, status; rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } - rsprintf("Location: /%s/%s%s\r\n\r\nredir\r\n", - logbook_enc, tag, mail_param); + rsprintf("Location: %s%s\r\n\r\nredir\r\n", + tag, mail_param); } /*------------------------------------------------------------------*/ @@ -5617,9 +5633,9 @@ char date[80], text[TEXT_SIZE], old_data_dir[256], tag[32], rsprintf(loc("Message copied successfully from \"%s\" to \"%s\""), logbook, dst_logbook); rsprintf("\n"); - rsprintf("%s %s\n", + rsprintf("%s %s\n", gt("Cell BGColor"), loc("Go to"), logbook, src_path, logbook); - rsprintf("%s %s\n", + rsprintf("%s %s\n", gt("Cell BGColor"), loc("Go to"), dst_logbook, dst_logbook); rsprintf("\n"); @@ -5860,7 +5876,7 @@ FILE *f; { if (!save_config()) return; - redirect(""); + redirect("."); return; } @@ -5878,10 +5894,18 @@ FILE *f; logf("Logout of user \"%s\" from logbook \"%s\"",getparam("unm"),logbook); /* delete user cookies */ - rsprintf("Set-Cookie: upwd=; path=/%s; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n", logbook_enc, str); - rsprintf("Set-Cookie: unm=; path=/%s; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n", logbook_enc, str); + if (getcfg("global", "Password file", str)) + { + rsprintf("Set-Cookie: upwd=; path=/; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Set-Cookie: unm=; path=/; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + } + else + { + rsprintf("Set-Cookie: upwd=; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Set-Cookie: unm=; expires=Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + } - rsprintf("Location: /\r\n\r\nredir\r\n"); + rsprintf("Location: ../\r\n\r\nredir\r\n"); return; } @@ -6178,10 +6202,10 @@ FILE *f; url_encode(ref); if (equal_ustring(cmd, loc("Copy to"))) - rsprintf(" %s |\n", + rsprintf(" %s |\n", logbook_enc, path, loc("Copy to"), ref, menu_item[i]); else - rsprintf(" %s |\n", + rsprintf(" %s |\n", logbook_enc, path, loc("Move to"), ref, menu_item[i]); } else @@ -6201,10 +6225,10 @@ FILE *f; strcpy(ref, str); url_encode(ref); if (equal_ustring(menu_item[i], loc("Copy to"))) - rsprintf(" %s \"%s\" |\n", + rsprintf(" %s \"%s\" |\n", logbook_enc, path, loc("Copy to"), ref, loc("Copy to"), str); else - rsprintf(" %s \"%s\" |\n", + rsprintf(" %s \"%s\" |\n", logbook_enc, path, loc("Move to"), ref, loc("Move to"), str); } } @@ -6215,9 +6239,9 @@ FILE *f; url_encode(str); if (i < n-1) - rsprintf(" %s |\n", logbook_enc, path, str, menu_item[i]); + rsprintf(" %s |\n", path, str, menu_item[i]); else - rsprintf(" %s \n", logbook_enc, path, str, menu_item[i]); + rsprintf(" %s \n", path, str, menu_item[i]); } } @@ -6248,14 +6272,14 @@ FILE *f; if (atoi(gt("Menu2 use images")) == 1) { - rsprintf("\n", - loc("First entry"), logbook_enc); - rsprintf("\n", - loc("Previous entry"), logbook_enc); - rsprintf("\n", - loc("Next entry"), logbook_enc); - rsprintf("\n", - loc("Last entry"), logbook_enc); + rsprintf("\n", + loc("First entry")); + rsprintf("\n", + loc("Previous entry")); + rsprintf("\n", + loc("Next entry")); + rsprintf("\n", + loc("Last entry")); } else { @@ -6374,14 +6398,14 @@ FILE *f; if (orig_tag[0]) { rsprintf("", gt("Categories bgcolor1")); - sprintf(ref, "/%s/%s", logbook_enc, orig_tag); + sprintf(ref, "%s", orig_tag); rsprintf("%s:", loc("In reply to"), gt("Menu2 bgcolor")); rsprintf("%s\n", ref, orig_tag); } if (reply_tag[0]) { rsprintf("", gt("Categories bgcolor1")); - sprintf(ref, "/%s/%s", logbook_enc, reply_tag); + sprintf(ref, "%s", reply_tag); rsprintf("%s:", loc("Reply to this"), gt("Menu2 bgcolor")); rsprintf("%s\n", ref, reply_tag); } @@ -6419,7 +6443,7 @@ FILE *f; rsprintf("%s:\n", attr_list[i], gt("Categories bgcolor2")); if (attrib[i][0]) - rsprintf("", logbook_enc, attrib[i]); + rsprintf("", attrib[i]); rsprintf(" \n"); } else @@ -6441,7 +6465,7 @@ FILE *f; rsprintf("\n", gt("Frame color")); if (*gt("BGTimage")) - rsprintf("

\n", logbook_enc, gt("BGTimage"), gt("Text BGColor")); + rsprintf("

\n", gt("BGTimage"), gt("Text BGColor")); else rsprintf("

\n", gt("Text BGColor")); @@ -6481,7 +6505,7 @@ FILE *f; strcpy(str, attachment[index]); str[13] = 0; - sprintf(ref, "/%s/%s/%s", logbook_enc, str, attachment[index]+14); + sprintf(ref, "%s/%s", str, attachment[index]+14); rsprintf("
\n", gt("Frame color")); @@ -6804,7 +6828,7 @@ char str[10000], logbook[256]; strcpy(str, logbook); url_encode(str); - rsprintf("", str, logbook); + rsprintf("", str, logbook); str[0] = 0; getcfg(logbook, "Comment", str); @@ -6943,13 +6967,16 @@ struct tm *gmt; } /* get optional expriation from configuration file */ - exp = 24; + exp = 0; if (getcfg(logbook, "Write password expiration", str)) exp = atof(str); if (exp == 0) { - rsprintf("Set-Cookie: wpwd=%s; path=/%s\r\n", enc_pwd, logbook_enc); + if (getcfg("global", "Write password", str)) + rsprintf("Set-Cookie: wpwd=%s; path=/\r\n", enc_pwd); + else + rsprintf("Set-Cookie: wpwd=%s\r\n", enc_pwd); } else { @@ -6958,10 +6985,16 @@ struct tm *gmt; gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%y %H:%M:%S GMT", gmt); - rsprintf("Set-Cookie: wpwd=%s; path=/%s; expires=%s\r\n", enc_pwd, logbook_enc, str); + if (getcfg("global", "Write password", str)) + rsprintf("Set-Cookie: wpwd=%s; path=/; expires=%s\r\n", enc_pwd, logbook_enc, str); + else + rsprintf("Set-Cookie: wpwd=%s; expires=%s\r\n", enc_pwd, logbook_enc, str); } - sprintf(str, "/%s/%s", logbook_enc, getparam("redir")); + sprintf(str, "%s", getparam("redir")); + if (!str[0]) + strcpy(str, "."); + rsprintf("Location: %s\r\n\r\nredir\r\n", str); return; } @@ -6983,13 +7016,16 @@ struct tm *gmt; } /* get optional expriation from configuration file */ - exp = 24; + exp = 0; if (getcfg(logbook, "Admin password expiration", str)) exp = atof(str); if (exp == 0) { - rsprintf("Set-Cookie: apwd=%s; path=/%s\r\n", enc_pwd, logbook_enc); + if (getcfg("global", "Admin password", str)) + rsprintf("Set-Cookie: apwd=%s; path=/\r\n", enc_pwd); + else + rsprintf("Set-Cookie: apwd=%s\r\n", enc_pwd); } else { @@ -6998,10 +7034,16 @@ struct tm *gmt; gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%y %H:%M:%S GMT", gmt); - rsprintf("Set-Cookie: apwd=%s; path=/%s; expires=%s\r\n", enc_pwd, logbook_enc, str); + if (getcfg("global", "Admin password", str)) + rsprintf("Set-Cookie: apwd=%s; path=/; expires=%s\r\n", enc_pwd); + else + rsprintf("Set-Cookie: apwd=%s; expires=%s\r\n", enc_pwd); } - sprintf(str, "/%s/%s", logbook_enc, getparam("redir")); + sprintf(str, "%s", getparam("redir")); + if (!str[0]) + strcpy(str, "."); + rsprintf("Location: %s\r\n\r\nredir\r\n", str); return; } @@ -7028,14 +7070,22 @@ struct tm *gmt; } /* get optional expriation from configuration file */ - exp = 24; + exp = 0; if (getcfg(logbook, "Login expiration", str)) exp = atof(str); if (exp == 0) { - rsprintf("Set-Cookie: upwd=%s; path=/%s\r\n", enc_pwd, logbook_enc); - rsprintf("Set-Cookie: unm=%s; path=/%s\r\n", getparam("uname"), logbook_enc); + if (getcfg("global", "Password file", str)) + { + rsprintf("Set-Cookie: upwd=%s; path=/\r\n", enc_pwd); + rsprintf("Set-Cookie: unm=%s; path=/\r\n", getparam("uname")); + } + else + { + rsprintf("Set-Cookie: upwd=%s\r\n", enc_pwd); + rsprintf("Set-Cookie: unm=%s\r\n", getparam("uname")); + } } else { @@ -7044,11 +7094,22 @@ struct tm *gmt; gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%y %H:%M:%S GMT", gmt); - rsprintf("Set-Cookie: upwd=%s; path=/%s; expires=%s\r\n", enc_pwd, logbook_enc, str); - rsprintf("Set-Cookie: unm=%s; path=/%s; expires=%s\r\n", getparam("uname"), logbook_enc, str); + if (getcfg("global", "Password file", str)) + { + rsprintf("Set-Cookie: upwd=%s; path=/; expires=%s\r\n", enc_pwd, str); + rsprintf("Set-Cookie: unm=%s; path=/; expires=%s\r\n", getparam("uname"), str); + } + else + { + rsprintf("Set-Cookie: upwd=%s; expires=%s\r\n", enc_pwd, str); + rsprintf("Set-Cookie: unm=%s; expires=%s\r\n", getparam("uname"), str); + } } - sprintf(str, "/%s/%s", logbook_enc, getparam("redir")); + sprintf(str, "%s", getparam("redir")); + if (!str[0]) + strcpy(str, "."); + rsprintf("Location: %s\r\n\r\nredir\r\n", str); return; } @@ -7416,6 +7477,9 @@ struct timeval timeout; status = select(FD_SETSIZE, (void *) &readfds, NULL, NULL, (void *) &timeout); + if (_abort) + break; + if (FD_ISSET(lsock, &readfds)) { len = sizeof(acc_addr); @@ -7748,9 +7812,10 @@ struct timeval timeout; strcpy(logbook, str); strcpy(logbook_enc, logbook); url_encode(logbook_enc); + strcat(logbook_enc, "/"); /* redirect to logbook, necessary to get optional cookies for that logbook */ - redirect(""); + redirect(logbook_enc); send(_sock, return_buffer, strlen(return_buffer), 0); @@ -8074,6 +8139,8 @@ struct timeval timeout; } } while (!_abort); + + printf("Server aborted.\n"); } /*------------------------------------------------------------------*/ @@ -8196,7 +8263,7 @@ char *cfgbuffer, str[256], *p; int main(int argc, char *argv[]) { -int i; +int i, fh; int tcp_port = 80, daemon = FALSE; char read_pwd[80], write_pwd[80], admin_pwd[80], str[80]; time_t now; @@ -8313,7 +8380,39 @@ usage: } } + /* check for configuration file */ + fh = open(cfg_file, O_RDONLY | O_BINARY); + if (fh < 0) + { + printf("Configuration file \"%s\" not found.\n", cfg_file); + return 1; + } + close(fh); + +#ifdef OS_UNIX + { + int pid; + FILE *f; + + /* crate /var/run/elogd.pid file */ + pid = getpid(); + f = fopen("/var/run/elogd.pid", "w"); + if (f) + { + fprintf(f, "%d\n", pid); + fclose(f); + } + } + + signal(SIGTERM, ctrlc_handler); + signal(SIGINT, ctrlc_handler); +#endif + server_loop(tcp_port, daemon); +#ifdef OS_UNIX + unlink("/var/run/elogd.pid"); +#endif + return 0; }
%s
%s