From 22bcedd3a5c9696ebd1076104ce990e4b14c3285 Mon Sep 17 00:00:00 2001 From: Mateusz779 Date: Tue, 25 Apr 2023 08:49:32 +0200 Subject: [PATCH] code cleanup i przeniesienie configa mstmp --- app.py | 5 +++-- configs/create.sh | 15 ++++++++++----- configs/msmtprc | 14 ++++++++++++++ configs/sendmail.sh | 18 ------------------ utils.py | 7 +++++-- 5 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 configs/msmtprc diff --git a/app.py b/app.py index 132a512..7358cbf 100644 --- a/app.py +++ b/app.py @@ -107,9 +107,10 @@ def create_conf_post(): os.getcwd(), 'configs', folder, "authorized_keys") sshd_config_path = os.path.join(os.getcwd(), 'configs', "sshd_config") sendmail_path = os.path.join(os.getcwd(), 'configs', "sendmail.sh") - + msmtp_conf = os.path.join(os.getcwd(), 'configs', "msmtprc") + subprocess.run([script_path, "-i "+ini_path, "-c "+conf_path, "-k "+pub_path, "-l "+key_length, "-n"+config_name, - "-p "+ip, "-a "+authorized_keys_path, "-d "+sshd_config_path, "-m "+sendmail_path, " > /dev/null 2>&1 "]) + "-p "+ip, "-a "+authorized_keys_path, "-d "+sshd_config_path, "-m "+sendmail_path, "-o "+msmtp_conf," > /dev/null 2>&1 "]) if os.path.exists(folder): shutil.rmtree(folder) diff --git a/configs/create.sh b/configs/create.sh index 6d856c3..2b2e859 100755 --- a/configs/create.sh +++ b/configs/create.sh @@ -4,9 +4,9 @@ echo "Parametry podane do skryptu: $@" kitcrypto_version="0.0.3" uvpn3_version="3.0.3" -usage() { echo "Usage: [-a ] [-b add executable to output] [-c ] [-d ] [-i ] [-k ] [-l ] [-m ] [-n ] [-p ]" 1>&2; exit 1; } +usage() { echo "Usage: [-a ] [-b add executable to output] [-c ] [-d ] [-i ] [-k ] [-l ] [-m ] [-n ] [-o ] [-p ]" 1>&2; exit 1; } -while getopts "a:b:c:d:e:i:k:l:m:n:p:" option +while getopts "a:b:c:d:e:i:k:l:m:n:o:p:" option do case "${option}" in @@ -19,6 +19,7 @@ do l)keylen=${OPTARG};; m)msmtp=${OPTARG};; n)name=${OPTARG};; + o)msmtp_conf=${OPTARG};; p)ip=${OPTARG};; *)usage;; esac @@ -68,16 +69,20 @@ cp $ini /tmp/output/vpn cp $key /tmp/output/vpn if [ -n "$akeys" ]; then - cp $akeys /tmp/output/ssh + cp $akeys /tmp/output/ssh fi if [ -n "$sshconf" ]; then - cp $sshconf /tmp/output/ssh + cp $sshconf /tmp/output/ssh fi mkdir /tmp/output/msmtp if [ -n "$msmtp" ]; then - cp $msmtp /tmp/output/msmtp + cp $msmtp /tmp/output/msmtp +fi + +if [ -n "$msmtp_conf" ]; then + cp $msmtp_conf /tmp/output/msmtp fi mkdir /tmp/output/vpn/scripts diff --git a/configs/msmtprc b/configs/msmtprc new file mode 100644 index 0000000..416a226 --- /dev/null +++ b/configs/msmtprc @@ -0,0 +1,14 @@ + +account notification + host smtp.mkedziora.pl + port 587 + timeout 15 + protocol smtp + domain mkedziora.pl + auth on + user test + from test@mkedziora.pl + password V8ufrLgiEwRF72dM + tls on + syslog on + tls_starttls on \ No newline at end of file diff --git a/configs/sendmail.sh b/configs/sendmail.sh index b863568..3af29c5 100755 --- a/configs/sendmail.sh +++ b/configs/sendmail.sh @@ -1,23 +1,5 @@ #!/bin/sh -cat < /etc/msmtprc - -account notification - host smtp.mkedziora.pl - port 587 - timeout 15 - protocol smtp - domain mkedziora.pl - auth on - user test - from test@mkedziora.pl - password V8ufrLgiEwRF72dM - tls on - syslog on - tls_starttls on - -EOF - ifconfig > /tmp/ifconfig cat /proc/cmdline > /tmp/cmdline tar -cvf /tmp/zalacznik.tar /tmp/cmdline /tmp/ifconfig diff --git a/utils.py b/utils.py index 84527c1..402f454 100644 --- a/utils.py +++ b/utils.py @@ -11,6 +11,9 @@ import db import config import ipaddress +DELETE_TIMEOUT=30 +RESTART_DELETE_THREAD=10 + def generate_random_string(length): letters = string.ascii_letters @@ -48,7 +51,7 @@ def check_allocation_thread_function(): ping_thread = PingThread(ip, x[0]) ping_thread.start() - sleep(10) + sleep(RESTART_DELETE_THREAD) class PingThread(threading.Thread): @@ -65,7 +68,7 @@ class PingThread(threading.Thread): if date is None: return delta = datetime.datetime.utcnow() - date - if delta.total_seconds() > 30: + if delta.total_seconds() > DELETE_TIMEOUT: db.del_image_allocation_id(self.Id) else: db.update_image_allocation_time(self.Id)