Ver código fonte

add bdsmail app

Bob Mottram 7 anos atrás
pai
commit
2ba7792ebb

BIN
man/freedombone-template.1.gz Ver arquivo


+ 274
- 0
src/freedombone-app-bdsmail Ver arquivo

@@ -0,0 +1,274 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Brain Dead Simple Mail Server for i2p
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+VARIANTS='full full-vim'
32
+
33
+IN_DEFAULT_INSTALL=0
34
+SHOW_ON_ABOUT=1
35
+
36
+BDSMAIL_REPO="https://github.com/majestrate/bdsmail"
37
+BDSMAIL_COMMIT='6a2296b0b8e6c3da61081b85802e7b1cc88ca285'
38
+
39
+bdsmail=(MY_USERNAME)
40
+
41
+function logging_on_bdsmail {
42
+    echo -n ''
43
+}
44
+
45
+function logging_off_bdsmail {
46
+    echo -n ''
47
+}
48
+
49
+function remove_user_bdsmail {
50
+    remove_username="$1"
51
+}
52
+
53
+function add_user_bdsmail {
54
+    new_username="$1"
55
+    new_user_password="$2"
56
+
57
+    if [ ! -d /home/$new_username/.mutt ]; then
58
+        mkdir /home/$new_username/.mutt
59
+        cp /etc/skel/.mutt/bdsmail /home/$new_username/.mutt
60
+    fi
61
+    sed -i "s|username|$new_username|g" /home/$new_username/.mutt/bdsmail
62
+    chown -R $new_username:$new_username /home/$new_username/.mutt
63
+    echo '0'
64
+}
65
+
66
+function install_interactive_bdsmail {
67
+    echo -n ''
68
+    APP_INSTALLED=1
69
+}
70
+
71
+function change_password_bdsmail {
72
+    curr_username="$1"
73
+    new_user_password="$2"
74
+}
75
+
76
+function reconfigure_bdsmail {
77
+    # This is used if you need to switch identity. Dump old keys and generate new ones
78
+    echo -n ''
79
+}
80
+
81
+function upgrade_bdsmail {
82
+    CURR_BDSMAIL_COMMIT=$(get_completion_param "bdsmail commit")
83
+    if [[ "$CURR_BDSMAIL_COMMIT" == "$BDSMAIL_COMMIT" ]]; then
84
+        return
85
+    fi
86
+
87
+    # update to the next commit
88
+    set_repo_commit /etc/bdsmail "bdsmail commit" "$BDSMAIL_COMMIT" $BDSMAIL_REPO
89
+    chown -R bdsmail:bdsmail /etc/bdsmail
90
+}
91
+
92
+function backup_local_bdsmail {
93
+    systemctl stop bdsmail
94
+
95
+    source_directory=/etc/bdsmail
96
+
97
+    function_check backup_directory_to_usb
98
+    dest_directory=bdsmail
99
+    backup_directory_to_usb $source_directory $dest_directory
100
+
101
+    systemctl start bdsmail
102
+}
103
+
104
+function restore_local_bdsmail {
105
+    systemctl stop bdsmail
106
+
107
+    temp_restore_dir=/root/tempbdsmail
108
+    bdsmail_dir=/etc/bdsmail
109
+
110
+    function_check restore_directory_from_usb
111
+    restore_directory_from_usb $temp_restore_dir bdsmail
112
+    if [ -d $temp_restore_dir ]; then
113
+        if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
114
+            cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
115
+        else
116
+            if [ ! -d $bdsmail_dir ]; then
117
+                mkdir $bdsmail_dir
118
+            fi
119
+            cp -rp $temp_restore_dir/* $bdsmail_dir
120
+        fi
121
+        chown -R bdsmail:bdsmail $bdsmail_dir
122
+        rm -rf $temp_restore_dir
123
+    fi
124
+
125
+    systemctl start bdsmail
126
+}
127
+
128
+function backup_remote_bdsmail {
129
+    systemctl stop bdsmail
130
+
131
+    source_directory=/etc/bdsmail
132
+
133
+    function_check backup_directory_to_friend
134
+    dest_directory=bdsmail
135
+    backup_directory_to_friend $source_directory $dest_directory
136
+
137
+    systemctl start bdsmail
138
+}
139
+
140
+function restore_remote_bdsmail {
141
+    systemctl stop bdsmail
142
+
143
+    temp_restore_dir=/root/tempbdsmail
144
+    bdsmail_dir=/etc/bdsmail
145
+
146
+    function_check restore_directory_from_friend
147
+    restore_directory_from_friend $temp_restore_dir bdsmail
148
+    if [ -d $temp_restore_dir ]; then
149
+        if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
150
+            cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
151
+        else
152
+            if [ ! -d $bdsmail_dir ]; then
153
+                mkdir $bdsmail_dir
154
+            fi
155
+            cp -rp $temp_restore_dir/* $bdsmail_dir
156
+        fi
157
+        chown -R bdsmail:bdsmail $bdsmail_dir
158
+        rm -rf $temp_restore_dir
159
+    fi
160
+
161
+    systemctl start bdsmail
162
+}
163
+
164
+function remove_bdsmail {
165
+    if [ -f /etc/systemd/system/bdsmail.service ]; then
166
+        systemctl stop bdsmail
167
+        systemctl disable bdsmail
168
+        rm /etc/systemd/system/bdsmail.service
169
+    fi
170
+    userdel -r bdsmail
171
+
172
+    remove_app bdsmail
173
+    remove_completion_param install_bdsmail
174
+    sed -i '/bdsmail/d' $COMPLETION_FILE
175
+    rm -rf /etc/skel/.mutt
176
+    remove_i2p
177
+}
178
+
179
+function install_bdsmail {
180
+    if [ -d /etc/bdsmail ]; then
181
+        rm -rf /etc/bdsmail
182
+    fi
183
+
184
+    if [ -d /repos/bdsmail ]; then
185
+        mkdir /etc/bdsmail
186
+        cp -r -p /repos/bdsmail/. /etc/bdsmail
187
+        cd /etc/bdsmail
188
+        git pull
189
+    else
190
+        git_clone $BDSMAIL_REPO /etc/bdsmail
191
+    fi
192
+
193
+    if [ ! -d /etc/bdsmail ]; then
194
+        echo $'Unable to clone bdsmail repo'
195
+        exit 5735735
196
+    fi
197
+
198
+    cd /etc/bdsmail
199
+    git checkout $BDSMAIL_COMMIT -b $BDSMAIL_COMMIT
200
+    set_completion_param "bdsmail commit" "$BDSMAIL_COMMIT"
201
+
202
+    useradd -d /etc/bdsmail -s /bin/false bdsmail
203
+
204
+    make make GOROOT=/home/go/go${GO_VERSION}
205
+    if [ ! -f /etc/bdsmail/bin/bdsconfig ]; then
206
+        echo $'Unable to make bdsmail'
207
+        exit 87923567842
208
+    fi
209
+
210
+    install_i2p
211
+
212
+    # create configuration file
213
+    /etc/bdsmail/bin/bdsconfig > /etc/bdsmail/config.ini
214
+    echo '[maild]' > /etc/bdsmail/config.ini
215
+    echo 'i2paddr = 127.0.0.1:7656' >> /etc/bdsmail/config.ini
216
+    echo 'i2pkeyfile = bdsmail-privkey.dat' >> /etc/bdsmail/config.ini
217
+    echo 'bindmail = 127.0.0.1:2525' >> /etc/bdsmail/config.ini
218
+    echo 'bindweb = 127.0.0.1:8489' >> /etc/bdsmail/config.ini
219
+    echo 'domain = localhost' >> /etc/bdsmail/config.ini
220
+    echo 'maildir = mail' >> /etc/bdsmail/config.ini
221
+    echo 'database = localhost.sqlite' >> /etc/bdsmail/config.ini
222
+    echo 'assets = contrib/assets/web' >> /etc/bdsmail/config.ini
223
+
224
+    echo '[Unit]' > /etc/systemd/system/bdsmail.service
225
+    echo 'Description=bdsmail' >> /etc/systemd/system/bdsmail.service
226
+    echo 'After=syslog.target' >> /etc/systemd/system/bdsmail.service
227
+    echo 'After=network.target' >> /etc/systemd/system/bdsmail.service
228
+    echo '' >> /etc/systemd/system/bdsmail.service
229
+    echo '[Service]' >> /etc/systemd/system/bdsmail.service
230
+    echo 'Type=simple' >> /etc/systemd/system/bdsmail.service
231
+    echo 'User=bdsmail' >> /etc/systemd/system/bdsmail.service
232
+    echo 'Group=bdsmail' >> /etc/systemd/system/bdsmail.service
233
+    echo 'WorkingDirectory=/etc/bdsmail' >> /etc/systemd/system/bdsmail.service
234
+    echo 'ExecStart=/etc/bdsmail/bin/maild /etc/bdsmail/config.ini' >> /etc/systemd/system/bdsmail.service
235
+    echo 'Restart=always' >> /etc/systemd/system/bdsmail.service
236
+    echo 'Environment="USER=bdsmail"' >> /etc/systemd/system/bdsmail.service
237
+    echo '' >> /etc/systemd/system/bdsmail.service
238
+    echo '[Install]' >> /etc/systemd/system/bdsmail.service
239
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/bdsmail.service
240
+    systemctl enable bdsmail
241
+    chown -R bdsmail:bdsmail /etc/bdsmail
242
+    systemctl start bdsmail
243
+
244
+    echo '#!/usr/bin/env python2' > /etc/bdsmail/get_address
245
+    echo 'import base64, hashlib, sys' >> /etc/bdsmail/get_address
246
+    echo 'with open(sys.argv[1]) as f:' >> /etc/bdsmail/get_address
247
+    echo "    print(base64.b32encode(hashlib.sha256(base64.b64decode(f.read(516), '-~')).digest()).strip('=')+\".b32.i2p\")" >> /etc/bdsmail/get_address
248
+    chmod +x  >> /etc/bdsmail/get_address
249
+
250
+    echo '#!/bin/bash' > /usr/bin/bdsmail_domain
251
+    echo 'cd /etc/bdsmail' >> /usr/bin/bdsmail_domain
252
+    echo 'python2 get_address bdsmail-privkey.dat' >> /usr/bin/bdsmail_domain
253
+    chmod +x /usr/bin/bdsmail_domain
254
+
255
+    # Create mutt configuration
256
+    mkdir /etc/skel/.mutt
257
+    echo 'set mbox_type=Maildir' > /etc/skel/.mutt/bdsmail
258
+    echo 'set smtp_url=smtp://127.0.0.1:2525/' >> /etc/skel/.mutt/bdsmail
259
+    echo 'set use_from=yes' >> /etc/skel/.mutt/bdsmail
260
+    echo "set from=username@$(bdsmail_domain)" >> /etc/skel/.mutt/bdsmail
261
+    echo 'set spoolfile=/etc/bdsmail/mail/username' >> /etc/skel/.mutt/bdsmail
262
+
263
+    # mutt configuration for the admin user
264
+    if [ ! -d /home/$MY_USERNAME/.mutt ]; then
265
+        mkdir /home/$MY_USERNAME/.mutt
266
+    fi
267
+    cp /etc/skel/.mutt/bdsmail /home/$MY_USERNAME/.mutt
268
+    sed -i "s|username|$MY_USERNAME|g" /home/$MY_USERNAME/.mutt/bdsmail
269
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt
270
+
271
+    APP_INSTALLED=1
272
+}
273
+
274
+# NOTE: deliberately there is no "exit 0"

+ 5
- 1
src/freedombone-backup-local Ver arquivo

@@ -13,7 +13,7 @@
13 13
 # License
14 14
 # =======
15 15
 #
16
-# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
16
+# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
17 17
 #
18 18
 # This program is free software: you can redistribute it and/or modify
19 19
 # it under the terms of the GNU Affero General Public License as published by
@@ -177,6 +177,10 @@ function backup_users {
177 177
                 fi
178 178
                 backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
179 179
             fi
180
+            if [ -d /home/$USERNAME/.mutt ]; then
181
+                echo $"Backing up Mutt configurations for $USERNAME"
182
+                backup_directory_to_usb /home/$USERNAME/.mutt mutt/${USERNAME}configs
183
+            fi
180 184
 
181 185
             # Backup email
182 186
             if [ -d /home/$USERNAME/Maildir ]; then

+ 4
- 0
src/freedombone-backup-remote Ver arquivo

@@ -231,6 +231,10 @@ function backup_users {
231 231
                 fi
232 232
                 backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME
233 233
             fi
234
+            if [ -d /home/$USERNAME/.mutt ]; then
235
+                echo $"Backing up Mutt configurations for $USERNAME"
236
+                backup_directory_to_friend /home/$USERNAME/.mutt mutt/${USERNAME}configs
237
+            fi
234 238
 
235 239
             # procmail settings
236 240
             if [ -f /home/$USERNAME/.procmailrc ]; then

+ 8
- 0
src/freedombone-restore-local Ver arquivo

@@ -404,10 +404,18 @@ function restore_mutt_settings {
404 404
     if [ -d $USB_MOUNT/backup/mutt ]; then
405 405
         for d in $USB_MOUNT/backup/mutt/*/ ; do
406 406
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
407
+
408
+            # skip over configurations
409
+            if [[ "$USERNAME" == *'configs' ]]; then
410
+                continue
411
+            fi
412
+
407 413
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
408 414
                 if [ ! -d /home/$USERNAME ]; then
409 415
                     ${PROJECT_NAME}-adduser $USERNAME
410 416
                 fi
417
+                echo $"Restoring Mutt configurations for $USERNAME"
418
+                restore_directory_from_usb /home/$USERNAME/.mutt mutt/${USERNAME}configs
411 419
                 echo $"Restoring Mutt settings for $USERNAME"
412 420
                 temp_restore_dir=/root/tempmutt
413 421
                 restore_directory_from_usb $temp_restore_dir mutt/$USERNAME

+ 8
- 0
src/freedombone-restore-remote Ver arquivo

@@ -360,11 +360,19 @@ function restore_mutt_settings {
360 360
     fi
361 361
     for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
362 362
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
363
+
364
+        # skip over configurations
365
+        if [[ "$USERNAME" == *'configs' ]]; then
366
+            continue
367
+        fi
368
+
363 369
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
364 370
             if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
365 371
                 if [ ! -d /home/$USERNAME ]; then
366 372
                     ${PROJECT_NAME}-adduser $USERNAME
367 373
                 fi
374
+                echo $"Restoring Mutt configurations for $USERNAME"
375
+                restore_directory_from_friend /home/$USERNAME/.mutt mutt/${USERNAME}configs
368 376
                 echo $"Restoring Mutt settings for $USERNAME"
369 377
                 temp_restore_dir=/root/tempmutt
370 378
                 restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME