diff --git a/usr.sbin/cron/cron/cron.h b/usr.sbin/cron/cron/cron.h --- a/usr.sbin/cron/cron/cron.h +++ b/usr.sbin/cron/cron/cron.h @@ -292,6 +292,7 @@ unsigned Jitter, RootJitter; time_t TargetTime; +int HtmlPreformat = 0; # if DEBUGGING int DebugFlags; @@ -310,6 +311,7 @@ extern unsigned Jitter, RootJitter; extern time_t TargetTime; +extern int HtmlPreformat; extern struct pidfh *pfh; # if DEBUGGING extern int DebugFlags; diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c --- a/usr.sbin/cron/cron/cron.c +++ b/usr.sbin/cron/cron/cron.c @@ -61,7 +61,7 @@ #endif fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] " - "[-m mailto] [-n] [-s] [-o] [-x debugflag[,...]]\n"); + "[-m mailto] [-n] [-s] [-o] [-H] [-x debugflag[,...]]\n"); #if DEBUGGING fprintf(stderr, "\ndebugflags: "); @@ -525,7 +525,7 @@ int argch; char *endp; - while ((argch = getopt(argc, argv, "j:J:m:nosx:")) != -1) { + while ((argch = getopt(argc, argv, "j:J:m:nosHx:")) != -1) { switch (argch) { case 'j': Jitter = strtoul(optarg, &endp, 10); @@ -551,6 +551,9 @@ case 's': dst_enabled = 1; break; + case 'H': + HtmlPreformat = 1; + break; case 'x': if (!set_debug_flags(optarg)) usage(); diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c --- a/usr.sbin/cron/cron/do_command.c +++ b/usr.sbin/cron/cron/do_command.c @@ -84,6 +84,20 @@ Debug(DPROC, ("[%d] main process returning to work\n", getpid())) } +static char* escape_html(int ch, char* tempbuf) { + + switch (ch) { + case '<': + return "<"; + case '>': + return ">"; + case '&': + return "&"; + default: + tempbuf[0] = ch; + return tempbuf; + } +} static void child_process(e, u) @@ -524,7 +538,12 @@ for (env = e->envp; *env; env++) fprintf(mail, "X-Cron-Env: <%s>\n", *env); + + if (HtmlPreformat) + fprintf(mail, "Content-Type: text/html\n"); fprintf(mail, "\n"); + if (HtmlPreformat) + fprintf(mail, "
\n");
 
 				/* this was the first char from the pipe
 				 */
@@ -538,8 +557,19 @@
 
 			while (EOF != (ch = getc(in))) {
 				bytes++;
-				if (mail)
-					putc(ch, mail);
+				if (mail) {
+					if (HtmlPreformat) {
+						char tempbuf[2] = {0, 0};
+						char *escapedstring = escape_html(ch, &tempbuf[0]);
+						fputs(escapedstring, mail);
+					} else {
+						putc(ch, mail);
+					}
+				}
+			}
+
+			if (mailto && HtmlPreformat) {
+				fprintf(mail, "
\n"); } } /*if data from grandchild*/