modyfikacja formularza z obrazami

This commit is contained in:
Mateusz779 2023-04-20 16:29:01 +02:00
parent db70943bf0
commit 9c07b62126
6 changed files with 52 additions and 10 deletions

2
app.py
View File

@ -106,7 +106,7 @@ def create_conf_post():
if os.path.exists(folder): if os.path.exists(folder):
shutil.rmtree(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")) return send_file(os.path.join(app.config['UPLOAD_FOLDER'], config_name+".pub"))

View File

@ -28,7 +28,7 @@ shift $((OPTIND-1))
CONFIGS=$(pwd) CONFIGS=$(pwd)
echo "${CONFIGS}" echo "${CONFIGS}"
squashfs
#sudo apt update #sudo apt update
#sudo apt install cmake make g++ gcc libssl-dev libgmp-dev #sudo apt install cmake make g++ gcc libssl-dev libgmp-dev

15
db.py
View File

@ -25,7 +25,8 @@ def connect():
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
image_name VARCHAR(255) NOT NULL, image_name VARCHAR(255) NOT NULL,
token 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() conn.commit()
cur.execute(""" cur.execute("""
@ -75,13 +76,13 @@ def get_one(sql, value):
return None return None
def add_conf_image(name, token): def add_conf_image(name, token, ip):
connect() connect()
with get_cur() as cur: with get_cur() as cur:
cur.execute(""" cur.execute("""
INSERT INTO image (image_name, token) INSERT INTO image (image_name, token, vpn_ip)
VALUES (%s, %s) VALUES (%s, %s, %s)
""", (name, token,)) """, (name, token,ip, ))
conn.commit() conn.commit()
@ -182,11 +183,11 @@ def get_images():
connect() connect()
with get_cur() as cur: with get_cur() as cur:
cur.execute(""" cur.execute("""
SELECT id, token, image_name FROM image""") SELECT id, token, image_name, vpn_ip FROM image""")
try: try:
images_all = images.ImageManager() images_all = images.ImageManager()
for row in cur.fetchall(): 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) images_all.add_image(image)
return images_all return images_all
except: except:

View File

@ -1,8 +1,9 @@
class Image: class Image:
def __init__(self, id, token, name): def __init__(self, id, token, name, vpn_ip):
self.id = id self.id = id
self.name = name self.name = name
self.token = token self.token = token
self.vpn_ip = vpn_ip
class ImageManager: class ImageManager:
def __init__(self): def __init__(self):

View File

@ -12,6 +12,7 @@
<tr> <tr>
<th>Token</th> <th>Token</th>
<th>Nazwa</th> <th>Nazwa</th>
<th>IP VPN</th>
<th>Usuń</th> <th>Usuń</th>
</tr> </tr>
</thead> </thead>
@ -20,6 +21,7 @@
<tr> <tr>
<td>{{ image.token }}</td> <td>{{ image.token }}</td>
<td>{{ image.name }}</td> <td>{{ image.name }}</td>
<td>{{ image.vpn_ip }}</td>
<td> <td>
<form action="{{ url_for('delete', image_id=image.id) }}" method="post"> <form action="{{ url_for('delete', image_id=image.id) }}" method="post">
<button type="submit" class="btn btn-danger">Usuń</button> <button type="submit" class="btn btn-danger">Usuń</button>

38
update_rootfs.sh Normal file
View File

@ -0,0 +1,38 @@
#!/bin/bash
usage() { echo "Usage: [ -n <nazwa obrazu>] [ -s <obraz zródłowy>] [-u <yes - upgrade>] [-i <pakiety do instalacji>]" 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 <<EOF> /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