# HG changeset patch # User Aleksej Bobylev # Date 1409049110 -10800 # Node ID e96aa956e72ea7112bf7e4e621761a32ec07471c # Parent ce9cbd90365aef8cda0f96c00304033d1202c391 tramys-client, tramys-server: now using http headers only (no more additional info in the server logs); added a lot of comments. diff -r ce9cbd90365a -r e96aa956e72e tramys-client/receipt --- a/tramys-client/receipt Mon Aug 25 10:52:38 2014 +0200 +++ b/tramys-client/receipt Tue Aug 26 13:31:50 2014 +0300 @@ -1,7 +1,7 @@ # SliTaz package receipt. PACKAGE="tramys-client" -VERSION="140824" +VERSION="140826" CATEGORY="system-tools" SHORT_DESC="Tool for managing translation files for SliTaz GNU/Linux, client part" MAINTAINER="al.bobylev@gmail.com" diff -r ce9cbd90365a -r e96aa956e72e tramys-client/stuff/tramys2 --- a/tramys-client/stuff/tramys2 Mon Aug 25 10:52:38 2014 +0200 +++ b/tramys-client/stuff/tramys2 Tue Aug 26 13:31:50 2014 +0300 @@ -6,6 +6,7 @@ . /etc/slitaz/slitaz.conf . /lib/libtaz.sh +# Ask for root access in order to install the files in the system. if [ $(id -u) != 0 ]; then exec tazbox su $0 $@; exit 0 fi @@ -14,8 +15,14 @@ WORKING=$(mktemp -d) LOG="/tmp/tramys.log" TGZ="/tmp/tramys.tgz" +URL="http://cook.slitaz.org/tramys2.cgi" + +# Common Yad options. YADCONF="--center --window-icon=config-language --image=config-language --image-on-top" +# First step. Describes the functions of the program. +# It is possible to set the language. +# Also here the user has the ability to stop the program. yad $YADCONF --title="tramys (1/3)" --text="$(_ \ 'Now translations for all installed programs will be found and downloaded. You can change locale if you want, or proceed. @@ -27,23 +34,44 @@ 1) exit 0 ;; esac -busybox wget -U "$(cd $INSTALLED; ls -1 | tr '\n' ' ')" \ - "http://cook.slitaz.org/tramys2.cgi?lang=$LANG&rel=$(cat /etc/slitaz-release)" \ - -O - | tee $LOG | \ +# your locale -> HTTP_ACCEPT_LANGUAGE +# your SliTaz release -> HTTP_ACCEPT (different releases have different translations) +# your installed packages list -> HTTP_COOKIE (list=...) +# Note clean address "tramys2.cgi" in the server access logs. +# +# Server sending and Yad shows user useful info using log widget. +# We are temporarily stored this log in the $LOG file in order to get +# a download token (see below). +# Here the user can refuse to download the file. +busybox wget --header "Accept-Language: $LANG" \ + --header "Accept: $(cat /etc/slitaz-release)" \ + --header "Cookie: list=$(cd $INSTALLED; ls -1 | tr '\n' ' ')" \ + $URL -O - | tee $LOG | \ yad $YADCONF --title="tramys (2/3)" --progress --width=320 --text="$(_ \ 'The server processes the request. Please wait.')" \ --enable-log --log-expanded \ --button "gtk-cancel:1" --button "gtk-go-forward:0" -case $? in - 1) exit 0 ;; +ANSWER=$? + +# In the last line of log server gives us a download token. +# We can download archive which the server has prepared for us. +# Get download token and remove log. +DLKEY=$(tail -n1 $LOG); rm -f $LOG + +case $ANSWER in + 1) + # We need to remove archive that the user has refused to download. + # This command passed in HTTP_COOKIE (rm=...) + busybox wget --header "Cookie: rm=$DLKEY" $URL -O /dev/null; exit 0 ;; esac -DLKEY=$(tail -n1 $LOG); rm -f $LOG - -busybox wget "http://cook.slitaz.org/tramys2.cgi?dl=$DLKEY" -O $TGZ 2>&1 | \ -yad $YADCONF --title="tramys (3/3)" --progress --pulsate --width=320 \ - --text="$(_ \ +# We want to download the file. Show pulsate progress bar. +# This command passed in HTTP_COOKIE (dl=...) +# Also here the user can terminate file downloading. +busybox wget --header "Cookie: dl=$DLKEY" $URL -O $TGZ 2>&1 | \ + yad $YADCONF --title="tramys (3/3)" --progress --pulsate --width=320 \ + --text="$(_ \ 'Downloading in progress. Please wait.')" \ --button "gtk-cancel:1" --button "gtk-ok:0" @@ -51,11 +79,21 @@ 1) exit 0 ;; esac | \ +# Unpack archive content to a temporary folder. busybox tar -xz -C $WORKING -f $TGZ +# All folders and files in the archive are owned by user www and group www. +# This is because the CGI script on the server is executed by the user www. +# If we had just unpacked the archive content into our file system, then there +# would be a big trouble. For example, all folders: /, /usr, /usr/share, +# /usr/share/locale, etc. would be owned by user www and become unavailable +# for a regular user. So force all folders and files to root own. chown -R root:root $WORKING +# copy all translation files to root file system. cp -fpr $WORKING/* / +# remove temporary folder and file, they are no longer needed. rm -f $TGZ rm -rf $WORKING +# Final message. yad $YADCONF --title="tramys" --text="$(_ \ 'Translation files have been installed in your system.')" diff -r ce9cbd90365a -r e96aa956e72e tramys-client/stuff/tramys2.desktop --- a/tramys-client/stuff/tramys2.desktop Mon Aug 25 10:52:38 2014 +0200 +++ b/tramys-client/stuff/tramys2.desktop Tue Aug 26 13:31:50 2014 +0300 @@ -2,6 +2,7 @@ Type=Application Name=tramys Comment=Translate My SliTaz! +Comment[ru]=Переведите свой SliTaz! Exec=tramys2 Icon=config-language Categories=GTK;Settings;DesktopSettings; diff -r ce9cbd90365a -r e96aa956e72e tramys-server/receipt --- a/tramys-server/receipt Mon Aug 25 10:52:38 2014 +0200 +++ b/tramys-server/receipt Tue Aug 26 13:31:50 2014 +0300 @@ -1,7 +1,7 @@ # SliTaz package receipt. PACKAGE="tramys-server" -VERSION="140824" +VERSION="140826" CATEGORY="system-tools" SHORT_DESC="Tool for managing translation files for SliTaz GNU/Linux, server part" MAINTAINER="al.bobylev@gmail.com" diff -r ce9cbd90365a -r e96aa956e72e tramys-server/stuff/tramys2.cgi --- a/tramys-server/stuff/tramys2.cgi Mon Aug 25 10:52:38 2014 +0200 +++ b/tramys-server/stuff/tramys2.cgi Tue Aug 26 13:31:50 2014 +0300 @@ -4,40 +4,34 @@ # Aleksej Bobylev , 2014 # How to use: -# 1. tramys2.cgi?lang=$LANG&rel=$RELEASE to generate archive -# Pass packages list in HTTP_USER_AGENT header -# (seems it have no restrictions for length and no encoded symbols ' ' and '+') -# 2. tramys2.cgi?dl=$DL_KEY to download archive (user can cancel downloading) +# 1. Request for archive: +# HTTP_ACCEPT_LANGUAGE -> users locale +# HTTP_ACCEPT -> SliTaz release +# HTTP_COOKIE (list=...) -> space-separated list of packages to process +# +# 2. Remove archive that the user has refused to download: +# HTTP_COOKIE (rm=DLKEY) -> remove /tmp/tmp.DLKEY.tgz file +# +# 3. Send archive to user: +# HTTP_COOKIE (dl=DLKEY) -> send /tmp/tmp.DLKEY.tgz file . /usr/bin/httpd_helper.sh -WORKING=$(mktemp -d) -DATADIR=/usr/share/tramys +WORKING=$(busybox mktemp -d) # make temp working dir /tmp/tmp.?????? +DATADIR=/usr/share/tramys # this folder contains lists -# hide script -if [ "x$(GET lang)$(GET rel)$(GET dl)" == "x" ]; then - echo -e "HTTP/1.1 404 Not Found\nContent-Type: text/html\n\n404 - Not Found

404 - Not Found

" - exit -fi +# Get user settings from HTTP headers. +lang="$HTTP_ACCEPT_LANGUAGE" +rel="$HTTP_ACCEPT" +cmd="${HTTP_COOKIE%%=*}" +arg="${HTTP_COOKIE#*=}" -# begin: compress and give to client -if [ "x$(GET dl)" != "x" ]; then - WORKING="/tmp/tmp.$(echo $(GET dl) | tr -cd 'A-Za-z0-9')" # avoid relative paths - cat <404 - Not Found

404 - Not Found

" + exit ;; +esac + exit 0