Added IE javascript

SVN revision: 1378
This commit is contained in:
Stefan Ritt 2005-05-17 11:08:48 +00:00
parent e83df08c91
commit bfda8f78cc

View File

@ -6,6 +6,9 @@
Contents: Web server program for Electronic Logbook ELOG Contents: Web server program for Electronic Logbook ELOG
$Log$ $Log$
Revision 1.664 2005/05/17 11:08:48 ritt
Added IE javascript
Revision 1.663 2005/05/17 07:02:46 ritt Revision 1.663 2005/05/17 07:02:46 ritt
Changed 'set current time' to 'insert current time' Changed 'set current time' to 'insert current time'
@ -2620,7 +2623,7 @@ INT sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to,
char *str, *p, boundary[256], file_name[MAX_PATH_LENGTH]; char *str, *p, boundary[256], file_name[MAX_PATH_LENGTH];
time_t now; time_t now;
struct tm *ts; struct tm *ts;
char list[1024][NAME_LENGTH], buffer[256], charset[256], subject_enc[2000]; char list[1024][NAME_LENGTH], buffer[256], charset[256], subject_enc[2000], decoded[256];
memset(error, 0, error_size); memset(error, 0, error_size);
@ -2673,17 +2676,89 @@ INT sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to,
write_logfile(lbs, str); write_logfile(lbs, str);
} while (str[0]); } while (str[0]);
snprintf(str, strsize - 1, "HELO %s\r\n", host_name); if (getcfg(lbs->name, "SMTP username", str, strsize)) {
send(s, str, strlen(str), 0);
if (verbose) snprintf(str, strsize - 1, "EHLO %s\r\n", host_name);
efputs(str); send(s, str, strlen(str), 0);
write_logfile(lbs, str); if (verbose)
recv_string(s, str, strsize, 3000); efputs(str);
if (verbose) write_logfile(lbs, str);
efputs(str);
write_logfile(lbs, str); do {
if (!check_smtp_error(str, 250, error, error_size)) recv_string(s, str, strsize, 3000);
goto smtp_error; if (verbose)
efputs(str);
write_logfile(lbs, str);
if (!check_smtp_error(str, 250, error, error_size))
goto smtp_error;
} while (stristr(str, " OK") == NULL);
} else {
snprintf(str, strsize - 1, "HELO %s\r\n", host_name);
send(s, str, strlen(str), 0);
if (verbose)
efputs(str);
write_logfile(lbs, str);
recv_string(s, str, strsize, 3000);
if (verbose)
efputs(str);
write_logfile(lbs, str);
if (!check_smtp_error(str, 250, error, error_size))
goto smtp_error;
}
/* optional authentication */
if (getcfg(lbs->name, "SMTP username", str, strsize)) {
snprintf(str, strsize - 1, "AUTH LOGIN\r\n");
send(s, str, strlen(str), 0);
if (verbose)
efputs(str);
write_logfile(lbs, str);
recv_string(s, str, strsize, 3000);
if (strchr(str, '\r'))
*strchr(str, '\r') = 0;
base64_decode(str+4, decoded);
strcat(decoded, "\n");
if (verbose)
efputs(decoded);
write_logfile(lbs, decoded);
if (!check_smtp_error(str, 334, error, error_size))
goto smtp_error;
getcfg(lbs->name, "SMTP username", decoded, sizeof(decoded));
base64_encode(decoded, str);
strcat(str, "\r\n");
send(s, str, strlen(str), 0);
if (verbose)
efputs(str);
write_logfile(lbs, str);
recv_string(s, str, strsize, 3000);
if (strchr(str, '\r'))
*strchr(str, '\r') = 0;
base64_decode(str+4, decoded);
strcat(decoded, "\n");
if (verbose)
efputs(decoded);
write_logfile(lbs, decoded);
if (!check_smtp_error(str, 334, error, error_size))
goto smtp_error;
getcfg(lbs->name, "SMTP password", str, strsize);
strcat(str, "\r\n");
send(s, str, strlen(str), 0);
if (verbose)
efputs(str);
write_logfile(lbs, str);
recv_string(s, str, strsize, 3000);
if (verbose)
efputs(str);
write_logfile(lbs, str);
if (!check_smtp_error(str, 235, error, error_size))
goto smtp_error;
}
snprintf(str, strsize - 1, "MAIL FROM: %s\r\n", from); snprintf(str, strsize - 1, "MAIL FROM: %s\r\n", from);
send(s, str, strlen(str), 0); send(s, str, strlen(str), 0);
@ -8951,38 +9026,81 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL
/* elcode() gets called by selecting ELCode buttons */ /* elcode() gets called by selecting ELCode buttons */
rsprintf("function elcode(text, tag, value) \n"); if (stristr(browser, "MSIE") && !stristr(browser, "opera")) { /* Internet Explorer */
rsprintf("{ \n"); rsprintf("function elcode(text, tag, value) \n");
rsprintf(" var selection = ''; \n"); rsprintf("{ \n");
rsprintf(" var str; \n"); rsprintf(" text.focus(); \n");
rsprintf(" \n"); rsprintf(" sel = document.selection; \n");
rsprintf(" selection = text.value.substring(text.selectionStart, text.selectionEnd); \n"); rsprintf(" rng = sel.createRange(); \n");
rsprintf(" if (tag == '') \n"); rsprintf(" rng.colapse; \n");
rsprintf(" str = selection + value; \n"); rsprintf(" \n");
rsprintf(" else if (value == '') \n"); rsprintf(" is_range = rng.text.length > 0; \n");
rsprintf(" str = '[' + tag + ']' + selection + '[/' + tag + ']'; \n"); rsprintf(" if (tag == '') \n");
rsprintf(" else \n"); rsprintf(" str = rng.text + value; \n");
rsprintf(" str = '[' + tag + '=' + value + ']' + selection + '[/' + tag + ']'; \n"); rsprintf(" else if (value == '') \n");
rsprintf(" \n"); rsprintf(" str = '[' + tag + ']' + rng.text + '[/' + tag + ']'; \n");
rsprintf(" start = text.selectionStart; \n"); rsprintf(" else \n");
rsprintf(" end = text.textLength; \n"); rsprintf(" str = '[' + tag + '=' + value + ']' + rng.text + '[/' + tag + ']'; \n");
rsprintf(" endtext = text.value.substring(text.selectionEnd, end); \n"); rsprintf(" \n");
rsprintf(" starttext = text.value.substring(0, start); \n"); rsprintf(" rng.text = str; \n");
rsprintf(" text.value = starttext + str + endtext; \n"); rsprintf(" if (!is_range) { \n");
rsprintf(" if (selection.length > 0) { \n"); rsprintf(" rng.moveStart('character', -tag.length-3); \n");
rsprintf(" text.selectionStart = start; \n"); rsprintf(" rng.moveEnd('character', -tag.length-3); \n");
rsprintf(" text.selectionEnd = text.selectionStart + str.length; \n"); rsprintf(" rng.select(); \n");
rsprintf(" } else { \n"); rsprintf(" } \n");
rsprintf(" if (tag == '') \n"); rsprintf(" \n");
rsprintf(" text.selectionStart = start + value.length; \n"); rsprintf(" text.focus(); \n");
rsprintf(" else \n"); rsprintf("} \n");
rsprintf(" text.selectionStart = start + tag.length + 2; \n"); } else if (stristr(browser, "Mozilla") && !stristr(browser, "opera") && !stristr(browser, "konqueror")) {
rsprintf(" text.selectionEnd = text.selectionStart; \n"); /* mozilla, firefox, netscape */
rsprintf(" } \n"); rsprintf("function elcode(text, tag, value) \n");
rsprintf(" \n"); rsprintf("{ \n");
rsprintf(" text.focus(); \n"); rsprintf(" var selection = ''; \n");
rsprintf("} \n"); rsprintf(" var str; \n");
rsprintf(" \n");
rsprintf(" selection = text.value.substring(text.selectionStart, text.selectionEnd); \n");
rsprintf(" \n");
rsprintf(" if (tag == '') \n");
rsprintf(" str = selection + value; \n");
rsprintf(" else if (value == '') \n");
rsprintf(" str = '[' + tag + ']' + selection + '[/' + tag + ']'; \n");
rsprintf(" else \n");
rsprintf(" str = '[' + tag + '=' + value + ']' + selection + '[/' + tag + ']'; \n");
rsprintf(" \n");
rsprintf(" start = text.selectionStart; \n");
rsprintf(" end = text.textLength; \n");
rsprintf(" endtext = text.value.substring(text.selectionEnd, end); \n");
rsprintf(" starttext = text.value.substring(0, start); \n");
rsprintf(" text.value = starttext + str + endtext; \n");
rsprintf(" if (selection.length > 0) { \n");
rsprintf(" text.selectionStart = start; \n");
rsprintf(" text.selectionEnd = text.selectionStart + str.length; \n");
rsprintf(" } else { \n");
rsprintf(" if (tag == '') \n");
rsprintf(" text.selectionStart = start + value.length; \n");
rsprintf(" else \n");
rsprintf(" text.selectionStart = start + tag.length + 2; \n");
rsprintf(" text.selectionEnd = text.selectionStart; \n");
rsprintf(" } \n");
rsprintf(" \n");
rsprintf(" text.focus(); \n");
rsprintf("} \n");
} else {
rsprintf("function elcode(text, tag, value) \n");
rsprintf("{ \n");
rsprintf(" var str; \n");
rsprintf(" \n");
rsprintf(" if (tag == '') \n");
rsprintf(" str = value; \n");
rsprintf(" else if (value == '') \n");
rsprintf(" str = '[' + tag + ']' + '[/' + tag + ']'; \n");
rsprintf(" else \n");
rsprintf(" str = '[' + tag + '=' + value + ']' + '[/' + tag + ']'; \n");
rsprintf(" \n");
rsprintf(" text.value += str; \n");
rsprintf(" text.focus(); \n");
rsprintf("} \n");
}
rsprintf("//-->\n"); rsprintf("//-->\n");
rsprintf("</script>\n\n"); rsprintf("</script>\n\n");
@ -23263,7 +23381,7 @@ void create_password(char *logbook, char *name, char *pwd)
eprintf("Cannot create \"%s\".\n", config_file); eprintf("Cannot create \"%s\".\n", config_file);
return; return;
} }
sprintf(str, "[%s]\n%s=%s\n", logbook, name, pwd); sprintf(str, "[%s]\n%s = %s\n", logbook, name, pwd);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
close(fh); close(fh);
eprintf("File \"%s\" created with password in logbook \"%s\".\n", config_file, logbook); eprintf("File \"%s\" created with password in logbook \"%s\".\n", config_file, logbook);
@ -23292,7 +23410,7 @@ void create_password(char *logbook, char *name, char *pwd)
/* replace existing password */ /* replace existing password */
i = (int) (p - cfgbuffer); i = (int) (p - cfgbuffer);
write(fh, cfgbuffer, i); write(fh, cfgbuffer, i);
sprintf(str, "%s=%s\n", name, pwd); sprintf(str, "%s = %s\n", name, pwd);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
eprintf("Password replaced in logbook \"%s\".\n", logbook); eprintf("Password replaced in logbook \"%s\".\n", logbook);
while (*p && *p != '\n') while (*p && *p != '\n')
@ -23317,7 +23435,7 @@ void create_password(char *logbook, char *name, char *pwd)
p++; p++;
i = (int) (p - cfgbuffer); i = (int) (p - cfgbuffer);
write(fh, cfgbuffer, i); write(fh, cfgbuffer, i);
sprintf(str, "%s=%s\n", name, pwd); sprintf(str, "%s = %s\n", name, pwd);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
eprintf("Password added to logbook \"%s\".\n", logbook); eprintf("Password added to logbook \"%s\".\n", logbook);
/* write remainder of file */ /* write remainder of file */
@ -23330,7 +23448,7 @@ void create_password(char *logbook, char *name, char *pwd)
} else { /* write new logbook entry */ } else { /* write new logbook entry */
write(fh, cfgbuffer, strlen(cfgbuffer)); write(fh, cfgbuffer, strlen(cfgbuffer));
sprintf(str, "\n[%s]\n%s=%s\n\n", logbook, name, pwd); sprintf(str, "\n[%s]\n%s = %s\n\n", logbook, name, pwd);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
eprintf("Password added to new logbook \"%s\".\n", logbook); eprintf("Password added to new logbook \"%s\".\n", logbook);
} }
@ -23611,8 +23729,8 @@ int run_service(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i, j, n, fh, tcp_port_cl, silent, sync_flag; int i, j, n, fh, tcp_port_cl, silent, sync_flag;
char read_pwd[80], write_pwd[80], admin_pwd[80], str[256], logbook[256], char read_pwd[80], write_pwd[80], admin_pwd[80], smtp_pwd[80], str[256],
clone_url[256], error_str[256], file_name[256]; logbook[256], clone_url[256], error_str[256], file_name[256];
time_t now; time_t now;
struct tm *tms; struct tm *tms;
struct stat finfo; struct stat finfo;
@ -23630,8 +23748,8 @@ int main(int argc, char *argv[])
tzset(); tzset();
/* initialize variables */ /* initialize variables */
read_pwd[0] = write_pwd[0] = admin_pwd[0] = logbook[0] = clone_url[0] = 0; read_pwd[0] = write_pwd[0] = admin_pwd[0] = smtp_pwd[0] = 0;
logbook_dir[0] = resource_dir[0] = logbook_dir[0] = 0; logbook[0] = clone_url[0] = logbook_dir[0] = resource_dir[0] = logbook_dir[0] = 0;
silent = tcp_port_cl = sync_flag = 0; silent = tcp_port_cl = sync_flag = 0;
use_keepalive = TRUE; use_keepalive = TRUE;
running_as_daemon = FALSE; running_as_daemon = FALSE;
@ -23669,7 +23787,7 @@ int main(int argc, char *argv[])
sync_flag = 1; sync_flag = 1;
else if (argv[i][0] == '-' && argv[i][1] == 'M') else if (argv[i][0] == '-' && argv[i][1] == 'M')
sync_flag = 2; sync_flag = 2;
else if (argv[i][1] == 't') { else if (argv[i][1] == 'T') {
time(&now); time(&now);
tms = localtime(&now); tms = localtime(&now);
printf("Actual date/time: %02d%02d%02d_%02d%02d%02d\n", printf("Actual date/time: %02d%02d%02d_%02d%02d%02d\n",
@ -23716,6 +23834,8 @@ int main(int argc, char *argv[])
strcpy(write_pwd, argv[++i]); strcpy(write_pwd, argv[++i]);
else if (argv[i][1] == 'a') else if (argv[i][1] == 'a')
strcpy(admin_pwd, argv[++i]); strcpy(admin_pwd, argv[++i]);
else if (argv[i][1] == 't')
strcpy(smtp_pwd, argv[++i]);
else if (argv[i][1] == 'l') else if (argv[i][1] == 'l')
strcpy(logbook, argv[++i]); strcpy(logbook, argv[++i]);
else if (argv[i][1] == 'n') else if (argv[i][1] == 'n')
@ -23729,7 +23849,7 @@ int main(int argc, char *argv[])
printf("%s\n", ELOGID); printf("%s\n", ELOGID);
printf("usage: elogd [-a <pwd>] [-C <url>] [-c <file>] [-D] [-d <dir>] "); printf("usage: elogd [-a <pwd>] [-C <url>] [-c <file>] [-D] [-d <dir>] ");
printf("[-f <file>] [-h] [-k] [-l <logbook>] [-M] [-m] [-n <hostname>] "); printf("[-f <file>] [-h] [-k] [-l <logbook>] [-M] [-m] [-n <hostname>] ");
printf("[-p <port>] [-r <pwd>] [-S] [-s <dir>] [-v] [-w <pwd>] [-x]\n\n"); printf("[-p <port>] [-r <pwd>] [-S] [-s <dir>] [-t <pwd>] [-v] [-w <pwd>] [-x]\n\n");
printf(" -a <pwd> create/overwrite admin password in config file\n"); printf(" -a <pwd> create/overwrite admin password in config file\n");
printf(" -C <url> clone remote elogd configuration\n"); printf(" -C <url> clone remote elogd configuration\n");
printf(" -c <file> specify configuration file\n"); printf(" -c <file> specify configuration file\n");
@ -23748,6 +23868,7 @@ int main(int argc, char *argv[])
printf(" -r <pwd> create/overwrite read password in config file\n"); printf(" -r <pwd> create/overwrite read password in config file\n");
printf(" -S be silent\n"); printf(" -S be silent\n");
printf(" -s <dir> specify resource directory (themes, icons, ...)\n"); printf(" -s <dir> specify resource directory (themes, icons, ...)\n");
printf(" -t <pwd> create/overwrite SMTP password in config file\n");
printf(" -v debugging output\n"); printf(" -v debugging output\n");
printf(" -w <pwd> create/overwrite write password in config file\n"); printf(" -w <pwd> create/overwrite write password in config file\n");
printf(" -x enable execution of shell commands\n\n"); printf(" -x enable execution of shell commands\n\n");
@ -24004,6 +24125,12 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (smtp_pwd[0]) {
do_crypt(smtp_pwd, str);
create_password("global", "SMTP Password", str);
exit(EXIT_SUCCESS);
}
/* get port from configuration file */ /* get port from configuration file */
if (tcp_port_cl != 0) if (tcp_port_cl != 0)
elog_tcp_port = tcp_port_cl; elog_tcp_port = tcp_port_cl;