# HG changeset patch # User Christophe Lincoln # Date 1489366319 -3600 # Node ID 3d4f8134bd2fee98c336549832ebac3fc513e7b8 # Parent 02eed56243733ca1fc178b806cca6eeda6595911 Use helper as as SHell library diff -r 02eed5624373 -r 3d4f8134bd2f lib/helper.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/helper.sh Mon Mar 13 01:51:59 2017 +0100 @@ -0,0 +1,117 @@ +#!/bin/sh +# +# TazWeb Helper - Handle bookmarks and cookies +# +# Coding: No libtaz.sh and so it is usable on any Linux distro +# +# Copyright (C) 2017 SliTaz GNU/Linux - BSD License +# See AUTHORS and LICENSE for detailed information +# + +config="$HOME/.config/tazweb" +bm_txt="$config/bookmarks.txt" +bm_html="$config/bookmarks.html" +cookies_txt="$config/cookies.txt" +cookies_html="$config/cookies.html" + +export TEXTDOMAIN='tazweb-lib' + +# Parse cmdline options and store values in a variable +for opt in "$@"; do + opt_name="${opt%%=*}" + opt_name="${opt_name#--}" + case "$opt" in + --*=*) export $opt_name="${opt#*=}" ;; + --*) export $opt_name="on" ;; + esac +done + +# HTML 5 header with built-in minimal CSS. Usage: html_header "title" +html_header() { + local title="$1" + cat << EOT + + + + + $title + + + +
+

$title

+EOT +} + +# HTML 5 footer: html_footer content +html_footer() { + cat << EOT +
+ + + +EOT +} + +# Generate bookmarks.html +html_bookmarks() { + html_header "$(gettext 'Bookmarks')" > ${bm_html} + echo '' >> ${bm_html} + html_footer "$(cat $bm_txt | wc -l) $(gettext "Bookmarks") - $(date)" \ + >> ${bm_html} + # Security fix from old cgi-bin bookmarks.cgi + chown ${USER}.${USER} ${bm_txt}; chmod 0600 ${bm_txt} +} + +edit_bookmarks() { + yad --text-info \ + --center --width=640 --height=480 --filename=${bm_txt} +} + +# Generate cookies.html (for direct view of cookies in TazWeb) +html_cookies() { + html_header "$(gettext 'Cookies')" > ${cookies_html} + echo '
' >> ${cookies_html}
+	IFS="|"
+	cat ${cookies_txt} | while read line
+	do
+		cat >> ${cookies_html} << EOT
+${line#\#HttpOnly_}
+EOT
+	done; unset IFS
+	echo '
' >> ${cookies_html} + html_footer $(cat $cookies_txt | wc -l) $(gettext "Cookies") - $(date) \ + >> ${cookies_html} +} + +clean_cookies() { + rm ${cookies_txt}; touch ${cookies_txt} +} + +# +# Execute any shell_function +# +case "$1" in + + *_*) + cmd=${1}; shift; ${cmd} ${@} ;; + + *) grep "[a-z]_*()" ${0} | awk '{print $1}' ;; + +esac; exit 0 diff -r 02eed5624373 -r 3d4f8134bd2f tazweb-helper --- a/tazweb-helper Mon Mar 13 01:50:53 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -#!/bin/sh -# -# TazWeb Helper - Handle bookmarks (No libtaz.sh: usable on any Linux distro) -# - -tazweb="$(pwd)/tazweb" -config="$HOME/.config/tazweb" -bm_txt="$config/bookmarks.txt" -bm_html="$config/bookmarks.html" - -help() { - cat << EOT - -$(gettext "Usage:") $(basename $0) [bookmarks] --option - -$(gettext "Options:") - --raw Show raw bookmarks.txt in textmode - --html Show html bookmarks in TazWeb - -EOT -} - -# HTML 5 header with built-in minimal CSS -html_header() { - cat << EOT - - - - - TazWeb - Bookmarks - - - -
-

TazWeb Bookmarks

- -
- - - -EOT -} - -# Generate bookmarks.html -html_bookmarks() { - html_header > ${bm_html} - IFS="|" - cat ${bm_txt} | while read title url null - do - cat >> ${bm_html} << EOT -
  • ${title}
  • -EOT - done - unset IFS - html_footer >> ${bm_html} - # Security fix from old cgi-bin bookmarks.cgi - chown ${USER}.${USER} ${bm_txt}; chmod 0600 ${bm_txt} -} - -# -# Commands -# -case "$1" in - - -b|bookmarks) - if [ "$raw" ]; then - cat ${config}/bookmarks.txt - fi - if [ "$html" ]; then - html_bookmarks - ${tazweb} file:///${config}/bookmarks.html & - fi ;; - - *_*) ${1} ;; - - *|-h|help) help ;; - -esac; exit 0