tazweb rev 179
Use helper as as SHell library
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Mar 13 01:51:59 2017 +0100 (2017-03-13) |
parents | 02eed5624373 |
children | dd3b94d5bca8 |
files | lib/helper.sh tazweb-helper |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/lib/helper.sh Mon Mar 13 01:51:59 2017 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TazWeb Helper - Handle bookmarks and cookies 1.7 +# 1.8 +# Coding: No libtaz.sh and so it is usable on any Linux distro 1.9 +# 1.10 +# Copyright (C) 2017 SliTaz GNU/Linux - BSD License 1.11 +# See AUTHORS and LICENSE for detailed information 1.12 +# 1.13 + 1.14 +config="$HOME/.config/tazweb" 1.15 +bm_txt="$config/bookmarks.txt" 1.16 +bm_html="$config/bookmarks.html" 1.17 +cookies_txt="$config/cookies.txt" 1.18 +cookies_html="$config/cookies.html" 1.19 + 1.20 +export TEXTDOMAIN='tazweb-lib' 1.21 + 1.22 +# Parse cmdline options and store values in a variable 1.23 +for opt in "$@"; do 1.24 + opt_name="${opt%%=*}" 1.25 + opt_name="${opt_name#--}" 1.26 + case "$opt" in 1.27 + --*=*) export $opt_name="${opt#*=}" ;; 1.28 + --*) export $opt_name="on" ;; 1.29 + esac 1.30 +done 1.31 + 1.32 +# HTML 5 header with built-in minimal CSS. Usage: html_header "title" 1.33 +html_header() { 1.34 + local title="$1" 1.35 + cat << EOT 1.36 +<!DOCTYPE html> 1.37 +<html lang="en"> 1.38 +<head> 1.39 + <meta charset="utf-8" /> 1.40 + <title>$title</title> 1.41 + <style type="text/css"> 1.42 + body { margin: 2% 10%; font-size: 92%; } ul { padding: 0; } 1.43 + h1 { color: #ccc; border-bottom: 2px solid #ccc; } 1.44 + ul a { text-decoration: none; } ul a:hover { text-decoration: underline; } 1.45 + li { list-style-type: none; line-height: 1.4em; padding: 0; } 1.46 + footer { font-size: 80%; border-top: 2px solid #ccc; padding: 5px 0; color: #888; } 1.47 + </style> 1.48 +</head> 1.49 +<body> 1.50 +<section id="content"> 1.51 +<h1>$title</h1> 1.52 +EOT 1.53 +} 1.54 + 1.55 +# HTML 5 footer: html_footer content 1.56 +html_footer() { 1.57 + cat << EOT 1.58 +</section> 1.59 +<footer> 1.60 + ${@} 1.61 +</footer> 1.62 +</body> 1.63 +</html> 1.64 +EOT 1.65 +} 1.66 + 1.67 +# Generate bookmarks.html 1.68 +html_bookmarks() { 1.69 + html_header "$(gettext 'Bookmarks')" > ${bm_html} 1.70 + echo '<ul>' >> ${bm_html} 1.71 + IFS="|" 1.72 + cat ${bm_txt} | while read title url null 1.73 + do 1.74 + cat >> ${bm_html} << EOT 1.75 + <li><a href="${url}">${title}</a></li> 1.76 +EOT 1.77 + done; unset IFS 1.78 + echo '</ul>' >> ${bm_html} 1.79 + html_footer "$(cat $bm_txt | wc -l) $(gettext "Bookmarks") - $(date)" \ 1.80 + >> ${bm_html} 1.81 + # Security fix from old cgi-bin bookmarks.cgi 1.82 + chown ${USER}.${USER} ${bm_txt}; chmod 0600 ${bm_txt} 1.83 +} 1.84 + 1.85 +edit_bookmarks() { 1.86 + yad --text-info \ 1.87 + --center --width=640 --height=480 --filename=${bm_txt} 1.88 +} 1.89 + 1.90 +# Generate cookies.html (for direct view of cookies in TazWeb) 1.91 +html_cookies() { 1.92 + html_header "$(gettext 'Cookies')" > ${cookies_html} 1.93 + echo '<pre>' >> ${cookies_html} 1.94 + IFS="|" 1.95 + cat ${cookies_txt} | while read line 1.96 + do 1.97 + cat >> ${cookies_html} << EOT 1.98 +${line#\#HttpOnly_} 1.99 +EOT 1.100 + done; unset IFS 1.101 + echo '</pre>' >> ${cookies_html} 1.102 + html_footer $(cat $cookies_txt | wc -l) $(gettext "Cookies") - $(date) \ 1.103 + >> ${cookies_html} 1.104 +} 1.105 + 1.106 +clean_cookies() { 1.107 + rm ${cookies_txt}; touch ${cookies_txt} 1.108 +} 1.109 + 1.110 +# 1.111 +# Execute any shell_function 1.112 +# 1.113 +case "$1" in 1.114 + 1.115 + *_*) 1.116 + cmd=${1}; shift; ${cmd} ${@} ;; 1.117 + 1.118 + *) grep "[a-z]_*()" ${0} | awk '{print $1}' ;; 1.119 + 1.120 +esac; exit 0
2.1 --- a/tazweb-helper Mon Mar 13 01:50:53 2017 +0100 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,93 +0,0 @@ 2.4 -#!/bin/sh 2.5 -# 2.6 -# TazWeb Helper - Handle bookmarks (No libtaz.sh: usable on any Linux distro) 2.7 -# 2.8 - 2.9 -tazweb="$(pwd)/tazweb" 2.10 -config="$HOME/.config/tazweb" 2.11 -bm_txt="$config/bookmarks.txt" 2.12 -bm_html="$config/bookmarks.html" 2.13 - 2.14 -help() { 2.15 - cat << EOT 2.16 - 2.17 -$(gettext "Usage:") $(basename $0) [bookmarks] --option 2.18 - 2.19 -$(gettext "Options:") 2.20 - --raw Show raw bookmarks.txt in textmode 2.21 - --html Show html bookmarks in TazWeb 2.22 - 2.23 -EOT 2.24 -} 2.25 - 2.26 -# HTML 5 header with built-in minimal CSS 2.27 -html_header() { 2.28 - cat << EOT 2.29 -<!DOCTYPE html> 2.30 -<html lang="en"> 2.31 -<head> 2.32 - <meta charset="utf-8" /> 2.33 - <title>TazWeb - Bookmarks</title> 2.34 - <style type="text/css"> 2.35 - body { margin: 2% 10%; font-size: 94%; } ul { padding: 0; } 2.36 - h1 { color: #888; border-bottom: 4px solid #888; } 2.37 - ul a { text-decoration: none; } ul a:hover { text-decoration: underline; } 2.38 - li { list-style-type: none; color: #666; line-height: 1.4em; padding: 0; } 2.39 - footer { font-size: 80%; border-top: 1px solid #888; padding: 5px 0; } 2.40 - </style> 2.41 -</head> 2.42 -<body> 2.43 -<section id="content"> 2.44 -<h1>TazWeb Bookmarks</h1> 2.45 -<ul> 2.46 -EOT 2.47 -} 2.48 - 2.49 -# HTML 5 footer 2.50 -html_footer() { 2.51 - cat << EOT 2.52 -</ul> 2.53 -</section> 2.54 -<footer> 2.55 - $(cat $bm_txt | wc -l) $(gettext "bookmarks") 2.56 -</footer> 2.57 -</body> 2.58 -</html> 2.59 -EOT 2.60 -} 2.61 - 2.62 -# Generate bookmarks.html 2.63 -html_bookmarks() { 2.64 - html_header > ${bm_html} 2.65 - IFS="|" 2.66 - cat ${bm_txt} | while read title url null 2.67 - do 2.68 - cat >> ${bm_html} << EOT 2.69 - <li><a href="${url}">${title}</a></li> 2.70 -EOT 2.71 - done 2.72 - unset IFS 2.73 - html_footer >> ${bm_html} 2.74 - # Security fix from old cgi-bin bookmarks.cgi 2.75 - chown ${USER}.${USER} ${bm_txt}; chmod 0600 ${bm_txt} 2.76 -} 2.77 - 2.78 -# 2.79 -# Commands 2.80 -# 2.81 -case "$1" in 2.82 - 2.83 - -b|bookmarks) 2.84 - if [ "$raw" ]; then 2.85 - cat ${config}/bookmarks.txt 2.86 - fi 2.87 - if [ "$html" ]; then 2.88 - html_bookmarks 2.89 - ${tazweb} file:///${config}/bookmarks.html & 2.90 - fi ;; 2.91 - 2.92 - *_*) ${1} ;; 2.93 - 2.94 - *|-h|help) help ;; 2.95 - 2.96 -esac; exit 0