Commit 8b734e42 authored by Aflitos, Saulo Alves's avatar Aflitos, Saulo Alves
Browse files

more separation

parent a28d618f
......@@ -30,3 +30,4 @@ rsync
config.keylen
config.secret
flask_sslify.py
from flask import Flask
app = Flask(__name__)
app.jinja_env.globals['trim_blocks' ] = True
app.jinja_env.add_extension('jinja2.ext.do')
app.config.from_object(__name__)
......@@ -4,6 +4,7 @@ import io
import base64
import subprocess
import ssl
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
......@@ -18,8 +19,8 @@ MAX_CONTENT_LENGTH = 128*1024*1024
SSL_KEY_LENGTH = 2048
print "IMPORTING FUNCTIONS"
sys.path.insert(0, os.path.dirname(os.path.abspath( __file__ )))
from routes import *
......@@ -323,6 +324,18 @@ def load_config( args ):
app.config["SSL_CERT" ] = ssl_cert
app.config["SSL_KEY" ] = ssl_key
#ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
#ctx = ssl.create_default_context( ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))
#ctx = ssl.create_default_context( purpose=Purpose.SERVER_AUTH )
#ctx.load_cert_chain(ssl_cert, ssl_key)
#context = ssl.create_default_context( ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) )
#context.load_cert_chain('yourserver.crt', 'yourserver.key')
#app.config["SSL_CONTEXT" ] = ctx
def run_action(args):
......
......@@ -38,7 +38,9 @@ def init( args ):
def start():
if app.config['HAS_LOGIN']:
print "SSL ENABLED: access by https://127.0.0.1:%d" % app.config["SERVER_PORT" ]
app.run(port=app.config["SERVER_PORT" ], host='0.0.0.0', ssl_context=(app.config["SSL_CERT"], app.config["SSL_KEY"]))
#app.run(port=app.config["SERVER_PORT" ], host='0.0.0.0', ssl_context=app.config["SSL_CONTEXT"])
else:
print "SSL DISABLED: access by http://127.0.0.1:%d" % app.config["SERVER_PORT" ]
app.run(port=app.config["SERVER_PORT" ], host='0.0.0.0')
......
......@@ -3,6 +3,6 @@ apt-get install -y python-setuptools python-dev python-numpy python-scipy python
a2enmod wsgi
pip install --requirement requirements.txt
pip install --user --requirement requirements.txt
ln -s ibrowser.conf /etc/apache2/mods-available/ibrowser.conf
......@@ -10,7 +10,7 @@ a2enmod wsgi
virtualenv venv && source ./venv/bin/activate
#(takes a while)
pip install --requirement requirements.txt
pip install --user --requirement requirements.txt
cd data && scp -c arcfour assembly@assembly:/home/assembly/tomato150/programs/iBrowser/iBrowser.data.tar.gz . && tar xvzf iBrowser.data.tar.gz && rm iBrowser.data.tar.gz && cd - python ibrowser.py
......
import glob
import sys
import os
from operator import itemgetter
print "importing flask"
from flask import Flask, request, session, send_file, escape, g, redirect, url_for, abort, render_template, flash, make_response, jsonify, Markup, Response, send_from_directory, Blueprint, json
print "importing jinja2"
from jinja2 import TemplateNotFound, Markup
import glob
from operator import itemgetter
print "importing user database"
sys.path.insert(0, os.path.dirname(os.path.abspath( __file__ )))
from user_database import *
DATABASES_DB_NAME = 0
......@@ -16,129 +24,6 @@ DATABASES_INTERFACE = 4
app = Flask(__name__)
app.jinja_env.globals['trim_blocks' ] = True
app.jinja_env.add_extension('jinja2.ext.do')
app.config.from_object(__name__)
from flask.ext.sqlalchemy import SQLAlchemy
user_db = SQLAlchemy(app)
#https://github.com/mrjoes/flask-admin/blob/master/examples/auth/app.py
class User(user_db.Model):
id = user_db.Column(user_db.Integer, primary_key=True)
first_name = user_db.Column(user_db.String(100))
last_name = user_db.Column(user_db.String(100))
login = user_db.Column(user_db.String( 80), unique=True)
email = user_db.Column(user_db.String(120))
password = user_db.Column(user_db.String(400))
salt = user_db.Column(user_db.String(400))
# Flask-Login integration
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return self.id
# Required for administrative interface
def __unicode__(self):
return self.login
def __repr__(self):
return "<User id %s first_name %s last_name %s login %s email %s password %s salt %s>" % \
tuple([str(x) for x in [ self.id, self.first_name, self.last_name, self.login, self.email, self.password, self.salt]])
import hashlib
import random
import time
import sys
import os
import sha3
from datetime import datetime
def check_user_exists(username):
return user_db.session.query(User).filter_by(login=username).count() > 0
def get_user(username):
return user_db.session.query(User).filter_by(login=username).first()
def get_users():
users = [ x.login for x in User.query.order_by(User.login) ]
users.sort()
return users
def add_user(username, password, salt):
if check_user_exists(username):
raise KeyError
user = User()
user.login = username
user.password = password
user.salt = salt
user_db.session.add(user)
user_db.session.commit()
def get_salt(username):
return get_user(username).salt
def verify_user_credentials(username, password, noonce):
user = get_user( username )
pwd = user.password
cry = generate_password_hash(noonce+pwd)
print "verify_user_credentials: user %s pwd %s cry %s password %s" % ( user, pwd, cry, password )
if cry == password:
return True
else:
return False
def del_user(username):
user = get_user(username)
user_db.session.delete(user)
user_db.session.commit()
def generate_password_hash(seq):
return sha3.sha3_512( seq.encode('utf-8') ).hexdigest()
#return hashlib.sha512( seq ).hexdigest()
def gen_noonce():
return generate_password_hash( str(random.randint(0, sys.maxint)) + str(time.time()) + str(datetime.now().microsecond) )
@app.before_request
def before_request():
"""
......
import sys
import os
import hashlib
import random
import time
from datetime import datetime
print "importing sha3"
import sha3
from flask.ext.sqlalchemy import SQLAlchemy
sys.path.insert(0, os.path.dirname(os.path.abspath( __file__ )))
from apper import *
user_db = SQLAlchemy(app)
#https://github.com/mrjoes/flask-admin/blob/master/examples/auth/app.py
class User(user_db.Model):
id = user_db.Column(user_db.Integer, primary_key=True)
first_name = user_db.Column(user_db.String(100))
last_name = user_db.Column(user_db.String(100))
login = user_db.Column(user_db.String( 80), unique=True)
email = user_db.Column(user_db.String(120))
password = user_db.Column(user_db.String(400))
salt = user_db.Column(user_db.String(400))
# Flask-Login integration
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return self.id
# Required for administrative interface
def __unicode__(self):
return self.login
def __repr__(self):
return "<User id %s first_name %s last_name %s login %s email %s password %s salt %s>" % \
tuple([str(x) for x in [ self.id, self.first_name, self.last_name, self.login, self.email, self.password, self.salt]])
def check_user_exists(username):
return user_db.session.query(User).filter_by(login=username).count() > 0
def get_user(username):
return user_db.session.query(User).filter_by(login=username).first()
def get_users():
users = [ x.login for x in User.query.order_by(User.login) ]
users.sort()
return users
def add_user(username, password, salt):
if check_user_exists(username):
raise KeyError
user = User()
user.login = username
user.password = password
user.salt = salt
user_db.session.add(user)
user_db.session.commit()
def get_salt(username):
return get_user(username).salt
def verify_user_credentials(username, password, noonce):
user = get_user( username )
pwd = user.password
cry = generate_password_hash(noonce+pwd)
print "verify_user_credentials: user %s pwd %s cry %s password %s" % ( user, pwd, cry, password )
if cry == password:
return True
else:
return False
def del_user(username):
user = get_user(username)
user_db.session.delete(user)
user_db.session.commit()
def generate_password_hash(seq):
return sha3.sha3_512( seq.encode('utf-8') ).hexdigest()
#return hashlib.sha512( seq ).hexdigest()
def gen_noonce():
return generate_password_hash( str(random.randint(0, sys.maxint)) + str(time.time()) + str(datetime.now().microsecond) )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment