tazbug view tazbug @ rev 60
bugs.cgi: Dont show file path in results
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Jan 07 20:43:48 2014 +0100 (2014-01-07) |
parents | 291785fb21f7 |
children |
line source
1 #!/bin/sh
2 #
3 # TazBug Command line tool. Help to encrypt password, key and post on the
4 # the server side.
5 #
6 # Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
7 #
8 . /usr/lib/slitaz/httphelper
9 [ -f "/etc/slitaz/tazbug.conf" ] && . /etc/slitaz/tazbug.conf
10 [ -f "tazbug.conf" ] && . tazbug.conf
12 # Use same key for SliTaz sites.
13 conf=$HOME/.config/slitaz/account.conf
15 # Internationalization: $(gettext "")
16 . /usr/bin/gettext.sh
17 TEXTDOMAIN='tazbug'
18 export TEXTDOMAIN
20 # Parse cmdline options.
21 for opt in "$@"
22 do
23 case "$opt" in
24 --bug=*)
25 bug="${opt#--bug=}" ;;
26 --desc=*)
27 desc="${opt#--desc=}" ;;
28 --msg=*)
29 msg="${opt#--msg=}" ;;
30 --priority=*)
31 priority=${opt#--priority=} ;;
32 --pkgs=*)
33 pkgs="${opt#--pkgs=}" ;;
34 --name=*)
35 name="${opt#--name=}" ;;
36 --user=*)
37 user=${opt#--user=} ;;
38 --mail=*)
39 mail=${opt#--mail=} ;;
40 --pass=*)
41 pass=${opt#--pass=} ;;
42 esac
43 done
45 #
46 # Functions
47 #
49 # --> in /usr/lib/slitaz/httphelper
50 # httpd -e dont work with GET URL requests
51 http_urlencode() {
52 #space: + or %20
53 sed -e 's/ /+/g; s/!/%21/g; s/"/%22/g; s/#/%23/g; s/%/%25/g; s/&/%26/g'
54 }
56 # Usage.
57 usage() {
58 cat << EOT
60 $(gettext 'Usage:') $(basename $0) $(gettext '[command] [args]')
62 $(gettext 'Commands:')
63 gen-key $(gettext "Recreate the SliTaz secure key.")
64 gen-config $(gettext "Create a new SliTaz account configuration.")
65 signup $(gettext "Create a new account on SliTaz Bugs.")
66 new-msg $(gettext "Send a new message to an open bug.")
67 new-bug $(gettext "Send a new bug report.")
69 $(gettext 'Examples:')
70 $(basename $0) signup --name="Real Name" --user=login \\
71 --mail=mail@domain --pass=password
72 $(basename $0) new-msg --bug=0 --msg="Message for bug with ID 0"
74 EOT
75 }
77 # Check cmdline user info args
78 check_info_args() {
79 [ ! "$name" ] && gettext "Missing real name" && echo && exit 0
80 [ ! "$user" ] && gettext "Missing login name" && echo && exit 0
81 [ ! "$mail" ] && gettext "Missing email" && echo && exit 0
82 [ ! "$pass" ] && gettext "Missing password" && echo && exit 0
83 }
85 # Crypt pass when login
86 crypt_pass() {
87 echo -n "$1" | md5sum | awk '{print $1}'
88 }
90 # Gen a config file
91 gen_config() {
92 gettext "Creating SliTaz account configuration..."; echo
93 mkdir -p $HOME/.config/slitaz
94 cat > $conf << EOT
95 # SliTaz account configuration
97 NAME="$name"
98 USER="$user"
99 MAIL="$mail"
100 KEY=""
101 EOT
102 chmod 0600 $conf
103 }
105 # Gen the secure key: gen_key login mail passwd
106 gen_key() {
107 gettext "Creating SliTaz secure key..."; echo
108 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
109 sed -i s"/KEY=.*/KEY=\"$key\"/" $conf
110 chmod 0600 $conf
111 }
113 #
114 # Commands
115 #
117 case "$1" in
118 gen-key)
119 # MD5 key
120 [ ! "$pass" ] && gettext "Missing password" && echo && exit 0
121 . $conf || exit 1
122 gen_key $USER $MAIL $pass ;;
123 gen-config)
124 # Recreate a config file if values have changed sites must be updated
125 check_info_args
126 gen_config
127 gen_key ;;
128 signup)
129 # Create an account on the server
130 check_info_args
131 echo ""
132 echo "Sending account request for: $name ($user)"
133 # 'gen_key user:mail:passwd' locally but don't send it. It will be
134 # generated on server from the user login, mail and encrypted password
135 # so it is not transmited in GET urls.
136 gen_config
137 pass=$(crypt_pass $pass)
138 name="$(echo $name | http_urlencode)"
139 gen_key
140 . $conf
141 echo "Secure key: $KEY"
142 # Wget GET url
143 busybox wget "${WEB_URL}?signup=$user&name=$name&mail=$mail&pass=$pass" \
144 -O /tmp/bug.msg
145 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
146 new-msg)
147 # Post a new message: ID message
148 . $conf || exit 1
149 [ ! "$bug" ] && gettext "Missing bug ID" && echo && exit 0
150 [ ! "$msg" ] && gettext "Missing message" && echo && exit 0
151 msg="$(echo $msg | http_urlencode)"
152 # Wget GET url
153 busybox wget \
154 "${WEB_URL}?key=$KEY&bug=$bug&msg=$msg" -O /tmp/bug.msg
155 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
156 new-bug)
157 # Post a new bug: bug desc priority pkgs
158 . $conf || exit 1
159 [ ! "$bug" ] && gettext "Missing bug title" && echo && exit 0
160 [ ! "$desc" ] && gettext "Missing description" && echo && exit 0
161 [ ! "$priority" ] && gettext "Missing bug priority" && echo && exit 0
162 bug="$(echo $bug | http_urlencode)"
163 desc="$(echo $desc | http_urlencode)"
164 releases="$(basename $(cat /var/lib/tazpkg/mirror))"
165 # Wget GET url
166 busybox wget \
167 "${WEB_URL}?key=$KEY&bug=$bug&desc=$desc&priority=$priority&pkgs=$pkgs&releases=$releases" \
168 -O /tmp/bug.msg
169 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
170 *)
171 usage ;;
172 esac
174 exit 0