Discussion:
[rancid] html colorized mail diffs
nachofw
2016-01-30 01:45:52 UTC
Permalink
Hi guys, im trying to send colorized mails diffs from rancid.I’ve found a very nice bash script that converts the output from diff to html. Can anyone help me make it work with rancid? So far I have tried this config with no succes:MAILHEADERS="Content-Type: text/html; charset=ISO-8859-1"; export MAILHEADERSDIFFSCRIPT="diff2html"; export DIFFSCRIPT The script which works perfectly from command line: #!/bin/bash## Convert diff output to colorized HTML. cat <<XX<html><head><title>Colorized Diff</title></head><style>.diffdiv  { border: solid 1px black;           }.comment  { color: gray;                       }.diff     { color: #8A2BE2;                    }.minus3   { color: blue;                       }.plus3    { color: maroon;                     }.at2      { color: lime;                       }.plus     { color: green; background: #E7E7E7; }.minus    { color: red;   background: #D7D7D7; }.only     { color: purple;                     }</style><body><pre>XX echo -n '<span class="comment">' first=1diffseen=0lastonly=0 OIFS=$IFSIFS='' # The -r option keeps the backslash from being an escape char.read -r s while [[ $? -eq 0 ]]do    # Get beginning of line to determine what type    # of diff line it is.    t1=${s:0:1}    t2=${s:0:2}    t3=${s:0:3}    t4=${s:0:4}    t7=${s:0:7}     # Determine HTML class to use.    if    [[ "$t7" == 'Only in' ]]; then        cls='only'        if [[ $diffseen -eq 0 ]]; then            diffseen=1            echo -n '</span>'        else            if [[ $lastonly -eq 0 ]]; then                echo "</div>"            fi        fi        if [[ $lastonly -eq 0 ]]; then            echo "<div class='diffdiv'>"        fi        lastonly=1    elif [[ "$t4" == 'diff' ]]; then        cls='diff'        if [[ $diffseen -eq 0 ]]; then            diffseen=1            echo -n '</span>'        else            echo "</div>"        fi        echo "<div class='diffdiv'>"        lastonly=0    elif  [[ "$t3" == '+++'  ]]; then        cls='plus3'        lastonly=0    elif  [[ "$t3" == '---'  ]]; then        cls='minus3'        lastonly=0    elif  [[ "$t2" == '@@'   ]]; then        cls='at2'        lastonly=0    elif  [[ "$t1" == '+'    ]]; then        cls='plus'        lastonly=0    elif  [[ "$t1" == '-'    ]]; then        cls='minus'        lastonly=0    else        cls=        lastonly=0    fi     # Convert &, <, > to HTML entities.    s=$(sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' <<<"$s")    if [[ $first -eq 1 ]]; then        first=0    else        echo    fi     # Output the line.    if [[ "$cls" ]]; then        echo -n '<span class="'${cls}'">'${s}'</span>'    else        echo -n ${s}    fi    read -r sdoneIFS=$OIFS if [[ $diffseen -eq 0  &&  $onlyseen -eq 0 ]]; then     echo -n '</span>'else    echo "</div>"fiecho cat <<XX</pre></body></html>XX # vim: tabstop=4: shiftwidth=4: noexpandtab:# kate: tab-width 4; indent-width 4; replace-tabs false;  
heasley
2016-01-30 19:23:31 UTC
Permalink
Hi guys, im trying to send colorized mails diffs from rancid.I’ve found a very nice bash script that converts the output from diff to html. Can anyone help me make it work with rancid? So far I have tried this config with no succes:MAILHEADERS="Content-Type: text/html; charset=ISO-8859-1"; export MAILHEADERSDIFFSCRIPT="diff2html"; export DIFFSCRIPT The script which works perfectly from command line: #!/bin/bash## Convert diff output to colorized HTML. cat <<XX<html><head><title>Colorized Diff</title></head><style>.diffdiv  { border: solid 1px black;           }.comment  { color: gray;                       }.diff     { color: #8A2BE2;                    }.minus3   { color: blue;                       }.plus3    { color: maroon;                     }.at2      { color: lime;                       }.plus     { color: green; background: #E7E7E7; }.minus    { color: red;   background: #D7D7D7; }.only     { color: purple;                     }</style><body><pre>XX echo -n '<span class="comment">' first=1diffseen=0lastonly=0 OIFS=$IFSIFS='' # The -r option keeps the backslash from being an escape char.read -r s while [[ $? -eq 0 ]]do    # Get beginning of line to determine what type    # of diff line it is.    t1=${s:0:1}    t2=${s:0:2}    t3=${s:0:3}    t4=${s:0:4}    t7=${s:0:7}     # Determine HTML class to use.    if    [[ "$t7" == 'Only in' ]]; then        cls='only'        if [[ $diffseen -eq 0 ]]; then            diffseen=1            echo -n '</span>'        else            if [[ $lastonly -eq 0 ]]; then                echo "</div>"            fi        fi        if [[ $lastonly -eq 0 ]]; then            echo "<div class='diffdiv'>"        fi        lastonly=1    elif [[ "$t4" == 'diff' ]
i can't parse that mess of html that you sent, but if you want color html, try
http://stackoverflow.com/questions/3827862/convert-raw-diff-file-to-colorized-html-output
in your procmailrc. might be able to use that in DIFFSCRIPT too.
Ignacio Freyre
2016-01-30 19:46:04 UTC
Permalink
I'm resending this mail from a diferent client, the last one got messed up.




Hi guys, im trying to send colorized mails diffs from rancid.
I’ve found a very nice bash script that converts the output from diff to html.
Can anyone help me make it work with rancid? So far I have tried this config with no succes:
MAILHEADERS="Content-Type: text/html; charset=ISO-8859-1"; export MAILHEADERS
DIFFSCRIPT="diff2html"; export DIFFSCRIPT
The script which works perfectly from command line:

http://www.linuxjournal.com/content/convert-diff-output-colorized-html
Ignacio Freyre
2016-02-02 15:58:02 UTC
Permalink
thanks heasley, ultimately i made it work just changing the rancid config file.

the python script is much more easy to read, i went with that one.




1) chmod +x /var/lib/rancid/diff2html.py




2) config change -> /etc/rancid/rancid.conf
MAILHEADERS="Content-Type: text/html; charset=ISO-8859-1"; export MAILHEADERS
DIFFSCRIPT="/var/lib/rancid/diff2html.py"; export DIFFSCRIPT




scripts (both of them work):
http://stackoverflow.com/questions/3827862/convert-raw-diff-file-to-colorized-html-output
http://www.linuxjournal.com/content/convert-diff-output-colorized-html
Loading...