Skip to content

Commit 121c1ce

Browse files
committed
add-mailaccount.sh
1 parent c945c26 commit 121c1ce

7 files changed

Lines changed: 90 additions & 45 deletions

File tree

backup/wetransfer

install-cron.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22
#
33
# Install cron jobs from the script header.
4+
#
45
# E.g. "# CRON-HOURLY :/usr/local/bin/example.sh"
5-
# In cron syntax "# CRON-D :09,39 * * * * root /usr/local/bin/example.sh"
6+
# Cron syntax: "# CRON-D :09,39 * * * * root /usr/local/bin/example.sh"
67
# See: man 5 crontab
78
#
89
# VERSION :0.2

mail/add-mailaccount.sh

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22
#
33
# Add a virtual mail account to courier-mta.
44
#
5-
# VERSION :0.2
6-
# DATE :2014-12-25
5+
# VERSION :0.3
6+
# DATE :2015-01-30
77
# AUTHOR :Viktor Szépe <viktor@szepe.net>
88
# LICENSE :The MIT License (MIT)
99
# URL :https://github.com/szepeviktor/debian-server-tools
1010
# BASH-VERSION :4.2+
1111
# LOCATION :/usr/local/sbin/add-mailaccount.sh
12-
# DEPENDS :apt-get install courier-authdaemon courier-mta-ssl
12+
# DEPENDS :apt-get install courier-authdaemon courier-mta-ssl pwgen
13+
# DEPENDS :security/password2remember.sh
1314

14-
ACCOUNT="$1"
15-
MAILROOT="/var/mail"
1615
VIRTUAL_UID="1999"
1716
COURIER_AUTH_DBNAME="horde4"
18-
CA_CERTIFICATES="/etc/ssl/certs/ca-certificates.crt"
1917

2018
Error() {
2119
echo "ERROR: $*"
2220
exit $1
2321
}
2422

25-
[ -z "$ACCOUNT" ] && Error 1 "No account given."
26-
[ -d "$MAILROOT" ] || Error 1 "Mail root (${MAILROOT}) does not exist."
23+
ACCOUNT="$1"
24+
MAILROOT="/var/mail"
25+
CA_CERTIFICATES="/etc/ssl/certs/ca-certificates.crt"
2726

2827
[ "$(id --user)" == 0 ] || Error 1 "Only root is allowed to add mail accounts."
28+
[ -z "$ACCOUNT" ] && Error 1 "No account given."
29+
[ -d "$MAILROOT" ] || Error 1 "Mail root (${MAILROOT}) does not exist."
2930

3031
# inputs
3132
for V in EMAIL PASS DESC HOMEDIR; do
@@ -34,8 +35,11 @@ for V in EMAIL PASS DESC HOMEDIR; do
3435
DEFAULT="$ACCOUNT"
3536
;;
3637
PASS)
37-
#TODO: xkcd-style password
3838
DEFAULT="$(pwgen 8 1)$((RANDOM % 10))"
39+
# xkcd-style password
40+
WORDLIST_HU="/usr/local/share/password2remember/password2remember_hu.txt"
41+
[ -f "$WORDLIST_HU" ] \
42+
&& DEFAULT="$(xkcdpass -d . -w "$WORDLIST_HU" -n 4)"
3943
;;
4044
HOMEDIR)
4145
DEFAULT="${MAILROOT}/${EMAIL##*@}/${EMAIL%%@*}"
@@ -45,8 +49,6 @@ for V in EMAIL PASS DESC HOMEDIR; do
4549
;;
4650
esac
4751

48-
#read -e -p "${V}? " -i "$DEFAULT" VALUE
49-
#eval "$V"="'$VALUE'"
5052
read -e -p "${V}? " -i "$DEFAULT" "$V"
5153
done
5254

@@ -59,47 +61,62 @@ if ! getent passwd "$VIRTUAL_UID" &> /dev/null; then
5961
getent passwd "$VIRTUAL_UID"
6062
fi
6163

