add trashmail create script
This commit is contained in:
parent
c6ecc07812
commit
b180cdb6a6
1 changed files with 128 additions and 0 deletions
128
bin/trashmail
Executable file
128
bin/trashmail
Executable file
|
@ -0,0 +1,128 @@
|
||||||
|
#!/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
|
||||||
|
|
||||||
|
OWN_DOMAIN=schuerz.at
|
||||||
|
TARGET_MAIL=wertstoffe@xundeenergie.at
|
||||||
|
LDAP_HOST=ldap.schuerz.at
|
||||||
|
BIND_DN=cn=admin,dc=schuerz,dc=at
|
||||||
|
PASS_ID="LDAP/binddn-admin"
|
||||||
|
HASHED_DEFAULT=true
|
||||||
|
|
||||||
|
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}
|
||||||
|
$(pwgen -s 50 1)
|
||||||
|
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}
|
Loading…
Reference in a new issue