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.
81 lines
2.6 KiB
81 lines
2.6 KiB
from flask import Flask, render_template, redirect, url_for, request |
|
from time import sleep |
|
from sshtunnel import open_tunnel |
|
import paramiko |
|
from getpass import getpass |
|
from arango import ArangoClient |
|
from config import host_adress, db_arango |
|
from html_page import html_text |
|
|
|
# Route for handling the login page logic |
|
|
|
|
|
# import the Flask class from the flask module |
|
from flask import Flask, render_template |
|
|
|
# create the application object |
|
app = Flask(__name__) |
|
|
|
# use decorators to link the function to a url |
|
@app.route("/") |
|
def home(): |
|
return "Hello, World!" # return a string |
|
|
|
|
|
@app.route("/welcome") |
|
def welcome(): |
|
return render_template("welcome.html") # render a template |
|
|
|
@app.route("/result") |
|
def result(url): |
|
return render_template(url) # render a template |
|
|
|
@app.route("/login", methods=["GET", "POST"]) |
|
def login(): |
|
error = None |
|
if request.method == "POST": |
|
credentials = { |
|
"lasse": "test" |
|
} |
|
if ( |
|
request.form["username"] not in credentials |
|
or request.form["password"] != credentials[request.form["username"]] |
|
): |
|
sleep(2) |
|
error = "Fel lösenord. Testa igen." |
|
else: |
|
sleep(2) |
|
username = 'Webbapp' |
|
pwd = 'jagged-CUTTER-lyon-yourself-scavenge' |
|
path_to_key="/Users/Lasse/.ssh/id_rsa" |
|
pwd_key = getpass('Key pwd: ') |
|
|
|
with open_tunnel( |
|
(host_adress, 2210), |
|
ssh_username="lasse", |
|
ssh_pkey=paramiko.RSAKey.from_private_key_file( |
|
path_to_key, password=pwd_key |
|
), |
|
ssh_private_key_password=pwd_key, |
|
remote_bind_address=("127.0.0.1", 8529)) as server: |
|
|
|
port_arango = server.local_bind_port # En annan port än den "vanliga", ska användas nedan. |
|
|
|
db = ArangoClient(hosts=f'{"http://127.0.0.1"}:{port_arango}').db( |
|
db_arango, username=username, password=pwd, |
|
) |
|
|
|
r = db.collection('members').random() |
|
html = html_text.replace('RESULTAT', r['_key']) |
|
with open('/Users/Lasse/Datorgemensamt/Programmeringsprojekt/Facebook/fb-scraper/fb-webbapp/templates/test.html', 'w') as page: |
|
page.write(html) |
|
# Gör söking, skapa sida, returnera den.a |
|
return render_template('test.html') |
|
|
|
return render_template("login.html", error=error) |
|
|
|
|
|
|
|
# start the server with the 'run()' method |
|
if __name__ == "__main__": |
|
app.run(debug=False)
|
|
|