slitaz-dev-tools rev 245

tazwikiss: use sedesc()
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Sep 02 10:14:11 2015 +0200 (2015-09-02)
parents ea02fe275b3f
children 9b17c1b64360
files tazwikiss/rootfs/var/www/wiki/index.sh tazwikiss/rootfs/var/www/wiki/pages/Aide.txt tazwikiss/rootfs/var/www/wiki/pages/Help.txt tazwikiss/rootfs/var/www/wiki/plugins/wkp_Upload.sh
line diff
     1.1 --- a/tazwikiss/rootfs/var/www/wiki/index.sh	Thu Aug 20 21:26:04 2015 +0200
     1.2 +++ b/tazwikiss/rootfs/var/www/wiki/index.sh	Wed Sep 02 10:14:11 2015 +0200
     1.3 @@ -56,6 +56,12 @@
     1.4  	cache_auth "$PASSWORD"
     1.5  }
     1.6  
     1.7 +sedesc()
     1.8 +{
     1.9 +	echo "$1" | sed 's|[/&"]|\\&|g' | \
    1.10 +		sed ':a;N;$!ba;s|\n|\\n|g;s|'$(echo -en "\r")'||g'
    1.11 +}
    1.12 +
    1.13  plugin_call_method()
    1.14  {
    1.15  	local status
    1.16 @@ -154,7 +160,7 @@
    1.17  EOT
    1.18  )"
    1.19  else
    1.20 -	CONTENT="$(sed -e "s#%page%#$PAGE_TITLE#" <<EOT
    1.21 +	CONTENT="$(sed -e "s/%page%/$(sedesc "$PAGE_TITLE")/" <<EOT
    1.22  $DEFAULT_CONTENT
    1.23  EOT
    1.24  )"
    1.25 @@ -320,7 +326,7 @@
    1.26  		 	-e 's/(phone)/\&#9742;/' -e 's/(wphone)/\&#9743;/' \
    1.27  		 	-e 's/(skull)/\&#9760;/' -e 's/(radioactive)/\&#9762;/' \
    1.28  		 	-e 's/(sad)/\&#9785;/'  -e 's/(smile)/\&#9786;/' \
    1.29 -		 	-e 's/(recycle)/\&#9742;/' -e 's/(wheelchair)/\&#9755;/' \
    1.30 +		 	-e 's/(recycle)/\&#9842;/' -e 's/(wheelchair)/\&#9855;/' \
    1.31  		 	-e 's/(wflag)/\&#9872;/' -e 's/(bflag)/\&#9873;/' \
    1.32  		 	-e 's/(anchor)/\&#9875;/' -e 's/(flower)/\&#9880;/' \
    1.33  		 	-e 's/(gear)/\&#9881;/' -e 's/(volt)/\&#9889;/' \
    1.34 @@ -375,8 +381,8 @@
    1.35  EOT
    1.36  )"
    1.37  		while read link; do
    1.38 -			[ -s $PAGES_DIR$link.txt ] && continue
    1.39 -			CONTENT="$(sed "s|\\?page=$link\"|& class=\"pending\"|" <<EOT
    1.40 +			[ -s "$PAGES_DIR$link.txt" ] && continue
    1.41 +			CONTENT="$(sed "s/\\?page=$(sedesc "$link")\"/& class=\"pending\"/" <<EOT
    1.42  $CONTENT
    1.43  EOT
    1.44  )"
    1.45 @@ -410,7 +416,7 @@
    1.46  	<h$i><a href="#$label">$line</a></h$i>
    1.47  EOT
    1.48  )"
    1.49 -				CONTENT="$(sed "s#^!!* *$line\$#<h$i><a name=\"$label\">$line</a></h$i>#" <<EOT
    1.50 +				CONTENT="$(sed "s/^!!* *$(sedesc "$line")\$/<h$i><a name=\"$label\">$(sedesc "$line")<\/a><\/h$i>/" <<EOT
    1.51  $CONTENT
    1.52  EOT
    1.53  )"
    1.54 @@ -462,10 +468,10 @@
    1.55  [ "$action" != "edit" ] && HELP=""
    1.56  
    1.57  [ -r "$template" ] || die "'$template' is missing!"
    1.58 -html="$(sed -e "s#{\([^}]*\)RECENT_CHANGES\([^}]*\)}#\1$RECENT\2#" \
    1.59 -           -e "s#{\([^}]*\)HOME\([^}]*\)}#\1$HOME\2#" \
    1.60 -           -e "s#{\([^}]*\)HELP\([^}]*\)}#$HELP#" \
    1.61 -           -e "s#{SEARCH}#<form method=\"get\" action=\"$urlbase?page=$(urlencode "$PAGE_TITLE" | sed 's/#/\\#/g')\"><div><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$(htmlentities $(GET query) )\" tabindex=\"1\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" accesskey=\"q\" /></div></form>#" \
    1.62 +html="$(sed -e "s/{\([^}]*\)RECENT_CHANGES\([^}]*\)}/\1$(sedesc "$RECENT")\2/" \
    1.63 +           -e "s/{\([^}]*\)HOME\([^}]*\)}/\1$(sedesc "$HOME")\2/" \
    1.64 +           -e "s/{\([^}]*\)HELP\([^}]*\)}/$(sedesc "$HELP")/" \
    1.65 +           -e "s/{SEARCH}/<form method=\"get\" action=\"$(sedesc "$urlbase?page=$(urlencode "$PAGE_TITLE" | sed 's/#/\\#/g')")\"><div><input type=\"hidden\" name=\"action\" value=\"search\" \/><input type=\"text\" name=\"query\" value=\"$(sedesc "$(htmlentities $(GET query) )")\" tabindex=\"1\" \/> <input type=\"submit\" value=\"$(sedesc "$SEARCH_BUTTON")\" accesskey=\"q\" \/><\/div><\/form>/" \
    1.66             < $template )"
    1.67  [ "$action" != "" -a "$action" != "edit" -o ! -e "$PAGE_txt" ] && TIME="-"
    1.68  plugin_call_method template
    1.69 @@ -478,37 +484,31 @@
    1.70  if $editable ; then
    1.71  	EDIT="$PROTECTED_BUTTON"
    1.72  	[ -w "$PAGE_txt" -o ! -e "$PAGE_txt" ] &&
    1.73 -        EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&amp;action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>"
    1.74 +        EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")&amp;action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>"
    1.75  fi
    1.76  [ -n "$toc" ] && toc="\1$toc\2"
    1.77  AUTH_GET=""
    1.78  AUTH_POST=""
    1.79  if authentified; then
    1.80 -	AUTH_GET="auth=$AUTH\&"
    1.81 +	AUTH_GET="auth=$AUTH&"
    1.82  	AUTH_POST="\n<input type=\"hidden\" name=\"auth\" value=\"$AUTH\" />"
    1.83  fi
    1.84  
    1.85  header "Content-type: text/html"
    1.86 -sed	-e "s#{ERROR}#$ERROR#"		-e "s#{WIKI_TITLE}#$WIKI_TITLE#" \
    1.87 -	-e "s|{\([^}]*\)HISTORY\([^}]*\)}|${HISTORY//&/\&}|" \
    1.88 -	-e "s|{PAGE_TITLE}|${PAGE_TITLE_str//&/\&}|" \
    1.89 -	-e "s|{\([^}]*\)EDIT\([^}]*\)}|\1${EDIT//&/\&}\2|" \
    1.90 -	-e "s|{\([^}]*\)TOC\([^}]*\)}|$(awk '{ printf "%s\\n" $0 }' <<EOT | \
    1.91 -		sed -e 's/&/\\\&/g' -e 's/|/\\|/g'
    1.92 -$toc
    1.93 -EOT
    1.94 -)|" \
    1.95 -	-e "s#{PAGE_TITLE_BRUT}#$(htmlentities "$PAGE_TITLE")#" \
    1.96 -	-e "s#{LAST_CHANGE}#$LAST_CHANGES :#" \
    1.97 -	-e "s#{CONTENT}#$(awk '{ printf "%s\\n" $0 }' <<EOT | \
    1.98 -		sed -e 's/&/\\\&/g' -e 's/#/\\#/g'
    1.99 -$CONTENT
   1.100 -EOT
   1.101 -)#" \
   1.102 -	-e "s#{LANG}#$LANG#"		-e "s#href=\"?#href=\"$urlbase?#g" \
   1.103 -	-e "s#$urlbase?#&$AUTH_GET#g" -e "s#action=\"$urlbase\">#&$AUTH_POST#g" \
   1.104 -	-e "s#{WIKI_VERSION}#$WIKI_VERSION#" \
   1.105 -	-e "s#{TIME}#$TIME#"		-e "s#{DATE}#$datew#" \
   1.106 -	-e "s#{IP}#$REMOTE_ADDR#"	-e "s#{COOKIE}##" <<EOT
   1.107 +sed	-e "s/{ERROR}/$(sedesc "$ERROR")/" \
   1.108 +	-e "s/{WIKI_TITLE}/$(sedesc "$WIKI_TITLE")/" \
   1.109 +	-e "s/{\([^}]*\)HISTORY\([^}]*\)}/$(sedesc "$HISTORY")/" \
   1.110 +	-e "s/{PAGE_TITLE}/$(sedesc "$PAGE_TITLE_str")/" \
   1.111 +	-e "s/{\([^}]*\)EDIT\([^}]*\)}/\1$(sedesc "$EDIT")\2/" \
   1.112 +	-e "s/{\([^}]*\)TOC\([^}]*\)}/$(sedesc "$TOC")/" \
   1.113 +	-e "s/{PAGE_TITLE_BRUT}/$(sedesc "$(htmlentities "$PAGE_TITLE")")/" \
   1.114 +	-e "s/{LAST_CHANGE}/$(sedesc "$LAST_CHANGES") :/" \
   1.115 +	-e "s/{CONTENT}/$(sedesc "$CONTENT")/" \
   1.116 +	-e "s/{LANG}/$(sedesc "$LANG")/" \
   1.117 +	-e "s/href=\"?/href=\"$(sedesc "$urlbase?$AUTH_GET")/g" \
   1.118 +	-e "s/action=\"$(sedesc "$urlbase")\">/&$(sedesc "$AUTH_POST")/g" \
   1.119 +	-e "s/{WIKI_VERSION}/$(sedesc "$WIKI_VERSION")/" \
   1.120 +	-e "s/{TIME}/$(sedesc "$TIME")/" -e "s/{DATE}/$(sedesc "$datew")/" \
   1.121 +	-e "s/{IP}/$REMOTE_ADDR/" -e "s/{COOKIE}//" -e "s/{RSS}//" <<EOT
   1.122  $html
   1.123  EOT
     2.1 --- a/tazwikiss/rootfs/var/www/wiki/pages/Aide.txt	Thu Aug 20 21:26:04 2015 +0200
     2.2 +++ b/tazwikiss/rootfs/var/www/wiki/pages/Aide.txt	Wed Sep 02 10:14:11 2015 +0200
     2.3 @@ -49,6 +49,13 @@
     2.4  Certains caractères spéciaux sont reconnus :
     2.5  * Flèches : &lt;^-- : &lt;--, ^--> : -->, &lt;^--> : &lt;-->
     2.6  * Copyrights : ^(c) ou ^(C) : (c), ^(r) ou ^(R) : (r)
     2.7 +* Fractions : ^(1/2) : (1/2), ^(1/4) : (1/4), ^(3/4) : (3/4)
     2.8 +* Divers : ^(+-) : (+-), ^(!=) : (!=)
     2.9 +* Quelques icônes : ^(phone) : (phone), ^(wphone) : (wphone), ^(bflag) : (bflag), ^(
    2.10 +wflag) : (wflag) ^(radioactive) : (radioactive), ^(sad) : (sad), ^(smile) : (sm
    2.11 +ile), ^(recycle) : (recycle), ^(wheelchair) : (wheelchair), ^(anchor) : (anchor
    2.12 +), ^(flower) : (flower), ^(gear) : (gear), ^(volt) : (volt), ^(warn) : (warn), 
    2.13 +^(skull) : (skull), ^(star) : (star)
    2.14  ----
    2.15  Les liens externes et les adresses eMail sont reconnus automagiquement ...
    2.16  ^http://wikiss.tuxfamily.org/ --> http://wikiss.tuxfamily.org/
     3.1 --- a/tazwikiss/rootfs/var/www/wiki/pages/Help.txt	Thu Aug 20 21:26:04 2015 +0200
     3.2 +++ b/tazwikiss/rootfs/var/www/wiki/pages/Help.txt	Wed Sep 02 10:14:11 2015 +0200
     3.3 @@ -9,10 +9,10 @@
     3.4  
     3.5  ----
     3.6  
     3.7 -Tiles use the exclamation mark '''!'''%%
     3.8 -^! Big%%
     3.9 -^!! Less big%%
    3.10 -^!!! Smaller%%
    3.11 +Tiles use the exclamation mark '''!'''
    3.12 +^! Big
    3.13 +^!! Less big
    3.14 +^!!! Smaller
    3.15  gives you :
    3.16  ! Big
    3.17  !! Less big
    3.18 @@ -31,10 +31,10 @@
    3.19  
    3.20  ----
    3.21  
    3.22 -Stroke of a work use quote and two dashes%%
    3.23 +Stroke of a work use quote and two dashes
    3.24  ^'--Stroked--' --> '--Stroked--'
    3.25  
    3.26 -the same applies for underline, quote followed by by two underscore%%
    3.27 +the same applies for underline, quote followed by by two underscore
    3.28  ^'__Underlined__' --> '__Underlined__'
    3.29  
    3.30  ----
    3.31 @@ -53,10 +53,10 @@
    3.32  
    3.33  ----
    3.34  
    3.35 -The code, and all of those things where formatting is important, use the braces %%
    3.36 -^{{import sys%%
    3.37 -if len(sys.argv) == 2:%%
    3.38 -   print "Hello",sys.argv^[1]}}%%
    3.39 +The code, and all of those things where formatting is important, use the braces
    3.40 +^{{import sys
    3.41 +if len(sys.argv) == 2:
    3.42 +   print "Hello",sys.argv^[1]}}
    3.43  give :
    3.44  {{import sys
    3.45  if len(sys.argv) == 2:
    3.46 @@ -65,13 +65,16 @@
    3.47  ----
    3.48  
    3.49  The separation between paragraphs of text is done through an empty line.
    3.50 -To force a line break in the middle of a paragraph, use: ^%%
    3.51 +To force a line break in the middle of a paragraph, use: ^
    3.52  
    3.53  ----
    3.54  
    3.55  Some special characters are recognized:
    3.56 -* Arrows : &lt;^-- : &lt;--, ^--> : -->, &lt;^--> : &lt;-->
    3.57 -* Copyrights : ^(c) or ^(C) : (c), ^(r) or ^(R) : (r)
    3.58 +* Arrows: &lt;^-- : &lt;--, ^--> : -->, &lt;^--> : &lt;-->
    3.59 +* Copyrights: ^(c) or ^(C) : (c), ^(r) or ^(R) : (r)
    3.60 +* Fractions: ^(1/2) : (1/2), ^(1/4) : (1/4), ^(3/4) : (3/4)
    3.61 +* Miscellaneous: ^(+-) : (+-), ^(!=) : (!=)
    3.62 +* Some icons: ^(phone) : (phone), ^(wphone) : (wphone), ^(bflag) : (bflag), ^(wflag) : (wflag) ^(radioactive) : (radioactive), ^(sad) : (sad), ^(smile) : (smile), ^(recycle) : (recycle), ^(wheelchair) : (wheelchair), ^(anchor) : (anchor), ^(flower) : (flower), ^(gear) : (gear), ^(volt) : (volt), ^(warn) : (warn), ^(skull) : (skull), ^(star) : (star)
    3.63  
    3.64  ----
    3.65  
    3.66 @@ -79,7 +82,7 @@
    3.67  '''^['''Accueil''']''' --> [Accueil]
    3.68  
    3.69  If a page does not exists, it will be created on first click.
    3.70 -Click on "SandBox" below and you will be able to create it ...%%
    3.71 +Click on "SandBox" below and you will be able to create it ...
    3.72  [SandBox]
    3.73  
    3.74  To link a wiki-page with a different text use :
    3.75 @@ -97,21 +100,21 @@
    3.76  
    3.77  ----
    3.78  
    3.79 -Images are automagically inserted with the picture URL between square brackets%%
    3.80 +Images are automagically inserted with the picture URL between square brackets
    3.81  '''^['''^http://wikiss.tuxfamily.org/img/logo_100.png''']''' -->
    3.82  [http://wikiss.tuxfamily.org/img/logo_100.png]
    3.83  
    3.84 -You can also use an image as a link : %%
    3.85 +You can also use an image as a link : 
    3.86  '''^['''^http://wikiss.tuxfamily.org/img/logo_100.png'''|'''^http://wikiss.tuxfamily.org/''']''' --> 
    3.87  [http://wikiss.tuxfamily.org/img/logo_100.png|http://wikiss.tuxfamily.org/]
    3.88  
    3.89  But also position the image on a floating left or right: 
    3.90  [http://wikiss.tuxfamily.org/img/logo_100.png|left] [http://wikiss.tuxfamily.org/img/logo_100.png|http://wikiss.tuxfamily.org|right]
    3.91 -%%
    3.92  
    3.93 -&lt;-- '''^['''^http://wikiss.tuxfamily.org/img/logo_100.png'''|left]'''%%
    3.94 +
    3.95 +&lt;-- '''^['''^http://wikiss.tuxfamily.org/img/logo_100.png'''|left]'''
    3.96  '''^['''^http://wikiss.tuxfamily.org/img/logo_100.png'''|'''^http://wikiss.tuxfamily.org'''|right]''' -->
    3.97 -%%
    3.98 +
    3.99  
   3.100  ----
   3.101  
   3.102 @@ -119,7 +122,7 @@
   3.103  
   3.104  ----
   3.105  
   3.106 -Finally, in order to neutralize the syntax WiKiss, use the caret ^ %%
   3.107 +Finally, in order to neutralize the syntax WiKiss, use the caret ^ 
   3.108  Thus, enter '''^^^['''WiKiss''']''' can display ^[WiKiss] rather than [WiKiss]
   3.109  
   3.110  ----
     4.1 --- a/tazwikiss/rootfs/var/www/wiki/plugins/wkp_Upload.sh	Thu Aug 20 21:26:04 2015 +0200
     4.2 +++ b/tazwikiss/rootfs/var/www/wiki/plugins/wkp_Upload.sh	Wed Sep 02 10:14:11 2015 +0200
     4.3 @@ -11,7 +11,7 @@
     4.4  {
     4.5  	case "$(GET action)" in
     4.6  	edit)	UPLOAD="<a href=\"$urlbase?action=upload\">$UPLOAD</a>"
     4.7 -		html="$(sed "s|HISTORY|$UPLOAD / HISTORY|" <<EOT
     4.8 +		html="$(sed "s|HISTORY|$(sedesc "$UPLOAD") / HISTORY|" <<EOT
     4.9  $html
    4.10  EOT
    4.11  )" ;;