tazpanel view pkgs.cgi @ rev 42

Add settings.cgi and split user config from index.cgi, add need CSS stuff and up POT
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 07 01:22:07 2011 +0200 (2011-04-07)
parents 5f2f88618292
children 13b1019d68d8
line source
1 #!/bin/sh
2 #
3 # TazPKG CGI interface - Manage packages via the a browse
4 #
5 # This CGI interface intensively use tazpkg to manage package and have
6 # it own code for some tasks. Please KISS it important and keep speed
7 # in mind. Thanks, Pankso.
8 #
9 # (C) 2011 SliTaz GNU/Linux - GNU gpl v2
10 #
11 echo "Content-Type: text/html"
12 echo ""
14 . lib/libtazpanel
15 get_config
17 # Include gettext helper script.
18 . /usr/bin/gettext.sh
20 # Export package name for gettext.
21 TEXTDOMAIN='tazpanel'
22 export TEXTDOMAIN
24 # xHTML 5 header
25 TITLE="- Packages"
26 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
28 # DEBUG mode
29 if [ $DEBUG == "1" ]; then
30 echo "<p class='debug'>$REQUEST_METHOD ${QUERY_STRING}</p>"
31 fi
33 # We need packages information for list and search
34 parse_packages_desc() {
35 while read line
36 do
37 echo '<tr>'
38 pkg=$(echo $line | cut -d "|" -f 1)
39 vers=$(echo $line | cut -d "|" -f 2)
40 desc=$(echo $line | cut -d "|" -f 3)
41 web=$(echo $line | cut -d "|" -f 5)
42 if [ -d $INSTALLED/$pkg ]; then
43 echo -e "<td><input type='checkbox' name='pkg' value=\"$pkg\">\n
44 <a href='$SCRIPT_NAME?info=$pkg'>
45 <img src='$IMAGES/tazpkg-installed.png'/>$pkg</a></td>"
46 else
47 echo -e "<td><input type='checkbox' name='pkg' value=\"$pkg\">\n
48 <img src='$IMAGES/tazpkg.png'/>$pkg</td>"
49 fi
50 echo "<td>$vers</td>"
51 echo "<td class='desc'>$desc</td>"
52 echo "<td><a href='$web'>web</a></td>"
53 echo '</tr>'
54 done
55 }
57 # Remove status and ESC char from tazpkg commands output
58 filter_tazpkg_msgs() {
59 grep ^[a-zA-Z0-9] | sed s'/\.*\]//'
60 }
62 # Display a full summary of packages stats
63 packages_summary() {
64 gettext "Last recharge : "
65 stat=`stat -c %y $LOCALSTATE/packages.list | \
66 sed 's/\(:..\):.*/\1/' | awk '{print $1}'`
67 mtime=`find /var/lib/tazpkg/packages.list -mtime +10`
68 echo -n "$stat "
69 if [ "$mtime" ]; then
70 echo "(Older than 10 days)"
71 else
72 echo "(Not older than 10 days)"
73 fi
74 gettext "Installed packages : "
75 ls $INSTALLED | wc -l
76 gettext "Mirrored packages : "
77 cat $LOCALSTATE/packages.list | wc -l
78 gettext "Upgradeable packages : "
79 cat $LOCALSTATE/upgradeable-packages.list | wc -l
80 gettext "Installed files : "
81 cat $INSTALLED/*/files.list | wc -l
82 gettext "Blocked packages : "
83 cat $LOCALSTATE/blocked-packages.list | wc -l
84 }
86 # Parse mirrors list to be able to have an icon an remove link
87 list_mirrors() {
88 cat $LOCALSTATE/mirrors | while read line
89 do
90 cat << EOT
91 <li><a href="$SCRIPT_NAME?config=rm-mirror=$line"><img
92 src="$IMAGES/clear.png" /></a><a href="$line">$line</a></li>
93 EOT
94 done
95 }
97 #
98 # xHTML functions
99 #
101 # ENTER will search but user may search for a button, so put one.
102 search_form() {
103 cat << EOT
104 <div class="search">
105 <form method="get" action="$SCRIPT_NAME">
106 <p>
107 <input type="text" name="search" size="20">
108 <input type="submit" value="`gettext "Search"`">
109 </p>
110 </form>
111 </div>
112 EOT
113 }
115 table_head() {
116 cat << EOT
117 <tr id="thead">
118 <td>`gettext "Name"`</td>
119 <td>`gettext "Version"`</td>
120 <td>`gettext "Description"`</td>
121 <td>`gettext "Web"`</td>
122 </tr>
123 EOT
124 }
126 sidebar() {
127 cat << EOT
128 <div id="sidebar">
129 <h4>Categories</h4>
130 <a class="active_base-system" href="$SCRIPT_NAME?cat=base-system">Base-system</a>
131 <a class="active_x-window" href="$SCRIPT_NAME?cat=x-window">X window</a>
132 <a class="active_utilities" href="$SCRIPT_NAME?cat=utilities">Utilities</a>
133 <a class="active_network" href="$SCRIPT_NAME?cat=network">Network</a>
134 <a class="active_games" href="$SCRIPT_NAME?cat=games">Games</a>
135 <a class="active_graphics" href="$SCRIPT_NAME?cat=graphics">Graphics</a>
136 <a class="active_office" href="$SCRIPT_NAME?cat=office">Office</a>
137 <a class="active_multimedia" href="$SCRIPT_NAME?cat=multimedia">Multimedia</a>
138 <a class="active_developement" href="$SCRIPT_NAME?cat=development">Development</a>
139 <a class="active_system-tools" href="$SCRIPT_NAME?cat=system-tools">System tools</a>
140 <a class="active_security" href="$SCRIPT_NAME?cat=security">Security</a>
141 <a class="active_misc" href="$SCRIPT_NAME?cat=misc">Misc</a>
142 <a class="active_meta" href="$SCRIPT_NAME?cat=meta">Meta</a>
143 <a class="active_non-free" href="$SCRIPT_NAME?cat=non-free">Non free</a>
144 </div>
145 EOT
146 }
148 # For my packages list
149 list_actions() {
150 cat << EOT
151 <div class="float-left">
152 `gettext "Selection:"`
153 <input type="submit" name="do" value="Remove" />
154 </div>
155 <div class="float-right">
156 `gettext "List:"`
157 <input type="submit" name="recharge" value="Recharge" />
158 <input type="submit" name="upgradeable" value="Upgrade" />
159 </div>
160 EOT
161 }
163 # For list-cat
164 list_cat_action() {
165 cat << EOT
166 <div class="float-left">
167 `gettext "Selection:"`
168 <input type="submit" name="do" value="Install" />
169 <input type="submit" name="do" value="Remove" />
170 </div>
171 <div class="float-right">
172 `gettext "List:"`
173 <input type="submit" name="recharge" value="Recharge" />
174 <input type="submit" name="upgradeable" value="Upgrade" />
175 <a class="button" href='$SCRIPT_NAME?list'>
176 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
177 </div>
178 EOT
179 }
181 # For search with JS function to toogle all pkgs
182 list_full_actions() {
183 cat << EOT
184 <div class="float-left">
185 `gettext "Selection:"`
186 <input type="submit" name="do" value="Install" />
187 <input type="submit" name="do" value="Remove" />
188 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
189 </div>
190 <div class="float-right">
191 `gettext "List:"`
192 <input type="submit" name="recharge" value="Recharge" />
193 <input type="submit" name="upgradeable" value="Upgrade" />
194 <a class="button" href='$SCRIPT_NAME?list'>
195 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
196 </div>
197 EOT
198 }
200 # For upgrade with JS function to toogle all pkgs and no 'Upgrade' button
201 list_up_actions() {
202 cat << EOT
203 <div class="float-left">
204 `gettext "Selection:"`
205 <input type="submit" name="do" value="Install" />
206 <input type="submit" name="do" value="Remove" />
207 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
208 </div>
209 <div class="float-right">
210 `gettext "List:"`
211 <input type="submit" name="recharge" value="Recharge" />
212 <a class="button" href='$SCRIPT_NAME?list'>
213 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
214 </div>
215 EOT
216 }
218 #
219 # Commands
220 #
222 case "$QUERY_STRING" in
223 list*)
224 # List installed packages. This is the default because parsing
225 # the full packages.desc can be long and take some resources
226 cd $INSTALLED
227 search_form
228 sidebar
229 cat << EOT
230 <h2>`gettext "My packages"`</h2>
231 <form method='get' action='$SCRIPT_NAME'>
232 <div id="actions">
233 EOT
234 list_actions
235 echo '</div>'
236 table_start
237 table_head
238 for pkg in *
239 do
240 . $pkg/receipt
241 echo '<tr>'
242 # Use default tazpkg icon since all packages displayed are
243 # installed
244 echo "<td class='pkg'>
245 <input type='checkbox' name='pkg' value=\"$pkg\" />
246 <a href='$SCRIPT_NAME?info=$pkg'><img
247 src='$IMAGES/tazpkg-installed.png'/>$pkg</a></td>"
248 echo "<td>$VERSION</td>"
249 echo "<td class='desc'>$SHORT_DESC</td>"
250 echo "<td><a href='$WEB_SITE'>web</a></td>"
251 echo '</tr>'
252 done
253 table_end
254 list_actions
255 echo '</form>' ;;
256 cat*)
257 # List all available packages by category on mirror. Listing all
258 # packages is to resource intensive and not usefull.
259 cd $LOCALSTATE
260 category=${QUERY_STRING#cat=}
261 [ "${QUERY_STRING}" == "cat" ] && category="base-system"
262 search_form
263 sidebar | sed s/"active_${category}"/"active"/
264 cat << EOT
265 <h2>`gettext "Category:"` $category</h2>
266 <form method='get' action='$SCRIPT_NAME'>
267 <div id="actions">
268 EOT
269 list_cat_action
270 echo '</div>'
271 table_start
272 table_head
273 grep "| $category |" packages.desc | parse_packages_desc
274 table_end
275 list_cat_action
276 echo '</form>' ;;
277 search=*)
278 # Search for packages
279 pkg=${QUERY_STRING#*=}
280 cd $LOCALSTATE
281 search_form
282 sidebar
283 cat << EOT
284 <h2>`gettext "Search packages"`</h2>
285 <form method="get" action="$SCRIPT_NAME">
286 <div id="actions">
287 EOT
288 list_full_actions
289 echo '</div>'
290 table_start
291 table_head
292 grep $pkg packages.desc | parse_packages_desc
293 table_end
294 echo '</form>' ;;
295 recharge*)
296 # Let recharge the packages list
297 search_form
298 sidebar
299 cat << EOT
300 <h2>`gettext "Recharge"`</h2>
301 <form method='get' action='$SCRIPT_NAME'>
302 <div id="actions">
303 <div class="float-left">
304 <p>
305 `gettext "Recharge will check for new or updated packages...
306 please wait"`
307 </p>
308 </div>
309 <div class="float-right">
310 <p>
311 <a class="button" href='$SCRIPT_NAME?list'>
312 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
313 </p>
314 </div>
315 </div>
316 <pre>
317 EOT
318 tazpkg recharge | filter_tazpkg_msgs
319 echo '</pre>'
320 echo '<p>'
321 gettext "Packages lists are up-to-date"
322 echo '</p>' ;;
323 upgradeable*)
324 cd $LOCALSTATE
325 search_form
326 sidebar
327 cat << EOT
328 <h2>`gettext "Upgradeable packages"`</h2>
329 <form method="get" action="$SCRIPT_NAME">
330 <div id="actions">
331 EOT
332 list_up_actions
333 tazpkg upgradeable
334 echo '</div>'
335 table_start
336 table_head
337 for pkg in `cat upgradeable-packages.list`
338 do
339 grep "^$pkg |" $LOCALSTATE/packages.desc | parse_packages_desc
340 done
341 table_end
342 list_up_actions
343 echo '</form>' ;;
344 do=*)
345 # Do an action on one or some packages
346 cmdline=`echo ${QUERY_STRING#do=} | sed s'/&/ /g'`
347 cmd=`echo ${cmdline} | awk '{print $1}'`
348 pkgs=`echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//`
349 case $cmd in
350 install|Install)
351 cmd=get-install opt=--forced ;;
352 remove|Remove)
353 cmd=remove ;;
354 esac
355 search_form
356 sidebar
357 cat << EOT
358 <h2>Tazpkg: $cmd</h2>
359 <form method="get" action="$SCRIPT_NAME">
360 <div id="actions">
361 <div class="float-left">
362 <p>
363 `gettext "Performing task on packages... please wait"`
364 </p>
365 </div>
366 <div class="float-right">
367 <p>
368 <a class="button" href='$SCRIPT_NAME?list'>
369 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
370 </p>
371 </div>
372 </div>
373 EOT
374 echo '<pre class="pre-main">'
375 gettext "Executing $cmd for:$pkgs"
376 echo '</pre>'
377 for pkg in $pkgs
378 do
379 echo '<pre>'
380 echo 'y' | tazpkg $cmd $pkg $opt 2>/dev/null | filter_tazpkg_msgs
381 echo '</pre>'
382 done ;;
383 info=*)
384 pkg=${QUERY_STRING#*=}
385 search_form
386 sidebar
387 . $INSTALLED/$pkg/receipt
388 files=`cat $INSTALLED/$pkg/files.list | wc -l`
389 cat << EOT
390 <h2>`gettext "Package"` $PACKAGE</h2>
391 <div id="actions">
392 <div class="float-left">
393 <p>
394 <a class="button" href='$SCRIPT_NAME?do=remove&$pkg'>`gettext "Remove"`</a>
395 </p>
396 </div>
397 <div class="float-right">
398 <p>
399 <a class="button" href='$SCRIPT_NAME?list'>
400 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
401 </p>
402 </div>
403 </div>
404 <pre>
405 Name : $PACKAGE
406 Version : $VERSION
407 Description : $SHORT_DESC
408 Category : $CATEGORY
409 Maintainer : $MAINTAINER
410 Depends : `for i in $DEPENDS; do echo -n \
411 "<a href="$SCRIPT_NAME?info=$i">$i</a> "; done`
412 Website : <a href="$WEB_SITE">$WEB_SITE</a>
413 Sizes : $PACKED_SIZE/$UNPACKED_SIZE
414 </pre>
416 <p>`gettext "Installed files:"` `cat $INSTALLED/$pkg/files.list | wc -l`</p>
417 <pre>
418 `cat $INSTALLED/$pkg/files.list`
419 </pre>
420 EOT
421 ;;
422 config*)
423 # Tazpkg configuration page
424 cmd=${QUERY_STRING#*=}
425 case "$cmd" in
426 clean)
427 rm -rf /var/cache/tazpkg/* ;;
428 add-mirror*=http*|add-mirror*=ftp*)
429 # Decode url
430 mirror=`httpd -d ${cmd#*=}`
431 echo "$mirror" >> $LOCALSTATE/mirrors ;;
432 rm-mirror=http://*|rm-mirror=ftp://*)
433 mirror=${QUERY_STRING#*=rm-mirror=}
434 sed -i -e "s@$mirror@@" -e '/^$/d' $LOCALSTATE/mirrors ;;
435 esac
436 cache_files=`find /var/cache/tazpkg -name *.tazpkg | wc -l`
437 cache_size=`du -sh /var/cache/tazpkg`
438 sidebar
439 cat << EOT
440 <h2>`gettext "Configuration"`</h2>
441 <div>
442 <p>`gettext "Tazpkg configuration and settings"`</p>
443 </div>
444 <div>
445 <form method="get" action="$SCRIPT_NAME">
446 <p>
447 `gettext "Packages in the cache:"` $cache_files ($cache_size)
448 <input type="hidden" name="config" value="clean" />
449 <input type="submit" value="Clean" />
450 </p>
451 </form>
452 </div>
454 <h3>`gettext "Current mirror list"`</h3>
455 <div class="box">
456 <ul>
457 `list_mirrors`
458 </ul>
459 </div>
460 <form method="get" action="$SCRIPT_NAME">
461 <p>
462 <input type="hidden" name="config" value="add-mirror" />
463 <input type="text" name="mirror" size="60">
464 <input type="submit" value="Add mirror" />
465 </p>
466 </form>
467 EOT
468 ;;
469 *)
470 #
471 # Default to summary
472 #
473 search_form
474 sidebar
475 cat << EOT
476 <h2>`gettext "Summary"`</h2>
477 <div id="actions">
478 `gettext "Overview of all installed and mirrored packages"`
479 </div>
480 <pre class="pre-main">
481 `packages_summary`
482 </pre>
483 <a class="button" href='$SCRIPT_NAME?list'>
484 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
485 <a class="button" href='$SCRIPT_NAME?recharge'>
486 <img src="$IMAGES/recharge.png" />`gettext "Recharge list"`</a>
487 <a class="button" href='$SCRIPT_NAME?upgradeable'>
488 <img src="$IMAGES/update.png" />`gettext "Check upgrade"`</a>
489 <a class="button" href='$SCRIPT_NAME?config'>
490 <img src="$IMAGES/edit.png" />`gettext "Configuration"`</a>
492 <h3>`gettext "Latest log entries"`</h3>
493 <pre>
494 `tail -n 6 /var/log/tazpkg.log | fgrep "-" | \
495 awk '{print $1, $2, $3, $4, $5, $6, $7}'`
496 </pre>
498 EOT
499 ;;
500 esac
502 # xHTML 5 footer
503 xhtml_footer
504 exit 0