Bläddra i källkod

Adding xmpp users defined within the app script

Bob Mottram 7 år sedan
förälder
incheckning
925d3b05eb
2 ändrade filer med 21 tillägg och 106 borttagningar
  1. 0
    100
      src/freedombone-addxmpp
  2. 21
    6
      src/freedombone-app-xmpp

+ 0
- 100
src/freedombone-addxmpp Visa fil

@@ -1,100 +0,0 @@
1
-#!/bin/bash
2
-#
3
-# .---.                  .              .
4
-# |                      |              |
5
-# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
-# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
-# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
-#
9
-#                    Freedom in the Cloud
10
-#
11
-
12
-# Adds an xmpp user
13
-
14
-# License
15
-# =======
16
-#
17
-# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
18
-#
19
-# This program is free software: you can redistribute it and/or modify
20
-# it under the terms of the GNU Affero General Public License as published by
21
-# the Free Software Foundation, either version 3 of the License, or
22
-# (at your option) any later version.
23
-#
24
-# This program is distributed in the hope that it will be useful,
25
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-# GNU Affero General Public License for more details.
28
-#
29
-# You should have received a copy of the GNU Affero General Public License
30
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-
32
-PROJECT_NAME='freedombone'
33
-
34
-export TEXTDOMAIN=${PROJECT_NAME}-addxmpp
35
-export TEXTDOMAINDIR="/usr/share/locale"
36
-
37
-EMAIL_ADDRESS=
38
-NEW_USER_PASSWORD=
39
-
40
-function show_help {
41
-    echo ''
42
-    echo $"${PROJECT_NAME}-addxmpp -e [email address] -p [password]"
43
-    echo ''
44
-    exit 0
45
-}
46
-
47
-while [[ $# > 1 ]]
48
-do
49
-    key="$1"
50
-
51
-    case $key in
52
-        -h|--help)
53
-            show_help
54
-            ;;
55
-        -e|--email)
56
-            shift
57
-            EMAIL_ADDRESS="$1"
58
-            ;;
59
-        -p|--password|--passphrase)
60
-            shift
61
-            NEW_USER_PASSWORD="$1"
62
-            ;;
63
-        *)
64
-            # unknown option
65
-            ;;
66
-    esac
67
-    shift
68
-done
69
-
70
-if [ ! -d /etc/prosody ]; then
71
-    echo $'xmpp server is not installed'
72
-    exit 0
73
-fi
74
-
75
-if [ ! $EMAIL_ADDRESS ]; then
76
-    show_help
77
-    exit 1
78
-fi
79
-
80
-USERNAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $1}')
81
-if [ ! $NEW_USER_PASSWORD ]; then
82
-    prosodyctl adduser $EMAIL_ADDRESS
83
-else
84
-    DOMAIN_NAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $2}')
85
-    prosodyctl register $USERNAME $DOMAIN_NAME "$NEW_USER_PASSWORD"
86
-    if [ ! "$?" = "0" ]; then
87
-        exit 2
88
-    fi
89
-fi
90
-
91
-# add the xmpp address to email headers
92
-if [ -f /home/$USERNAME/.muttrc ]; then
93
-    if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
94
-        echo "my_hdr Jabber-ID: $EMAIL_ADDRESS" >> /home/$USERNAME/.muttrc
95
-    else
96
-        sed -i "s|my_hdr Jabber-ID.*|my_hdr Jabber-ID: $EMAIL_ADDRESS|g" /home/$USERNAME/.muttrc
97
-    fi
98
-fi
99
-
100
-exit 0

+ 21
- 6
src/freedombone-app-xmpp Visa fil

@@ -271,16 +271,31 @@ function add_user_xmpp {
271 271
     new_user_password="$2"
272 272
 
273 273
     XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
274
-    ${PROJECT_NAME}-pass -u $new_username -a xmpp -p "$new_user_password"
274
+    ${PROJECT_NAME}-pass -u "$new_username" -a xmpp -p "$new_user_password"
275 275
 
276 276
     if [[ $ONION_ONLY != "no" ]]; then
277
-        ${PROJECT_NAME}-addxmpp -e "$new_username@$XMPP_ONION_HOSTNAME" -p "$new_user_password"
277
+        DOMAIN_NAME=$XMPP_ONION_HOSTNAME
278 278
     else
279
-        ${PROJECT_NAME}-addxmpp -e "$new_username@$HOSTNAME" -p "$new_user_password"
279
+        DOMAIN_NAME=$HOSTNAME
280 280
     fi
281
-    if [ ! "$?" = "0" ]; then
282
-        echo '1'
283
-        return
281
+    EMAIL_ADDRESS="$new_username@$DOMAIN_NAME"
282
+
283
+    if [ ${#new_user_password} -eq 0 ]; then
284
+        prosodyctl adduser $EMAIL_ADDRESS
285
+    else
286
+        prosodyctl register "$new_username" $DOMAIN_NAME "$new_user_password"
287
+        if [ ! "$?" = "0" ]; then
288
+            exit 653456375
289
+        fi
290
+    fi
291
+
292
+    # add the xmpp address to email headers
293
+    if [ -f /home/$new_username/.muttrc ]; then
294
+        if ! grep -q "Jabber-ID" /home/$new_username/.muttrc; then
295
+            echo "my_hdr Jabber-ID: $EMAIL_ADDRESS" >> /home/$new_username/.muttrc
296
+        else
297
+            sed -i "s|my_hdr Jabber-ID.*|my_hdr Jabber-ID: $EMAIL_ADDRESS|g" /home/$new_username/.muttrc
298
+        fi
284 299
     fi
285 300
 
286 301
     add_user_xmpp_client "$new_username" "$new_user_password"