tazweb view data/bookmarks.cgi @ rev 144

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sat Apr 05 20:15:13 2014 +0100 (2014-04-05)
parents b499c4de5634
children 68248b2673dd
line source
1 #!/bin/sh
2 #
3 # TazWeb Bookmarks CGI handler
4 # Copyright (C) 2014 SliTaz GNU/Linux - BSD License
5 #
6 . /usr/lib/slitaz/httphelper.sh
8 script="$SCRIPT_NAME"
9 home="$(GET home)"
10 user="$(basename $home)"
11 config="/home/$user/.config/tazweb"
12 bookmarks="$config/bookmarks.txt"
14 # Security check
15 if [ "$REMOTE_ADDR" != "127.0.0.1" ]; then
16 echo "Security exit" && exit 1
17 fi
19 # HTML 5 header with built-in minimal CSS
20 html_header() {
21 cat << EOT
22 <!DOCTYPE html>
23 <html lang="en">
24 <head>
25 <meta charset="utf-8" />
26 <title>TazWeb - Bookmarks</title>
27 <style type="text/css">
28 body { margin: 2% 10%; } .rm { color: #666; } ul { padding: 0; }
29 .rm:hover { text-decoration: none; color: #B70000; }
30 h1 { color: #666; border-bottom: 4px solid #666; }
31 a { text-decoration: none; } a:hover { text-decoration: underline; }
32 li { list-style-type: none; color: #666; line-height: 1.4em; padding: 0; }
33 footer { font-size: 80%; border-top: 2px solid #666; padding: 5px 0; }
34 </style>
35 </head>
36 <body>
37 <section id="content">
39 EOT
40 }
42 # HTML 5 footer
43 html_footer() {
44 cat << EOT
46 </section>
48 <footer>
49 <a href="$script?home=$home">Bookmarks</a> -
50 <a href="$script?raw&amp;home=$home">bookmarks.txt</a>
51 </footer>
53 </body>
54 </html>
55 EOT
56 }
58 # Handle GET actions: continue or exit
60 case " $(GET) " in
61 *\ raw\ *)
62 # View bookmarks file
63 header
64 html_header
65 echo "<h1>TazWeb: bookmarks.txt</h1>"
66 echo "<pre>"
67 cat ${bookmarks}
68 echo "</pre>"
69 html_footer && exit 0 ;;
70 *\ rm\ *)
71 # Remove a bookmark item and continue
72 url=$(GET rm)
73 [ "$url" ] || continue
74 sed -i s"#.*${url}.*##" ${bookmarks}
75 sed -i "/^$/"d ${bookmarks} ;;
76 esac
78 # Show all bookmarks
79 header
80 html_header
81 echo '<h1>TazWeb Bookmarks</h1>'
82 echo '<ul>'
83 IFS="|"
84 cat ${bookmarks} | while read title url null
85 do
86 cat << EOT
87 <li><a class="rm" href="?rm=$url&amp;home=$home">&otimes;<a/>
88 <a href="${url}">${title}<a/></li>
89 EOT
90 done
91 unset IFS
92 echo '</ul>'
93 html_footer
95 exit 0