Procházet zdrojové kódy

Separate maildir encryption command

Bob Mottram před 9 roky
rodič
revize
5afa722a9f
2 změnil soubory, kde provedl 105 přidání a 105 odebrání
  1. 12
    105
      src/freedombone
  2. 93
    0
      src/freedombone-encrypt-mail

+ 12
- 105
src/freedombone Zobrazit soubor

@@ -3585,9 +3585,9 @@ function time_synchronisation {
3585 3585
   fi
3586 3586
 
3587 3587
   if [ -f /usr/local/bin/${PROJECT_NAME}-update-date ]; then
3588
-	  cp /usr/local/bin/${PROJECT_NAME}-update-date /usr/bin/updatedate
3588
+      cp /usr/local/bin/${PROJECT_NAME}-update-date /usr/bin/updatedate
3589 3589
   else
3590
-	  cp /usr/bin/${PROJECT_NAME}-update-date /usr/bin/updatedate
3590
+      cp /usr/bin/${PROJECT_NAME}-update-date /usr/bin/updatedate
3591 3591
   fi
3592 3592
   chmod +x /usr/bin/updatedate
3593 3593
 
@@ -4804,114 +4804,21 @@ function encrypt_all_email {
4804 4804
   if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_NONMAILBOX" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
4805 4805
       return
4806 4806
   fi
4807
-  if grep -Fxq "encrypt_all_email" $COMPLETION_FILE; then
4808
-      return
4809
-  fi
4810 4807
   if [[ $GPG_ENCRYPT_STORED_EMAIL != "yes" ]]; then
4811 4808
       return
4812 4809
   fi
4813
-  echo '#!/bin/bash' > /usr/bin/encmaildir
4814
-  echo '#' >> /usr/bin/encmaildir
4815
-  echo '# GPLv2' >> /usr/bin/encmaildir
4816
-  echo '# GPG Encrypt a Maildir using gpgit.pl' >> /usr/bin/encmaildir
4817
-  echo '# Oct 03, 2014' >> /usr/bin/encmaildir
4818
-  echo '#' >> /usr/bin/encmaildir
4819
-  echo '# Change log:' >> /usr/bin/encmaildir
4820
-  echo '#   Sep 03, 2011' >> /usr/bin/encmaildir
4821
-  echo '#     - Temporary file is based on file_owner to avoid' >> /usr/bin/encmaildir
4822
-  echo '#        issues with permission differences.' >> /usr/bin/encmaildir
4823
-  echo '#     - Temporary file is removed after run.' >> /usr/bin/encmaildir
4824
-  echo '#     - Optional arguments passed to "find".' >> /usr/bin/encmaildir
4825
-  echo '#     - Full paths to binaries.' >> /usr/bin/encmaildir
4826
-  echo '#     - Removed unneccessary need of "cat", "grep", etc.' >> /usr/bin/encmaildir
4827
-  echo '#   Sep 04, 2011' >> /usr/bin/encmaildir
4828
-  echo '#     - Dont remove Dovecot index/uid unless messages' >> /usr/bin/encmaildir
4829
-  echo '#       have been GPG encrypted.' >> /usr/bin/encmaildir
4830
-  echo '#     - Adjust file tests to not just use -e' >> /usr/bin/encmaildir
4831
-  echo '#     - Quote all file operations' >> /usr/bin/encmaildir
4832
-  echo '#   Sep 05, 2011' >> /usr/bin/encmaildir
4833
-  echo '#     - Dont arbitrarily copy files, only overwrite the file' >> /usr/bin/encmaildir
4834
-  echo '#       in ~/Maildir if it differs after calling gpgencmail.pl' >> /usr/bin/encmaildir
4835
-  echo '#     - Only rebuild the index if we have modified ~/Maildir' >> /usr/bin/encmaildir
4836
-  echo '#   Oct 03, 2014' >> /usr/bin/encmaildir
4837
-  echo '#     - Minor modifications for use with Freedombone' >> /usr/bin/encmaildir
4838
-  echo '' >> /usr/bin/encmaildir
4839
-  echo 'if [[ -z "$1" || -z "$2" || -z "$3" ]]; then' >> /usr/bin/encmaildir
4840
-  echo '  echo "Usage is ./encmaildir.sh    {optional arguments passed to find for messages such as -mtime 0}"' >> /usr/bin/encmaildir
4841
-  echo '  exit 0' >> /usr/bin/encmaildir
4842
-  echo 'fi' >> /usr/bin/encmaildir
4843
-  echo '' >> /usr/bin/encmaildir
4844
-  echo 'MAIL_DIR=$1' >> /usr/bin/encmaildir
4845
-  echo 'EMAIL_ADDRESS=$2' >> /usr/bin/encmaildir
4846
-  echo 'USERNAME=$3' >> /usr/bin/encmaildir
4847
-  echo 'if [ ! -d "$MAIL_DIR" ]; then' >> /usr/bin/encmaildir
4848
-  echo "  MAIL_DIR='/home/$MY_USERNAME/Maildir'" >> /usr/bin/encmaildir
4849
-  echo 'fi' >> /usr/bin/encmaildir
4850
-  echo '' >> /usr/bin/encmaildir
4851
-  echo 'if [ ! $EMAIL_ADDRESS ]; then' >> /usr/bin/encmaildir
4852
-  echo "  EMAIL_ADDRESS='$MY_EMAIL_ADDRESS'" >> /usr/bin/encmaildir
4853
-  echo 'fi' >> /usr/bin/encmaildir
4854
-  echo '' >> /usr/bin/encmaildir
4855
-  echo 'if [ ! $USERNAME ]; then' >> /usr/bin/encmaildir
4856
-  echo "  USERNAME='$MY_USERNAME'" >> /usr/bin/encmaildir
4857
-  echo 'fi' >> /usr/bin/encmaildir
4858
-  echo '' >> /usr/bin/encmaildir
4859
-  echo '# Does this key exist?' >> /usr/bin/encmaildir
4860
-  echo 'gpg --list-keys "$EMAIL_ADDRESS" > /dev/null 2>&1' >> /usr/bin/encmaildir
4861
-  echo 'if [ $? -gt 0 ]; then' >> /usr/bin/encmaildir
4862
-  echo '  echo "A GPG key for $EMAIL_ADDRESS could not be found!"' >> /usr/bin/encmaildir
4863
-  echo '  exit 0' >> /usr/bin/encmaildir
4864
-  echo 'fi' >> /usr/bin/encmaildir
4865
-  echo '' >> /usr/bin/encmaildir
4866
-  echo '# Find all files in the Maildir specified.' >> /usr/bin/encmaildir
4867
-  echo 'echo "Calling find"' >> /usr/bin/encmaildir
4868
-  echo -n 'find "$MAIL_DIR" -type f -regex ' >> /usr/bin/encmaildir
4869
-  echo -n "'.*/\(cur\|new\)/.*' " >> /usr/bin/encmaildir
4870
-  echo '$4|while read line; do' >> /usr/bin/encmaildir
4871
-  echo '     gpgit.pl --encrypt-mode prefer-inline "$EMAIL_ADDRESS"  "/tmp/msg_$USERNAME"' >> /usr/bin/encmaildir
4872
-  echo '' >> /usr/bin/encmaildir
4873
-  echo '     # Check to see if there are differences between the existing' >> /usr/bin/encmaildir
4874
-  echo '     # Maildir file and what was created by gpgit.pl' >> /usr/bin/encmaildir
4875
-  echo '     diff -qa "$line" "/tmp/msg_$USERNAME" > /dev/null 2>&1;' >> /usr/bin/encmaildir
4876
-  echo '     if [ $? -gt 0 ]; then' >> /usr/bin/encmaildir
4877
-  echo '       # Preserve timestamps, set ownership.' >> /usr/bin/encmaildir
4878
-  echo '       chown $USERNAME:$USERNAME "/tmp/msg_$USERNAME"' >> /usr/bin/encmaildir
4879
-  echo '       chmod 600   "/tmp/msg_$USERNAME"' >> /usr/bin/encmaildir
4880
-  echo '       touch   "/tmp/msg_$USERNAME" --reference="$line"' >> /usr/bin/encmaildir
4881
-  echo '' >> /usr/bin/encmaildir
4882
-  echo '       # Unlink the original Maildir message' >> /usr/bin/encmaildir
4883
-  echo '       unlink "$line"' >> /usr/bin/encmaildir
4884
-  echo '' >> /usr/bin/encmaildir
4885
-  echo '       # Strip message sizes, retain experimental flags' >> /usr/bin/encmaildir
4886
-  echo '       # and status flags, and copy the file over.' >> /usr/bin/encmaildir
4887
-  echo '       STRIPSIZES=$(/bin/echo "$line"|/bin/sed -e "s/W=[[:digit:]]*//" -e "s/S=[[:digit:]]*//" -e "s/,,//" -e "s/,:2/:2/")' >> /usr/bin/encmaildir
4888
-  echo '       cp -av "/tmp/msg_$USERNAME" "$STRIPSIZES"' >> /usr/bin/encmaildir
4889
-  echo '' >> /usr/bin/encmaildir
4890
-  echo '       #Indexes must be rebuilt, weve modified Maildir.' >> /usr/bin/encmaildir
4891
-  echo '       touch "/tmp/rebuild_index_$USERNAME"' >> /usr/bin/encmaildir
4892
-  echo '     else' >> /usr/bin/encmaildir
4893
-  echo '       echo "Not copying, no differences between /tmp/msg_$USERNAME and $line"' >> /usr/bin/encmaildir
4894
-  echo '     fi' >> /usr/bin/encmaildir
4895
-  echo '' >> /usr/bin/encmaildir
4896
-  echo '     # Remove the temporary file' >> /usr/bin/encmaildir
4897
-  echo '     unlink "/tmp/msg_$USERNAME"' >> /usr/bin/encmaildir
4898
-  echo 'done' >> /usr/bin/encmaildir
4899
-  echo '' >> /usr/bin/encmaildir
4900
-  echo '# Remove Dovecot index and uids for regeneration.' >> /usr/bin/encmaildir
4901
-  echo 'if [ -f "/tmp/rebuild_index_$USERNAME" ]; then' >> /usr/bin/encmaildir
4902
-  echo '  echo "Removing Dovecot indexes and uids"' >> /usr/bin/encmaildir
4903
-  echo -n '  find "$MAIL_DIR" -type f -regex ' >> /usr/bin/encmaildir
4904
-  echo "'.*\(dovecot-\|dovecot\.\|\.uidvalidity\).*' -delete" >> /usr/bin/encmaildir
4905
-  echo '' >> /usr/bin/encmaildir
4906
-  echo '  # Remove the temporary file' >> /usr/bin/encmaildir
4907
-  echo '  unlink "/tmp/rebuild_index_$USERNAME"' >> /usr/bin/encmaildir
4908
-  echo 'else' >> /usr/bin/encmaildir
4909
-  echo '  echo "No messages found needing GPG encryption, not' >> /usr/bin/encmaildir
4910
-  echo '  echo "removing Dovecot indexes and UIDs."' >> /usr/bin/encmaildir
4911
-  echo 'fi' >> /usr/bin/encmaildir
4912
-  echo 'exit 0' >> /usr/bin/encmaildir
4810
+
4811
+  if [ -f /usr/local/bin/${PROJECT_NAME}-encrypt-mail ]; then
4812
+      cp /usr/local/bin/${PROJECT_NAME}-encrypt-mail /usr/bin/encmaildir
4813
+  else
4814
+      cp /usr/bin/${PROJECT_NAME}-encrypt-mail /usr/bin/encmaildir
4815
+  fi
4913 4816
   chmod +x /usr/bin/encmaildir
4914 4817
 
4818
+  if grep -Fxq "encrypt_all_email" $COMPLETION_FILE; then
4819
+      return
4820
+  fi
4821
+
4915 4822
   if [ ! /home/$MY_USERNAME/README ]; then
4916 4823
       touch /home/$MY_USERNAME/README
4917 4824
   fi

+ 93
- 0
src/freedombone-encrypt-mail Zobrazit soubor

@@ -0,0 +1,93 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# GPG Encrypt a Maildir using gpgit.pl
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2014-2015 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU 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 General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+
31
+USERNAME=$1
32
+
33
+ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
34
+
35
+if [ ! $USERNAME ]; then
36
+    USERNAME=$ADMIN_USER
37
+fi
38
+
39
+MAIL_DIR=/home/$USERNAME/Maildir
40
+EMAIL_ADDRESS=$USERNAME@$HOSTNAME
41
+
42
+# Does this key exist?
43
+gpg --list-keys "$EMAIL_ADDRESS" > /dev/null 2>&1
44
+if [ $? -gt 0 ]; then
45
+    echo $"A GPG key for $EMAIL_ADDRESS could not be found!"
46
+    exit 0
47
+fi
48
+
49
+# Find all files in the Maildir specified.
50
+echo $"Calling find"
51
+find "$MAIL_DIR" -type f -regex '.*/\(cur\|new\)/.*' $4|while read line; do
52
+    gpgit.pl --encrypt-mode prefer-inline "$EMAIL_ADDRESS"  "/tmp/msg_$USERNAME"
53
+
54
+    # Check to see if there are differences between the existing
55
+    # Maildir file and what was created by gpgit.pl
56
+    diff -qa "$line" "/tmp/msg_$USERNAME" > /dev/null 2>&1;
57
+    if [ $? -gt 0 ]; then
58
+        # Preserve timestamps, set ownership.
59
+        chown $USERNAME:$USERNAME "/tmp/msg_$USERNAME"
60
+        chmod 600   "/tmp/msg_$USERNAME"
61
+        touch   "/tmp/msg_$USERNAME" --reference="$line"
62
+
63
+        # Unlink the original Maildir message
64
+        unlink "$line"
65
+
66
+        # Strip message sizes, retain experimental flags
67
+        # and status flags, and copy the file over.
68
+        STRIPSIZES=$(/bin/echo "$line"|/bin/sed -e "s/W=[[:digit:]]*//" -e "s/S=[[:digit:]]*//" -e "s/,,//" -e "s/,:2/:2/")
69
+        cp -av "/tmp/msg_$USERNAME" "$STRIPSIZES"
70
+
71
+        #Indexes must be rebuilt, weve modified Maildir.
72
+        touch "/tmp/rebuild_index_$USERNAME"
73
+    else
74
+        echo $"Not copying, no differences between /tmp/msg_$USERNAME and $line"
75
+    fi
76
+
77
+    # Remove the temporary file
78
+    unlink "/tmp/msg_$USERNAME"
79
+done
80
+
81
+# Remove Dovecot index and uids for regeneration.
82
+if [ -f "/tmp/rebuild_index_$USERNAME" ]; then
83
+    echo $"Removing Dovecot indexes and uids"
84
+    find "$MAIL_DIR" -type f -regex '.*\(dovecot-\|dovecot\.\|\.uidvalidity\).*' -delete
85
+
86
+    # Remove the temporary file
87
+    unlink "/tmp/rebuild_index_$USERNAME"
88
+else
89
+    echo -n $"No messages found needing GPG encryption, not"
90
+    echo $"removing Dovecot indexes and UIDs."
91
+fi
92
+
93
+exit 0