tazweb annotate lib/helper.sh @ rev 202
Small clean to tazweb.c and more update to NG
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Mar 18 14:45:40 2017 +0100 (2017-03-18) |
parents | e7d04c8609e2 |
children | 5066ec4b2402 |
rev | line source |
---|---|
pankso@179 | 1 #!/bin/sh |
pankso@179 | 2 # |
pankso@179 | 3 # TazWeb Helper - Handle bookmarks and cookies |
pankso@179 | 4 # |
pankso@179 | 5 # Coding: No libtaz.sh and so it is usable on any Linux distro |
pankso@179 | 6 # |
pankso@179 | 7 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License |
pankso@179 | 8 # See AUTHORS and LICENSE for detailed information |
pankso@179 | 9 # |
pankso@179 | 10 |
pankso@179 | 11 config="$HOME/.config/tazweb" |
pankso@179 | 12 bm_txt="$config/bookmarks.txt" |
pankso@179 | 13 bm_html="$config/bookmarks.html" |
pankso@179 | 14 cookies_txt="$config/cookies.txt" |
pankso@179 | 15 cookies_html="$config/cookies.html" |
pankso@179 | 16 |
al@188 | 17 export TEXTDOMAIN='tazweb' |
pankso@179 | 18 |
pankso@179 | 19 # Parse cmdline options and store values in a variable |
al@188 | 20 for opt in $@; do |
pankso@179 | 21 opt_name="${opt%%=*}" |
pankso@179 | 22 opt_name="${opt_name#--}" |
pankso@179 | 23 case "$opt" in |
pankso@179 | 24 --*=*) export $opt_name="${opt#*=}" ;; |
pankso@179 | 25 --*) export $opt_name="on" ;; |
pankso@179 | 26 esac |
pankso@179 | 27 done |
pankso@179 | 28 |
pankso@179 | 29 # HTML 5 header with built-in minimal CSS. Usage: html_header "title" |
pankso@179 | 30 html_header() { |
pankso@179 | 31 local title="$1" |
al@188 | 32 cat <<EOT |
pankso@179 | 33 <!DOCTYPE html> |
pankso@179 | 34 <html lang="en"> |
pankso@179 | 35 <head> |
al@188 | 36 <meta charset="UTF-8"> |
pankso@179 | 37 <title>$title</title> |
pankso@195 | 38 <link rel="stylesheet" href="/usr/share/doc/tazweb/style.css"> |
pankso@179 | 39 </head> |
pankso@179 | 40 <body> |
pankso@195 | 41 <header> |
pankso@195 | 42 <h1>$1</h1> |
pankso@195 | 43 </header> |
pankso@195 | 44 <main> |
pankso@179 | 45 EOT |
pankso@179 | 46 } |
pankso@179 | 47 |
pankso@179 | 48 # HTML 5 footer: html_footer content |
pankso@179 | 49 html_footer() { |
al@188 | 50 cat <<EOT |
pankso@195 | 51 </main> |
al@188 | 52 <footer> |
al@188 | 53 $@ |
al@188 | 54 </footer> |
pankso@179 | 55 </body> |
pankso@179 | 56 </html> |
pankso@179 | 57 EOT |
pankso@179 | 58 } |
pankso@179 | 59 |
pankso@179 | 60 # Generate bookmarks.html |
pankso@179 | 61 html_bookmarks() { |
al@188 | 62 { |
al@188 | 63 html_header "$(gettext 'Bookmarks')" |
pankso@197 | 64 echo '<ul style="list-style-type: none;">' |
al@188 | 65 |
al@188 | 66 IFS="|" |
al@188 | 67 while read title url null; do |
al@188 | 68 echo "<li><a href=\"$url\">$title</a></li>" |
pankso@192 | 69 done < ${bm_txt} |
al@188 | 70 unset IFS |
al@188 | 71 |
al@188 | 72 echo '</ul>' |
al@191 | 73 num=$(wc -l < $bm_txt) |
al@191 | 74 html_footer "$(printf "$(ngettext "%d bookmark" "%d bookmarks" "$num")" "$num") - $(date)" |
pankso@192 | 75 } > ${bm_html} |
al@188 | 76 |
pankso@179 | 77 # Security fix from old cgi-bin bookmarks.cgi |
pankso@192 | 78 chown $USER:$USER ${bm_txt}; chmod 0600 ${bm_txt} |
pankso@179 | 79 } |
pankso@179 | 80 |
pankso@192 | 81 # List all bookmarks |
pankso@192 | 82 bookmarks_list() { |
pankso@194 | 83 text= |
pankso@192 | 84 cat ${bm_txt} | while read title url; do |
pankso@192 | 85 echo -e "$title\n$url" |
pankso@192 | 86 done | yad --list \ |
pankso@192 | 87 --title="$(gettext 'TazWeb Bookmarks')" \ |
pankso@194 | 88 --text="$(gettext 'Click on a value to edit - Right click to remove a bookmark')\n" \ |
pankso@192 | 89 --text-align=center \ |
pankso@192 | 90 --mouse --width=640 --height=480 \ |
pankso@192 | 91 --skip-taskbar \ |
pankso@192 | 92 --window-icon=/usr/share/icons/hicolor/32x32/apps/tazweb.png \ |
pankso@192 | 93 --editable --print-all \ |
pankso@192 | 94 --tooltip-column=2 \ |
pankso@192 | 95 --search-column=1 \ |
pankso@192 | 96 --column="$(gettext 'Title')" \ |
pankso@192 | 97 --column="$(gettext 'URL')" |
pankso@192 | 98 } |
pankso@192 | 99 |
paul@196 | 100 # Rebuild bookmarks.txt since some entries may have been edited and remove |
pankso@192 | 101 # selected (TRUE) entries. |
pankso@192 | 102 bookmarks_handler() { |
pankso@192 | 103 IFS="|" |
pankso@192 | 104 bookmarks_list | while read title url null; do |
pankso@192 | 105 echo "$title|$url" >> ${bm_txt}.tmp |
pankso@192 | 106 done; unset IFS |
pankso@192 | 107 if [ -f "${bm_txt}.tmp" ]; then |
pankso@192 | 108 mv -f ${bm_txt}.tmp ${bm_txt} |
pankso@192 | 109 fi |
pankso@179 | 110 } |
pankso@179 | 111 |
pankso@179 | 112 # Generate cookies.html (for direct view of cookies in TazWeb) |
pankso@179 | 113 html_cookies() { |
al@188 | 114 { |
al@188 | 115 html_header "$(gettext 'Cookies')" |
pankso@195 | 116 echo '<pre style="overflow: auto;">' |
al@188 | 117 |
al@188 | 118 while read line; do |
al@188 | 119 echo "${line#\#HttpOnly_}" |
pankso@192 | 120 done < ${cookies_txt} |
al@188 | 121 |
al@188 | 122 echo '</pre>' |
al@191 | 123 num=$(wc -l < $cookies_txt) |
al@191 | 124 html_footer "$(printf "$(ngettext "%d cookie" "%d cookies" "$num")" "$num") - $(date)" |
pankso@192 | 125 } > ${cookies_html} |
pankso@179 | 126 } |
pankso@179 | 127 |
pankso@179 | 128 clean_cookies() { |
pankso@192 | 129 rm ${cookies_txt}; touch ${cookies_txt} |
pankso@179 | 130 } |
pankso@179 | 131 |
pankso@179 | 132 # |
pankso@179 | 133 # Execute any shell_function |
pankso@179 | 134 # |
pankso@179 | 135 case "$1" in |
pankso@179 | 136 |
al@188 | 137 *_*) |
pankso@192 | 138 cmd=${1}; shift; ${cmd} ${@} ;; |
pankso@179 | 139 |
al@188 | 140 *) grep "[a-z]_*()" $0 | awk '{print $1}' ;; |
al@188 | 141 |
al@188 | 142 esac |
al@188 | 143 exit 0 |