2021-02-15 15:16:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# creates trash email for registration for online-services
|
|
|
|
# email is hashed from domain of service + login-username from linux-system
|
|
|
|
# or only unhashed service-domain
|
|
|
|
# this created email-address is added to LDAP target email als dcMailAlias
|
|
|
|
# also added to pass passwordmanager of user
|
|
|
|
|
2021-02-15 15:27:28 +01:00
|
|
|
[ -e ${MSC_BASE}/defaults.conf ] && . ${MSC_BASE}/defaults.conf
|
|
|
|
|
|
|
|
LDAP_HOST=${LDAP_HOST_DEFAULT}
|
|
|
|
BIND_DN=${LDAP_ADMIN_BIND_DN}
|
|
|
|
PASS_ID=${PASS_ID_LDAP_ADMIN}
|
|
|
|
OWN_DOMAIN=${TRASHMAIL_OWN_DOMAIN_DEFAULT}
|
|
|
|
TARGET_MAIL=${TRASHMAIL_TARGET_MAIL_DEFAULT}
|
|
|
|
HASHED_DEFAULT=${TRASHMAIL_HASHED_DEFAULT}
|
2021-02-15 15:16:49 +01:00
|
|
|
|
|
|
|
set -- $(getopt -u -o fh --long force,hashed,not-hashed -- "$@" )
|
|
|
|
|
|
|
|
while : ; do
|
|
|
|
case $1 in
|
|
|
|
-n|--not-hashed)
|
|
|
|
HASHED=false
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--hashed)
|
|
|
|
HASHED=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f|--force)
|
|
|
|
FORCE=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
wrong argument $1
|
|
|
|
shift
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
URL=$1
|
|
|
|
|
|
|
|
case $URL in
|
|
|
|
http*)
|
|
|
|
DEST_DOMAIN=$(echo $URL|awk -F/ '{print $3}')
|
|
|
|
;;
|
|
|
|
[a-zA-Z]*)
|
|
|
|
DEST_DOMAIN=${URL,,}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
logwarn "$URL is no regular url"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "Create a trashmail-address for ${DEST_DOMAIN}" >&2
|
|
|
|
|
|
|
|
|
|
|
|
if ${HASHED:-$HASHED_DEFAULT}; then
|
|
|
|
TRASHUSER="$(echo ${DEST_DOMAIN}${USER}|md5sum -|awk '{print $1}')"
|
|
|
|
else
|
|
|
|
TRASHUSER=${DEST_DOMAIN}
|
|
|
|
fi
|
|
|
|
|
|
|
|
TRASHMAIL=${TRASHUSER}@${OWN_DOMAIN}
|
|
|
|
echo $TRASHMAIL
|
|
|
|
|
|
|
|
PASS_ENTRY="${PASS_PREFIX%/}${PASS_PREFIX:+/}${DEST_DOMAIN}/${TRASHMAIL}"
|
|
|
|
|
|
|
|
set -x
|
|
|
|
cat << EOF |ldapmodify -Z -H ldap://${LDAP_HOST} -D ${BIND_DN} -x -w $(pass ${PASS_ID}|head -n 1)
|
|
|
|
dn: dcSubMailAddress=${TARGET_MAIL},ou=mailaccounts,dc=schuerz,dc=at
|
|
|
|
changetype: modify
|
|
|
|
add: dcMailAlternateAddress
|
|
|
|
dcMailAlternateAddress: ${TRASHMAIL}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
echo pass find ${PASS_ENTRY}
|
|
|
|
pass find ${TRASHMAIL}
|
|
|
|
pass find ${TRASHMAIL}|grep -v "Search Terms"
|
|
|
|
case $? in
|
|
|
|
1)
|
|
|
|
# returncode 1 from grep means, no line selected. so no entry exists, create new one
|
|
|
|
echo "TEST1"
|
|
|
|
CREATE=true
|
|
|
|
;;
|
|
|
|
0)
|
|
|
|
echo FORCE: ${FORCE-false}
|
|
|
|
if ${FORCE-false} ; then
|
|
|
|
CREATE=true
|
|
|
|
else
|
|
|
|
echo "Current password for ${PASS_ENTRY} is $(pass ${PASS_ENTRY} |head -n1)."
|
|
|
|
read -p "Overwrite? [Y|n]: "
|
|
|
|
echo ""
|
|
|
|
case $REPLY in
|
|
|
|
y|Y)
|
|
|
|
CREATE=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CREATE=false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Something went wrong"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
CREATE=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${CREATE-false}; then
|
|
|
|
cat << EOF |pass insert -m ${PASS_ENTRY}
|
2021-02-25 22:38:20 +01:00
|
|
|
$(pwgen -y 50 1)
|
2021-02-15 15:16:49 +01:00
|
|
|
email: ${TRASHMAIL}
|
|
|
|
login: ${TRASHUSER}
|
|
|
|
url: ${URL}
|
|
|
|
comment: trashemail autogenerated, delete, when delete account there
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
set +x
|
|
|
|
#pass git commit "${PASS_ENTRY}"
|
|
|
|
pass -c ${PASS_ENTRY}
|