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("