modyfikacja formularza z obrazami
This commit is contained in:
		
							
								
								
									
										2
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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")) | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
							
								
								
									
										15
									
								
								db.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								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: | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
| @@ -12,6 +12,7 @@ | ||||
|             <tr> | ||||
|                 <th>Token</th> | ||||
|                 <th>Nazwa</th> | ||||
|                 <th>IP VPN</th> | ||||
|                 <th>Usuń</th> | ||||
|             </tr> | ||||
|         </thead> | ||||
| @@ -20,6 +21,7 @@ | ||||
|                 <tr> | ||||
|                     <td>{{ image.token }}</td> | ||||
|                     <td>{{ image.name }}</td> | ||||
|                     <td>{{ image.vpn_ip }}</td> | ||||
|                     <td> | ||||
|                         <form action="{{ url_for('delete', image_id=image.id) }}" method="post"> | ||||
|                             <button type="submit" class="btn btn-danger">Usuń</button> | ||||
|   | ||||
							
								
								
									
										38
									
								
								update_rootfs.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								update_rootfs.sh
									
									
									
									
									
										Normal 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 | ||||
		Reference in New Issue
	
	Block a user