You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
7 years ago
|
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template
|
||
|
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user
|
||
|
import json
|
||
|
import re
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
systemURL = '192.168.0.11:5000'
|
||
|
|
||
|
with open('links.json', 'r') as infile:
|
||
|
links = json.load(infile)
|
||
|
|
||
|
def codeValidation(code):
|
||
|
if len(code) not in range (5,6):
|
||
|
return False
|
||
|
if re.match('^[\w-]+$', code) is None:
|
||
|
return False
|
||
|
return True
|
||
|
|
||
|
def codeLink(code):
|
||
|
global links
|
||
|
if code not in links:
|
||
|
return False
|
||
|
if len(links[code]['url'])==0:
|
||
|
return None
|
||
|
return links[code]['url']
|
||
|
|
||
|
@app.route("/edit", methods=['GET', 'POST'])
|
||
|
def edit():
|
||
|
code = request.form.get("code")
|
||
|
print ("code: {}".format(code))
|
||
|
if codeLink(code) is False:
|
||
|
return render_template('invalid.html', code=code)
|
||
|
if codeLink(code) is not None:
|
||
|
return render_template('cantedit.html', url=codeLink(code))
|
||
|
url = request.form.get("url")
|
||
|
if url is None:
|
||
|
return render_template('editlink.html', code=code)
|
||
|
return render_template('success.html')
|
||
|
|
||
|
@app.route("/admin", methods=['GET', 'POST'])
|
||
|
def admin():
|
||
|
return render_template('admin.html')
|
||
|
|
||
|
@app.route("/list")
|
||
|
def list():
|
||
|
return render_template('message.html', message='Comming soon!™')
|
||
|
|
||
|
@app.route('/', defaults={'path': ''})
|
||
|
@app.route('/<path:path>')
|
||
|
def catch_all(path):
|
||
|
if len(path)==0:
|
||
|
return render_template('welcome.html')
|
||
|
if path in links:
|
||
|
if codeLink(path) is not None:
|
||
|
return redirect(links[path]['url'], code=302)
|
||
|
else:
|
||
|
return render_template('newcode.html', code=path)
|
||
|
else:
|
||
|
return render_template('invalid.html', code=path)
|