62-
# check domain
64+
# check email format
65+
# https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
66+
grep -qE '^[-a-z0-9_]+(\.[-a-z0-9_]+)*@([a-z0-9_][-a-z0-9_])*(\.[-a-z0-9_]+)+$' <<< "$EMAIL" || Error 8 'Non-regular email address'
67+
6368
NEW_DOMAIN="${EMAIL##*@}"
64-
grep -qr "^${NEW_DOMAIN//./\\.}$" /etc/courier/locals /etc/courier/esmtpacceptmailfor.dir || Error 10 "This domain is not accepted here (${NEW_DOMAIN})"
65-
grep -qr "^${NEW_DOMAIN//./\\.}$" /etc/courier/hosteddomains || echo "[WARNING] This domain is not hosted here (${NEW_DOMAIN})" >&2
69+
NEW_MAILDIR="${MAILROOT}/${NEW_DOMAIN}/${EMAIL%%@*}/Maildir"
70+
#?
71+
72+
# check home
73+
[ -d "$HOMEDIR" ] && Error 9 "This home ($HOMEDIR) already exists."
74+
75+
# check domain
76+
grep -qFxr "${NEW_DOMAIN}" /etc/courier/locals /etc/courier/esmtpacceptmailfor.dir || Error 10 "This domain is not accepted here (${NEW_DOMAIN})"
77+
grep -qFxr "${NEW_DOMAIN}" /etc/courier/hosteddomains || echo "[WARNING] This domain is not hosted here (${NEW_DOMAIN})" >&2
6678

6779
# account folder and maildir
68-
NEW_MAILDIR="${MAILROOT}/${NEW_DOMAIN}/${EMAIL%%@*}"
69-
mkdir -v -p "${MAILROOT}/${NEW_DOMAIN}" || Error 12 "Failed to create dir: (${MAILROOT}/${NEW_DOMAIN})"
70-
chown -v "$VIRTUAL_UID":"$VIRTUAL_UID" "${MAILROOT}/${NEW_DOMAIN}" || Error 13 "Cannot chown (${MAILROOT}/${NEW_DOMAIN})"
71-
chmod -v o-rx "${MAILROOT}/${NEW_DOMAIN}" || Error 14 "Cannot chmod (${MAILROOT}/${NEW_DOMAIN})"
72-
sudo -u virtual maildirmake "$NEW_MAILDIR" && echo "Maildir OK." || Error 15 "Cannot create maildir (${NEW_MAILDIR})"
80+
install -o "$VIRTUAL_UID" -g "$VIRTUAL_UID" -m "u=rwx" -d "${MAILROOT}/${NEW_DOMAIN}/${EMAIL%%@*}" || Error 12 "Failed to install dir: (${MAILROOT}/${NEW_DOMAIN})"
81+
#?
82+
sudo -u virtual -- maildirmake "$NEW_MAILDIR" && echo "Maildir OK." || Error 15 "Cannot create maildir (${NEW_MAILDIR})"
7383

7484
# special folders
75-
sudo -u virtual maildirmake -f Drafts "$NEW_MAILDIR" && echo "Drafts OK." || Error 20 "Cannot create Drafts folder"
76-
sudo -u virtual maildirmake -f Sent "$NEW_MAILDIR" && echo "Sent OK." || Error 21 "Cannot create Sent folder"
77-
sudo -u virtual maildirmake -f Trash "$NEW_MAILDIR" && echo "Trash OK." || Error 22 "Cannot create Trash folder"
85+
sudo -u virtual -- maildirmake -f Drafts "$NEW_MAILDIR" && echo "Drafts OK." || Error 20 "Cannot create Drafts folder"
86+
sudo -u virtual -- maildirmake -f Sent "$NEW_MAILDIR" && echo "Sent OK." || Error 21 "Cannot create Sent folder"
87+
sudo -u virtual -- maildirmake -f Trash "$NEW_MAILDIR" && echo "Trash OK." || Error 22 "Cannot create Trash folder"
88+
# removal instruction
89+
echo "Remove home: rm -rf '${HOMEDIR}'"
7890

