Last active
November 17, 2016 08:30
-
-
Save frdmn/11170715 to your computer and use it in GitHub Desktop.
LiveConfig mail path lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################### | |
# LiveConfig mail path lookup by Jonas Friedmann (iWelt AG) # | |
# [email protected] # | |
# http://frd.mn # | |
# http://twitter.com/frdmn # | |
############################################################### | |
STRING=${1} | |
# Check for arguments | |
if [[ -z ${STRING} ]]; then | |
echo "Error: No argument found." | |
echo "Examples:" | |
echo " $ /lc-mailpath web10p2" | |
echo " $ /lc-mailpath [email protected]" | |
exit | |
fi | |
if [[ ${STRING} == *@* ]]; then | |
# Found format | |
# Substitue strings | |
ACCOUNT=${STRING/@*/} | |
DOMAIN=${STRING/*@/} | |
# Parse sqlite | |
CONTRACT_NUMMER=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select D_CONTRACTID from DOMAINS where D_NAME = '${DOMAIN}';") | |
WEB_NUMMER=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select HC_NAME from HOSTINGCONTRACTS where HC_ID = '${CONTRACT_NUMMER}';") | |
FOLDER=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select MB_FOLDER from MAILBOXES where MB_NAME = '${ACCOUNT}' AND MB_DOMAIN = '${DOMAIN}';") | |
if [[ -z ${WEB_NUMMER} ]]; then | |
echo "Error: Couldn't found \"$1\"" | |
exit | |
elif [[ -z ${FOLDER} ]]; then | |
echo "Error: Couldn't found \"$1\"" | |
exit | |
else | |
echo "${WEB_NUMMER}p${FOLDER}" | |
fi | |
elif [[ ${STRING} == web*p* ]]; then | |
# Found format | |
# Substitue strings | |
WEB_NUMMER=${STRING/p*/} | |
EDITED_WEB_NUMMER=${WEB_NUMMER/web/} | |
FOLDER=${STRING/web*p/} | |
# Sqlite parsen | |
CONTRACT_ID=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select AC_CONTRACTID from ACCOUNTS where AC_LOGIN = 'web${EDITED_WEB_NUMMER}';") | |
ACCOUNT=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select MB_NAME from MAILBOXES where MB_CONTRACTID = '${CONTRACT_ID}' AND MB_FOLDER = '${FOLDER}';") | |
DOMAIN=$(sqlite3 /var/lib/liveconfig/liveconfig.db "select MB_DOMAIN from MAILBOXES where MB_CONTRACTID = '${CONTRACT_ID}' AND MB_FOLDER = '${FOLDER}';") | |
if [[ -z ${CONTRACT_ID} ]]; then | |
echo "Error: Couldn't found \"$1\"" | |
exit | |
elif [[ -z ${ACCOUNT} ]]; then | |
echo "Error: Couldn't found \"$1\"" | |
exit | |
elif [[ -z ${DOMAIN} ]]; then | |
echo "Error: Couldn't found \"$1\"" | |
exit | |
else | |
echo "${ACCOUNT}@${DOMAIN}" | |
fi | |
else | |
echo "Error: No valid format found in ${STRING}!" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment