diff --git a/Makefile b/Makefile index ddafe5de..8c660758 100644 --- a/Makefile +++ b/Makefile @@ -173,18 +173,25 @@ install: $(EXECS) @$(INSTALL) -v -m 0644 scripts/*.js $(ELOGDIR)/scripts/ @echo "Installing CKeditor to $(ELOGDIR)/scripts/ckeditor" - cp -r scripts/* $(ELOGDIR)/scripts + @cp -r scripts/* $(ELOGDIR)/scripts @echo "Installing resources to $(ELOGDIR)/resources" @$(INSTALL) -m 0644 resources/* $(ELOGDIR)/resources/ - @$(INSTALL) -m 0644 ssl/* $(ELOGDIR)/ssl/ + @if [ ! -f $(ELOGDIR)/ssl/server.crt ]; then \ + $(INSTALL) -v -m 0644 ssl/server.crt $(ELOGDIR)/ssl/ ;\ + fi + @if [ ! -f $(ELOGDIR)/ssl/server.key ]; then \ + $(INSTALL) -v -m 0644 ssl/server.key $(ELOGDIR)/ssl/ ;\ + fi @echo "Installing themes to $(ELOGDIR)/themes" @$(INSTALL) -m 0644 themes/default/icons/* $(ELOGDIR)/themes/default/icons/ - @for file in `find themes/default -type f | grep -v .svn` ; \ + @for file in `find themes/default -type f | grep -v .svn` ;\ do \ - $(INSTALL) -m 0644 $$file $(ELOGDIR)/themes/default/`basename $$file` ;\ - done + if [ ! -f $(ELOGDIR)/themes/default/`basename $$file` ]; then \ + $(INSTALL) -m 0644 $$file $(ELOGDIR)/themes/default/`basename $$file` ;\ + fi; \ + done @echo "Installing example logbook to $(ELOGDIR)/logbooks/demo" @if [ ! -f $(ELOGDIR)/logbooks/demo ]; then \ @@ -193,7 +200,9 @@ install: $(EXECS) @sed "s#\@PREFIX\@#$(PREFIX)#g" elogd.init_template > elogd.init @mkdir -p -m 0755 $(RCDIR) - @$(INSTALL) -v -m 0755 elogd.init $(RCDIR)/elogd + @if [ ! -f $(RCDIR)/elogd ]; then \ + @$(INSTALL) -v -m 0755 elogd.init $(RCDIR)/elogd ; \ + fi @if [ ! -f $(ELOGDIR)/elogd.cfg ]; then \ $(INSTALL) -v -m 644 elogd.cfg $(ELOGDIR)/elogd.cfg ; \ diff --git a/scripts/ckeditor/plugins/fileupload/dialogs/fileupload.js b/scripts/ckeditor/plugins/fileupload/dialogs/fileupload.js index 7ff1782d..c9efcfea 100644 --- a/scripts/ckeditor/plugins/fileupload/dialogs/fileupload.js +++ b/scripts/ckeditor/plugins/fileupload/dialogs/fileupload.js @@ -73,7 +73,7 @@ CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) { } formData.append('cmd', "Upload"); // Command for server to recognize this as an file upload - var URL = '/' + parent.logbook + '/upload.html?next_attachment=' + parent.next_attachment; + var URL = 'upload.html?next_attachment=' + parent.next_attachment; $.ajax({ xhr: function() diff --git a/scripts/ckeditor/plugins/image2/dialogs/image2.js b/scripts/ckeditor/plugins/image2/dialogs/image2.js index eae8ee97..3c36a001 100755 --- a/scripts/ckeditor/plugins/image2/dialogs/image2.js +++ b/scripts/ckeditor/plugins/image2/dialogs/image2.js @@ -572,7 +572,7 @@ CKEDITOR.dialog.add( 'image2', function( editor ) { } formData.append('cmd', "Upload"); // Command for server to recognize this as an file upload - var URL = '/' + parent.logbook + '/upload.html?next_attachment=' + parent.next_attachment; + var URL = 'upload.html?next_attachment=' + parent.next_attachment; $.ajax({ xhr: function() diff --git a/scripts/load-ckeditor.js b/scripts/load-ckeditor.js index 3cc2d834..4a78a42f 100755 --- a/scripts/load-ckeditor.js +++ b/scripts/load-ckeditor.js @@ -4,7 +4,7 @@ // // NOTE: This function works SYNCRHONOUSLY function localize(str) { - var URL = '/' + parent.logbook + "/?cmd=loc&value=" + str; + var URL = "?cmd=loc&value=" + str; return $.ajax({ type: "GET", @@ -13,8 +13,6 @@ function localize(str) { }).responseText; } -console.log(localize("Submit")); - // After the page has loaded, load the Ckeditor and the attachment dropbox $(document).ready(function() { @@ -29,7 +27,6 @@ $(document).ready(function() { // Make the editor bigger (at least 500px high and 80% of the viewport otherwise) var width = Math.max(500, 0.8 * $(window).height() ); - console.log(width); editor.resize("100%", new String(width)); // Create a new command with the desired exec function @@ -147,7 +144,7 @@ $(document).ready(function() { formData.append('cmd', "Upload"); // Command for server to recognize this as an file upload if (tests.formdata) { - var URL = '/' + parent.logbook + '/upload.html?next_attachment=' + parent.next_attachment; + var URL = 'upload.html?next_attachment=' + parent.next_attachment; // set the flag so the chkupload validator doesn't trigger uploading_dropped_files = true; diff --git a/src/elogd.c b/src/elogd.c index 3faa8f17..ca18ed2b 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -77,11 +77,15 @@ char rem_host_ip[256]; int _sock; BOOL use_keepalive, enable_execute = FALSE; BOOL fckedit_exist, image_magick_exist; -int _verbose, _current_message_id; +int _verbose_level, _current_message_id; int _logging_level, _ssl_flag; LOGBOOK *lb_list = NULL; +#define VERBOSE_URL 1 +#define VERBOSE_INFO 2 +#define VERBOSE_DEBUG 3 + #ifdef HAVE_SSL SSL *_ssl_con; #endif @@ -179,6 +183,9 @@ struct { "", ""},}; +char _convert_cmd[256]; +char _identify_cmd[256]; + #ifdef OS_WINNT int run_service(void); #endif @@ -302,14 +309,14 @@ static BOOL chkext(const char *str, const char *ext) return TRUE; } -int is_verbose(void) +int get_verbose(void) { - return _verbose; + return _verbose_level; } void set_verbose(int v) { - _verbose = v; + _verbose_level = v; } /* workaround for some gcc versions bug for "%c" format (see strftime(3) */ @@ -935,7 +942,7 @@ int my_shell(char *cmd, char *result, int size) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to group \"%s\"\n", str); if (!getcfg("global", "Usr", str, sizeof(str)) || setuser(str) < 0) { @@ -948,14 +955,14 @@ int my_shell(char *cmd, char *result, int size) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to user \"%s\"\n", str); } /* execute shell with redirection to /tmp/elog-shell */ sprintf(str, "/bin/sh -c \"%s\" > /tmp/elog-shell 2>&1", cmd); - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { efputs("Going to execute: "); efputs(str); efputs("\n"); @@ -1931,7 +1938,7 @@ void compose_email_header(LOGBOOK * lbs, char *subject, char *from, char *to, ch offset = (-(int) my_timezone()); if (ts->tm_isdst) offset += 3600; - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { sprintf(str, "timezone: %d, offset: %d\n", (int) my_timezone(), (int) offset); efputs(str); } @@ -2051,7 +2058,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c memset(error, 0, error_size); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("\n\nEmail from %s to %s, SMTP host %s:\n", from, to, smtp_host); sprintf(buffer, "Email from %s to ", from); strlcat(buffer, to, sizeof(buffer)); @@ -2089,7 +2096,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c str = xmalloc(strsize); recv_string(s, str, strsize, 10000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); @@ -2097,7 +2104,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c do { str[0] = 0; recv_string(s, str, strsize, 300); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); } while (str[0]); @@ -2106,13 +2113,13 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "EHLO %s\r\n", host_name); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); do { recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) @@ -2124,11 +2131,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "HELO %s\r\n", host_name); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) @@ -2140,7 +2147,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "AUTH LOGIN\r\n"); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); @@ -2148,13 +2155,13 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c *strchr(str, '\r') = 0; if (atoi(str) != 334) { strcat(str, "\n"); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); } else { base64_decode(str + 4, decoded); strcat(decoded, "\n"); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); } @@ -2165,7 +2172,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c base64_encode((unsigned char *) decoded, (unsigned char *) str, strsize); strcat(str, "\r\n"); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); recv_string(s, str, strsize, 3000); @@ -2173,7 +2180,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c *strchr(str, '\r') = 0; base64_decode(str + 4, decoded); strcat(decoded, "\n"); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(decoded); write_logfile(lbs, decoded); if (!check_smtp_error(str, 334, error, error_size)) @@ -2182,11 +2189,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c getcfg(lbs->name, "SMTP password", str, strsize); strcat(str, "\r\n"); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 235, error, error_size)) @@ -2195,11 +2202,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "MAIL FROM: %s\r\n", from); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); @@ -2215,13 +2222,13 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "RCPT TO: <%s>\r\n", list[i]); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); /* increased timeout for SMTP servers with long alias lists */ recv_string(s, str, strsize, 30000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); @@ -2231,11 +2238,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "DATA\r\n"); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 354, error, error_size)) @@ -2255,11 +2262,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c } send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 10000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 250, error, error_size)) @@ -2267,11 +2274,11 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c snprintf(str, strsize - 1, "QUIT\r\n"); send(s, str, strlen(str), 0); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); recv_string(s, str, strsize, 3000); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) efputs(str); write_logfile(lbs, str); if (!check_smtp_error(str, 221, error, error_size)) @@ -3627,7 +3634,7 @@ int fnmatch1(const char *pattern, const char *string) /*------------------------------------------------------------------*/ -int ss_file_find(char *path, char *pattern, char **plist) +int ss_file_find(const char *path, char *pattern, char **plist) /******************************************************************** Routine: ss_file_find @@ -3712,11 +3719,10 @@ int eli_compare(const void *e1, const void *e2) /*------------------------------------------------------------------*/ -void generate_new_file_name(char *file_name, char *path, int size) +void generate_subdir_name(char *file_name, char *subdir, int size) { - char fn[MAX_PATH_LENGTH], subdir[MAX_PATH_LENGTH]; - int status, year, month; - static int first = TRUE; + char fn[MAX_PATH_LENGTH], path[MAX_PATH_LENGTH]; + int year, month; // extract path from file_name strlcpy(path, file_name, size); @@ -3737,30 +3743,7 @@ void generate_new_file_name(char *file_name, char *path, int size) else sprintf(subdir, "19%02d", year); - // create new subdir - strlcat(path, subdir, size); -#ifdef OS_WINNT - status = mkdir(path); -#else - status = mkdir(path, 0755); -#endif - - if (status == 0) { - if (first) { - eprintf("\nFound old directory structure. Creating subdirectories and moving files...\n"); - first = FALSE; - } - eprintf("Created directory \"%s\"\n", path); - } else { - if (errno != EEXIST) { - eprintf("generate_new_file_name: %s\n", strerror(errno)); - eprintf("Cannot create directory \"%s\"\n", path); - } - } - - // assemble new path - strlcat(path, DIR_SEPARATOR_STR, size); - strlcat(path, fn, size); + strlcat(subdir, DIR_SEPARATOR_STR, size); } /*------------------------------------------------------------------*/ @@ -3768,18 +3751,45 @@ void generate_new_file_name(char *file_name, char *path, int size) int restructure_dir(char *dir) { char *file_list; - int n1, n2, index; - char file_name[MAX_PATH_LENGTH], old_path[MAX_PATH_LENGTH], new_path[MAX_PATH_LENGTH]; + int n1, n2, index, status; + char old_path[MAX_PATH_LENGTH], new_path[MAX_PATH_LENGTH], + subdir[MAX_PATH_LENGTH]; + static int first = TRUE; /* go through all entry files */ n1 = ss_file_find(dir, "??????a.log", &file_list); for (index = 0; index < n1; index++) { - strlcpy(file_name, dir, sizeof(file_name)); - strlcat(file_name, file_list + index * MAX_PATH_LENGTH, sizeof(file_name)); - strlcpy(old_path, file_name, sizeof(old_path)); - strlcpy(new_path, old_path, sizeof(new_path)); + generate_subdir_name(file_list + index * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + + // create new subdir + strlcpy(new_path, dir, MAX_PATH_LENGTH); + strlcat(new_path, subdir, MAX_PATH_LENGTH); + +#ifdef OS_WINNT + status = mkdir(new_path); +#else + status = mkdir(new_path, 0755); +#endif + + if (status == 0) { + if (first) { + eprintf("\nFound old directory structure. Creating subdirectories and moving files...\n"); + first = FALSE; + } + eprintf("Created directory \"%s\"\n", new_path); + } else { + if (errno != EEXIST) { + eprintf("generate_subdir_name: %s\n", strerror(errno)); + eprintf("Cannot create directory \"%s\"\n", new_path); + } + } + + strlcpy(old_path, dir, sizeof(old_path)); + strlcat(old_path, file_list + index * MAX_PATH_LENGTH, sizeof(old_path)); + strlcpy(new_path, dir, sizeof(new_path)); + strlcat(new_path, subdir, sizeof(new_path)); + strlcat(new_path, file_list + index * MAX_PATH_LENGTH, sizeof(new_path)); - generate_new_file_name(old_path, new_path, sizeof(new_path)); rename(old_path, new_path); } if (file_list) @@ -3788,12 +3798,24 @@ int restructure_dir(char *dir) /* go through all attachment files */ n2 = ss_file_find(dir, "??????_??????_*", &file_list); for (index = 0; index < n2; index++) { - strlcpy(file_name, dir, sizeof(file_name)); - strlcat(file_name, file_list + index * MAX_PATH_LENGTH, sizeof(file_name)); - strlcpy(old_path, file_name, sizeof(old_path)); - strlcpy(new_path, old_path, sizeof(new_path)); + generate_subdir_name(file_list + index * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + + // create new subdir + strlcpy(new_path, dir, MAX_PATH_LENGTH); + strlcat(new_path, subdir, MAX_PATH_LENGTH); + +#ifdef OS_WINNT + status = mkdir(new_path); +#else + status = mkdir(new_path, 0755); +#endif + + strlcpy(old_path, dir, sizeof(old_path)); + strlcat(old_path, file_list + index * MAX_PATH_LENGTH, sizeof(old_path)); + strlcpy(new_path, dir, sizeof(new_path)); + strlcat(new_path, subdir, sizeof(new_path)); + strlcat(new_path, file_list + index * MAX_PATH_LENGTH, sizeof(new_path)); - generate_new_file_name(old_path, new_path, sizeof(new_path)); rename(old_path, new_path); } if (file_list) @@ -3808,7 +3830,7 @@ int parse_file(LOGBOOK *lbs, char *file_name) { char str[256], date[256], *buffer, *p, *pn, in_reply_to[80]; int length, i, fh, len; - + fh = open(file_name, O_RDONLY | O_BINARY, 0644); if (fh < 0) { @@ -3840,6 +3862,10 @@ int parse_file(LOGBOOK *lbs, char *file_name) return EL_MEM_ERROR; } + strlcpy(lbs->el_index[*lbs->n_el_index].subdir, file_name+strlen(lbs->data_dir), 256); + if (strrchr(lbs->el_index[*lbs->n_el_index].subdir, DIR_SEPARATOR)) + *(strrchr(lbs->el_index[*lbs->n_el_index].subdir, DIR_SEPARATOR)+1) = 0; + if (strrchr(file_name, DIR_SEPARATOR)) strlcpy(str, strrchr(file_name, DIR_SEPARATOR)+1, sizeof(str)); else @@ -3864,7 +3890,7 @@ int parse_file(LOGBOOK *lbs, char *file_name) MD5_checksum(p, len, lbs->el_index[*lbs->n_el_index].md5_digest); if (lbs->el_index[*lbs->n_el_index].message_id > 0) { - if (is_verbose() > 1) { + if (get_verbose() >= VERBOSE_INFO) { eprintf(" ID %3d, %s, ofs %5d, %s, MD5=", lbs->el_index[*lbs->n_el_index].message_id, str, lbs->el_index[*lbs->n_el_index].offset, lbs->el_index[*lbs->n_el_index].in_reply_to ? "reply" : "thead"); @@ -3891,12 +3917,64 @@ int parse_file(LOGBOOK *lbs, char *file_name) /*------------------------------------------------------------------*/ +int scan_dir_tree(LOGBOOK *lbs, const char *dir, char **file_list, int *n) +{ + int index, n_files; + char str[MAX_PATH_LENGTH]; + char *fl, *p; + + fl = NULL; + n_files = ss_file_find(dir, "*", &fl); + if (n_files == 0) { + if (fl) + xfree(fl); + return 0; + } + + if (*file_list == NULL) + *file_list = (char *)xmalloc(n_files*MAX_PATH_LENGTH); + else + *file_list = (char *)xrealloc(*file_list, ((*n)+n_files)*MAX_PATH_LENGTH); + + /* go through all files */ + for (index = 0; index < n_files; index++) { + if (fnmatch1("??????a.log", &fl[index * MAX_PATH_LENGTH]) == 0) { + p = *file_list + ((*n) * MAX_PATH_LENGTH); + strlcpy(p, dir, MAX_PATH_LENGTH); + if (p[strlen(p)-1] != DIR_SEPARATOR) + strlcat(p, DIR_SEPARATOR_STR, MAX_PATH_LENGTH); + strlcat(p, fl + index * MAX_PATH_LENGTH, MAX_PATH_LENGTH); + (*n)++; + } + } + + /* go through all sub-directories */ + for (index = 0; index < n_files; index++) { + if (fnmatch1("????", &fl[index * MAX_PATH_LENGTH]) == 0 || + fnmatch1("??", &fl[index * MAX_PATH_LENGTH]) == 0) { + if (strieq(fl + index * MAX_PATH_LENGTH, "..")) + continue; + strlcpy(str, dir, sizeof(str)); + if (str[strlen(str)-1] != DIR_SEPARATOR) + strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); + strlcat(str, fl + index * MAX_PATH_LENGTH, sizeof(str)); + scan_dir_tree(lbs, str, file_list, n); + } + } + + if (fl) + xfree(fl); + + return *n; +} + +/*------------------------------------------------------------------*/ + int el_build_index(LOGBOOK * lbs, BOOL rebuild) /* scan all ??????a.log files and build an index table in eli[] */ { - char *file_list, *dir_list, error_str[256], base_dir[256], dir[256], str[256], - file_name[MAX_PATH_LENGTH], *buffer; - int dindex, index, n; + char *file_list, error_str[256], base_dir[256], *buffer; + int index, n; int i, status; unsigned char digest[16]; @@ -3912,7 +3990,7 @@ int el_build_index(LOGBOOK * lbs, BOOL rebuild) /* get data directory */ strcpy(base_dir, lbs->data_dir); - if (is_verbose() > 1) { + if (get_verbose() >= VERBOSE_DEBUG) { /* show MD5 from config file */ load_config_section(lbs->name, &buffer, error_str); @@ -3939,61 +4017,19 @@ int el_build_index(LOGBOOK * lbs, BOOL rebuild) return EL_UPGRADE; } - if (is_verbose() > 1) + if (get_verbose() >= VERBOSE_DEBUG) eprintf("Entries:\n"); // move files to directories if (new layout to reduce number of files per directory) - // ## restructure_dir(base_dir); + restructure_dir(base_dir); - dir_list = NULL; - n = ss_file_find(base_dir, "????", &dir_list); - if (n == 0) { - if (dir_list) - xfree(dir_list); - dir_list = NULL; - //return EL_EMPTY; - } - - /* go through all directories */ - for (dindex = 0; dindex < n; dindex++) { - file_list = NULL; - strlcpy(dir, base_dir, sizeof(str)); - strlcat(dir, dir_list + dindex * MAX_PATH_LENGTH, sizeof(str)); - strlcat(dir, DIR_SEPARATOR_STR, sizeof(str)); - n = ss_file_find(dir, "??????a.log", &file_list); - - /* go through all files */ - for (index = 0; index < n; index++) { - strlcpy(file_name, dir, sizeof(file_name)); - strlcat(file_name, file_list + index * MAX_PATH_LENGTH, sizeof(file_name)); - - status = parse_file(lbs, file_name); - if (status != SUCCESS) { - if (file_list) - xfree(file_list); - return status; - } - } - - if (file_list) - xfree(file_list); - } - file_list = NULL; - n = ss_file_find(base_dir, "??????a.log", &file_list); - if (n == 0) { - if (file_list) - xfree(file_list); - file_list = NULL; - return EL_EMPTY; - } - + n = 0; + scan_dir_tree(lbs, base_dir, &file_list, &n); + /* go through all files */ for (index = 0; index < n; index++) { - strlcpy(file_name, base_dir, sizeof(file_name)); - strlcat(file_name, file_list + index * MAX_PATH_LENGTH, sizeof(file_name)); - - status = parse_file(lbs, file_name); + status = parse_file(lbs, file_list+index*MAX_PATH_LENGTH); if (status != SUCCESS) { if (file_list) xfree(file_list); @@ -4007,7 +4043,7 @@ int el_build_index(LOGBOOK * lbs, BOOL rebuild) /* sort entries according to date */ qsort(lbs->el_index, *lbs->n_el_index, sizeof(EL_INDEX), eli_compare); - if (is_verbose() > 1) { + if (get_verbose() >= VERBOSE_DEBUG) { eprintf("After sort:\n"); for (i = 0; i < *lbs->n_el_index; i++) eprintf(" ID %3d, %s, ofs %5d\n", lbs->el_index[i].message_id, lbs->el_index[i].file_name, @@ -4139,7 +4175,7 @@ int el_index_logbooks() #endif if (j == 0) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Created directory \"%s\"\n", str); } else { eprintf("el_index_logbooks: %s\n", strerror(errno)); @@ -4159,7 +4195,7 @@ int el_index_logbooks() /* check if other logbook uses the same directory */ for (j = 0; j < n; j++) if (strcmp(lb_list[j].data_dir, lb_list[n].data_dir) == 0) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Logbook \"%s\" uses same directory as logbook \"%s\"\n", logbook, lb_list[j].name); lb_list[n].el_index = lb_list[j].el_index; lb_list[n].n_el_index = lb_list[j].n_el_index; @@ -4167,17 +4203,17 @@ int el_index_logbooks() } if (j == n) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Indexing logbook \"%s\" in \"%s\" ... ", logbook, lb_list[n].data_dir); eflush(); status = el_build_index(&lb_list[n], FALSE); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) if (status == EL_SUCCESS) eprintf("ok\n"); } if (status == EL_EMPTY) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Found empty logbook \"%s\"\n", logbook); } else if (status == EL_UPGRADE) { eprintf("Please upgrade data files in \"%s\" with the elconv program.\n", data_dir); @@ -4361,7 +4397,7 @@ int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ if (index == *lbs->n_el_index) return EL_NO_MSG; - sprintf(file_name, "%s%s", lbs->data_dir, lbs->el_index[index].file_name); + sprintf(file_name, "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_RDONLY | O_BINARY, 0644); if (fh < 0) { /* file might have been deleted, rebuild index */ @@ -4500,7 +4536,7 @@ int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffer, int buffer_size, char *full_name) { - char file_name[MAX_PATH_LENGTH], ext_file_name[MAX_PATH_LENGTH + 100], str[MAX_PATH_LENGTH], *p; + char file_name[MAX_PATH_LENGTH], ext_file_name[MAX_PATH_LENGTH + 100], str[MAX_PATH_LENGTH], *p, subdir[MAX_PATH_LENGTH]; int fh; time_t now; struct tm tms; @@ -4533,6 +4569,18 @@ int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffe strlcpy(full_name, ext_file_name, MAX_PATH_LENGTH); strlcpy(str, lbs->data_dir, sizeof(str)); + generate_subdir_name(ext_file_name, subdir, sizeof(subdir)); + strlcat(str, subdir, sizeof(str)); + if (strlen(str) > 0 && str[strlen(str)-1] == DIR_SEPARATOR) + str[strlen(str)-1] = 0; + +#ifdef OS_WINNT + mkdir(str); +#else + mkdir(str, 0755); +#endif + + strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); strlcat(str, ext_file_name, sizeof(str)); /* save attachment */ @@ -4556,15 +4604,18 @@ int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffe void el_delete_attachment(LOGBOOK * lbs, char *file_name) { int i; - char str[MAX_PATH_LENGTH]; + char str[MAX_PATH_LENGTH], subdir[MAX_PATH_LENGTH]; strlcpy(str, lbs->data_dir, sizeof(str)); + generate_subdir_name(file_name, subdir, sizeof(subdir)); + strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); remove(str); strlcat(str, ".png", sizeof(str)); remove(str); for (i = 0;; i++) { strlcpy(str, lbs->data_dir, sizeof(str)); + strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); sprintf(str + strlen(str), "-%d.png", i); if (file_exist(str)) { @@ -4573,6 +4624,7 @@ void el_delete_attachment(LOGBOOK * lbs, char *file_name) } strlcpy(str, lbs->data_dir, sizeof(str)); + strlcat(str, subdir, sizeof(str)); strlcat(str, file_name, sizeof(str)); if (strrchr(str, '.')) *strrchr(str, '.') = 0; @@ -4603,7 +4655,7 @@ int el_retrieve_attachment(LOGBOOK * lbs, int message_id, int n, char name[MAX_P if (index == *lbs->n_el_index) return EL_NO_MSG; - sprintf(file_name, "%s%s", lbs->data_dir, lbs->el_index[index].file_name); + sprintf(file_name, "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_RDONLY | O_BINARY, 0644); if (fh < 0) { /* file might have been deleted, rebuild index */ @@ -4696,11 +4748,11 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n \********************************************************************/ { - int n, i, j, size, fh, index, tail_size, orig_size, delta, reply_id; + int n, i, j, size, fh, index, tail_size, orig_size, delta, reply_id, status; char file_name[256], dir[256], str[NAME_LENGTH], date1[256], attrib[MAX_N_ATTR][NAME_LENGTH], reply_to1[MAX_REPLY_TO * 10], in_reply_to1[MAX_REPLY_TO * 10], encoding1[80], *message, *p, *old_text, *buffer; - char attachment_all[64 * MAX_ATTACHMENTS]; + char attachment_all[64 * MAX_ATTACHMENTS], subdir[MAX_PATH_LENGTH]; time_t ltime; tail_size = orig_size = 0; @@ -4728,7 +4780,7 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n return -1; } - sprintf(file_name, "%s%s", lbs->data_dir, lbs->el_index[index].file_name); + sprintf(file_name, "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { xfree(message); @@ -4830,7 +4882,18 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n sprintf(file_name, "%c%c%02d%c%ca.log", date1[14], date1[15], i + 1, date1[5], date1[6]); - sprintf(str, "%s%s", dir, file_name); + generate_subdir_name(file_name, subdir, sizeof(subdir)); + sprintf(str, "%s%s", dir, subdir); + if (strlen(str) > 0 && str[strlen(str)-1] == DIR_SEPARATOR) + str[strlen(str)-1] = 0; + +#ifdef OS_WINNT + status = mkdir(str); +#else + status = mkdir(str, 0755); +#endif + + sprintf(str, "%s%s%s", dir, subdir, file_name); fh = open(str, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { xfree(message); @@ -5060,7 +5123,7 @@ int el_delete_message(LOGBOOK * lbs, int message_id, BOOL delete_attachments, if (index == *lbs->n_el_index) return -1; - sprintf(file_name, "%s%s", lbs->data_dir, lbs->el_index[index].file_name); + sprintf(file_name, "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_RDWR | O_BINARY, 0644); if (fh < 0) return EL_FILE_ERROR; @@ -7374,7 +7437,7 @@ void show_http_header(LOGBOOK * lbs, BOOL expires, char *cookie) if (expires) { rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); } rsprintf("\r\n"); @@ -7391,8 +7454,8 @@ void show_plain_header(int size, char *file_name) rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); } - // rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Pragma: no-cache\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); rsprintf("Content-Type: text/plain\r\n"); rsprintf("Content-disposition: attachment; filename=\"%s\"\r\n", file_name); if (size) @@ -8271,9 +8334,7 @@ int exist_file(char *file_name) void send_file_direct(char *file_name) { int fh, i, length, delta; - char str[MAX_PATH_LENGTH], dir[MAX_PATH_LENGTH], charset[80], format[80]; - time_t now; - struct tm *gmt; + char str[MAX_PATH_LENGTH], dir[MAX_PATH_LENGTH], charset[80]; getcwd(dir, sizeof(dir)); fh = open(file_name, O_RDONLY | O_BINARY); @@ -8289,14 +8350,9 @@ void send_file_direct(char *file_name) /* set expiration time to one day if no thumbnail */ if (isparam("thumb")) { rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); } else { - time(&now); - now += (int) (3600 * 24); - gmt = gmtime(&now); - strcpy(format, "%A, %d-%b-%y %H:%M:%S GMT"); - strftime(str, sizeof(str), format, gmt); - rsprintf("Expires: %s\r\n", str); + rsprintf("Cache-control: public, max-age=86400\r\n"); } if (keep_alive) { @@ -9295,7 +9351,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL svalue[MAX_N_ATTR + 10][NAME_LENGTH], owner[256], locked_by[256], class_value[80], class_name[80], ua[NAME_LENGTH], mid[80], title[256], login_name[256], full_name[256], cookie[256], orig_author[256], attr_moptions[MAX_N_LIST][NAME_LENGTH], ref[256], file_enc[256], tooltip[10000], - enc_attr[NAME_LENGTH], user_email[256], cmd[256], thumb_name[256], **user_list, fid[20], upwd[80]; + enc_attr[NAME_LENGTH], user_email[256], cmd[256], thumb_name[256], **user_list, fid[20], upwd[80], + subdir[256]; time_t now, ltime; char fl[8][NAME_LENGTH]; struct tm *pts; @@ -11484,6 +11541,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } else { strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(att[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, att[index], sizeof(file_name)); display_inline = is_image(file_name) || is_ascii(file_name); @@ -11530,9 +11589,9 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* ImageMagick available, so get image size */ rsprintf("%s \n", att[index] + 14); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) - sprintf(cmd, "identify -format '%%wx%%h' '%s[0]'", file_name); + sprintf(cmd, "%s -format '%%wx%%h' '%s[0]'", _identify_cmd, file_name); else - sprintf(cmd, "identify -format '%%wx%%h' '%s'", file_name); + sprintf(cmd, "%s -format '%%wx%%h' '%s'", _identify_cmd, file_name); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) if (cmd[i] == '\'') @@ -13327,7 +13386,7 @@ int ascii_compare2(const void *s1, const void *s2) void show_config_page(LOGBOOK * lbs) { - char str[256], user[80], password[80], full_name[80], user_email[80], logbook[256], auth[32], **user_list; + char str[256], user[80], password[80], full_name[256], user_email[256], logbook[256], auth[32], **user_list; int i, n, inactive; BOOL email_notify[1000]; @@ -13416,10 +13475,11 @@ void show_config_page(LOGBOOK * lbs) qsort(user_list, n, sizeof(char *), ascii_compare); for (i = 0; i < n; i++) { + get_user_line(lbs, user_list[i], NULL, full_name, user_email, NULL, NULL, NULL); if (strcmp(user_list[i], user) == 0) - rsprintf("%s\n", user_list[i], user_list[i]); + rsprintf("%s <%s>\n", user_list[i], user_list[i], user_email); else - rsprintf("%s\n", user_list[i], user_list[i]); + rsprintf("%s <%s>\n", user_list[i], user_list[i], user_email); } for (i = 0; i < n; i++) @@ -14283,7 +14343,7 @@ int show_download_page(LOGBOOK * lbs, char *path) if (index == *lbs->n_el_index) return EL_NO_MSG; - sprintf(file_name, "%s%s", lbs->data_dir, lbs->el_index[index].file_name); + sprintf(file_name, "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); fh = open(file_name, O_RDWR | O_BINARY, 0644); if (fh < 0) return EL_FILE_ERROR; @@ -15141,7 +15201,7 @@ int show_md5_page(LOGBOOK * lbs) rsprintf("Connection: close\r\n"); rsprintf("Content-Type: text/plain;charset=%s\r\n", DEFAULT_HTTP_CHARSET); rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n\r\n"); /* calculate MD5 for logbook section in config file */ load_config_section(lbs->name, &buffer, error_str); @@ -15399,6 +15459,8 @@ int submit_message(LOGBOOK * lbs, char *host, int message_id, char *error_str) for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment[i][0]) { strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[i], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[i], sizeof(file_name)); fh = open(file_name, O_RDONLY | O_BINARY); @@ -15464,6 +15526,8 @@ int submit_message(LOGBOOK * lbs, char *host, int message_id, char *error_str) for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment[i][0]) { strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[i], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[i], sizeof(file_name)); fh = open(file_name, O_RDONLY | O_BINARY); @@ -15914,7 +15978,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) /* check version */ p = strstr(buffer, "ELOG HTTP "); if (!p) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); sprintf(error_str, "Remote server is not an ELOG server"); xfree(buffer); @@ -15922,7 +15986,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) } version = atoi(p + 10) * 100 + atoi(p + 12) * 10 + atoi(p + 14); if (version < 254) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); strlcpy(str, p + 10, 10); @@ -15937,7 +16001,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) /* evaluate status */ p = strchr(buffer, ' '); if (p == NULL) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); *strchr(str, '?') = 0; @@ -15949,7 +16013,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) p++; status = atoi(p); if (status == 401) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); eprintf("Please enter password to access remote elogd server: "); @@ -15957,7 +16021,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) while (pwd[strlen(pwd) - 1] == '\n' || pwd[strlen(pwd) - 1] == '\r') pwd[strlen(pwd) - 1] = 0; } else if (status != 200) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); *strchr(str, '?') = 0; @@ -15970,7 +16034,7 @@ void receive_config(LOGBOOK * lbs, char *server, char *error_str) p = strstr(buffer, "\r\n\r\n"); if (p == NULL) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) puts(buffer); xfree(buffer); sprintf(error_str, loc("Cannot receive \"%s\""), str); @@ -16452,7 +16516,7 @@ void synchronize_logbook(LOGBOOK * lbs, int mode, BOOL sync_all) } /* compare MD5s */ - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf("CONFIG : "); for (j = 0; j < 16; j++) eprintf("%02X", digest[j]); @@ -16576,7 +16640,7 @@ void synchronize_logbook(LOGBOOK * lbs, int mode, BOOL sync_all) if (exist_remote && exist_cache) { /* compare MD5s */ - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf("ID%-5d: ", message_id); for (j = 0; j < 16; j++) eprintf("%02X", lbs->el_index[i_msg].md5_digest[j]); @@ -16719,7 +16783,7 @@ void synchronize_logbook(LOGBOOK * lbs, int mode, BOOL sync_all) if (!equal_md5(md5_cache[i_cache].md5_digest, lbs->el_index[i_msg].md5_digest)) { /* compare MD5s */ - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf("ID%-5d: ", message_id); for (j = 0; j < 16; j++) eprintf("%02X", lbs->el_index[i_msg].md5_digest[j]); @@ -16859,7 +16923,7 @@ void synchronize_logbook(LOGBOOK * lbs, int mode, BOOL sync_all) lbs->el_index[i_msg].md5_digest)) { /* compare MD5s */ - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf("ID%-5d: ", message_id); for (j = 0; j < 16; j++) eprintf("%02X", lbs->el_index[i_msg].md5_digest[j]); @@ -16966,7 +17030,7 @@ void synchronize_logbook(LOGBOOK * lbs, int mode, BOOL sync_all) if (!equal_md5(md5_cache[i_cache].md5_digest, md5_remote[i_remote].md5_digest)) { /* compare MD5s */ - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf("ID-%5: none", message_id); eprintf("\nCache : "); for (j = 0; j < 16; j++) @@ -17186,7 +17250,7 @@ void display_line(LOGBOOK * lbs, int message_id, int number, char *mode, int exp int absolute_link) { char str[NAME_LENGTH], ref[256], *nowrap, rowstyle[80], tdstyle[80], format[256], - file_name[MAX_PATH_LENGTH], *slist, *svalue, comment[256], param[80]; + file_name[MAX_PATH_LENGTH], *slist, *svalue, comment[256], param[80], subdir[256]; char display[NAME_LENGTH], attr_icon[80]; int i, j, n, i_line, index, colspan, n_attachments, line_len, thumb_status, max_line_len, n_lines, max_n_lines; @@ -17881,6 +17945,8 @@ void display_line(LOGBOOK * lbs, int message_id, int number, char *mode, int exp url_encode(ref, sizeof(ref)); /* for file names with special characters like "+" */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); thumb_status = create_thumbnail(lbs, file_name); @@ -17945,6 +18011,8 @@ void display_line(LOGBOOK * lbs, int message_id, int number, char *mode, int exp colspan, loc("Attachment"), index + 1, ref, attachment[index] + 14); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); if (is_ascii(file_name) && !chkext(attachment[index], ".PS") @@ -17967,6 +18035,8 @@ void display_line(LOGBOOK * lbs, int message_id, int number, char *mode, int exp rsprintf(""); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); f = fopen(file_name, "rt"); @@ -21440,7 +21510,7 @@ void format_email_attachments(LOGBOOK * lbs, int message_id, int attachment_type char *multipart_boundary, int content_id) { int i, index, n_att, fh, n, is_inline, length; - char str[256], file_name[256], buffer[256], domain[256]; + char str[256], file_name[256], buffer[256], domain[256], subdir[256]; /* count attachments */ for (n_att = 0; att_file[n_att][0] && n_att < MAX_ATTACHMENTS; n_att++); @@ -21494,6 +21564,8 @@ void format_email_attachments(LOGBOOK * lbs, int message_id, int attachment_type /* encode file */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(att_file[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, att_file[index], sizeof(file_name)); if (is_image(file_name)) { get_thumb_name(file_name, str, sizeof(str), 0); @@ -22094,7 +22166,7 @@ int execute_shell(LOGBOOK * lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LE { int i; char slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH]; - char shell_cmd[10000], tail[1000], str[NAME_LENGTH], *p; + char shell_cmd[10000], tail[1000], str[NAME_LENGTH], *p, subdir[256]; if (!enable_execute) { eprintf("Shell execution not enabled via -x flag.\n"); @@ -22115,10 +22187,12 @@ int execute_shell(LOGBOOK * lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LE strlcpy(tail, p + strlen("$attachments"), sizeof(tail)); *p = 0; for (i = 0; i < MAX_ATTACHMENTS; i++) - if (att_file[i][0] && strlen(shell_cmd) + strlen(lbs->data_dir) + strlen(att_file[i]) + generate_subdir_name(att_file[i], subdir, sizeof(subdir)); + if (att_file[i][0] && strlen(shell_cmd) + strlen(lbs->data_dir) + strlen(subdir) + strlen(att_file[i]) < sizeof(shell_cmd) + 1) { strcpy(p, "\""); strcat(p, lbs->data_dir); + strlcat(str, subdir, sizeof(str)); strlcpy(str, att_file[i], sizeof(str)); str_escape(str, sizeof(str)); strcat(p, str); @@ -23048,7 +23122,7 @@ void submit_elog(LOGBOOK * lbs) n = strbreak(list, (char (*)[1500]) mail_list, 200, ",", FALSE); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("\n%s to %s\n\n", str, list); for (i = 0; i < n; i++) { @@ -23282,7 +23356,7 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i int size, i, j, n, n_done, n_done_reply, n_reply, index, status, fh, source_id, message_id, thumb_status, next_id = 0; char str[256], str2[256], file_name[MAX_PATH_LENGTH], thumb_name[MAX_PATH_LENGTH], - *attrib, date[80], *text, msg_str[32], in_reply_to[80], + *attrib, date[80], *text, msg_str[32], in_reply_to[80], subdir[256], reply_to[MAX_REPLY_TO * 10], *attachment, encoding[80], locked_by[256], *buffer, *list; LOGBOOK *lbs_dest; BOOL bedit; @@ -23358,6 +23432,8 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment[i * MAX_PATH_LENGTH]) { strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment + i * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment + i * MAX_PATH_LENGTH, sizeof(file_name)); fh = open(file_name, O_RDONLY | O_BINARY); @@ -23382,6 +23458,8 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i /* check for thumbnail */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment + i * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment + i * MAX_PATH_LENGTH, sizeof(file_name)); thumb_status = get_thumb_name(file_name, thumb_name, sizeof(thumb_name), 0); @@ -23615,9 +23693,9 @@ int create_thumbnail(LOGBOOK * lbs, char *file_name) strlcat(str, ".png", sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) - snprintf(cmd, sizeof(cmd), "convert %s '%s[0-7]'%s '%s'", thumb_options, file_name, thumb_size, str); + snprintf(cmd, sizeof(cmd), "%s %s '%s[0-7]'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); else - snprintf(cmd, sizeof(cmd), "convert %s '%s'%s '%s'", thumb_options, file_name, thumb_size, str); + snprintf(cmd, sizeof(cmd), "%s %s '%s'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) @@ -23627,7 +23705,7 @@ int create_thumbnail(LOGBOOK * lbs, char *file_name) snprintf(str, sizeof(str), "SHELL \"%s\"", cmd); write_logfile(lbs, str); - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf(str); eprintf("\n"); } @@ -23698,7 +23776,7 @@ int get_thumb_name(const char *file_name, char *thumb_name, int size, int index) void call_image_magick(LOGBOOK * lbs) { - char str[256], cmd[256], file_name[256], thumb_name[256]; + char str[256], cmd[256], file_name[256], thumb_name[256], subdir[256]; int cur_width, cur_height, new_size, cur_rot, new_rot, i, thumb_status; if (!isparam("req") || !isparam("img")) { @@ -23707,10 +23785,12 @@ void call_image_magick(LOGBOOK * lbs) } strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(getparam("img"), subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, getparam("img"), sizeof(file_name)); thumb_status = get_thumb_name(file_name, thumb_name, sizeof(thumb_name), 0); - sprintf(cmd, "identify -format '%%wx%%h %%c' '%s'", thumb_name); + sprintf(cmd, "%s -format '%%wx%%h %%c' '%s'", _identify_cmd, thumb_name); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) if (cmd[i] == '\'') @@ -23740,30 +23820,30 @@ void call_image_magick(LOGBOOK * lbs) i = cmd[0] = 0; if (strieq(getparam("req"), "rotleft")) { new_rot = (cur_rot + 360 - 90) % 360; - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, new_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, new_rot, cur_height, new_rot, thumb_name); } if (strieq(getparam("req"), "rotright")) { new_rot = (cur_rot + 90) % 360; - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, new_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, new_rot, cur_height, new_rot, thumb_name); } if (strieq(getparam("req"), "original")) { new_size = (int) (cur_width / 1.5); - sprintf(cmd, "convert '%s' '%s'", file_name, thumb_name); + sprintf(cmd, "%s '%s' '%s'", _convert_cmd, file_name, thumb_name); } if (strieq(getparam("req"), "smaller")) { new_size = (int) (cur_width / 1.5); - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, cur_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, cur_rot, new_size, cur_rot, thumb_name); } if (strieq(getparam("req"), "larger")) { new_size = (int) (cur_width * 1.5); - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, cur_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, cur_rot, new_size, cur_rot, thumb_name); } @@ -23794,7 +23874,7 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) format[80], slist[MAX_N_ATTR + 10][NAME_LENGTH], file_name[MAX_PATH_LENGTH], gattr[MAX_N_ATTR][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], *p, lbk_list[MAX_N_LIST][NAME_LENGTH], comment[256], class_name[80], class_value[80], - fl[8][NAME_LENGTH], list[MAX_N_ATTR][NAME_LENGTH], domain[256]; + fl[8][NAME_LENGTH], list[MAX_N_ATTR][NAME_LENGTH], domain[256], subdir[256]; FILE *f; BOOL first, show_text, display_inline, subtable, email; struct tm *pts; @@ -24601,6 +24681,8 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) /* determine size of attachment */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); thumb_status = create_thumbnail(lbs, file_name); @@ -24733,6 +24815,8 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) rsprintf("\n"); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); if (!att_hide[index] && display_inline) { @@ -26492,8 +26576,8 @@ void show_uploader_finished(LOGBOOK * lbs) void show_uploader_json(LOGBOOK *lbs) { char charset[256]; - char filename[256], thumbname[256], attchname[256]; - int i, j, attch_count; + char filename[256], thumbname[256], attchname[256], subdir[256]; + int i, j; // maximum number of files that can be uploaded this way (drag and drop into the editor) const long MAX_FILE_COUNT = 100; @@ -26502,7 +26586,7 @@ void show_uploader_json(LOGBOOK *lbs) rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision + 33); rsprintf("Accept-Ranges: bytes\r\n"); rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); if (keep_alive) { rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); @@ -26511,7 +26595,7 @@ void show_uploader_json(LOGBOOK *lbs) strcpy(charset, DEFAULT_HTTP_CHARSET); rsprintf("Content-Type: application/json;charset=%s\r\n\r\n", charset); - attch_count = strtol(getparam("drop-count"), NULL, 10); + long attch_count = strtol(getparam("drop-count"), NULL, 10); // limit the number of files that can be uploaded if(attch_count > MAX_FILE_COUNT) { @@ -26529,6 +26613,8 @@ void show_uploader_json(LOGBOOK *lbs) rsprintf(" \"fullName\": \"%s\",\r\n", getparam(attchname)); strlcpy(filename, lbs->data_dir, sizeof(filename)); + generate_subdir_name(getparam(attchname), subdir, sizeof(subdir)); + strlcat(filename, subdir, sizeof(filename)); strlcat(filename, getparam(attchname), sizeof(filename)); @@ -26587,7 +26673,7 @@ void interprete(char *lbook, char *path) edit_id[80], file_name[256], command[256], enc_path[256], dec_path[256], uname[80], full_name[256], user_email[256], logbook[256], logbook_enc[256], *experiment, group[256], css[256], *pfile, attachment[MAX_PATH_LENGTH], str3[NAME_LENGTH], - thumb_name[256], sid[32], error_str[256], *s; + thumb_name[256], sid[32], error_str[256], subdir[256]; LOGBOOK *lbs; FILE *f; @@ -26617,7 +26703,7 @@ void interprete(char *lbook, char *path) rsputs(loc(getparam("value"))); /* dummy strings for JS-only translations */ - s = loc("Drop attachments here..."); + char *s = loc("Drop attachments here..."); s = loc("Insert Timestamp"); if (s) s = NULL; // avoid compiler warning @@ -27155,6 +27241,8 @@ void interprete(char *lbook, char *path) pfile[13] = '_'; /* file from data directory requested */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(pfile, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, pfile, sizeof(file_name)); } else { /* file from theme directory requested */ @@ -27790,7 +27878,7 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /* set attachment filename */ strlcpy(file_name, p, sizeof(file_name)); if (file_name[0]) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("decode_post: Found CSV/XML import file\n"); } @@ -27851,7 +27939,7 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /* remove spaces */ btou(file_name); if (file_name[0]) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("decode_post: Found attachment %s\n", file_name); /* check filename for invalid characters */ if (strpbrk(file_name, ",;+=")) { @@ -27930,7 +28018,8 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b } } else if (file_name[0]) { /* save attachment */ - el_submit_attachment(lbs, file_name, string, (int) (p - string), full_name); + if (el_submit_attachment(lbs, file_name, string, (int) (p - string), full_name) < 0) + return; sprintf(str, "attachment%d", n_att++); setparam(str, full_name); } @@ -27999,8 +28088,8 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /*------------------------------------------------------------------*/ -#define N_MAX_CONNECTION 10 -#define KEEP_ALIVE_TIME 60 +#define N_MAX_CONNECTION 100 +#define KEEP_ALIVE_TIME 60 int ka_sock[N_MAX_CONNECTION]; int ka_time[N_MAX_CONNECTION]; @@ -28030,14 +28119,14 @@ int process_http_request(const char *request, int i_conn) if (!strchr(request, '\r')) return 0; - if (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { strlcpy(str, request, sizeof(str)); if (strchr(str, '\r')) *strchr(str, '\r') = 0; if (strchr(str, '\n')) *strchr(str, '\n') = 0; eputs(str); - } else if (is_verbose() > 1) { + } else if (get_verbose() >= VERBOSE_DEBUG) { eputs("\n"); eputs(request); } @@ -28391,7 +28480,7 @@ int process_http_request(const char *request, int i_conn) for (i = 0; i < n; i++) { if (strieq(rem_host, host_list[i]) || strieq(rem_host_ip, host_list[i]) || strieq(host_list[i], "all")) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", strieq(rem_host_ip, host_list[i]) ? rem_host_ip : rem_host, host_list[i]); authorized = 0; @@ -28400,7 +28489,7 @@ int process_http_request(const char *request, int i_conn) if (host_list[i][0] == '.') { if (strlen(rem_host) > strlen(host_list[i]) && strieq(host_list[i], rem_host + strlen(rem_host) - strlen(host_list[i]))) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", rem_host, host_list[i]); authorized = 0; @@ -28412,7 +28501,7 @@ int process_http_request(const char *request, int i_conn) if (strlen(str) > strlen(host_list[i])) str[strlen(host_list[i])] = 0; if (strieq(host_list[i], str)) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", rem_host_ip, host_list[i]); authorized = 0; @@ -28431,7 +28520,7 @@ int process_http_request(const char *request, int i_conn) for (i = 0; i < n; i++) { if (strieq(rem_host, host_list[i]) || strieq(rem_host_ip, host_list[i]) || strieq(host_list[i], "all")) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", strieq(rem_host_ip, host_list[i]) ? rem_host_ip : rem_host, host_list[i]); authorized = 1; @@ -28440,7 +28529,7 @@ int process_http_request(const char *request, int i_conn) if (host_list[i][0] == '.') { if (strlen(rem_host) > strlen(host_list[i]) && strieq(host_list[i], rem_host + strlen(rem_host) - strlen(host_list[i]))) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", rem_host, host_list[i]); authorized = 1; @@ -28452,7 +28541,7 @@ int process_http_request(const char *request, int i_conn) if (strlen(str) > strlen(host_list[i])) str[strlen(host_list[i])] = 0; if (strieq(host_list[i], str)) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", rem_host_ip, host_list[i]); authorized = 1; @@ -28590,9 +28679,9 @@ 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 (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { eprintf("Returned %d bytes\n", length); - } else if (is_verbose() == 2) { + } else if (get_verbose() >= VERBOSE_DEBUG) { if (strrchr(net_buffer, '/')) strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); else @@ -28601,7 +28690,7 @@ void send_return(int _sock, const char *net_buffer) eputs(header_buffer); 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); + eprintf("\n<%d bytes of \"%s\">\n\n", length, str); else eputs(p + 4); eprintf("\n"); @@ -28646,18 +28735,21 @@ void send_return(int _sock, const char *net_buffer) #endif } - if (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { eprintf("Returned %d bytes\n", return_length); - } else if (is_verbose() == 2) { + } else if (get_verbose() == VERBOSE_DEBUG) { if (strrchr(net_buffer, '/')) strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); else str[0] = 0; eprintf("==== Return ================================\n"); 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", return_length, str); - else + || chkext(net_buffer, ".ico") || chkext(net_buffer, ".pdf") || return_length > 10000) { + if (str[0]) + eprintf("\n<%d bytes of \"%s\">\r\n", return_length, str); + else + eprintf("\n<%d bytes>\r\n", return_length); + } else eputs(return_buffer); eprintf("\n\n"); } @@ -28853,7 +28945,7 @@ SSL_CTX *init_ssl(void) void server_loop(void) { - int status, i, n_error, broken, min, i_min, i_conn, more_requests; + int status, i, broken, min, i_min, i_conn, more_requests; char str[1000], logbook[256], logbook_enc[256]; char *pend; int lsock, len, flag, content_length, header_length; @@ -28978,7 +29070,7 @@ void server_loop(void) if (strchr(str, ' ')) *strchr(str, ' ') = 0; eprintf("revision %s\n", str); - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { getcwd(str, sizeof(str)); if (strchr(config_file, DIR_SEPARATOR) == NULL) eprintf("Config file : %s%c%s\n", str, DIR_SEPARATOR, config_file); @@ -29067,7 +29159,7 @@ void server_loop(void) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to group \"%s\"\n", str); if (!getcfg("global", "Usr", str, sizeof(str)) || seteuser(str) < 0) { @@ -29080,7 +29172,7 @@ void server_loop(void) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to user \"%s\".\n", str); } #endif @@ -29100,8 +29192,33 @@ void server_loop(void) eprintf("CKeditor NOT detected\n"); /* check for ImageMagick */ - my_shell("convert -version", str, sizeof(str)); + strlcpy(_convert_cmd, "convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); image_magick_exist = (strstr(str, "ImageMagick") != NULL); + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/usr/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/usr/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/usr/local/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/usr/local/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/opt/local/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/opt/local/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (image_magick_exist) eprintf("ImageMagick detected\n"); else @@ -29112,11 +29229,11 @@ void server_loop(void) eprintf("Keep-alive disabled\n"); /* build logbook indices */ - if (!is_verbose() && !running_as_daemon) + if (get_verbose() == 0 && !running_as_daemon) eprintf("Indexing logbooks ... "); if (el_index_logbooks() != EL_SUCCESS) exit(EXIT_FAILURE); - if (!is_verbose() && !running_as_daemon) + if (get_verbose() == 0 && !running_as_daemon) eputs("done"); #ifndef HAVE_KRB5 @@ -29186,7 +29303,7 @@ void server_loop(void) _ssl_con = SSL_new(ssl_ctx); SSL_set_fd(_ssl_con, _sock); if (SSL_accept(_ssl_con) < 0) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("SSL_accept failed\n"); closesocket(_sock); ka_sock[i_conn] = 0; @@ -29242,25 +29359,29 @@ void server_loop(void) strcpy(remote_host[i_conn], (char *) inet_ntoa(rem_addr)); strcpy(rem_host, remote_host[i_conn]); + + if (get_verbose() == VERBOSE_URL) + eprintf("Open connection #%d on socket %d\n", i, _sock); + + /* start over */ + continue; } - else { - /* check if open connection received data */ - for (i = 0; i < N_MAX_CONNECTION; i++) - if (ka_sock[i] > 0 && FD_ISSET(ka_sock[i], &readfds)) - break; - if (i == N_MAX_CONNECTION) { - _sock = 0; - } else { - i_conn = i; - _sock = ka_sock[i_conn]; + /* check if open connection received data */ + for (i = 0; i < N_MAX_CONNECTION; i++) + if (ka_sock[i] > 0 && FD_ISSET(ka_sock[i], &readfds)) + break; + if (i == N_MAX_CONNECTION) { + _sock = 0; + } else { + i_conn = i; + _sock = ka_sock[i_conn]; #ifdef HAVE_SSL - _ssl_con = ka_ssl_con[i_conn]; + _ssl_con = ka_ssl_con[i_conn]; #endif - ka_time[i_conn] = (int) time(NULL); - memcpy(&rem_addr, &remote_addr[i_conn], sizeof(rem_addr)); - strcpy(rem_host, remote_host[i_conn]); - } + ka_time[i_conn] = (int) time(NULL); + memcpy(&rem_addr, &remote_addr[i_conn], sizeof(rem_addr)); + strcpy(rem_host, remote_host[i_conn]); } /* turn off keep_alive by default */ @@ -29275,7 +29396,6 @@ void server_loop(void) do { /* pipleline loop */ header_length = 0; - n_error = 0; broken = FALSE; return_length = -1; do { @@ -29295,6 +29415,9 @@ void server_loop(void) #endif i = recv(_sock, net_buffer + len, net_buffer_size - len, 0); + if (get_verbose() == VERBOSE_URL) + eprintf("Connection #%d received %d bytes on socket %d\n", i_conn, i, _sock); + } else break; @@ -29303,6 +29426,12 @@ void server_loop(void) broken = TRUE; break; } + /* abort if connection has been closed */ + if (i == 0) { + broken = TRUE; + break; + } + if (i > 0) len += i; @@ -29321,16 +29450,6 @@ void server_loop(void) net_buffer_size += 100000; } - /* abort if 100x received zero bytes */ - if (i == 0) { - n_error++; - if (n_error == 100) { - broken = TRUE; - break; - } - continue; - } - /* repeat until empty line received (fragmented TCP packets!) */ } while (strstr(net_buffer, "\r\n\r\n") == 0); } @@ -29441,7 +29560,7 @@ void server_loop(void) return_length = -1; break; } else { - if (strlen(net_buffer) > 0 && is_verbose()) { + if (strlen(net_buffer) > 0 && get_verbose() >= VERBOSE_INFO) { strcpy(str, "Received unknown HTTP command: "); strencode2(str, net_buffer, sizeof(str)); show_error(str); @@ -29452,14 +29571,14 @@ void server_loop(void) } while (1); if (broken) { - if (is_verbose()) - eprintf("TCP connection broken\n"); + if (get_verbose() >= VERBOSE_URL) + eprintf("TCP connection #%d on socket %d closed\n", i_conn, _sock); keep_alive = FALSE; break; } if (strncmp(net_buffer, "POST", 4) == 0 && len < header_length + content_length) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Incomplete POST request\n"); keep_alive = FALSE; break; @@ -30131,10 +30250,11 @@ int main(int argc, char *argv[]) if (argv[i][0] == '-' && argv[i][1] == 'D') running_as_daemon = TRUE; else if (argv[i][0] == '-' && argv[i][1] == 'v') { - if (atoi(&argv[i][2]) > 0) - set_verbose(atoi(&argv[i][2])); - else - set_verbose(2); + if (i < argc-1 && atoi(argv[i+1]) > 0) { + set_verbose(atoi(argv[i+1])); + i++; + } else + set_verbose(VERBOSE_INFO); } else if (argv[i][0] == '-' && argv[i][1] == 'S') silent = TRUE; else if (argv[i][0] == '-' && argv[i][1] == 'k') @@ -30219,7 +30339,7 @@ int main(int argc, char *argv[]) printf(" -S be silent\n"); printf(" -s specify resource directory (themes, icons, ...)\n"); printf(" -t create/overwrite SMTP password in config file\n"); - printf(" -v debugging output\n"); + printf(" -v verbose output (1:URL, 2:INFO, 3:DEBUG)\n"); printf(" -x enable execution of shell commands\n\n"); #ifdef OS_WINNT printf("Windows service funtions:\n"); diff --git a/src/elogd.h b/src/elogd.h index e03b8ddf..ce4b06f6 100644 --- a/src/elogd.h +++ b/src/elogd.h @@ -229,6 +229,7 @@ long _timezone; typedef struct { int message_id; + char subdir[256]; char file_name[32]; time_t file_time; int offset; diff --git a/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout b/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout index bcc73204..61562469 100644 --- a/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout +++ b/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout @@ -13,10 +13,10 @@ 4A8AA611133AD3F7E07C7C33DCF50244FB7A1AB5 bitbucket.org:tmidas/mxml.git FDBEF18BB209C3ECA837D3C38A566472CB958C8E - https://bitbucket.org/ritt/elog.git + bitbucket.org:ritt/elog.git IDESourceControlProjectPath - xcode/elogd.xcodeproj/project.xcworkspace + xcode/elogd.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary 4A8AA611133AD3F7E07C7C33DCF50244FB7A1AB5 @@ -25,7 +25,7 @@ ../../.. IDESourceControlProjectURL - https://bitbucket.org/ritt/elog.git + bitbucket.org:ritt/elog.git IDESourceControlProjectVersion 111 IDESourceControlProjectWCCIdentifier
"); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); f = fopen(file_name, "rt"); @@ -21440,7 +21510,7 @@ void format_email_attachments(LOGBOOK * lbs, int message_id, int attachment_type char *multipart_boundary, int content_id) { int i, index, n_att, fh, n, is_inline, length; - char str[256], file_name[256], buffer[256], domain[256]; + char str[256], file_name[256], buffer[256], domain[256], subdir[256]; /* count attachments */ for (n_att = 0; att_file[n_att][0] && n_att < MAX_ATTACHMENTS; n_att++); @@ -21494,6 +21564,8 @@ void format_email_attachments(LOGBOOK * lbs, int message_id, int attachment_type /* encode file */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(att_file[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, att_file[index], sizeof(file_name)); if (is_image(file_name)) { get_thumb_name(file_name, str, sizeof(str), 0); @@ -22094,7 +22166,7 @@ int execute_shell(LOGBOOK * lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LE { int i; char slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH]; - char shell_cmd[10000], tail[1000], str[NAME_LENGTH], *p; + char shell_cmd[10000], tail[1000], str[NAME_LENGTH], *p, subdir[256]; if (!enable_execute) { eprintf("Shell execution not enabled via -x flag.\n"); @@ -22115,10 +22187,12 @@ int execute_shell(LOGBOOK * lbs, int message_id, char attrib[MAX_N_ATTR][NAME_LE strlcpy(tail, p + strlen("$attachments"), sizeof(tail)); *p = 0; for (i = 0; i < MAX_ATTACHMENTS; i++) - if (att_file[i][0] && strlen(shell_cmd) + strlen(lbs->data_dir) + strlen(att_file[i]) + generate_subdir_name(att_file[i], subdir, sizeof(subdir)); + if (att_file[i][0] && strlen(shell_cmd) + strlen(lbs->data_dir) + strlen(subdir) + strlen(att_file[i]) < sizeof(shell_cmd) + 1) { strcpy(p, "\""); strcat(p, lbs->data_dir); + strlcat(str, subdir, sizeof(str)); strlcpy(str, att_file[i], sizeof(str)); str_escape(str, sizeof(str)); strcat(p, str); @@ -23048,7 +23122,7 @@ void submit_elog(LOGBOOK * lbs) n = strbreak(list, (char (*)[1500]) mail_list, 200, ",", FALSE); - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("\n%s to %s\n\n", str, list); for (i = 0; i < n; i++) { @@ -23282,7 +23356,7 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i int size, i, j, n, n_done, n_done_reply, n_reply, index, status, fh, source_id, message_id, thumb_status, next_id = 0; char str[256], str2[256], file_name[MAX_PATH_LENGTH], thumb_name[MAX_PATH_LENGTH], - *attrib, date[80], *text, msg_str[32], in_reply_to[80], + *attrib, date[80], *text, msg_str[32], in_reply_to[80], subdir[256], reply_to[MAX_REPLY_TO * 10], *attachment, encoding[80], locked_by[256], *buffer, *list; LOGBOOK *lbs_dest; BOOL bedit; @@ -23358,6 +23432,8 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i for (i = 0; i < MAX_ATTACHMENTS; i++) if (attachment[i * MAX_PATH_LENGTH]) { strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment + i * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment + i * MAX_PATH_LENGTH, sizeof(file_name)); fh = open(file_name, O_RDONLY | O_BINARY); @@ -23382,6 +23458,8 @@ void copy_to(LOGBOOK * lbs, int src_id, char *dest_logbook, int move, int orig_i /* check for thumbnail */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment + i * MAX_PATH_LENGTH, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment + i * MAX_PATH_LENGTH, sizeof(file_name)); thumb_status = get_thumb_name(file_name, thumb_name, sizeof(thumb_name), 0); @@ -23615,9 +23693,9 @@ int create_thumbnail(LOGBOOK * lbs, char *file_name) strlcat(str, ".png", sizeof(str)); if (chkext(file_name, ".pdf") || chkext(file_name, ".ps")) - snprintf(cmd, sizeof(cmd), "convert %s '%s[0-7]'%s '%s'", thumb_options, file_name, thumb_size, str); + snprintf(cmd, sizeof(cmd), "%s %s '%s[0-7]'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); else - snprintf(cmd, sizeof(cmd), "convert %s '%s'%s '%s'", thumb_options, file_name, thumb_size, str); + snprintf(cmd, sizeof(cmd), "%s %s '%s'%s '%s'", _convert_cmd, thumb_options, file_name, thumb_size, str); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) @@ -23627,7 +23705,7 @@ int create_thumbnail(LOGBOOK * lbs, char *file_name) snprintf(str, sizeof(str), "SHELL \"%s\"", cmd); write_logfile(lbs, str); - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { eprintf(str); eprintf("\n"); } @@ -23698,7 +23776,7 @@ int get_thumb_name(const char *file_name, char *thumb_name, int size, int index) void call_image_magick(LOGBOOK * lbs) { - char str[256], cmd[256], file_name[256], thumb_name[256]; + char str[256], cmd[256], file_name[256], thumb_name[256], subdir[256]; int cur_width, cur_height, new_size, cur_rot, new_rot, i, thumb_status; if (!isparam("req") || !isparam("img")) { @@ -23707,10 +23785,12 @@ void call_image_magick(LOGBOOK * lbs) } strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(getparam("img"), subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, getparam("img"), sizeof(file_name)); thumb_status = get_thumb_name(file_name, thumb_name, sizeof(thumb_name), 0); - sprintf(cmd, "identify -format '%%wx%%h %%c' '%s'", thumb_name); + sprintf(cmd, "%s -format '%%wx%%h %%c' '%s'", _identify_cmd, thumb_name); #ifdef OS_WINNT for (i = 0; i < (int) strlen(cmd); i++) if (cmd[i] == '\'') @@ -23740,30 +23820,30 @@ void call_image_magick(LOGBOOK * lbs) i = cmd[0] = 0; if (strieq(getparam("req"), "rotleft")) { new_rot = (cur_rot + 360 - 90) % 360; - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, new_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, new_rot, cur_height, new_rot, thumb_name); } if (strieq(getparam("req"), "rotright")) { new_rot = (cur_rot + 90) % 360; - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, new_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, new_rot, cur_height, new_rot, thumb_name); } if (strieq(getparam("req"), "original")) { new_size = (int) (cur_width / 1.5); - sprintf(cmd, "convert '%s' '%s'", file_name, thumb_name); + sprintf(cmd, "%s '%s' '%s'", _convert_cmd, file_name, thumb_name); } if (strieq(getparam("req"), "smaller")) { new_size = (int) (cur_width / 1.5); - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, cur_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, cur_rot, new_size, cur_rot, thumb_name); } if (strieq(getparam("req"), "larger")) { new_size = (int) (cur_width * 1.5); - sprintf(cmd, "convert '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", file_name, cur_rot, + sprintf(cmd, "%s '%s' -rotate %d -thumbnail %d -set comment ' %d' '%s'", _convert_cmd, file_name, cur_rot, new_size, cur_rot, thumb_name); } @@ -23794,7 +23874,7 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) format[80], slist[MAX_N_ATTR + 10][NAME_LENGTH], file_name[MAX_PATH_LENGTH], gattr[MAX_N_ATTR][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], *p, lbk_list[MAX_N_LIST][NAME_LENGTH], comment[256], class_name[80], class_value[80], - fl[8][NAME_LENGTH], list[MAX_N_ATTR][NAME_LENGTH], domain[256]; + fl[8][NAME_LENGTH], list[MAX_N_ATTR][NAME_LENGTH], domain[256], subdir[256]; FILE *f; BOOL first, show_text, display_inline, subtable, email; struct tm *pts; @@ -24601,6 +24681,8 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) /* determine size of attachment */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); thumb_status = create_thumbnail(lbs, file_name); @@ -24733,6 +24815,8 @@ void show_elog_entry(LOGBOOK * lbs, char *dec_path, char *command) rsprintf("\n"); strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(attachment[index], subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, attachment[index], sizeof(file_name)); if (!att_hide[index] && display_inline) { @@ -26492,8 +26576,8 @@ void show_uploader_finished(LOGBOOK * lbs) void show_uploader_json(LOGBOOK *lbs) { char charset[256]; - char filename[256], thumbname[256], attchname[256]; - int i, j, attch_count; + char filename[256], thumbname[256], attchname[256], subdir[256]; + int i, j; // maximum number of files that can be uploaded this way (drag and drop into the editor) const long MAX_FILE_COUNT = 100; @@ -26502,7 +26586,7 @@ void show_uploader_json(LOGBOOK *lbs) rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision + 33); rsprintf("Accept-Ranges: bytes\r\n"); rsprintf("Pragma: no-cache\r\n"); - rsprintf("Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n"); + rsprintf("Cache-control: private, max-age=0, no-cache, no-store\r\n"); if (keep_alive) { rsprintf("Connection: Keep-Alive\r\n"); rsprintf("Keep-Alive: timeout=60, max=10\r\n"); @@ -26511,7 +26595,7 @@ void show_uploader_json(LOGBOOK *lbs) strcpy(charset, DEFAULT_HTTP_CHARSET); rsprintf("Content-Type: application/json;charset=%s\r\n\r\n", charset); - attch_count = strtol(getparam("drop-count"), NULL, 10); + long attch_count = strtol(getparam("drop-count"), NULL, 10); // limit the number of files that can be uploaded if(attch_count > MAX_FILE_COUNT) { @@ -26529,6 +26613,8 @@ void show_uploader_json(LOGBOOK *lbs) rsprintf(" \"fullName\": \"%s\",\r\n", getparam(attchname)); strlcpy(filename, lbs->data_dir, sizeof(filename)); + generate_subdir_name(getparam(attchname), subdir, sizeof(subdir)); + strlcat(filename, subdir, sizeof(filename)); strlcat(filename, getparam(attchname), sizeof(filename)); @@ -26587,7 +26673,7 @@ void interprete(char *lbook, char *path) edit_id[80], file_name[256], command[256], enc_path[256], dec_path[256], uname[80], full_name[256], user_email[256], logbook[256], logbook_enc[256], *experiment, group[256], css[256], *pfile, attachment[MAX_PATH_LENGTH], str3[NAME_LENGTH], - thumb_name[256], sid[32], error_str[256], *s; + thumb_name[256], sid[32], error_str[256], subdir[256]; LOGBOOK *lbs; FILE *f; @@ -26617,7 +26703,7 @@ void interprete(char *lbook, char *path) rsputs(loc(getparam("value"))); /* dummy strings for JS-only translations */ - s = loc("Drop attachments here..."); + char *s = loc("Drop attachments here..."); s = loc("Insert Timestamp"); if (s) s = NULL; // avoid compiler warning @@ -27155,6 +27241,8 @@ void interprete(char *lbook, char *path) pfile[13] = '_'; /* file from data directory requested */ strlcpy(file_name, lbs->data_dir, sizeof(file_name)); + generate_subdir_name(pfile, subdir, sizeof(subdir)); + strlcat(file_name, subdir, sizeof(file_name)); strlcat(file_name, pfile, sizeof(file_name)); } else { /* file from theme directory requested */ @@ -27790,7 +27878,7 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /* set attachment filename */ strlcpy(file_name, p, sizeof(file_name)); if (file_name[0]) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("decode_post: Found CSV/XML import file\n"); } @@ -27851,7 +27939,7 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /* remove spaces */ btou(file_name); if (file_name[0]) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("decode_post: Found attachment %s\n", file_name); /* check filename for invalid characters */ if (strpbrk(file_name, ",;+=")) { @@ -27930,7 +28018,8 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b } } else if (file_name[0]) { /* save attachment */ - el_submit_attachment(lbs, file_name, string, (int) (p - string), full_name); + if (el_submit_attachment(lbs, file_name, string, (int) (p - string), full_name) < 0) + return; sprintf(str, "attachment%d", n_att++); setparam(str, full_name); } @@ -27999,8 +28088,8 @@ void decode_post(char *logbook, LOGBOOK * lbs, const char *string, const char *b /*------------------------------------------------------------------*/ -#define N_MAX_CONNECTION 10 -#define KEEP_ALIVE_TIME 60 +#define N_MAX_CONNECTION 100 +#define KEEP_ALIVE_TIME 60 int ka_sock[N_MAX_CONNECTION]; int ka_time[N_MAX_CONNECTION]; @@ -28030,14 +28119,14 @@ int process_http_request(const char *request, int i_conn) if (!strchr(request, '\r')) return 0; - if (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { strlcpy(str, request, sizeof(str)); if (strchr(str, '\r')) *strchr(str, '\r') = 0; if (strchr(str, '\n')) *strchr(str, '\n') = 0; eputs(str); - } else if (is_verbose() > 1) { + } else if (get_verbose() >= VERBOSE_DEBUG) { eputs("\n"); eputs(request); } @@ -28391,7 +28480,7 @@ int process_http_request(const char *request, int i_conn) for (i = 0; i < n; i++) { if (strieq(rem_host, host_list[i]) || strieq(rem_host_ip, host_list[i]) || strieq(host_list[i], "all")) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", strieq(rem_host_ip, host_list[i]) ? rem_host_ip : rem_host, host_list[i]); authorized = 0; @@ -28400,7 +28489,7 @@ int process_http_request(const char *request, int i_conn) if (host_list[i][0] == '.') { if (strlen(rem_host) > strlen(host_list[i]) && strieq(host_list[i], rem_host + strlen(rem_host) - strlen(host_list[i]))) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", rem_host, host_list[i]); authorized = 0; @@ -28412,7 +28501,7 @@ int process_http_request(const char *request, int i_conn) if (strlen(str) > strlen(host_list[i])) str[strlen(host_list[i])] = 0; if (strieq(host_list[i], str)) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts deny\". Access denied.\n", rem_host_ip, host_list[i]); authorized = 0; @@ -28431,7 +28520,7 @@ int process_http_request(const char *request, int i_conn) for (i = 0; i < n; i++) { if (strieq(rem_host, host_list[i]) || strieq(rem_host_ip, host_list[i]) || strieq(host_list[i], "all")) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", strieq(rem_host_ip, host_list[i]) ? rem_host_ip : rem_host, host_list[i]); authorized = 1; @@ -28440,7 +28529,7 @@ int process_http_request(const char *request, int i_conn) if (host_list[i][0] == '.') { if (strlen(rem_host) > strlen(host_list[i]) && strieq(host_list[i], rem_host + strlen(rem_host) - strlen(host_list[i]))) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", rem_host, host_list[i]); authorized = 1; @@ -28452,7 +28541,7 @@ int process_http_request(const char *request, int i_conn) if (strlen(str) > strlen(host_list[i])) str[strlen(host_list[i])] = 0; if (strieq(host_list[i], str)) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Remote host \"%s\" matches \"%s\" in \"Hosts allow\". Access granted.\n", rem_host_ip, host_list[i]); authorized = 1; @@ -28590,9 +28679,9 @@ 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 (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { eprintf("Returned %d bytes\n", length); - } else if (is_verbose() == 2) { + } else if (get_verbose() >= VERBOSE_DEBUG) { if (strrchr(net_buffer, '/')) strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); else @@ -28601,7 +28690,7 @@ void send_return(int _sock, const char *net_buffer) eputs(header_buffer); 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); + eprintf("\n<%d bytes of \"%s\">\n\n", length, str); else eputs(p + 4); eprintf("\n"); @@ -28646,18 +28735,21 @@ void send_return(int _sock, const char *net_buffer) #endif } - if (is_verbose() == 1) { + if (get_verbose() < VERBOSE_DEBUG) { eprintf("Returned %d bytes\n", return_length); - } else if (is_verbose() == 2) { + } else if (get_verbose() == VERBOSE_DEBUG) { if (strrchr(net_buffer, '/')) strlcpy(str, strrchr(net_buffer, '/') + 1, sizeof(str)); else str[0] = 0; eprintf("==== Return ================================\n"); 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", return_length, str); - else + || chkext(net_buffer, ".ico") || chkext(net_buffer, ".pdf") || return_length > 10000) { + if (str[0]) + eprintf("\n<%d bytes of \"%s\">\r\n", return_length, str); + else + eprintf("\n<%d bytes>\r\n", return_length); + } else eputs(return_buffer); eprintf("\n\n"); } @@ -28853,7 +28945,7 @@ SSL_CTX *init_ssl(void) void server_loop(void) { - int status, i, n_error, broken, min, i_min, i_conn, more_requests; + int status, i, broken, min, i_min, i_conn, more_requests; char str[1000], logbook[256], logbook_enc[256]; char *pend; int lsock, len, flag, content_length, header_length; @@ -28978,7 +29070,7 @@ void server_loop(void) if (strchr(str, ' ')) *strchr(str, ' ') = 0; eprintf("revision %s\n", str); - if (is_verbose()) { + if (get_verbose() >= VERBOSE_INFO) { getcwd(str, sizeof(str)); if (strchr(config_file, DIR_SEPARATOR) == NULL) eprintf("Config file : %s%c%s\n", str, DIR_SEPARATOR, config_file); @@ -29067,7 +29159,7 @@ void server_loop(void) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to group \"%s\"\n", str); if (!getcfg("global", "Usr", str, sizeof(str)) || seteuser(str) < 0) { @@ -29080,7 +29172,7 @@ void server_loop(void) exit(EXIT_FAILURE); } } - } else if (is_verbose()) + } else if (get_verbose() >= VERBOSE_INFO) eprintf("Falling back to user \"%s\".\n", str); } #endif @@ -29100,8 +29192,33 @@ void server_loop(void) eprintf("CKeditor NOT detected\n"); /* check for ImageMagick */ - my_shell("convert -version", str, sizeof(str)); + strlcpy(_convert_cmd, "convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); image_magick_exist = (strstr(str, "ImageMagick") != NULL); + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/usr/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/usr/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/usr/local/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/usr/local/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (!image_magick_exist) { + strlcpy(_convert_cmd, "/opt/local/bin/convert", sizeof(_convert_cmd)); + strlcpy(_identify_cmd, "/opt/local/bin/identify", sizeof(_convert_cmd)); + sprintf(str, "%s -version", _convert_cmd); + my_shell(str, str, sizeof(str)); + image_magick_exist = (strstr(str, "ImageMagick") != NULL); + } + if (image_magick_exist) eprintf("ImageMagick detected\n"); else @@ -29112,11 +29229,11 @@ void server_loop(void) eprintf("Keep-alive disabled\n"); /* build logbook indices */ - if (!is_verbose() && !running_as_daemon) + if (get_verbose() == 0 && !running_as_daemon) eprintf("Indexing logbooks ... "); if (el_index_logbooks() != EL_SUCCESS) exit(EXIT_FAILURE); - if (!is_verbose() && !running_as_daemon) + if (get_verbose() == 0 && !running_as_daemon) eputs("done"); #ifndef HAVE_KRB5 @@ -29186,7 +29303,7 @@ void server_loop(void) _ssl_con = SSL_new(ssl_ctx); SSL_set_fd(_ssl_con, _sock); if (SSL_accept(_ssl_con) < 0) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("SSL_accept failed\n"); closesocket(_sock); ka_sock[i_conn] = 0; @@ -29242,25 +29359,29 @@ void server_loop(void) strcpy(remote_host[i_conn], (char *) inet_ntoa(rem_addr)); strcpy(rem_host, remote_host[i_conn]); + + if (get_verbose() == VERBOSE_URL) + eprintf("Open connection #%d on socket %d\n", i, _sock); + + /* start over */ + continue; } - else { - /* check if open connection received data */ - for (i = 0; i < N_MAX_CONNECTION; i++) - if (ka_sock[i] > 0 && FD_ISSET(ka_sock[i], &readfds)) - break; - if (i == N_MAX_CONNECTION) { - _sock = 0; - } else { - i_conn = i; - _sock = ka_sock[i_conn]; + /* check if open connection received data */ + for (i = 0; i < N_MAX_CONNECTION; i++) + if (ka_sock[i] > 0 && FD_ISSET(ka_sock[i], &readfds)) + break; + if (i == N_MAX_CONNECTION) { + _sock = 0; + } else { + i_conn = i; + _sock = ka_sock[i_conn]; #ifdef HAVE_SSL - _ssl_con = ka_ssl_con[i_conn]; + _ssl_con = ka_ssl_con[i_conn]; #endif - ka_time[i_conn] = (int) time(NULL); - memcpy(&rem_addr, &remote_addr[i_conn], sizeof(rem_addr)); - strcpy(rem_host, remote_host[i_conn]); - } + ka_time[i_conn] = (int) time(NULL); + memcpy(&rem_addr, &remote_addr[i_conn], sizeof(rem_addr)); + strcpy(rem_host, remote_host[i_conn]); } /* turn off keep_alive by default */ @@ -29275,7 +29396,6 @@ void server_loop(void) do { /* pipleline loop */ header_length = 0; - n_error = 0; broken = FALSE; return_length = -1; do { @@ -29295,6 +29415,9 @@ void server_loop(void) #endif i = recv(_sock, net_buffer + len, net_buffer_size - len, 0); + if (get_verbose() == VERBOSE_URL) + eprintf("Connection #%d received %d bytes on socket %d\n", i_conn, i, _sock); + } else break; @@ -29303,6 +29426,12 @@ void server_loop(void) broken = TRUE; break; } + /* abort if connection has been closed */ + if (i == 0) { + broken = TRUE; + break; + } + if (i > 0) len += i; @@ -29321,16 +29450,6 @@ void server_loop(void) net_buffer_size += 100000; } - /* abort if 100x received zero bytes */ - if (i == 0) { - n_error++; - if (n_error == 100) { - broken = TRUE; - break; - } - continue; - } - /* repeat until empty line received (fragmented TCP packets!) */ } while (strstr(net_buffer, "\r\n\r\n") == 0); } @@ -29441,7 +29560,7 @@ void server_loop(void) return_length = -1; break; } else { - if (strlen(net_buffer) > 0 && is_verbose()) { + if (strlen(net_buffer) > 0 && get_verbose() >= VERBOSE_INFO) { strcpy(str, "Received unknown HTTP command: "); strencode2(str, net_buffer, sizeof(str)); show_error(str); @@ -29452,14 +29571,14 @@ void server_loop(void) } while (1); if (broken) { - if (is_verbose()) - eprintf("TCP connection broken\n"); + if (get_verbose() >= VERBOSE_URL) + eprintf("TCP connection #%d on socket %d closed\n", i_conn, _sock); keep_alive = FALSE; break; } if (strncmp(net_buffer, "POST", 4) == 0 && len < header_length + content_length) { - if (is_verbose()) + if (get_verbose() >= VERBOSE_INFO) eprintf("Incomplete POST request\n"); keep_alive = FALSE; break; @@ -30131,10 +30250,11 @@ int main(int argc, char *argv[]) if (argv[i][0] == '-' && argv[i][1] == 'D') running_as_daemon = TRUE; else if (argv[i][0] == '-' && argv[i][1] == 'v') { - if (atoi(&argv[i][2]) > 0) - set_verbose(atoi(&argv[i][2])); - else - set_verbose(2); + if (i < argc-1 && atoi(argv[i+1]) > 0) { + set_verbose(atoi(argv[i+1])); + i++; + } else + set_verbose(VERBOSE_INFO); } else if (argv[i][0] == '-' && argv[i][1] == 'S') silent = TRUE; else if (argv[i][0] == '-' && argv[i][1] == 'k') @@ -30219,7 +30339,7 @@ int main(int argc, char *argv[]) printf(" -S be silent\n"); printf(" -s specify resource directory (themes, icons, ...)\n"); printf(" -t create/overwrite SMTP password in config file\n"); - printf(" -v debugging output\n"); + printf(" -v verbose output (1:URL, 2:INFO, 3:DEBUG)\n"); printf(" -x enable execution of shell commands\n\n"); #ifdef OS_WINNT printf("Windows service funtions:\n"); diff --git a/src/elogd.h b/src/elogd.h index e03b8ddf..ce4b06f6 100644 --- a/src/elogd.h +++ b/src/elogd.h @@ -229,6 +229,7 @@ long _timezone; typedef struct { int message_id; + char subdir[256]; char file_name[32]; time_t file_time; int offset; diff --git a/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout b/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout index bcc73204..61562469 100644 --- a/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout +++ b/xcode/elogd.xcodeproj/project.xcworkspace/xcshareddata/elogd.xccheckout @@ -13,10 +13,10 @@ 4A8AA611133AD3F7E07C7C33DCF50244FB7A1AB5 bitbucket.org:tmidas/mxml.git FDBEF18BB209C3ECA837D3C38A566472CB958C8E - https://bitbucket.org/ritt/elog.git + bitbucket.org:ritt/elog.git IDESourceControlProjectPath - xcode/elogd.xcodeproj/project.xcworkspace + xcode/elogd.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary 4A8AA611133AD3F7E07C7C33DCF50244FB7A1AB5 @@ -25,7 +25,7 @@ ../../.. IDESourceControlProjectURL - https://bitbucket.org/ritt/elog.git + bitbucket.org:ritt/elog.git IDESourceControlProjectVersion 111 IDESourceControlProjectWCCIdentifier