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