Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bitwarden_mailconfig.sh « apps - github.com/nextcloud/vm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2480aa3ec92f23c524dc6ee4ed869bdc3ee4ba67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash

# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/

# shellcheck disable=2034,2059
true
SCRIPT_NAME="Bitwarden Mail Configuration"
# shellcheck source=lib.sh
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode

# Must be root
root_check

# Check if Bitwarden is already installed
print_text_in_color "$ICyan" "Checking if Bitwarden is already installed..."
if is_docker_running
then
    if docker ps -a --format '{{.Names}}' | grep -Eq "bitwarden";
    then
        if [ ! -d "$BITWARDEN_HOME"/bwdata ]
        then
            msg_box "It seems like 'Bitwarden' isn't installed in $BITWARDEN_HOME.\n\nYou cannot run this script."
            exit 1
        fi
    else
        msg_box "It seems like 'Bitwarden' isn't installed.\n\nYou cannot run this script."
        exit 1
    fi
else
    msg_box "It seems like 'Bitwarden' isn't installed.\n\nYou cannot run this script."
    exit 1
fi

msg_box "This script lets you configure your mailserver settings for Bitwarden."
if ! yesno_box_yes "Do you want to continue?"
then
    exit
fi

# Insert globalSettings__mail__smtp__trustServer to global.override
if ! grep -q "^globalSettings__mail__smtp__trustServer=" "$BITWARDEN_HOME"/bwdata/env/global.override.env
then
    echo "globalSettings__mail__smtp__trustServer=false" >> "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi

# Insert globalSettings__mail__smtp__startTls to global.override
if ! grep -q "^globalSettings__mail__smtp__startTls=" "$BITWARDEN_HOME"/bwdata/env/global.override.env
then
    echo "globalSettings__mail__smtp__startTls=false" >> "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi

