tazweb view data/bookmarks.cgi @ rev 161

Allow IP v6 localhost address to bookmarks work; change "Bookmarks" icon; "cleanse pixmaps" action.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 03 00:47:25 2014 +0200 (2014-11-03)
parents 68248b2673dd
children
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 case $REMOTE_ADDR in
16 127.0.0.1|\[::ffff:127.0.0.1\]) ;;
17 *) header; echo "Security exit! Your IP: $REMOTE_ADDR"; exit 1
18 esac
20 # HTML 5 header with built-in minimal CSS
21 html_header() {
22 cat << EOT
23 <!DOCTYPE html>
24 <html lang="en">
25 <head>
26 <meta charset="utf-8" />
27 <title>TazWeb - Bookmarks</title>
28 <style type="text/css">
29 body { margin: 2% 10%; } .rm { color: #666; } ul { padding: 0; }
30 .rm:hover { text-decoration: none; color: #B70000; }
31 h1 { color: #666; border-bottom: 4px solid #666; }
32 a { text-decoration: none; } a:hover { text-decoration: underline; }
33 li { list-style-type: none; color: #666; line-height: 1.4em; padding: 0; }
34 footer { font-size: 80%; border-top: 2px solid #666; padding: 5px 0; }
35 textarea { width: 100%; height: 240px; font-size: 98%; }
36 </style>
37 </head>
38 <body>
39 <section id="content">
41 EOT
42 }
44 # HTML 5 footer
45 html_footer() {
46 cat << EOT
48 </section>
50 <footer>
51 <a href="$script?home=$home">Bookmarks</a>
52 - <a href="$script?raw&amp;home=$home">Raw</a>
53 - <a href="$script?edit&amp;home=$home">Edit</a>
54 </footer>
56 </body>
57 </html>
58 EOT
59 }
61 # Handle GET actions: continue or exit
63 case " $(GET) " in
65 *\ edit\ *)
66 header
67 html_header
68 cat << EOT
69 <h1>Bookmarks Edit</h1>
70 <form method="get" action="$script" name="edit">
71 <input type="hidden" name="save" />
72 <input type="hidden" name="home" value="$home" />
73 <textarea name="content">$(cat "$bookmarks")</textarea>
74 <p><input type="submit" value="$(gettext "Save bookmarks")" /></p>
75 </form>
76 EOT
77 html_footer && exit 0 ;;
79 *\ save\ *)
80 sed "s/$(echo -en '\r') /\n/g" > ${bookmarks} << EOT
81 $(GET content)
82 EOT
83 ;;
85 *\ raw\ *)
86 # View bookmarks file
87 header
88 html_header
89 echo '<h1>Raw Bookmarks</h1>'
90 echo "<pre>"
91 IFS="|"
92 cat ${bookmarks} | cat ${bookmarks} | while read title url null
93 do
94 echo "$title | <a href='$url'>$url</a>"
95 done
96 unset IFS
97 echo "</pre>"
98 html_footer && exit 0 ;;
100 *\ rm\ *)
101 # Remove a bookmark item and continue
102 url=$(GET rm)
103 [ "$url" ] || continue
104 sed -i s"#.*${url}.*##" ${bookmarks}
105 sed -i "/^$/"d ${bookmarks} ;;
107 esac
109 # Show all bookmarks
110 header
111 html_header
112 echo '<h1>TazWeb Bookmarks</h1>'
113 echo '<ul>'
114 IFS="|"
115 cat ${bookmarks} | while read title url null
116 do
117 cat << EOT
118 <li><a class="rm" href="?rm=$url&amp;home=$home">&otimes;<a/>
119 <a href="${url}">${title}<a/></li>
120 EOT
121 done
122 unset IFS
123 echo '</ul>'
124 html_footer
126 exit 0