usuwanie obrazow z bazy danych
This commit is contained in:
parent
4c7fa352dc
commit
9724dbde18
31
app.py
31
app.py
@ -67,10 +67,19 @@ def create_conf():
|
|||||||
|
|
||||||
@app.route('/api/createconf', methods=['POST'])
|
@app.route('/api/createconf', methods=['POST'])
|
||||||
def create_conf_post():
|
def create_conf_post():
|
||||||
|
auth_token = request.cookies.get('auth_token')
|
||||||
|
if auth_token != "" or auth_token is not None:
|
||||||
|
if db.get_user_bytoken(auth_token) is None:
|
||||||
|
return redirect("/login")
|
||||||
|
|
||||||
config_name = request.form['config_name']
|
config_name = request.form['config_name']
|
||||||
token_name = request.form['token_name']
|
token_name = request.form['token_name']
|
||||||
key_length = request.form['key_length']
|
key_length = request.form['key_length']
|
||||||
ip = request.form['ip']
|
ip = request.form['ip']
|
||||||
|
if db.get_conf_id_name(config_name+".squashfs") is not None:
|
||||||
|
return jsonify(message="400")
|
||||||
|
if db.get_conf_id(token_name) is not None:
|
||||||
|
return jsonify(message="400")
|
||||||
folder = utils.generate_random_string(5)
|
folder = utils.generate_random_string(5)
|
||||||
try:
|
try:
|
||||||
os.mkdir(os.path.join(os.getcwd(), 'configs', folder))
|
os.mkdir(os.path.join(os.getcwd(), 'configs', folder))
|
||||||
@ -117,10 +126,30 @@ def login_api():
|
|||||||
response.set_cookie('auth_token', auth_token)
|
response.set_cookie('auth_token', auth_token)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@app.route('/delete/<int:image_id>', methods=['POST'])
|
||||||
|
def delete(image_id):
|
||||||
|
auth_token = request.cookies.get('auth_token')
|
||||||
|
if auth_token != "" or auth_token is not None:
|
||||||
|
if db.get_user_bytoken(auth_token) is None:
|
||||||
|
return redirect("/login")
|
||||||
|
|
||||||
|
filename = db.get_conf_image_id(image_id)
|
||||||
|
squashfs = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||||
|
pubkey = os.path.join(app.config['UPLOAD_FOLDER'], filename.split(".")[0])
|
||||||
|
if os.path.exists(squashfs):
|
||||||
|
os.remove(squashfs)
|
||||||
|
if os.path.exists(pubkey):
|
||||||
|
os.remove(pubkey)
|
||||||
|
db.del_image(image_id)
|
||||||
|
|
||||||
|
return redirect(url_for('list_images'))
|
||||||
|
|
||||||
@app.route("/api/addimage", methods=['POST'])
|
@app.route("/api/addimage", methods=['POST'])
|
||||||
def add_image():
|
def add_image():
|
||||||
db.Connect()
|
auth_token = request.cookies.get('auth_token')
|
||||||
|
if auth_token != "" or auth_token is not None:
|
||||||
|
if db.get_user_bytoken(auth_token) is None:
|
||||||
|
return redirect("/login")
|
||||||
name = None
|
name = None
|
||||||
try:
|
try:
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
|
14
db.py
14
db.py
@ -89,6 +89,9 @@ def get_conf_image(token):
|
|||||||
return get_one("SELECT image_name FROM image WHERE token = %s", token)
|
return get_one("SELECT image_name FROM image WHERE token = %s", token)
|
||||||
|
|
||||||
|
|
||||||
|
def get_conf_image_id(id):
|
||||||
|
return get_one("SELECT image_name FROM image WHERE id = %s", id)
|
||||||
|
|
||||||
def get_conf_id(token):
|
def get_conf_id(token):
|
||||||
return get_one("SELECT id FROM image WHERE token = %s", token)
|
return get_one("SELECT id FROM image WHERE token = %s", token)
|
||||||
|
|
||||||
@ -188,6 +191,16 @@ def get_images():
|
|||||||
return images_all
|
return images_all
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def del_image(image_id):
|
||||||
|
connect()
|
||||||
|
with get_cur() as cur:
|
||||||
|
cur.execute("DELETE FROM image WHERE id = %s", (image_id,))
|
||||||
|
try:
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_image_allocation_all_id():
|
def get_image_allocation_all_id():
|
||||||
connect()
|
connect()
|
||||||
@ -201,7 +214,6 @@ def get_image_allocation_all_id():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_image_allocation_all():
|
def get_image_allocation_all():
|
||||||
connect()
|
connect()
|
||||||
with get_cur() as cur:
|
with get_cur() as cur:
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<td>{{ image.token }}</td>
|
<td>{{ image.token }}</td>
|
||||||
<td>{{ image.name }}</td>
|
<td>{{ image.name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" action="/api/delete_image/{{ image.id }}">
|
<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>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user