# Enter mailserver
while :
do
    MAIL_SERVER=$(input_box "Please enter the mailserver URL that you want to use.\nE.g. smtp.mail.de\nIf you don't want to change the mailserver, that is already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $MAIL_SERVER"
    then
        msg_box "OK, please try again."
    else
        break
    fi
done

# Enter if you want to use ssl
while :
do
    PROTOCOL=$(input_box "Please type in the encryption protocol for your mailserver.\nThe available options are 'SSL', 'STARTTLS' or 'none'.\n\nIf you don't want to change the protocol setting, that are already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $PROTOCOL"
    then
        msg_box "OK, please try again."
    else
        if [ "$PROTOCOL" = "SSL" ]
        then
            DEFAULT_PORT=465
            break
        elif [ "$PROTOCOL" = "none" ]
        then
            DEFAULT_PORT=25
            break
        elif [ "$PROTOCOL" = "STARTTLS" ]
        then
            DEFAULT_PORT=587
            break
        elif [ "$PROTOCOL" = "" ]
        then
            DEFAULT_PORT=""
            break
        else
            msg_box "The answer wasn't correct. Please type in 'SSL', 'STARTTLS', 'none' or leave the inputbox empty."
        fi
    fi
done

# Enter Port or just use standard port (defined by usage of ssl)
while :
do
    SMTP_PORT=$(input_box "Please enter the port for your mailserver. The default port based on your protocol setting is $DEFAULT_PORT?\nPlease type that port into the inputbox, if you want to use it.\n\nIf you don't want to change the port, that is already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $SMTP_PORT"
    then
        msg_box "OK, please try again."
    else
        break
    fi
done

# Enter your mail username
while :
do
    MAIL_USERNAME=$(input_box "Please enter the username for the login to your mail provider. E.g. mail@example.com\nPlease note: the domain used for your mail username and the mailserver domain have to match!\nIf you don't want to change the mail username that is already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $MAIL_USERNAME"
    then
        msg_box "OK, please try again."
    else
        break
    fi
done

# Enter your mailuser password
while :
do
    MAIL_PASSWORD=$(input_box "Please enter the password for your mailserver user.\nIf you don't want to change the password, that is already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $MAIL_PASSWORD"
    then
        msg_box "OK, please try again."
    else
        break
    fi
done

# Enter admin mailadresses
while :
do
    ADMIN_ACCOUNT=$(input_box "Please enter mailaccounts, that should have access to the Bitwarden admin-panel, reachable under https://your-bitwarden-domain/admin/.\nThey don't have to be registered Bitwarden accounts.\nTo make this setting work, your Bitwarden mailserver settings have to be correct.\nYou can enter just one e-mailaddress or enter more than one like so:\n'bitwarden@example.com,bitwarden2@example1.com,bitwarden3@example2.com'\nIf you want to keep the admin accounts that are already configured inside the global.override.env-file, just leave the box empty.")
    if ! yesno_box_yes "Is this correct? $ADMIN_ACCOUNT"
    then
        msg_box "OK, please try again."
    else
        break
    fi
done

# Get results and store in a variable:
RESULT="These are the settings that will be changed in global.override.env. Please check that everything seems correct.\n\n"
if [ -n "$MAIL_SERVER" ]
then
    RESULT+="Mailserver URL=$MAIL_SERVER\n"
fi
# SSL
if [ -n "$PROTOCOL" ]
then
    RESULT+="PROTOCOL=$PROTOCOL\n"
fi
# SMTP-Port
if [ -n "$SMTP_PORT" ]
then
    RESULT+="SMTP port=$SMTP_PORT\n"
fi
# Mail username
if [ -n "$MAIL_USERNAME" ]
then
    RESULT+="SMTP Username=$MAIL_USERNAME\n"
fi
# Mail password
if [ -n "$MAIL_PASSWORD" ]
then
    RESULT+="SMTP Password=$MAIL_PASSWORD\n"
fi
# Admin account(s)
if [ -n "$ADMIN_ACCOUNT" ]
then
    RESULT+="Admin account(s)=$ADMIN_ACCOUNT"
fi

# Present what we gathered, if everything okay, write to files
msg_box "$RESULT"
if ! yesno_box_yes "Do you want to proceed?"
then
    exit
fi

# Stop bitwarden
systemctl stop bitwarden

# Write to files
# mailserver
if [ -n "$MAIL_SERVER" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__host=.*|globalSettings__mail__smtp__host=$MAIL_SERVER|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi
# SSL
if [ "$PROTOCOL" = "SSL" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__ssl=.*|globalSettings__mail__smtp__ssl=true|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
    check_command sed -i "s|^globalSettings__mail__smtp__startTls=.*|globalSettings__mail__smtp__startTls=false|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
elif [ "$PROTOCOL" = "none" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__ssl=.*|globalSettings__mail__smtp__ssl=false|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
    check_command sed -i "s|^globalSettings__mail__smtp__startTls=.*|globalSettings__mail__smtp__startTls=false|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
elif [ "$PROTOCOL" = "STARTTLS" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__startTls=.*|globalSettings__mail__smtp__startTls=true|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
    check_command sed -i "s|^globalSettings__mail__smtp__ssl=.*|globalSettings__mail__smtp__ssl=false|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi
# SMTP-Port
if [ -n "$SMTP_PORT" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__port=.*|globalSettings__mail__smtp__port=$SMTP_PORT|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi
# Mail username
if [ -n "$MAIL_USERNAME" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__username=.*|globalSettings__mail__smtp__username=$MAIL_USERNAME|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi
# Mail password
if [ -n "$MAIL_PASSWORD" ]
then
    check_command sed -i "s|^globalSettings__mail__smtp__password=.*|globalSettings__mail__smtp__password=$MAIL_PASSWORD|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi
# Admin account(s)
if [ -n "$ADMIN_ACCOUNT" ]
then
    check_command sed -i "s|^adminSettings__admins=.*|adminSettings__admins=$ADMIN_ACCOUNT|g" "$BITWARDEN_HOME"/bwdata/env/global.override.env
fi

# Start Bitwarden
systemctl start bitwarden
msg_box "Your Bitwarden mailserver settings should be successfully changed by now.

If you experience any issues, please report them to $ISSUES"
exit