tazpanel rev 91
index.cgi: add diff button
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 14 17:46:05 2011 +0200 (2011-04-14) |
parents | b5df231d1010 |
children | ad764d516c05 |
files | index.cgi lib/libtazpanel |
line diff
1.1 --- a/index.cgi Thu Apr 14 13:14:34 2011 +0200 1.2 +++ b/index.cgi Thu Apr 14 17:46:05 2011 +0200 1.3 @@ -19,6 +19,33 @@ 1.4 TEXTDOMAIN='tazpanel' 1.5 export TEXTDOMAIN 1.6 1.7 +# Check wether a configuration file has been modified after installation 1.8 +file_is_modified() 1.9 +{ 1.10 + grep -l " $1$" $INSTALLED/*/md5sum | while read file; do 1.11 + 1.12 + # Found, but can we do diff ? 1.13 + [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break 1.14 + org=$(dirname $file)/volatile.cpio.gz 1.15 + zcat $org 2>/dev/null | cpio -t 2>/dev/null | \ 1.16 + grep -q "^${1#/}$" || break 1.17 + 1.18 + case "$2" in 1.19 + diff) 1.20 + tmp=/tmp/tazpanel$$ 1.21 + mkdir -p $tmp 1.22 + ( cd $tmp ; zcat $org | cpio -id ${1#/} ) 1.23 + diff -u $tmp$1 $1 1.24 + rm -rf $tmp ;; 1.25 + button) 1.26 + cat <<EOT 1.27 + <a class="button" href='/index.cgi?file=$1&action=diff'> 1.28 + <img src="/styles/default/images/help.png" />`gettext "Differences"`</a> 1.29 +EOT 1.30 + esac 1.31 + done 1.32 +} 1.33 + 1.34 # 1.35 # Things to do before displaying the page 1.36 # 1.37 @@ -33,7 +60,7 @@ 1.38 case " $(GET) " in 1.39 *\ file\ *) 1.40 # 1.41 - # Handle files (may have an edit function, we will see) 1.42 + # Handle files 1.43 # 1.44 TITLE="- File" 1.45 xhtml_header 1.46 @@ -49,6 +76,10 @@ 1.47 </textarea> 1.48 </form> 1.49 EOT 1.50 + elif [ "$(GET action)" == "diff" ]; then 1.51 + echo '<pre id="diff">' 1.52 + file_is_modified $file diff | syntax_highlighter diff 1.53 + echo '</pre>' 1.54 else 1.55 [ -n "$(POST content)" ] && 1.56 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT 1.57 @@ -58,10 +89,9 @@ 1.58 <div id="actions"> 1.59 <a class="button" href='/index.cgi?file=$file&action=edit'> 1.60 <img src="/styles/default/images/edit.png" />`gettext "Edit"`</a> 1.61 - 1.62 -</div> 1.63 -<pre> 1.64 EOT 1.65 + file_is_modified $file button 1.66 + echo -e "</div>\n<pre>" 1.67 # Handle file type by extension as a Web Server does it. 1.68 case "$file" in 1.69 *.conf|*.lst)
2.1 --- a/lib/libtazpanel Thu Apr 14 13:14:34 2011 +0200 2.2 +++ b/lib/libtazpanel Thu Apr 14 17:46:05 2011 +0200 2.3 @@ -34,7 +34,12 @@ 2.4 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;; 2.5 sh) 2.6 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \ 2.7 - -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g 2.8 + -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;; 2.9 + diff) 2.10 + sed -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \ 2.11 + -e s"#^-\([^']*\).#<span style='color: red;'>\0</span>#"g \ 2.12 + -e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \ 2.13 + -e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g ;; 2.14 esac 2.15 } 2.16