tazbug view tazbug @ rev 18

Tiny edits (again)
author Paul Issott <paul@slitaz.org>
date Tue Apr 03 23:03:41 2012 +0100 (2012-04-03)
parents 4e45eb4505eb
children 8d5eadf9ca7a
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 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 -e s'/!/%21/'g -e s'/"/%22/'g -e s'/#/%23/'g \
54 -e s'/%/%25/'g -e s'/&/%26/'g
55 }
57 # Usage.
58 usage() {
59 cat << EOT
61 Usage: $(basename $0) [command] [args]
63 Commands:
64 gen-key $(gettext "Recreate the SliTaz secure key.")
65 gen-config $(gettext "Create a new SliTaz account configuration.")
66 signup $(gettext "Create a new account on SliTaz Bugs.")
67 new-msg $(gettext "Send a new message to an open bug.")
68 new-bug $(gettext "Send a new bug report.")
70 Examples:
71 $(basename $0) signup --name="Real Name" --user=login \\
72 --mail=mail@domain --pass=password
73 $(basename $0) new-msg --bug=0 --msg="Message for bug with ID 0"
75 EOT
76 }
78 # Check cmdline user info args
79 check_info_args() {
80 [ ! "$name" ] && gettext "Missing real name" && echo && exit 0
81 [ ! "$user" ] && gettext "Missing login name" && echo && exit 0
82 [ ! "$mail" ] && gettext "Missing email" && echo && exit 0
83 [ ! "$pass" ] && gettext "Missing password" && echo && exit 0
84 }
86 # Crypt pass when login
87 crypt_pass() {
88 echo -n "$1" | md5sum | awk '{print $1}'
89 }
91 # Gen a config file
92 gen_config() {
93 gettext "Creating SliTaz account configuration..."; echo
94 mkdir -p $HOME/.config/slitaz
95 cat > $conf << EOT
96 # SliTaz account configuration
98 NAME="$name"
99 USER="$user"
100 MAIL="$mail"
101 KEY=""
102 EOT
103 chmod 0600 $conf
104 }
106 # Gen the secure key: gen_key login mail passwd
107 gen_key() {
108 gettext "Creating SliTaz secure key..."; echo
109 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
110 sed -i s"/KEY=.*/KEY=\"$key\"/" $conf
111 chmod 0600 $conf
112 }
114 #
115 # Commands
116 #
118 case "$1" in
119 gen-key)
120 # MD5 key
121 [ ! "$pass" ] && gettext "Missing password" && echo && exit 0
122 . $conf || exit 1
123 gen_key $USER $MAIL $pass ;;
124 gen-config)
125 # Recreate a config file if values have changed sites must be updated
126 check_info_args
127 gen_config
128 gen_key ;;
129 signup)
130 # Create an account on the server
131 check_info_args
132 echo ""
133 echo "Sending account request for: $name ($user)"
134 # 'gen_key user:mail:passwd' locally but don't send it. It will be
135 # generated on server from the user login, mail and encryted password
136 # so it is not transmited in GET urls.
137 gen_config
138 pass=$(crypt_pass $pass)
139 name="$(echo $name | http_urlencode)"
140 gen_key
141 . $conf
142 echo "Secure key: $KEY"
143 # Wget GET url
144 busybox wget "${WEB_URL}?signup=$user&name=$name&mail=$mail&pass=$pass" \
145 -O /tmp/bug.msg
146 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
147 new-msg)
148 # Post a new message: ID message
149 . $conf || exit 1
150 [ ! "$bug" ] && gettext "Missing bug ID" && echo && exit 0
151 [ ! "$msg" ] && gettext "Missing message" && echo && exit 0
152 msg="$(echo $msg | http_urlencode)"
153 # Wget GET url
154 busybox wget \
155 "${WEB_URL}?key=$KEY&bug=$bug&msg=$msg" -O /tmp/bug.msg
156 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
157 new-bug)
158 # Post a new bug: bug desc priority pkgs
159 . $conf || exit 1
160 [ ! "$bug" ] && gettext "Missing bug title" && echo && exit 0
161 [ ! "$desc" ] && gettext "Missing description" && echo && exit 0
162 [ ! "$priority" ] && gettext "Missing bug priority" && echo && exit 0
163 bug="$(echo $bug | http_urlencode)"
164 desc="$(echo $desc | http_urlencode)"
165 # Wget GET url
166 busybox wget \
167 "${WEB_URL}?key=$KEY&bug=$bug&desc=$desc&priority=$priority&pkgs=$pkgs" \
168 -O /tmp/bug.msg
169 cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;;
170 *)
171 usage ;;
172 esac
174 exit 0