diff --git a/app.py b/app.py index 53529b5..a15bf70 100644 --- a/app.py +++ b/app.py @@ -106,7 +106,7 @@ def create_conf_post(): if os.path.exists(folder): shutil.rmtree(folder) - db.add_conf_image(config_name+".squashfs", token_name) + db.add_conf_image(config_name+".squashfs", token_name, ip) return send_file(os.path.join(app.config['UPLOAD_FOLDER'], config_name+".pub")) diff --git a/configs/create.sh b/configs/create.sh index bfbfb7d..d38086d 100755 --- a/configs/create.sh +++ b/configs/create.sh @@ -28,7 +28,7 @@ shift $((OPTIND-1)) CONFIGS=$(pwd) echo "${CONFIGS}" - +squashfs #sudo apt update #sudo apt install cmake make g++ gcc libssl-dev libgmp-dev diff --git a/db.py b/db.py index 0e067fb..94e7055 100644 --- a/db.py +++ b/db.py @@ -25,7 +25,8 @@ def connect(): id SERIAL PRIMARY KEY, image_name VARCHAR(255) NOT NULL, token VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + vpn_ip INET );""") conn.commit() cur.execute(""" @@ -75,13 +76,13 @@ def get_one(sql, value): return None -def add_conf_image(name, token): +def add_conf_image(name, token, ip): connect() with get_cur() as cur: cur.execute(""" - INSERT INTO image (image_name, token) - VALUES (%s, %s) - """, (name, token,)) + INSERT INTO image (image_name, token, vpn_ip) + VALUES (%s, %s, %s) + """, (name, token,ip, )) conn.commit() @@ -182,11 +183,11 @@ def get_images(): connect() with get_cur() as cur: cur.execute(""" - SELECT id, token, image_name FROM image""") + SELECT id, token, image_name, vpn_ip FROM image""") try: images_all = images.ImageManager() for row in cur.fetchall(): - image = images.Image(id = row[0], token=row[1], name=row[2]) + image = images.Image(id = row[0], token=row[1], name=row[2], vpn_ip=row[3]) images_all.add_image(image) return images_all except: diff --git a/images.py b/images.py index 1462a2b..491bf2b 100644 --- a/images.py +++ b/images.py @@ -1,8 +1,9 @@ class Image: - def __init__(self, id, token, name): + def __init__(self, id, token, name, vpn_ip): self.id = id self.name = name self.token = token + self.vpn_ip = vpn_ip class ImageManager: def __init__(self): diff --git a/templates/images.html b/templates/images.html index 6ffa24d..7436f63 100644 --- a/templates/images.html +++ b/templates/images.html @@ -12,6 +12,7 @@ Token Nazwa + IP VPN Usuń @@ -20,6 +21,7 @@ {{ image.token }} {{ image.name }} + {{ image.vpn_ip }}
diff --git a/update_rootfs.sh b/update_rootfs.sh new file mode 100644 index 0000000..0cd389a --- /dev/null +++ b/update_rootfs.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +usage() { echo "Usage: [ -n ] [ -s ] [-u ] [-i ]" 1>&2; exit 1; } + +while getopts "n:u:i:s:" option +do + case "${option}" + in + n)name=${OPTARG};; + u)upgrade="yes";; + i)install=${OPTARG};; + s)squashfs=${OPTARG};; + *)usage;; + esac +done + +echo "$squashfs" +sudo unsquashfs -d /tmp/squashfs $squashfs +sudo mount --bind /dev/pts /tmp/squashfs/dev/pts +sudo mount --bind /proc /tmp/squashfs/proc +sudo chroot /tmp/squashfs/ /bin/bash -c 'cat < /etc/resolv.conf +nameserver 1.1.1.1 +EOF' +sudo chroot /tmp/squashfs/ /bin/bash -c 'apt update' + +if [ -n "$upgrade" ]; then + sudo chroot /tmp/squashfs/ /bin/bash -c 'DEBIAN_FRONTEND=noninteractive apt upgrade -y' +fi +if [ -n "$install" ]; then + sudo chroot /tmp/squashfs/ /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt install $install -y" +fi + +sudo chroot /tmp/squashfs/ /bin/bash -c 'apt clean all' +sudo umount /tmp/squashfs/dev/pts +sudo umount /tmp/squashfs/proc +sudo rm -rf $name.squashfs +sudo mksquashfs /tmp/squashfs/ $name.squashfs -b 1048576 -comp xz -Xdict-size 100% +sudo rm -rf /tmp/squashfs \ No newline at end of file