Explorar el Código

Can create reciprocal user accounts for friends to perform remote backups

Bob Mottram hace 9 años
padre
commit
71378cf715
Se han modificado 2 ficheros con 69 adiciones y 12 borrados
  1. 2
    2
      src/freedombone
  2. 67
    10
      src/freedombone-remote

+ 2
- 2
src/freedombone Ver fichero

@@ -439,11 +439,11 @@ function interactive_configuration_remote_backups {
439 439
           exit 87354
440 440
       fi
441 441
   fi
442
-  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH
442
+  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH -r yes
443 443
   if [ ! "$?" = "0" ]; then
444 444
       echo 'Command failed:'
445 445
       echo ''
446
-      echo "  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH"
446
+      echo "  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH -r yes"
447 447
       echo ''
448 448
       exit 65892
449 449
   fi

+ 67
- 10
src/freedombone-remote Ver fichero

@@ -45,6 +45,11 @@ entering_remote_backups_ctr=0
45 45
 # Title shown
46 46
 TITLE='Remote Backup'
47 47
 
48
+# Whether to include the capability of adding reciprocal user accounts
49
+# such that whoever is running a remote server can also use your server to
50
+# store backups
51
+RECIPROCAL="no"
52
+
48 53
 function show_help {
49 54
   echo ''
50 55
   echo 'freedombone-remote -u [username] -l [backup list filename] -m [min password length]'
@@ -56,6 +61,7 @@ function show_help {
56 61
   echo '  -u --username         User to create the backups.list file for'
57 62
   echo '  -l --list             Remote backup list (usually /home/$USER/backup.list)'
58 63
   echo '  -m --min              Minimum password length (characters)'
64
+  echo '  -r --reciprocal       Whether to add reciprocal user accounts'
59 65
   echo '  -t --title            Title shown'
60 66
   echo ''
61 67
   exit 0
@@ -91,6 +97,11 @@ case $key in
91 97
     shift
92 98
     TITLE="$1"
93 99
     ;;
100
+    # reciprocal user accounts
101
+    -r|--reciprocal)
102
+    shift
103
+    RECIPROCAL="yes"
104
+    ;;
94 105
     *)
95 106
     # unknown option
96 107
     ;;
@@ -123,18 +134,37 @@ function interactive_configuration_remote_backups {
123 134
   entering_remote_backups_ctr=1
124 135
 
125 136
   entering_remote_backups_done="no"
137
+  remote_ssh_username=""
138
+  remote_ssh_domain=""
139
+  remote_ssh_port=""
140
+  remote_ssh_password=""
141
+  remote_ssh_reciprocal_username=""
142
+  remote_ssh_reciprocal_password=""
126 143
   while [[ $entering_remote_backups_done == "no" ]]
127 144
   do
128 145
       data=$(tempfile 2>/dev/null)
129 146
       trap "rm -f $data" 0 1 2 5 15
130
-      dialog --backtitle "Freedombone Configuration" \
131
-          --title "$TITLE ${entering_remote_backups_ctr}" \
132
-          --form "\nPlease specify the SSH login details:" 11 55 4 \
133
-          "Username:" 1 1 "" 1 16 16 15 \
134
-          "Domain:" 2 1 "" 2 16 16 15 \
135
-          "SSH port:" 3 1 "22" 3 16 5 4 \
136
-          "Password:" 4 1 "" 4 16 20 100 \
137
-          2> $data
147
+      if [[ $RECIPROCAL == "yes" ]]; then
148
+          dialog --backtitle "Freedombone Configuration" \
149
+              --title "$TITLE ${entering_remote_backups_ctr}" \
150
+              --form "\nPlease specify the SSH login details for the remote server\n\nThe reciprocal entries are optional, and can be used if you wish to set up a user account on this system for whoever runs the remote server to also use for backups" 20 50 8 \
151
+              "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
152
+              "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
153
+              "SSH port:" 3 1 "22" 3 23 5 4 \
154
+              "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
155
+              "Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
156
+              "Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
157
+              2> $data
158
+      else
159
+          dialog --backtitle "Freedombone Configuration" \
160
+              --title "$TITLE ${entering_remote_backups_ctr}" \
161
+              --form "\nPlease specify the SSH login details for the remote server" 15 50 4 \
162
+              "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
163
+              "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
164
+              "SSH port:" 3 1 "22" 3 23 5 4 \
165
+              "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
166
+              2> $data
167
+      fi
138 168
       sel=$?
139 169
       case $sel in
140 170
           1) entering_remote_backups_done="yes";;
@@ -144,6 +174,8 @@ function interactive_configuration_remote_backups {
144 174
       remote_ssh_domain=$(cat $data | sed -n 2p)
145 175
       remote_ssh_port=$(cat $data | sed -n 3p)
146 176
       remote_ssh_password=$(cat $data | sed -n 4p)
177
+      remote_ssh_reciprocal_username=$(cat $data | sed -n 5p)
178
+      remote_ssh_reciprocal_password=$(cat $data | sed -n 6p)
147 179
       if [[ $remote_ssh_username != "" && \
148 180
           $remote_ssh_domain != "" && \
149 181
           $remote_ssh_port != "" && \
@@ -152,8 +184,33 @@ function interactive_configuration_remote_backups {
152 184
           if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
153 185
               dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
154 186
           else
155
-              echo "$remote_ssh_username@$remote_ssh_domain:$remote_ssh_port//home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
156
-              entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
187
+
188
+              if [[ $RECIPROCAL == "yes" ]]; then
189
+                  if [[ $remote_ssh_reciprocal_username != "" && \
190
+                        $remote_ssh_reciprocal_password != "" ]]; then
191
+                      if [ ${#remote_ssh_reciprocal_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
192
+                          dialog --title "Password quality check" --msgbox "The reciprocal password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
193
+                      else
194
+                          echo ${remote_ssh_reciprocal_username}:${remote_ssh_reciprocal_password}::::/home/${remote_ssh_reciprocal_username}:bash | newusers
195
+                          echo "$remote_ssh_username@$remote_ssh_domain:$remote_ssh_port//home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
196
+                          remote_ssh_username=""
197
+                          remote_ssh_domain=""
198
+                          remote_ssh_port=""
199
+                          remote_ssh_password=""
200
+                          remote_ssh_reciprocal_username=""
201
+                          remote_ssh_reciprocal_password=""
202
+                          entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
203
+                      fi
204
+                  fi
205
+              else
206
+                  echo "$remote_ssh_username@$remote_ssh_domain:$remote_ssh_port//home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
207
+                  remote_ssh_username=""
208
+                  remote_ssh_domain=""
209
+                  remote_ssh_port=""
210
+                  remote_ssh_password=""
211
+                  entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
212
+              fi
213
+
157 214
           fi
158 215
       else
159 216
           entering_remote_backups_done="yes"