code cleanup i przeniesienie configa mstmp

This commit is contained in:
Mateusz779 2023-04-25 08:49:32 +02:00
parent 913af1fc76
commit 22bcedd3a5
5 changed files with 32 additions and 27 deletions

3
app.py
View File

@ -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)

View File

@ -4,9 +4,9 @@ echo "Parametry podane do skryptu: $@"
kitcrypto_version="0.0.3"
uvpn3_version="3.0.3"
usage() { echo "Usage: [-a <root ssh authorized_keys>] [-b add executable to output] [-c <conf file>] [-d <sshd_config>] [-i <ini config>] [-k <pub server key>] [-l <priv key lenght>] [-m <msmtp script>] [-n <name>] [-p <vpn ipaddress>]" 1>&2; exit 1; }
usage() { echo "Usage: [-a <root ssh authorized_keys>] [-b add executable to output] [-c <conf file>] [-d <sshd_config>] [-i <ini config>] [-k <pub server key>] [-l <priv key lenght>] [-m <msmtp script>] [-n <name>] [-o <config for msmtp>] [-p <vpn ipaddress>]" 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
@ -80,6 +81,10 @@ if [ -n "$msmtp" ]; then
cp $msmtp /tmp/output/msmtp
fi
if [ -n "$msmtp_conf" ]; then
cp $msmtp_conf /tmp/output/msmtp
fi
mkdir /tmp/output/vpn/scripts
cat <<EOF> /tmp/output/vpn/scripts/starttap.sh
#!/bin/sh

14
configs/msmtprc Normal file
View File

@ -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

View File

@ -1,23 +1,5 @@
#!/bin/sh
cat <<EOF > /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

View File

@ -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)