-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
49 lines (35 loc) · 1.52 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
safedun-server
Created on Sun Oct 13 00:00:00 2019
Author: Adil Rahman
GitHub: https://github.com/adildsw/safedun-server
"""
import argparse
import socket
from backend import safedun
from flask import Flask, render_template, request, send_file
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/execute', methods=['POST'])
def execute():
mode = request.form['mode']
key = request.form['key']
cycle = int(request.form['cycle'])
file = request.files['file']
scrambler = safedun()
output_file = scrambler.generate(mode, cycle, key, file)
return send_file(output_file, as_attachment=True, attachment_filename="output.png")
if __name__ == "__main__":
host_ip = socket.gethostbyname(socket.gethostname())
parser = argparse.ArgumentParser(description="safedun Server Option Description")
parser.add_argument("-H", "--host", help="specify IP address to host server", required=False, default=host_ip)
parser.add_argument("-p", "--port", help="specify Port number to host server", required=False, default="5000")
parser.add_argument("-d", "--debug", help="specify whether the server will run on debug mode", required=False, default=False)
parser.add_argument("-l", "--local", help="host server in localhost", required=False, default=False)
argument = parser.parse_args()
if not argument.local == False:
argument.host = '127.0.0.1'
app.run(host=argument.host, port=argument.port, debug=argument.debug)