-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from v1tal3/development
v1.3.6 update
- Loading branch information
Showing
40 changed files
with
450 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*.log | ||
*.db | ||
*.vscode | ||
*.idea | ||
app/log/ | ||
log/* | ||
scripts_bank/logs/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint('auth', __name__) | ||
|
||
from app.auth import routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms.fields import StringField, PasswordField, SubmitField | ||
from wtforms.validators import DataRequired | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
"""User login form.""" | ||
|
||
user = StringField('Username', validators=[DataRequired()], render_kw={'autofocus': True}) | ||
pw = PasswordField('Password', validators=[DataRequired()]) | ||
submit_button = SubmitField('Login') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from app import app, logger, sshhandler | ||
from app.auth import bp | ||
from flask import redirect, request, render_template, session, url_for | ||
from app.auth.forms import LoginForm | ||
from app.scripts_bank.redis_logic import storeUserInRedis, deleteUserInRedis | ||
|
||
|
||
@bp.route('/login', methods=['GET', 'POST']) | ||
def login(): | ||
"""Login page for user to save credentials.""" | ||
form = LoginForm() | ||
if request.method == 'POST': | ||
# If page is accessed via form POST submission | ||
if form.validate_on_submit(): | ||
# Validate form | ||
if 'USER' in session: | ||
# If user already stored in session variable, return home page | ||
return redirect(url_for('viewHosts')) | ||
else: | ||
# Try to save user credentials in Redis. Return index if fails | ||
try: | ||
if storeUserInRedis(request.form['user'], request.form['pw']): | ||
logger.write_log('logged in') | ||
return redirect(url_for('viewHosts')) | ||
except: | ||
logger.write_log('failed to store user data in Redis when logging in') | ||
# Return login page if accessed via GET request | ||
return render_template('auth/login.html', title='Login with SSH credentials', form=form) | ||
|
||
|
||
@bp.route('/logout') | ||
def logout(): | ||
"""Disconnect all SSH sessions by user.""" | ||
sshhandler.disconnectAllSSHSessions() | ||
try: | ||
currentUser = session['USER'] | ||
deleteUserInRedis() | ||
logger.write_log('deleted user %s data stored in Redis' % (currentUser)) | ||
session.pop('USER', None) | ||
logger.write_log('deleted user %s as stored in session variable' % (currentUser), user=currentUser) | ||
u = session['UUID'] | ||
session.pop('UUID', None) | ||
logger.write_log('deleted UUID %s for user %s as stored in session variable' % (u, currentUser), user=currentUser) | ||
u = None | ||
except KeyError: | ||
logger.write_log('Exception thrown on logout.') | ||
return redirect(url_for('index')) | ||
logger.write_log('logged out') | ||
|
||
return redirect(url_for('index')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint('errors', __name__) | ||
|
||
from app.errors import handlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import render_template | ||
from app.errors import bp | ||
|
||
|
||
@bp.errorhandler(404) | ||
def not_found_error(error): | ||
"""Return 404 page on 404 error.""" | ||
return render_template('errors/404.html', error=error), 404 | ||
|
||
|
||
@bp.errorhandler(500) | ||
def handle_500(error): | ||
"""Return 500 page on 500 error.""" | ||
return render_template('errors/500.html', error=error), 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.