diff --git a/elogd.c b/elogd.c index 943fa75d..703fae2c 100755 --- a/elogd.c +++ b/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 2.138 2003/01/30 12:15:46 midas + CSS finished + Revision 2.137 2003/01/30 08:42:02 midas More CSS stuff @@ -608,6 +611,7 @@ char resource_dir[256]; char logbook_dir[256]; char tcp_hostname[256]; int tcp_port = 80; +char theme_name[80]; #define MAX_GROUPS 32 #define MAX_PARAM 100 @@ -701,7 +705,7 @@ struct { char type[32]; } filetype[] = { - { ".CSS", "text/css" }, + { ".CSS", "text/css" }, { ".JPG", "image/jpeg" }, { ".JPEG", "image/jpeg" }, { ".GIF", "image/gif" }, @@ -1633,166 +1637,6 @@ int n; /*------------------------------------------------------------------*/ -/* Parameter extraction from themes file */ - -typedef struct { - char name[32]; - char value[256]; - } THEME; - -THEME default_theme [] = { - - { "Table width", "100%" }, - { "Frame color", "#486090" }, - { "Cell BGColor", "#E6E6E6" }, - { "Border width", "0" }, - - { "Title BGColor", "#486090" }, - { "Title Fontcolor", "#FFFFFF" }, - { "Title Cellpadding", "0" }, - { "Title Image", "" }, - { "Title Image URL", "" }, - - { "LTab1 BGColor", "#486090" }, - { "LTab1 Fontcolor", "#FFFFFF" }, - { "LTab2 BGColor", "#E0E0E0" }, - { "LTab2 Fontcolor", "#FFFFFF" }, - { "GTab1 BGColor", "#486090" }, - { "GTab1 Fontcolor", "#FFFFFF" }, - { "GTab2 BGColor", "#FFFFB0" }, - { "GTab2 Fontcolor", "#808080" }, - - { "Merge menus", "1" }, - { "Use buttons", "0" }, - - { "Menu1 BGColor", "#E0E0E0" }, - { "Menu1 Align", "left" }, - { "Menu1 Cellpadding", "0" }, - - { "Menu2 BGColor", "#FFFFB0" }, - { "Menu2 Align", "center" }, - { "Menu2 Cellpadding", "0" }, - { "Menu2 use images", "0" }, - - { "Categories cellpadding", "3" }, - { "Categories border", "0" }, - { "Categories BGColor1", "#CCCCFF" }, - { "Categories BGColor2", "#DDEEBB" }, - - { "Text BGColor", "#FFFFFF" }, - - { "List bgcolor1", "#DDEEBB" }, - { "List bgcolor2", "#FFFFB0" }, - - { "BGImage", "" }, - { "BGTImage", "" }, - - { "Thread image", "" }, - { "Thread reply image", "" }, - - { "" } - -}; - -THEME *theme = NULL; -char theme_name[80]; - -/*------------------------------------------------------------------*/ - -void loadtheme(char *tn) -{ -FILE *f; -char *p, line[256], item[256], value[256], file_name[256]; -int i; - - if (theme == NULL) - theme = malloc(sizeof(default_theme)); - - /* copy default theme */ - memcpy(theme, default_theme, sizeof(default_theme)); - - /* use default if no name is given */ - if (tn == NULL) - return; - - memset(file_name, 0, sizeof(file_name)); - - strlcpy(file_name, resource_dir, sizeof(file_name)); - strlcat(file_name, "themes", sizeof(file_name)); - strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); - strlcat(file_name, tn, sizeof(file_name)); - strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); - strlcat(file_name, "theme.cfg", sizeof(file_name)); - - f = fopen(file_name, "r"); - if (f == NULL) - return; - - strcpy(theme_name, tn); - - do - { - line[0] = 0; - fgets(line, sizeof(line), f); - - /* ignore comments */ - if (line[0] == ';' || line[0] == '#') - continue; - - if (strchr(line, '=')) - { - /* split line into item and value, strop blanks */ - strcpy(item, line); - p = strchr(item, '='); - while ((*p == '=' || *p == ' ') && p > item) - *p-- = 0; - p = strchr(line, '='); - while (*p && (*p == '=' || *p == ' ')) - p++; - strcpy(value, p); - if (strlen(value) > 0) - { - p = value+strlen(value)-1; - while (p >= value && (*p == ' ' || *p == '\r' || *p == '\n')) - *(p--) = 0; - } - - /* find field in _theme and set it */ - for (i=0 ; theme[i].name[0] ; i++) - if (equal_ustring(item, theme[i].name)) - { - strcpy(theme[i].value, value); - break; - } - } - - } while (!feof(f)); - - fclose(f); - - return; -} - -/*------------------------------------------------------------------*/ - -/* get a certain theme attribute from currently loaded file */ - -char *gt(char *name) -{ -int i; - - if (theme == NULL) - loadtheme(NULL); - - for (i=0 ; theme[i].name[0] ; i++) - if (equal_ustring(theme[i].name, name)) - return theme[i].value; - - return ""; -} - -/*------------------------------------------------------------------*/ - void el_decode(char *message, char *key, char *result) { char *pc, *ph; @@ -4115,15 +3959,12 @@ LBLIST clb, flb, nlb, lbl; /* right cell */ rsprintf(""); - if (*gt("Title image URL")) - rsprintf("\n", gt("Title image URL")); + if (getcfg(logbook, "Title image URL", str)) + rsprintf("\n", str); - if (*gt("Title image")) - rsprintf("", gt("Title image")); - else - rsprintf("ELOG V%s  ", VERSION); + rsprintf(""); - if (*gt("Title image URL")) + if (getcfg(logbook, "Title image URL", str)) rsprintf("\n"); rsprintf("\n"); @@ -4244,8 +4085,10 @@ void send_file_direct(char *file_name) { int fh, i, length; char str[256]; +/* time_t now; struct tm *gmt; +*/ fh = open(file_name, O_RDONLY | O_BINARY); if (fh > 0) @@ -4258,11 +4101,13 @@ struct tm *gmt; rsprintf("Server: ELOG HTTP %s\r\n", VERSION); rsprintf("Accept-Ranges: bytes\r\n"); + /* time(&now); now += (int) (3600*3); gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%y %H:%M:%S GMT", gmt); rsprintf("Expires: %s\r\n", str); + */ if (use_keepalive) { @@ -4552,39 +4397,37 @@ int i, fh, wrong_pwd, size; show_standard_header(lbs, TRUE, loc("ELOG change password"), NULL); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); + rsprintf("
"); if (wrong_pwd == 1) - rsprintf("\n", loc("Wrong password")); + rsprintf("\n", loc("Wrong password")); if (wrong_pwd == 2) - rsprintf("\n", loc("New passwords do not match, please retype")); + rsprintf("\n", loc("New passwords do not match, please retype")); - rsprintf("\n", - gt("Title fontcolor"), loc("Change password for user"), user); + rsprintf("%s \"%s\"\n", loc("Change password for user"), user); if (!getcfg(lbs->name, "Admin user", str) || !strstr(str, getparam("unm")) != 0) { - rsprintf("\n", - gt("Cell BGColor"), loc("Old Password")); + rsprintf("\n"); } - rsprintf("\n", - gt("Cell BGColor"), loc("New Password")); - rsprintf("\n", - gt("Cell BGColor"), loc("Retype new password")); + rsprintf("\n", loc("New Password")); + rsprintf("\n"); - rsprintf("", - gt("Cell BGColor"), loc("Submit")); + rsprintf("\n", loc("Retype new password")); + rsprintf("\n"); - rsprintf("
%s!
%s!
%s!
%s!
\n", gt("Title bgcolor")); + rsprintf("
\n"); rsprintf("", user); - rsprintf("%s \"%s\"
%s:     
%s:\n", loc("Old Password")); + rsprintf("
%s:     
%s:     
%s:
%s:
\n"); + rsprintf("", + loc("Submit")); + + rsprintf("\n"); rsprintf("\r\n"); } @@ -6173,21 +6016,17 @@ char str[256], in_reply_to[80], reply_to[256]; str[0] = 0; show_standard_header(lbs, TRUE, "Delete ELog entry", str); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); + rsprintf("
"); + rsprintf("\n", gt("Title fontcolor"), - loc("Are you sure to delete these messages?")); + rsprintf("%s\n", loc("Are you sure to delete these messages?")); - rsprintf("\n"); if (reply) - rsprintf("\n", gt("Cell BGColor"), loc("and all its replies")); + rsprintf("\n", loc("and all their replies")); } else { - rsprintf("%s\n", gt("Title fontcolor"), - loc("Are you sure to delete this message?")); + rsprintf("%s\n", loc("Are you sure to delete this message?")); /* check for replies */ @@ -6232,9 +6070,9 @@ char str[256], in_reply_to[80], reply_to[256]; NULL, NULL, in_reply_to, reply_to, NULL, NULL); if (reply_to[0]) - rsprintf("\n", gt("Cell BGColor"), message_id, loc("and all its replies")); + rsprintf("\n", message_id, loc("and all its replies")); else - rsprintf("\n", gt("Cell BGColor"), message_id); + rsprintf("\n", message_id); /* put link to next message */ next = el_search_message(lbs, EL_NEXT, message_id, TRUE); @@ -6242,13 +6080,13 @@ char str[256], in_reply_to[80], reply_to[256]; rsprintf("\n", next); } - rsprintf("\n\n"); } - rsprintf("
\n"); /* define hidden field for command */ rsprintf("\n", loc("Delete")); - rsprintf("
", gt("Title bgcolor")); - if (!message_id) { - rsprintf("%s
\n", gt("Cell BGColor")); + rsprintf("
\n"); rsprintf("\n", getparam("nsel")); if (isparam("lastcmd")) @@ -6201,7 +6040,7 @@ char str[256], in_reply_to[80], reply_to[256]; sprintf(str, "s%d", i); if (isparam(str)) { - rsprintf("%s ", getparam(str)); + rsprintf("#%s ", getparam(str)); rsprintf("\n", str, getparam(str)); } @@ -6217,13 +6056,12 @@ char str[256], in_reply_to[80], reply_to[256]; rsprintf("
%s
%s
%d
%s
#%d
%s
%d
#%d
\n", - gt("Cell BGColor"), loc("Yes")); + rsprintf("
\n", + loc("Yes")); rsprintf("\n", loc("No")); rsprintf("
\n"); + rsprintf("\n"); rsprintf("\r\n"); } @@ -6256,12 +6094,14 @@ char str[256], in_reply_to[80], reply_to[256]; int show_download_page(LOGBOOK *lbs, char *path) { -char file_name[256], str[256]; +char file_name[256]; int index, message_id, fh, i, size; char message[TEXT_SIZE+1000], *p; +/* +char str[256]; time_t now; struct tm *gmt; - +*/ message_id = atoi(path); for (index = 0 ; index < *lbs->n_el_index ; index++) @@ -6301,11 +6141,13 @@ struct tm *gmt; rsprintf("Server: ELOG HTTP %s\r\n", VERSION); rsprintf("Accept-Ranges: bytes\r\n"); + /* time(&now); now += (int) (3600*3); gmt = gmtime(&now); strftime(str, sizeof(str), "%A, %d-%b-%y %H:%M:%S GMT", gmt); rsprintf("Expires: %s\r\n", str); + */ if (use_keepalive) { @@ -6415,29 +6257,14 @@ FILE *f; { /* if top level only, display reply icon if message has a reply */ if (getcfg(lbs->name, "Top level only", str) && atoi(str) == 1 && reply_to[0]) - { - if (*gt("Thread reply image")) - rsprintf(" ", ref, gt("Thread reply image")); - else - rsprintf(" %d > ", ref, message_id); - } + rsprintf(" ", ref); else { /* display standard icons */ if (level == 0) - { - if (*gt("Thread image")) - rsprintf(" ", ref, gt("Thread image")); - else - rsprintf(" %d ", ref, message_id); - } + rsprintf(" "); else - { - if (*gt("Thread reply image")) - rsprintf(" ", ref, gt("Thread reply image")); - else - rsprintf(" %d ", ref, message_id); - } + rsprintf(" ", ref); } } @@ -6497,19 +6324,9 @@ FILE *f; if (equal_ustring(mode, "Threaded")) { if (level == 0) - { - if (*gt("Thread image")) - rsprintf(" ", gt("Thread image")); - else - rsprintf(" %d ", message_id); - } + rsprintf(" "); else - { - if (*gt("Thread reply image")) - rsprintf(" ", gt("Thread reply image")); - else - rsprintf(" %d ", message_id); - } + rsprintf(" "); skip_comma = TRUE; } @@ -8911,11 +8728,9 @@ LOGBOOK *lbs_dest; sprintf(str, "%d", source_id); show_standard_header(lbs, FALSE, loc("Copy ELog entry"), str); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); + rsprintf("
"); + rsprintf("\n"); if (src_id) - rsprintf("\n", - gt("Cell BGColor"), loc("Go to"), lbs->name, source_id, lbs->name); + rsprintf("\n", + loc("Go to"), lbs->name, source_id, lbs->name); else { strcpy(str, getparam("lastcmd")); url_decode(str); - rsprintf("\n", - gt("Cell BGColor"), loc("Go to"), lbs->name, str, lbs->name); + rsprintf("\n", + loc("Go to"), lbs->name, str, lbs->name); } - rsprintf("\n", - gt("Cell BGColor"), loc("Go to"), lbs_dest->name, lbs_dest->name); + rsprintf("\n", + loc("Go to"), lbs_dest->name, lbs_dest->name); - rsprintf("
\n"); - rsprintf("
"); if (n>1) { if (n_done == 0) @@ -8935,21 +8750,21 @@ LOGBOOK *lbs_dest; rsprintf("
%s %s
%s %s
%s %s
%s %s
%s %s
%s %s
\n"); + rsprintf("\n"); rsprintf("\r\n"); return; @@ -9599,10 +9414,9 @@ BOOL first; strstr(att, ".JPEG") || strstr(att, ".PNG")) { - rsprintf("\n", gt("Frame color")); - rsprintf("", ref); - rsprintf("
", gt("Text bgcolor")); + rsprintf("
\n"); rsprintf("
\n\n"); + rsprintf("\n\n"); } else { @@ -9613,10 +9427,6 @@ BOOL first; /* display attachment */ rsprintf("\n"); - /* - rsprintf("\n", gt("Frame color")); - rsprintf("
", gt("Text bgcolor")); - */ if (!strstr(att, ".HTML")) rsprintf("
");
 
@@ -9715,35 +9525,31 @@ char  str[256];
     /* show web password page */
     show_standard_header(lbs, FALSE, loc("ELOG password"), NULL);
 
+    rsprintf("");
+
+    if (isparam("wpwd"))
+      rsprintf("\n", loc("Wrong password"));
+
+    rsprintf("
%s!
\n"); + /* define hidden fields for current destination */ if (redir[0]) rsprintf("\n", redir); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); - - if (isparam("wpwd")) - rsprintf("\n", loc("Wrong password")); - - rsprintf("\n", - gt("Title fontcolor"), loc("Please enter password to obtain write access")); - rsprintf("\n", gt("Cell BGColor")); + rsprintf("%s\n", loc("Please enter password to obtain write access")); + rsprintf("\n"); } else { - rsprintf("%s\n", - gt("Title fontcolor"), loc("Please enter password to obtain administration access")); - rsprintf("\n", gt("Cell BGColor")); + rsprintf("%s\n", loc("Please enter password to obtain administration access")); + rsprintf("\n"); } - rsprintf("", gt("Cell BGColor"), loc("Submit")); + rsprintf("", loc("Submit")); - rsprintf("
%s!
\n", gt("Title bgcolor")); - if (strcmp(name, "Write password") == 0) { - rsprintf("%s
\n"); + rsprintf("

\n"); rsprintf("\r\n"); @@ -9935,31 +9741,30 @@ char status, str[256], upwd[256], full_name[256], email[256]; /* define hidden fields for current destination */ rsprintf("\n", redir); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); + rsprintf("
"); if (isparam("wpwd")) - rsprintf("\n", loc("Wrong password")); + rsprintf("\n", loc("Wrong password")); - rsprintf("\n", loc("Please login")); - rsprintf("%s\n", - gt("Title fontcolor"), loc("Please login")); + rsprintf("\n", loc("Username")); + + rsprintf("\n", + getparam("unm")); - rsprintf("\n", - gt("Cell BGColor"), loc("Username"), getparam("unm")); - rsprintf("\n", - gt("Cell BGColor"), loc("Password")); + rsprintf("\n", loc("Password")); + + rsprintf("\n"); if (getcfg(lbs->name, "Self register", str) && atoi(str) > 0) - rsprintf("", - gt("Cell BGColor"), loc("Register as new user")); + rsprintf("", + loc("Register as new user")); - rsprintf("", - gt("Cell BGColor"), loc("Submit")); + rsprintf("", + loc("Submit")); - rsprintf("
%s!
%s!
\n", gt("Title bgcolor")); + rsprintf("
%s
%s:
%s:   
%s:   
%s:
%s
%s
\n"); + rsprintf("

\n"); rsprintf("\r\n"); @@ -9995,10 +9800,8 @@ char str[10000]; rsprintf("\n\n"); - rsprintf("

"); - rsprintf("
\n"); - - rsprintf("
\n"); + rsprintf(""); + rsprintf("\n", loc("Please select the one to connect to")); + rsprintf("%s:\n", loc("Please select the one to connect to")); } for (i=0 ; ; i++) @@ -10016,18 +9818,18 @@ char str[10000]; if (!lb_list[i].name[0]) break; - rsprintf("", lb_list[i].name_enc, lb_list[i].name); + rsprintf("", lb_list[i].name_enc, lb_list[i].name); str[0] = 0; getcfg(lb_list[i].name, "Comment", str); - rsprintf("\n", str); + rsprintf("\n", str); - rsprintf("\n"); } - rsprintf("
\n"); if (getcfg("global", "Welcome title", str)) { @@ -10006,9 +9809,8 @@ char str[10000]; } else { - rsprintf("\n"); rsprintf("%s.
\n", loc("Several logbooks are defined on this host")); - rsprintf("%s:
%s
%s%s %s "); + rsprintf(""); rsprintf(loc("%d entries"), *lb_list[i].n_el_index); rsprintf("
\n"); + rsprintf("
\n"); rsprintf("\r\n\r\n"); } @@ -10074,14 +9876,12 @@ char str[256]; { show_standard_header(lbs, FALSE, loc("ELOG registration"), ""); - rsprintf("

", - gt("Border width"), gt("Frame color")); - rsprintf("
\n", gt("Frame color")); - rsprintf("
"); + rsprintf(""); + rsprintf("\n
\n"); - rsprintf(loc("Your request has been forward the the administrator. You will be notified by email upon activation of your new account.")); + rsprintf(loc("Your request has been forwarded to the administrator. You will be notified by email upon activation of your new account.")); - rsprintf("
\n"); + rsprintf("
\n"); rsprintf("\n"); return 0; } @@ -10111,7 +9911,7 @@ int i, j, n, index, lb_index, message_id; double exp; char str[256], enc_pwd[80], file_name[256], command[80], ref[256]; char enc_path[256], dec_path[256], logbook[256], logbook_enc[256]; -char *experiment, *value, *group; +char *experiment, *value, *group, css[256]; time_t now; struct tm *gmt; LOGBOOK *lbs; @@ -10242,9 +10042,9 @@ FILE *f; /* get theme for logbook */ if (getcfg(logbook, "Theme", str)) - loadtheme(str); + strlcpy(theme_name, str, sizeof(theme_name)); else - loadtheme(NULL); /* get default values */ + strlcpy(theme_name, "default", sizeof(theme_name)); lb_index = i; lbs = lb_list+i; @@ -10375,22 +10175,30 @@ FILE *f; /* if password file given, check password and user name */ if (getcfg(logbook, "Password file", str)) { + /* get current CSS */ + strlcpy(css, "default.css", sizeof(css)); + if (lbs != NULL && getcfg(lbs->name, "CSS", str)) + strlcpy(css, str, sizeof(css)); + else if (lbs == NULL && getcfg("global", "CSS", str)) + strlcpy(css, str, sizeof(css)); + /* check if guest access */ if (getcfg(lbs->name, "Guest menu commands", str) && *getparam("unm") == 0) logf("Guest access"); - else - { - /* if no guest menu commands but self register, evaluate new user commands */ - if (getcfg(lbs->name, "Self register", str) && atoi(str) > 0) + else + if (strcmp(path, css) != 0) { - if (!do_self_register(lbs, command)) + /* if no guest menu commands but self register, evaluate new user commands */ + if (getcfg(lbs->name, "Self register", str) && atoi(str) > 0) + { + if (!do_self_register(lbs, command)) + return; + } + + logf("Connection of user \"%s\"",getparam("unm")); + if (!check_user_password(lbs, getparam("unm"), getparam("upwd"), getparam("cmdline"))) return; } - - logf("Connection of user \"%s\"",getparam("unm")); - if (!check_user_password(lbs, getparam("unm"), getparam("upwd"), getparam("cmdline"))) - return; - } } if (equal_ustring(command, loc("Login"))) @@ -11293,11 +11101,11 @@ struct timeval timeout; if (FD_ISSET(_sock, &readfds)) i = recv(_sock, net_buffer+len, sizeof(net_buffer)-len, 0); else - goto error; + goto finished; /* abort if connection got broken */ if (i<0) - goto error; + goto finished; if (i>0) len += i; @@ -11335,14 +11143,14 @@ struct timeval timeout; puts(return_buffer); printf("\n\n"); } - goto error; + goto finished; } if (i == 0) { n_error++; if (n_error == 100) - goto error; + goto finished; } /* finish when empty line received */ @@ -11404,20 +11212,20 @@ struct timeval timeout; return_length = strlen_retbuf+1; send(_sock, return_buffer, return_length, 0); - goto error; + goto finished; } else if (strstr(net_buffer, "OPTIONS") != NULL) - goto error; + goto finished; else { puts(net_buffer); - goto error; + goto finished; } } while (1); if (!strchr(net_buffer, '\r')) - goto error; + goto finished; /* initialize parametr array */ initparam(); @@ -11491,7 +11299,7 @@ struct timeval timeout; if (strncmp(net_buffer, "GET", 3) != 0 && strncmp(net_buffer, "POST", 4) != 0) - goto error; + goto finished; return_length = 0; @@ -11537,7 +11345,7 @@ struct timeval timeout; puts(return_buffer); printf("\n\n"); } - goto error; + goto finished; } } @@ -11567,7 +11375,21 @@ struct timeval timeout; send_file_direct(str); send(_sock, return_buffer, return_length, 0); - goto error; + goto finished; + } + else if (strstr(logbook, ".css")) + { + /* send default CSS file */ + strlcpy(str, resource_dir, sizeof(str)); + strlcat(str, "themes", sizeof(str)); + strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); + strlcat(str, "default", sizeof(str)); + strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); + strlcat(str, logbook, sizeof(str)); + send_file_direct(str); + send(_sock, return_buffer, return_length, 0); + + goto finished; } else { @@ -11586,7 +11408,7 @@ struct timeval timeout; puts(return_buffer); printf("\n\n"); } - goto error; + goto finished; } } @@ -11622,7 +11444,7 @@ struct timeval timeout; puts(return_buffer); printf("\n\n"); } - goto error; + goto finished; } } @@ -11734,7 +11556,7 @@ struct timeval timeout; if (!authorized) { keep_alive = 0; - goto error; + goto finished; } /* ask for password if configured */ @@ -11809,7 +11631,7 @@ struct timeval timeout; *strchr(net_buffer, '\r') = 0; if (!strstr(net_buffer, "HTTP")) - goto error; + goto finished; *(strstr(net_buffer, "HTTP")-1)=0; /* strip logbook from path */ @@ -11883,7 +11705,7 @@ redir: printf("\n\n"); } } - error: +finished: if (!keep_alive) {