def halt(): if network.checkIP(request.remote_addr): printv("Halting") func = request.environ.get('werkzeug.server.shutdown') if func is None: raise RuntimeError('Not running with the Werkzeug Server') func() return "PolarisHub shutting down..." else: return abort(403)
def opendir(): if network.checkIP(request.remote_addr): local_path = request.values.get('dir') printv(local_path) if platform == "win32": os.system("explorer {}".format(local_path)) elif platform == "darwin": os.system("open {}".format(local_path)) else: os.system("nautilus {}".format(local_path)) return "Success" else: return abort(403)
def get_dir(path): if os.path.isdir(path): path_list = os.listdir(path) # printv (path_list, path) printv(os.getcwd()) path_list = [(path_list[i], os.path.isfile(os.path.join(path, path_list[i])), os.path.join(path[len(os.getcwd()):], path_list[i])) for i in range(len(path_list))] printv("path_list", path_list) return path_list else: abort(404)
def generateCode(url, filename="qrcode.png"): qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(url) qr.make(fit=True) qr_name = os.path.join(os.getcwd(), 'temp', filename) img = qr.make_image(fill_color="black", back_color="white") img.save(qr_name) printv(qr_name) return qr_name, '/' + qr_name[qr_name.find("temp"):].replace("\\", "/")
def generateCode(url, filename = "qrcode.png"): version, level, qr_name = myqr.run( url, version = 1, level = 'H', picture = None, colorized = False, contrast = 1.0, brightness = 1.0, save_name = filename, save_dir = os.path.join(os.getcwd(), 'temp') ) printv(qr_name) return qr_name, '/' + qr_name[qr_name.find("temp"):].replace("\\", "/") # printv(version, level, qr_name)
def file(filename): printv("files/" + filename) local_path = os.path.join(os.getcwd(), 'files', filename) printv(local_path) is_admin = network.checkIP(request.remote_addr) if os.path.isfile(local_path): return send_file(local_path) elif os.path.isdir(local_path): return render_template('index.html', cwd=local_path.replace('\\', "\\\\") if platform == "win32" else local_path, dirs=file_handler.get_dir(local_path), is_admin=is_admin, user_settings=file_handler.get_settings(), ip=network.get_host_ip()) else: abort(404)
def qr(): file_path = request.values.get("filepath") printv(file_path, hash(file_path)) file_name = str(hash(file_path)) + ".png" printv(file_name) network_path = "http://{}:{}".format( network.get_host_ip(), request.host[request.host.find(":") + 1:]) + file_path printv("network_path", network_path) return render_template("qrcode.html", filepath=myqrcode.generateCode( network_path, file_name)[1], filename=file_path, user_settings=file_handler.get_settings())
def update_settings(new_settings): global settings printv(new_settings) # for items in new_settings: # printv (items) for key, value in new_settings.items(): # printv(items) # key, value = items printv((key, value)) if key in keys.keys() and keys[key](value): printv("key gets:", key) printv(key, value) if value: settings[key] = value else: settings = load_settings() return False if save_settings(): return True else: return False
from polarishub_flask.server.parser import printv # printv(sys.path) from flask import Flask, request, abort, send_file, render_template, redirect, url_for from polarishub_flask.server import network as server from polarishub_flask.server import file_handler as file_handler from polarishub_flask.server import myqrcode as myqrcode import json from polarishub_flask.server import help os_name = os.name platform = sys.platform # printv("os_name:", os_name) printv("platform:", platform) printv("cwd:", os.getcwd()) def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True, static_url_path='/static') app.config.from_mapping( SECRET_KEY='dev', # DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), ) if test_config is None: # load the instance config, if it exists, when not testing