This commit is contained in:
rootzoll
2020-08-02 14:59:28 +02:00
3 changed files with 27 additions and 20 deletions

View File

@@ -87,8 +87,8 @@ def ext(cmd=None, message=None, debug=False):
# e-Mail # e-Mail
def mail(recipient=None, message=None, subject=None, cert=None, encrypt=False, def mail(recipient: str = None, message: str = None, subject: str = None, cert: str = None,
from_name=None, from_address=None, debug=False): encrypt: bool = False, from_name: str = None, from_address: str = None, debug: bool = False):
if debug: if debug:
print("send mail") print("send mail")
print("msg: {}".format(message)) print("msg: {}".format(message))
@@ -107,7 +107,7 @@ def mail(recipient=None, message=None, subject=None, cert=None, encrypt=False,
'From: {} <{}>'.format(from_name, from_address), 'From: {} <{}>'.format(from_name, from_address),
"Subject: {}".format(subject), "Subject: {}".format(subject),
"", "",
"{}".format(message.encode('utf8')) "{}".format(message)
] ]
with open(cert, 'rb') as pem: with open(cert, 'rb') as pem:
@@ -122,7 +122,7 @@ def mail(recipient=None, message=None, subject=None, cert=None, encrypt=False,
msg['From'] = '{} <{}>'.format(from_name, from_address), msg['From'] = '{} <{}>'.format(from_name, from_address),
msg['To'] = recipient msg['To'] = recipient
msg.set_payload(message.encode('utf8')) msg.set_payload(message)
msg_to_send = msg.as_bytes() msg_to_send = msg.as_bytes()
# send message via e-Mail # send message via e-Mail
@@ -139,7 +139,7 @@ def mail(recipient=None, message=None, subject=None, cert=None, encrypt=False,
raise Exception(err) raise Exception(err)
def slack(message=None, debug=False): def slack(message: str = None, debug: bool = False):
if debug: if debug:
print("send slack") print("send slack")
print("msg: {}".format(message)) print("msg: {}".format(message))
@@ -148,4 +148,3 @@ def slack(message=None, debug=False):
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -40,6 +40,14 @@ if ! grep -Eq "^notifyMailHostname=.*" /mnt/hdd/raspiblitz.conf; then
echo "notifyMailHostname=$(hostname)" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null echo "notifyMailHostname=$(hostname)" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null
fi fi
if ! grep -Eq "^notifyMailFromAddress=.*" /mnt/hdd/raspiblitz.conf; then
echo "notifyMailFromAddress=rb@example.com" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null
fi
if ! grep -Eq "^notifyMailFromName=.*" /mnt/hdd/raspiblitz.conf; then
echo "notifyMailFromName=\"RB User\"" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null
fi
if ! grep -Eq "^notifyMailUser=.*" /mnt/hdd/raspiblitz.conf; then if ! grep -Eq "^notifyMailUser=.*" /mnt/hdd/raspiblitz.conf; then
echo "notifyMailUser=username" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null echo "notifyMailUser=username" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null
fi fi
@@ -72,11 +80,12 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "switching the NOTIFY ON" echo "switching the NOTIFY ON"
# install sstmp if not already present # install sstmp if not already present
/usr/bin/which ssmtp &>/dev/null if ! command -v ssmtp >/dev/null; then
[ $? -eq 0 ] || sudo apt-get install -y ssmtp sudo apt-get install -y ssmtp
fi
# install python lib for smime into virtual env # install python lib for smime into virtual env
/home/admin/python3-env-lnd/bin/python -m pip install smime sudo -H /usr/bin/python3 -m pip install smime
# write ssmtp config # write ssmtp config
cat << EOF | sudo tee /etc/ssmtp/ssmtp.conf >/dev/null cat << EOF | sudo tee /etc/ssmtp/ssmtp.conf >/dev/null
@@ -127,24 +136,22 @@ if [ "$1" = "send" ]; then
exit 1 exit 1
fi fi
/usr/bin/which ssmtp &>/dev/null if ! command -v ssmtp >/dev/null; then
if ! [ $? -eq 0 ]; then
echo "please run \"on\" first" echo "please run \"on\" first"
exit 1 exit 1
fi fi
# now parse settings from config and use to send the message # now parse settings from config and use to send the message
if [ "${notifyMethod}" = "ext" ]; then if [ "${notifyMethod}" = "ext" ]; then
/home/admin/python3-env-lnd/bin/python3 /home/admin/XXsendNotification.py ext ${notifyExtCmd} "$2" /usr/bin/python3 /home/admin/XXsendNotification.py ext ${notifyExtCmd} "$2"
elif [ "${notifyMethod}" = "mail" ]; then elif [ "${notifyMethod}" = "mail" ]; then
if [ "${notifyMailEncrypt}" = "on" ]; then if [ "${notifyMailEncrypt}" = "on" ]; then
/home/admin/python3-env-lnd/bin/python3 /home/admin/XXsendNotification.py mail "${@:3}" --cert ${notifyMailToCert} --encrypt ${notifyMailTo} "$2" /usr/bin/python3 /home/admin/XXsendNotification.py mail "${@:3}" --from-address "${notifyMailFromAddress}" --from-name "${notifyMailFromName}" --cert "${notifyMailToCert}" --encrypt ${notifyMailTo} "$2"
else else
/home/admin/python3-env-lnd/bin/python3 /home/admin/XXsendNotification.py mail "${@:3}" ${notifyMailTo} "$2" /usr/bin/python3 /home/admin/XXsendNotification.py mail "${@:3}" --from-address "${notifyMailFromAddress}" --from-name "${notifyMailFromName}" "${notifyMailTo}" "$2"
fi fi
elif [ "${notifyMethod}" = "slack" ]; then elif [ "${notifyMethod}" = "slack" ]; then
/home/admin/python3-env-lnd/bin/python3 /home/admin/XXsendNotification.py slack -h "$2" /usr/bin/python3 /home/admin/XXsendNotification.py slack -h "$2"
else else
echo "unknown notification method - check /mnt/hdd/raspiblitz.conf" echo "unknown notification method - check /mnt/hdd/raspiblitz.conf"
fi fi

View File

@@ -54,8 +54,8 @@ if Path("/mnt/hdd/raspiblitz.conf").is_file():
is_testnet = False is_testnet = False
ENV = "PROD" ENV = "PROD"
# DEFAULT_SHOPURL="shopdeu2vdhazvmllyfagdcvlpflzdyt5gwftmn4hjj3zw2oyelksaid.onion" DEFAULT_SHOPURL = "fulmo7x6yvgz6zs2b2ptduvzwevxmizhq23klkenslt5drxx2physlqd.onion"
DEFAULT_SHOPURL = "ip2tor.fulmo.org" # DEFAULT_SHOPURL = "ip2tor.fulmo.org"
LND_IP = "127.0.0.1" LND_IP = "127.0.0.1"
LND_ADMIN_MACAROON_PATH = "/mnt/hdd/app-data/lnd/data/chain/{0}/{1}net/admin.macaroon".format(cfg.network.value, LND_ADMIN_MACAROON_PATH = "/mnt/hdd/app-data/lnd/data/chain/{0}/{1}net/admin.macaroon".format(cfg.network.value,
cfg.chain.value) cfg.chain.value)
@@ -66,7 +66,8 @@ if Path("/mnt/hdd/raspiblitz.conf").is_file():
else: else:
ENV = "DEV" ENV = "DEV"
print("# blitz.ip2tor.py (development env)") print("# blitz.ip2tor.py (development env)")
DEFAULT_SHOPURL = "ip2tor.fulmo.org" DEFAULT_SHOPURL = "fulmo7x6yvgz6zs2b2ptduvzwevxmizhq23klkenslt5drxx2physlqd.onion"
# DEFAULT_SHOPURL = "ip2tor.fulmo.org"
LND_IP = "192.168.178.95" LND_IP = "192.168.178.95"
LND_ADMIN_MACAROON_PATH = "/Users/rotzoll/Downloads/RaspiBlitzCredentials/admin.macaroon" LND_ADMIN_MACAROON_PATH = "/Users/rotzoll/Downloads/RaspiBlitzCredentials/admin.macaroon"
LND_TLS_PATH = "/Users/rotzoll/Downloads/RaspiBlitzCredentials/tls.cert" LND_TLS_PATH = "/Users/rotzoll/Downloads/RaspiBlitzCredentials/tls.cert"
@@ -198,7 +199,7 @@ def apiPlaceOrderNew(session, shopurl, hostid, toraddressWithPort):
'product': "tor_bridge", 'product': "tor_bridge",
'host_id': hostid, 'host_id': hostid,
'tos_accepted': True, 'tos_accepted': True,
'comment': 'test', 'comment': 'RaspiBlitz',
'target': toraddressWithPort, 'target': toraddressWithPort,
'public_key': '' 'public_key': ''
} }