79-
# MySQL output
91+
# MySQL authentication
8092
if which mysql &> /dev/null \
8193
&& grep -q "^authmodulelist=.*\bauthmysql\b" /etc/courier/authdaemonrc; then
82-
mysql "$COURIER_AUTH_DBNAME" <<SQL
94+
mysql "$COURIER_AUTH_DBNAME" <<SQL && echo "User inserted into database. OK."
8395
-- USE ${COURIER_AUTH_DBNAME};
8496
INSERT INTO \`courier_horde\` (\`id\`, \`crypt\`, \`clear\`, \`name\`, \`uid\`, \`gid\`, \`home\`, \`maildir\`,
8597
\`defaultdelivery\`, \`quota\`, \`options\`, \`user_soft_expiration_date\`, \`user_hard_expiration_date\`, \`vac_msg\`, \`vac_subject\`, \`vac_stat\`) VALUES
86-
('${EMAIL}', ENCRYPT('${PASS}'), '', '${DESC}', ${VIRTUAL_UID}, ${VIRTUAL_UID}, '${HOMEDIR}', '', '', '', '', NULL, NULL, '', '', 'N');
98+
('${EMAIL}', ENCRYPT('${PASS}'), '', '${DESC}', ${VIRTUAL_UID}, ${VIRTUAL_UID}, '${HOMEDIR}', '${NEW_MAILDIR}', '', '', '', NULL, NULL, '', '', 'N');
8799
SQL
100+
# removal instruction
101+
echo "Remove user: -- USE ${COURIER_AUTH_DBNAME};"
102+
echo "Remove user: DELETE FROM \`courier_horde\` WHERE \`id\` = '${EMAIL}' LIMIT 1;"
88103
fi
89104

90-
# userdb
105+
# userdb authentication
91106
if which userdb userdbpw &> /dev/null \
92107
&& [ -r /etc/courier/userdb ] \
93108
&& grep -q "^authmodulelist=.*\bauthuserdb\b" /etc/courier/authdaemonrc; then
94-
userdb "$EMAIL" set "home=${NEW_MAILDIR}" || Error 30 "Failed to add to userdb"
109+
userdb "$EMAIL" set "home=${HOMEDIR}" || Error 30 "Failed to add to userdb"
95110
userdb "$EMAIL" set "mail=${NEW_MAILDIR}" || Error 31 "Failed to add to userdb"
96-
# man makeuserdb
111+
# 'maildir' is not necessary, see: man makeuserdb
97112
#userdb "$EMAIL" set "maildir=${NEW_MAILDIR}" || Error 32 "Failed to add to userdb"
98113
userdb "$EMAIL" set "uid=${VIRTUAL_UID}" || Error 33 "Failed to add to userdb"
99114
userdb "$EMAIL" set "gid=${VIRTUAL_UID}" || Error 34 "Failed to add to userdb"
100115
echo "$PASS" | userdbpw -md5 | userdb "$EMAIL" set systempw || Error 35 "Failed to add to userdb"
101116
[ -z "$DESC" ] || userdb "$EMAIL" set "fullname=${DESC}" || Error 36 "Failed to add to userdb"
102117
makeuserdb || Error 37 "Failed to make userdb"
118+
# removal instruction
119+
echo "Remove user: userdb '$EMAIL' del"
103120
fi
104121

105122
# SMTP authentication test

mail/extract-attachments/save_all_attachments.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ def gen_filename(name, part, addr, date, n):
131131
pre = '%s.%s.%d' % (date, addr, n)
132132
file = ''.join((pre, ext))
133133
else:
134-
#file = email.Header.decode_header(name)[0][0]
135134
file = part.get_filename()
136-
if email.Header.decode_header(file)[0][1] is not None:
137-
file = str(email.Header.decode_header(file)[0][0]).decode(email.Header.decode_header(file)[0][1])
135+
# no need to decode
136+
#file = email.Header.decode_header(name)[0][0]
137+
#if email.Header.decode_header(file)[0][1] is not None:
138+
# file = str(email.Header.decode_header(file)[0][0]).decode(email.Header.decode_header(file)[0][1])
138139
file = file.replace(' ', '_')
139140

140141
if type(file) is not type('') and type(file) is not unicode:
@@ -180,6 +181,7 @@ def walk_parts(msg, addr, date, dtime, count, msgnum):
180181
else:
181182
continue
182183
else:
184+
Debug(3, '''"dtypes=%s" % `dtypes`''')
183185
attachment,filename = None,None
184186
for key,val in dtypes:
185187
key = key.lower()

mysql/mysqltuner

security/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Custom certificate installation
2+
3+
/usr/local/share/ca-certificates
4+
15
### Store secret data in shares
26

37
#### gfshare

security/password2remember.sh

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,61 @@
22
#
33
# Generate 8 easy to remember passwords.
44
# First option is the acrostic word, second is a number to append.
5-
# Set P2R_LANG to any language name after you added the corresponding wordlist file.
6-
# The fixed delimiter is period (the `-d` option of xkcdpass)
75
#
8-
# VERSION :0.2
9-
# DATE :2014-08-27
6+
# Set P2R_LANG to any language code after you added the corresponding wordlist file (password2remember_<CODE>.txt).
7+
#
8+
# VERSION :0.3
9+
# DATE :2015-01-30
1010
# AUTHOR :Viktor Szépe <viktor@szepe.net>
1111
# LICENSE :The MIT License (MIT)
1212
# URL :https://github.com/szepeviktor/debian-server-tools
1313
# BASH-VERSION :4.2+
1414
# DEPENDS :pip install xkcdpass
15+
# LOCATION :/usr/local/bin/password2remember.sh
1516
# WORDLIST_HU :http://packetstormsecurity.com/files/32010/hungarian.gz.html
1617
# WORDLIST_HU2 :http://sourceforge.net/projects/wordlist-hu/
1718

1819
P2R_LANG="hu"
19-
20+
DELIMITER="."
2021

2122
ACROSTIC="$1"
2223
NUMBER="$2"
2324

2425
# capitalize the first letter
25-
capitalize() {
26+
Capitalize() {
2627
local LOWERCASE="$1"
2728

2829
echo -n "${LOWERCASE:0:1}" | tr '[:lower:]' '[:upper:]'
2930
echo -n "${LOWERCASE:1}"
3031
}
3132

33+
# add the number
34+
Append_number() {
35+
echo "$NUMBER"
36+
}
37+
38+
# locate the word list file
39+
Find_wordlist() {
40+
local WL="password2remember_${P2R_LANG}.txt"
41+
42+
[ -r "/usr/local/share/password2remember/${WL}" ] \
43+
&& WL="/usr/local/share/password2remember/${WL}"
44+
45+
echo "$WL"
46+
}
47+
48+
3249
[ -z "$ACROSTIC" ] || echo "a.c.r.o.s.t.i.c.: '${ACROSTIC}'"
3350
[ -z "$NUMBER" ] || echo "number: '${NUMBER}'"
3451

35-
# generate 8 passwords
52+
# generate 8 passwords choices
3653
for N in $(seq 1 8); do
37-
XKCDPASS="$(xkcdpass -d . -w "password2remember_${P2R_LANG}.txt" -n 4 --max=7 -a "$ACROSTIC")"
38-
39-
capitalize "$XKCDPASS"
40-
echo "$NUMBER"
54+
XKCDPASS="$(xkcdpass -d "$DELIMITER" -w "$(Find_wordlist)" -n 4 --max=7 -a "$ACROSTIC")"
55+
56+
if [ -z "$NUMBER" ]; then
57+
echo "$XKCDPASS"
58+
else
59+
Capitalize "$XKCDPASS"
60+
Append_number
61+
fi
4162
done

0 commit comments

Comments
 (0)