diff --git a/doc/ChangeLog b/doc/ChangeLog index 99710852..702ec433 100755 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,12 @@ +Version 2.3.1, released Februar xxx, 2003 +========================================= + +- All attributes in listing are now a link +- Link color & style in listings can be changed in CSS file +- Added option 'subst on edit = " +- Removed "number attachments", added "enable attachments" +- Redesigned attachment uploading + Version 2.3.0, released Februar 7th, 2003 ========================================= diff --git a/doc/config.html b/doc/config.html index 8882ee06..84abca4e 100755 --- a/doc/config.html +++ b/doc/config.html @@ -277,13 +277,6 @@ option. So if Logbook dir = /usr/local/elog/logbooks and ("\" under Windows), then it is used as an absolute path independent of the logbook dir.

-

  • Number Attachments = <number> -
    -The number of attachments which can be submitted in one entry. May be zero if no -attachments are needed. Maximum is defined by MAX_ATTACHMENTS in elogd.c -(10 by default). -

    -

  • Comment = <comment>
    The comment is displayed on the logbook selection list. The selection list is @@ -969,6 +962,14 @@ only requires attributes, this flag can be set to 0. Default is 1.

    +

  • Enable attachments = 0|1 +
    +This flag controls the attachment submission at the bottom of a message +entry page. If this flag is 0, the attachment section is not displayed. +This might be useful for logbooks where attachments are not used. Default +is 1. +

    +

  • Show attachments = 0|1
    This flag controls the display of attachments such as images on normal diff --git a/doc/index.html b/doc/index.html index 6a53bd20..58e0abf6 100755 --- a/doc/index.html +++ b/doc/index.html @@ -31,7 +31,7 @@  [Links]  * 

    Home of the Electronic Logbook package by Stefan Ritt

    -
      Current version is : 2.3.0  
    +
      Current version is : 2.3.1  

      What is ELOG ?  
    diff --git a/eloglang.german b/eloglang.german index a4037c90..f864434c 100755 --- a/eloglang.german +++ b/eloglang.german @@ -64,9 +64,6 @@ please select = bitte ausw Submit as HTML text = Als HTML Text abschicken Suppress Email notification = Email Benachrichtigung unterdrücken Resubmit as new entry = Als neuen Eintrag abschicken -If no attachments are resubmitted, the original ones are kept = Falls keine neuen Anhänge abgeschickt werden, werden die Originale behalten -To delete an old attachment, enter <delete> in the new attachment field = Um einen alten Anhang zu löschen, bitte <entfernen> eingeban - = Attachment = Anhang Attachments = Anhänge No message available = Kein Entrag vorhanden @@ -85,8 +82,6 @@ Please check that it exists and elogd has write access = Bitte Error: Attribute %s not supplied = Fehler: Attribut %s nicht ausgefüllt Please go back and enter the %s field = Bitte zurückgehen und das Feld %s ausfüllen Please use your browser's back button to go back = Bitte die Zurück-Taste Ihres Browsers betätigen -Original attachment = Alter Anhang -New attachment = Neuer Anhang Only user %s can edit this entry = Dieser Eintrag kann nur von %s verändert werden # @@ -226,3 +221,8 @@ Options = Optionen Error: start date after end date = Fehler: Anfangsdatum nach Enddatum and all their replies = und alle Antworten Your request has been forwarded to the administrator. You will be notified by email upon activation of your new account. = Ihr Gesuch wurde an den Administrator weitergeleitet. Sie werden per Email benachrichtigt, wenn Ihr Zugang aktiviert wurde. + +# +# New strings for V2.3.1 +Upload = Hochladen + diff --git a/src/elogd.c b/src/elogd.c index 888993f0..e8d8237c 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.7 2003/02/11 15:43:15 midas + Revised attachment upload + Revision 1.6 2003/02/10 10:48:32 midas All items in listing are now a link @@ -536,7 +539,7 @@ \********************************************************************/ /* Version of ELOG */ -#define VERSION "2.3.0" +#define VERSION "2.3.1" #include #include @@ -633,7 +636,7 @@ char theme_name[80]; #define MAX_GROUPS 32 #define MAX_PARAM 100 -#define MAX_ATTACHMENTS 10 +#define MAX_ATTACHMENTS 20 #define MAX_N_LIST 100 #define MAX_N_ATTR 50 #define VALUE_SIZE 256 @@ -646,8 +649,8 @@ char _param[MAX_PARAM][PARAM_LENGTH]; char _value[MAX_PARAM][VALUE_SIZE]; char _mtext[TEXT_SIZE]; char _cmdline[CMD_SIZE]; -char *_attachment_buffer[MAX_ATTACHMENTS]; -INT _attachment_size[MAX_ATTACHMENTS]; +char *_attachment_buffer; +INT _attachment_size; struct in_addr rem_addr; char rem_host[256]; INT _sock; @@ -2411,6 +2414,73 @@ char message[TEXT_SIZE+1000], attachment_all[64*MAX_ATTACHMENTS]; /*------------------------------------------------------------------*/ +int el_submit_attachment(LOGBOOK *lbs, char *afilename, char *buffer, + int buffer_size, char *full_name) +{ +char file_name[256], dir[256], str[256], *p; +int fh; +time_t now; +struct tm tms; + + /* strip directory, add date and time to filename */ + strcpy(file_name, afilename); + p = file_name; + while (strchr(p, ':')) + p = strchr(p, ':')+1; + while (strchr(p, '\\')) + p = strchr(p, '\\')+1; /* NT */ + while (strchr(p, '/')) + p = strchr(p, '/')+1; /* Unix */ + + /* assemble ELog filename */ + if (p[0]) + { + strcpy(dir, lbs->data_dir); + + time(&now); + memcpy(&tms, localtime(&now), sizeof(struct tm)); + + strcpy(str, p); + if (full_name) + sprintf(full_name, "%02d%02d%02d_%02d%02d%02d_%s", + tms.tm_year % 100, tms.tm_mon+1, tms.tm_mday, + tms.tm_hour, tms.tm_min, tms.tm_sec, str); + + sprintf(file_name, "%s%02d%02d%02d_%02d%02d%02d_%s", dir, + tms.tm_year % 100, tms.tm_mon+1, tms.tm_mday, + tms.tm_hour, tms.tm_min, tms.tm_sec, str); + + /* save attachment */ + fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); + if (fh < 0) + { + sprintf(str, "Cannot write attachment file \"%s\"", file_name); + show_error(str); + return -1; + } + else + { + write(fh, buffer, buffer_size); + close(fh); + } + } + + return 0; +} + +/*------------------------------------------------------------------*/ + +void el_delete_attachment(LOGBOOK *lbs, char *file_name) +{ +char str[256]; + + strlcpy(str, lbs->data_dir, sizeof(str)); + strlcat(str, file_name, sizeof(str)); + remove(str); +} + +/*------------------------------------------------------------------*/ + int el_submit(LOGBOOK *lbs, int message_id, char *date, char attr_name[MAX_N_ATTR][NAME_LENGTH], @@ -2419,8 +2489,6 @@ int el_submit(LOGBOOK *lbs, int message_id, char *in_reply_to, char *reply_to, char *encoding, char afilename[MAX_ATTACHMENTS][256], - char *buffer[MAX_ATTACHMENTS], - INT buffer_size[MAX_ATTACHMENTS], BOOL mark_original) /********************************************************************\ @@ -2443,8 +2511,6 @@ int el_submit(LOGBOOK *lbs, int message_id, char *encoding Text encoding, either HTML or plain char *afilename[] File name of attachments - char *buffer[] Attachment contents - INT *buffer_size[] Size of attachment in bytes char *tag If given, edit existing message INT *tag_size Maximum size of tag BOOL mark_original Tag original message for replies @@ -2456,74 +2522,12 @@ int el_submit(LOGBOOK *lbs, int message_id, { INT n, i, j, size, fh, index, tail_size, orig_size, delta, reply_id; struct tm tms; -char file_name[256], afile_name[MAX_ATTACHMENTS][256], dir[256], str[256], - attachment_all[64*MAX_ATTACHMENTS], +char file_name[256], dir[256], str[256], rep1[256], rep2[256]; time_t now, ltime; -char message[TEXT_SIZE+100], *p; +char message[TEXT_SIZE+100], *p, *buffer; BOOL bedit; - for (index = 0 ; index < MAX_ATTACHMENTS ; index++) - { - /* generate filename for attachment */ - afile_name[index][0] = file_name[0] = 0; - - if (equal_ustring(afilename[index], loc(""))) - { - strcpy(afile_name[index], loc("")); - } - else if (afilename[index][0] && buffer_size[index] == 0) - { - /* resubmission of existing attachment */ - strcpy(afile_name[index], afilename[index]); - } - else - { - if (afilename[index][0]) - { - /* strip directory, add date and time to filename */ - - strcpy(file_name, afilename[index]); - p = file_name; - while (strchr(p, ':')) - p = strchr(p, ':')+1; - while (strchr(p, '\\')) - p = strchr(p, '\\')+1; /* NT */ - while (strchr(p, '/')) - p = strchr(p, '/')+1; /* Unix */ - - /* assemble ELog filename */ - if (p[0]) - { - strcpy(dir, lbs->data_dir); - - time(&now); - memcpy(&tms, localtime(&now), sizeof(struct tm)); - - strcpy(str, p); - sprintf(afile_name[index], "%02d%02d%02d_%02d%02d%02d_%s", - tms.tm_year % 100, tms.tm_mon+1, tms.tm_mday, - tms.tm_hour, tms.tm_min, tms.tm_sec, str); - sprintf(file_name, "%s%02d%02d%02d_%02d%02d%02d_%s", dir, - tms.tm_year % 100, tms.tm_mon+1, tms.tm_mday, - tms.tm_hour, tms.tm_min, tms.tm_sec, str); - - /* save attachment */ - fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); - if (fh < 0) - { - printf("Cannot write attachment file \"%s\"", file_name); - } - else - { - write(fh, buffer[index], buffer_size[index]); - close(fh); - } - } - } - } - } - /* generate new file name YYMMDD.log in data directory */ strcpy(dir, lbs->data_dir); @@ -2557,7 +2561,7 @@ BOOL bedit; /* file might have been edited, rebuild index */ el_build_index(lbs, TRUE); return el_submit(lbs, message_id, date, attr_name, attr_value, n_attr, text, - in_reply_to, reply_to, encoding, afilename, buffer, buffer_size, TRUE); + in_reply_to, reply_to, encoding, afilename, TRUE); } /* check for correct ID */ @@ -2582,7 +2586,6 @@ BOOL bedit; el_decode(message, "Reply to: ", reply_to); if (equal_ustring(in_reply_to, "")) el_decode(message, "In reply to: ", in_reply_to); - el_decode(message, "Attachment: ", attachment_all); /* buffer tail of logfile */ lseek(fh, 0, SEEK_END); @@ -2690,50 +2693,24 @@ BOOL bedit; { for (i=n=0 ; i")))) - { - /* delete old attachment */ - strlcpy(str, lbs->data_dir, sizeof(str)); - strlcat(str, p, sizeof(str)); - remove(str); - } - - if (afile_name[i][0] && !equal_ustring(afile_name[i], loc(""))) + if (afilename[i][0]) { if (n == 0) { - sprintf(message+strlen(message), "%s", afile_name[i]); + sprintf(message+strlen(message), "%s", afilename[i]); n++; } else - sprintf(message+strlen(message), ",%s", afile_name[i]); + sprintf(message+strlen(message), ",%s", afilename[i]); } - - else if (p && !equal_ustring(afile_name[i], loc(""))) - { - if (n == 0) - { - sprintf(message+strlen(message), "%s", p); - n++; - } - else - sprintf(message+strlen(message), ",%s", p); - } - } } else { - sprintf(message+strlen(message), afile_name[0]); + sprintf(message+strlen(message), afilename[0]); for (i=1 ; in_attr, - message, in_reply_to, reply_to, enc, att, NULL, NULL, TRUE); + message, in_reply_to, reply_to, enc, att, TRUE); } /*------------------------------------------------------------------*/ @@ -3094,7 +3071,7 @@ char att_file[MAX_ATTACHMENTS][256]; } el_submit(lbs, atoi(list[i]), date, attr_list, attrib, lbs->n_attr, text, - in_reply_to, reply_to, encoding, att_file, _attachment_buffer, _attachment_size, TRUE); + in_reply_to, reply_to, encoding, att_file, TRUE); } el_retrieve(lbs, new_id, date, attr_list, attrib, lbs->n_attr, @@ -3123,7 +3100,7 @@ char att_file[MAX_ATTACHMENTS][256]; } el_submit(lbs, atoi(list[i]), date, attr_list, attrib, lbs->n_attr, text, - in_reply_to, reply_to, encoding, att_file, _attachment_buffer, _attachment_size, TRUE); + in_reply_to, reply_to, encoding, att_file, TRUE); } return EL_SUCCESS; @@ -3147,7 +3124,7 @@ char att_file[MAX_ATTACHMENTS][256]; /* submit as new message */ date[0] = 0; new_id = el_submit(lbs, 0, date, attr_list, attrib, lbs->n_attr, text, - in_reply_to, reply_to, encoding, att_file, _attachment_buffer, _attachment_size, FALSE); + in_reply_to, reply_to, encoding, att_file, FALSE); /* correct links */ el_correct_links(lbs, message_id, new_id); @@ -4475,9 +4452,9 @@ char str[80], date[80], attrib[MAX_N_ATTR][NAME_LENGTH], /*------------------------------------------------------------------*/ -void show_elog_new(LOGBOOK *lbs, int message_id, BOOL bedit) +void show_edit_form(LOGBOOK *lbs, int message_id, BOOL bedit, BOOL upload) { -int i, j, n, index, size, width, height, fh, length; +int i, j, n, index, size, width, height, fh, length, first; char str[1000], preset[1000], *p, star[80], comment[10000]; char list[MAX_N_ATTR][NAME_LENGTH], file_name[256], *buffer, format[256]; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], @@ -4493,11 +4470,69 @@ time_t now; if (message_id) { - /* get message for reply */ + if (upload) + { + /* get date */ + time(&now); + if (getcfg(lbs->name, "Date format", format)) + strftime(date, sizeof(str), format, localtime(&now)); + else + strcpy(date, ctime(&now)); - size = sizeof(text); - el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, - text, &size, orig_tag, reply_tag, att, encoding); + /* get attributes from parameters */ + for (i=0 ; in_attr ; i++) + { + if (attr_flags[i] & AF_MULTI) + { + attrib[i][0] = 0; + first = 1; + for (j=0 ; jn_attr, + text, &size, orig_tag, reply_tag, att, encoding); + } } else { @@ -4572,6 +4607,25 @@ time_t now; } } + /* subst attributes for edits */ + if (message_id && bedit) + { + for (index = 0 ; index < lbs->n_attr ; index++) + { + sprintf(str, "Subst on edit %s", attr_list[index]); + if (getcfg(lbs->name, str, preset)) + { + /* check if already second reply */ + if (orig_tag[0] == 0) + { + i = build_subst_list(lbs, slist, svalue, attrib); + strsubst(preset, slist, svalue, i); + strcpy(attrib[index], preset); + } + } + } + } + /* header */ show_html_header(lbs, FALSE, "ELOG"); @@ -5022,46 +5076,33 @@ time_t now; rsprintf("\n"); - if (getcfg(lbs->name, "Number attachments", str)) - n = atoi(str); - else - n = 5; - - if (n > MAX_ATTACHMENTS) - n = MAX_ATTACHMENTS; - - if (n > 0) + if (!getcfg(lbs->name, "Enable attachments", str) || atoi(str) > 0) { + i = 0; if (bedit) { - rsprintf("%s.
    \n", - loc("If no attachments are resubmitted, the original ones are kept")); - rsprintf("%s.\n", loc("To delete an old attachment, enter <delete> in the new attachment field")); - - for (i=0 ; i%s %d:
    %s %d:", - loc("Original attachment"), i+1, loc("New attachment"), i+1); - - rsprintf("%s
    ", att[i]+14); - rsprintf("\n", - i+1); + rsprintf("%s %d:\n", loc("Attachment"), i+1); + sprintf(str, "attachment%d", i); + rsprintf("\n"); + rsprintf("\n", str, att[i]); + rsprintf("%s\n", att[i]+14); + rsprintf("  \n", + i, loc("Delete")); } else - rsprintf("%s %d:\n", - loc("Attachment"), i+1, i+1); - } + break; + } - } - else - { - /* attachment */ - for (i=0 ; i%s %d:\n", - loc("Attachment"), i+1, i+1); - } + /* field for add attachment */ + rsprintf("%s %d:\n", + loc("Attachment"), i+1); + rsprintf("\n"); + rsprintf("  \n", loc("Upload")); + rsprintf("\n"); } rsprintf("\n"); @@ -6834,7 +6875,7 @@ int i, n; strlcat(menu_str, "Config, ", sizeof(menu_str)); } - strcpy(other_str, "Submit, Back, Search, Save, Download, Cancel, First, Last, Previous, Next, "); + strcpy(other_str, "Upload, Submit, Back, Search, Save, Download, Cancel, First, Last, Previous, Next, "); /* admin commands */ if (getcfg(lbs->name, "Admin user", str) && @@ -8436,7 +8477,7 @@ char str[256], file_name[256], error[1000], date[80], mail_list[MAX_N_LIST][NAME_LENGTH], list[10000], attrib[MAX_N_ATTR][NAME_LENGTH], subst_str[256], in_reply_to[80], reply_to[256], user[256], user_email[256], email_notify[256]; -char *buffer[MAX_ATTACHMENTS], mail_param[1000], *mail_to; +char mail_param[1000], *mail_to; char att_file[MAX_ATTACHMENTS][256]; char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH]; int i, j, n, missing, first, index, suppress, message_id, resubmit_orig, mail_to_size; @@ -8480,18 +8521,11 @@ int i, j, n, missing, first, index, suppress, message_id, resubmit_orig, mail return; } - /* check for valid attachment files */ + /* get attachments */ for (i=0 ; i"))) - { - sprintf(error, loc("Error: Attachment file %s invalid, please bo back and enter a proper file name"), getparam(str)); - show_error(error); - return; - } } /* compile substitution list */ @@ -8588,9 +8622,7 @@ int i, j, n, missing, first, index, suppress, message_id, resubmit_orig, mail message_id = el_submit(lbs, message_id, date, attr_list, attrib, lbs->n_attr, getparam("text"), in_reply_to, reply_to, *getparam("html") ? "HTML" : "plain", - att_file, - _attachment_buffer, - _attachment_size, TRUE); + att_file, TRUE); if (message_id <= 0) { @@ -8701,10 +8733,6 @@ int i, j, n, missing, first, index, suppress, message_id, resubmit_orig, mail free(mail_to); - for (i=0 ; iname, "Submit page", str)) { /* check if file starts with an absolute directory */ @@ -8743,7 +8771,7 @@ void copy_to(LOGBOOK *lbs, int src_id, char *dest_logbook, int move) int size, i, n, n_done, index, status, fh, source_id, message_id; char str[256], file_name[256], attrib[MAX_N_ATTR][NAME_LENGTH]; char date[80], text[TEXT_SIZE], msg_str[32], in_reply_to[80], reply_to[256], - attachment[MAX_ATTACHMENTS][256], encoding[80]; + attachment[MAX_ATTACHMENTS][256], encoding[80], *buffer; LOGBOOK *lbs_dest; for (i=0 ; lb_list[i].name[0] ; i++) @@ -8797,21 +8825,29 @@ LOGBOOK *lbs_dest; if (fh > 0) { lseek(fh, 0, SEEK_END); - _attachment_size[i] = TELL(fh); + size = TELL(fh); lseek(fh, 0, SEEK_SET); - _attachment_buffer[i] = malloc(_attachment_size[i]); + buffer = malloc(size); - if (_attachment_buffer[i]) - read(fh, _attachment_buffer[i], _attachment_size[i]); + if (buffer) + read(fh, buffer, size); close(fh); - } - /* stip date/time from file name */ - strlcpy(str, attachment[i], sizeof(str)); - strlcpy(attachment[i], str+14, NAME_LENGTH); + /* stip date/time from file name */ + strlcpy(file_name, attachment[i]+14, NAME_LENGTH); + + el_submit_attachment(lbs_dest, file_name, buffer, size, + attachment[i]); + + if (buffer) + free(buffer); + } + else + /* attachment is invalid */ + attachment[i][0] = 0; } /* submit in destination logbook without links, submit all attributes from @@ -8819,13 +8855,7 @@ LOGBOOK *lbs_dest; message_id = el_submit(lbs_dest, 0, date, attr_list, attrib, lbs->n_attr, text, "", "", encoding, - attachment, - _attachment_buffer, - _attachment_size, TRUE); - - for (i=0 ; iname, ""); } /*------------------------------------------------------------------*/ @@ -11744,7 +11819,13 @@ struct timeval timeout; { if (verbose) printf("%s\n", net_buffer+header_length); - decode_post(logbook, net_buffer+header_length, boundary, content_length); + + /* get logbook from list (needed for attachment dir) */ + for (i=0 ; lb_list[i].name[0] ; i++) + if (equal_ustring(logbook, lb_list[i].name)) + break; + + decode_post(&lb_list[i], net_buffer+header_length, boundary, content_length); } else {