commit 41726395893c5f95b25cc0ce5b5e7fe13c713661 Author: Daniel Muckerman Date: Sun Nov 1 16:50:52 2020 -0500 Initial commit diff --git a/.gitea/template b/.gitea/template new file mode 100644 index 0000000..d2e0ffe --- /dev/null +++ b/.gitea/template @@ -0,0 +1,8 @@ +# All jinja files, anywhere in the repository +**.j2 + +# Manifest.json +manifest.json + +# Dockerfile +Dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b235d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +.envrc +.DS_Store +.vscode/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ad31a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.7 + +LABEL maintainer="$REPO_OWNER" + +WORKDIR /project +ADD . /project +RUN rm /project/.envrc +RUN rm -rf /project/env + +RUN apt-get update && apt-get install -y python3-dev libldap2-dev libsasl2-dev libssl-dev + +RUN pip install -r requirements.txt +CMD ["flask","run","--host=0.0.0.0"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..8791d64 --- /dev/null +++ b/app.py @@ -0,0 +1,100 @@ +import ldap as l +from ldap3 import Server, Connection, ALL, MODIFY_REPLACE +from flask import Flask, g, request, session, redirect, url_for, render_template, send_from_directory +from flask_simpleldap import LDAP +from flask_bootstrap import Bootstrap +import os +from flask_cache_buster import CacheBuster + + +app = Flask(__name__) +Bootstrap(app) +app.secret_key = 'asdf' +app.debug = True + +# Base +app.config['LDAP_REALM_NAME'] = 'OpenLDAP Authentication' +app.config['LDAP_HOST'] = os.environ.get('LDAP_HOST') +app.config['LDAP_BASE_DN'] = os.environ.get('LDAP_BASE_DN') +app.config['LDAP_USERNAME'] = os.environ.get('LDAP_USERNAME') +app.config['LDAP_PASSWORD'] = os.environ.get('LDAP_PASSWORD') + +# OpenLDAP +app.config['LDAP_OBJECTS_DN'] = 'dn' +app.config['LDAP_OPENLDAP'] = True +app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=posixAccount)(uid=%s))' + +ldap = LDAP(app) + +config = { + 'extensions': ['.js', '.css', '.csv'], + 'hash_size': 10 +} + +cache_buster = CacheBuster(config=config) +cache_buster.register_cache_buster(app) + +server = Server(app.config['LDAP_HOST']) +conn = Connection(server, app.config['LDAP_USERNAME'], app.config['LDAP_PASSWORD'], auto_bind=True) + +@app.before_request +def before_request(): + g.user = None + if 'user_id' in session: + # This is where you'd query your database to get the user info. + g.user = {} + + +@app.route("/manifest.json") +def manifest(): + return send_from_directory('./', 'manifest.json') + + +@app.route('/') +@ldap.login_required +def index(): + user_dict = ldap.get_object_details(session['user_id']) + + if 'user_id' in session: + user = {'dn': 'cn={},cn=usergroup,ou=users,dc=technicalincompetence,dc=club'.format(user_dict['cn'][0].decode('ascii')), + 'firstName': user_dict['givenName'][0].decode('ascii'), + 'lastName': user_dict['sn'][0].decode('ascii'), + 'email': user_dict['mail'][0].decode('ascii'), + 'userName': user_dict['uid'][0].decode('ascii'), + } + + return render_template('home.j2') + + +@app.route('/about') +@ldap.login_required +def about(): + return render_template('about.j2') + + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if g.user: + return redirect(url_for('index')) + if request.method == 'POST': + user = request.form['user'] + passwd = request.form['passwd'] + test = ldap.bind_user(user, passwd) + if test is None or passwd == '': + return render_template('login.j2', error='Invalid credentials') + else: + session['user_id'] = request.form['user'] + session['passwd'] = request.form['passwd'] + + return redirect('/') + return render_template('login.j2') + + +@app.route('/logout') +def logout(): + session.pop('user_id', None) + return redirect(url_for('index')) + + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..166f7b1 --- /dev/null +++ b/manifest.json @@ -0,0 +1,22 @@ +{ + "short_name": "$REPO_NAME", + "name": "$REPO_NAME", + "description": "$REPO_DESCRIPTION", + "icons": [ + { + "src": "/images/icons-192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "/images/icons-512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": "/", + "background_color": "#343a40", + "theme_color": "#343a40", + "display": "standalone", + "scope": "/" + } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dd20e31 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +Flask==1.1.2 +Flask-Bootstrap4==4.0.2 +Flask-Login==0.5.0 +Flask-SimpleLDAP==1.4.0 +python-ldap==3.2.0 +ldap3==2.7 +Flask-Cache-Buster==1.0.1 \ No newline at end of file diff --git a/static/app-icon.png b/static/app-icon.png new file mode 100644 index 0000000..b443cf6 Binary files /dev/null and b/static/app-icon.png differ diff --git a/static/feather-sprite.svg b/static/feather-sprite.svg new file mode 100644 index 0000000..6e20a2c --- /dev/null +++ b/static/feather-sprite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..6020049 --- /dev/null +++ b/static/style.css @@ -0,0 +1,313 @@ +/* Scroll fix, try to disable overflow scrolling on mobile to make this feel more native */ +html, body { + width: 100%; + height: 100%; + overflow: hidden; + position: fixed; + padding-bottom: 0; + overscroll-behavior-y: none; +} + +/* Hide bootstrap tooltip arrows +I did this so I wouldn't have to deal with toolbar button alignment but you can change that if you want */ +.tooltip .arrow { + display: none; +} + +/* Navbar */ +.navbar { + position: absolute; + top: 0; + width: 100%; +} + +.toolbar-button { + padding-left: 2rem; + padding-top: .375rem; + line-height: 1.5; + color: white; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.toolbar-button:hover { + color: #ddd; + text-decoration: none; +} + +/* Sidebar */ +#sidebar { + padding-left: 20px; + background-color: #ecedee; + height: 100vh; + padding-top: 20px; + border-right: 1px solid darkgray; + position: fixed; + width: 250px; +} + +#sidebar a:hover { + text-decoration: none; +} + +#sidebar ul > li { + padding-bottom: 10px; +} + +#sidebar ul > li > a { + color: rgba(0,0,0,.5); +} + +#sidebar ul > li.active > a { + color: black; +} + +#sidebar div > a { + color: rgba(0,0,0,.5); +} + +#sidebar div.active > a { + color: black; +} + +/* Content area */ +.wrapper { + height: calc(100% - 56px); + overflow: auto; + position: fixed; + top: 56px; + width: 100%; + -webkit-overflow-scrolling: touch; + align-items: stretch; +} + +#content { + width: 100%; + padding: 20px; +} + +/* Dark theming */ +@media (prefers-color-scheme: dark) { + /* Custom Bootstrap dark theming */ + + body { + background-color: #111 !important; + color: #eee; + } + + .jumbotron { + background-color: #333 !important; + } + + .modal-content { + background-color: #111 !important; + color: #eee; + } + + .modal-header { + border-bottom: 1px solid #555 !important; + } + + .modal-header .close { + color: #eee !important; + text-shadow: 0 1px 0 #555 !important; + } + + .modal-footer { + border-top: 1px solid #555 !important; + } + + .bg-light { + background-color: #333 !important; + } + + .bg-white { + background-color: #000 !important; + } + + .bg-black { + background-color: #eee !important; + } + + .form-control { + display: block; + width: 100%; + height: calc(1.5em + 0.75rem + 2px); + padding: 0.375rem 0.75rem; + font-size: 1rem; + font-weight: 400; + line-height: 1.5; + color: #dee2e6; + background-color: #000; + background-clip: padding-box; + border: 1px solid #6c757d; + border-radius: 0.25rem; + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; + } + + @media (prefers-reduced-motion: reduce) { + .form-control { + transition: none; + } + } + + .form-control::-ms-expand { + background-color: transparent; + border: 0; + } + + .form-control:-moz-focusring { + color: transparent; + text-shadow: 0 0 0 #dee2e6; + } + + .form-control:focus { + color: #dee2e6; + background-color: #191d21; + border-color: #b3d7ff; + outline: 0; + box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); + } + + .form-control::-webkit-input-placeholder { + color: #6c757d; + opacity: 1; + } + + .form-control::-moz-placeholder { + color: #6c757d; + opacity: 1; + } + + .form-control::-ms-input-placeholder { + color: #6c757d; + opacity: 1; + } + + .form-control::placeholder { + color: #6c757d; + opacity: 1; + } + + .form-control:disabled, + .form-control[readonly] { + background-color: #343a40; + opacity: 1; + } + + .card { + background-color: #000; + border: 1px solid #6c757d; + } + + /* Sidebar */ + #sidebar { + padding-left: 20px; + background-color: #1a1d20; + height: 100vh; + padding-top: 20px; + border-right: 1px solid black; + } + + #sidebar ul > li { + padding-bottom: 10px; + } + + #sidebar ul > li > a { + color: rgba(255,255,255,.5); + } + + #sidebar ul > li.active > a { + color: white; + } + + #sidebar div > a { + color: rgba(255,255,255,.5); + } + + #sidebar div.active > a { + color: white; + } +} + +/* PWA theming fixes +Tested basically only on iOS, so Android, get fucked maybe */ +@media all and (display-mode: standalone) { + .navbar { + position: absolute; + top: 0; + width: 100%; + padding-top: 44px !important; + } + + .wrapper { + height: calc(100vh - 92px); + overflow: auto; + position: fixed; + top: 92px; + width: 100%; + align-items: stretch; + padding-left: env(safe-area-inset-left); + padding-right: env(safe-area-inset-right); + padding-bottom: env(safe-area-inset-bottom); + } + + /* Tweaks for size classes above portait phones */ + @media (min-width: 577px) { + .navbar { + position: absolute; + top: 0; + width: 100%; + padding-top: 24px !important; + } + + #navbarNavDropdown { + padding-left: env(safe-area-inset-left); + padding-right: env(safe-area-inset-right); + } + + .wrapper { + height: calc(100% - 72px); + overflow: auto; + position: fixed; + top: 72px; + width: 100%; + align-items: stretch; + padding-left: env(safe-area-inset-left); + padding-right: env(safe-area-inset-right); + padding-bottom: env(safe-area-insert-bottom); + } + } +} + +/* Hide sidebar on phones and portrait tablets */ +@media (max-width: 991.98px) { + #sidebar { + display: none !important; + } +} + +/* Display sidebar and hide nav menu for landscape tablets and desktop */ +@media (min-width: 991.98px) { + .navbar-nav { + display: none !important; + } + + #sidebar { + min-width: 250px; + max-width: 250px; + display: block !important; + } + + #content { + left: 250px; + width: calc(100% - 250px) !important; + position: relative; + } + + #sidebar.active { + margin-left: -250px; + } +} \ No newline at end of file diff --git a/templates/about.j2 b/templates/about.j2 new file mode 100644 index 0000000..51c3eee --- /dev/null +++ b/templates/about.j2 @@ -0,0 +1,64 @@ +{% extends "bootstrap/base.html" %} +{% block title %}$REPO_NAME{% endblock %} + +{% block metas %} +{{super()}} + + + + + +{% endblock %} + +{% block styles %} +{{super()}} + +{% endblock %} + +{% block navbar %} + {% include "fragments/navbar.j2" %} +{% endblock %} + +{% block content %} +
+ + + + +
+
+ Made with + and + in Outer Austin! +
+
+
+{% endblock %} + +{% block scripts %} +{{ super() }} + +{% endblock %} \ No newline at end of file diff --git a/templates/fragments/navbar.j2 b/templates/fragments/navbar.j2 new file mode 100644 index 0000000..0da32e4 --- /dev/null +++ b/templates/fragments/navbar.j2 @@ -0,0 +1,37 @@ + \ No newline at end of file diff --git a/templates/fragments/sidebar.j2 b/templates/fragments/sidebar.j2 new file mode 100644 index 0000000..7f197e6 --- /dev/null +++ b/templates/fragments/sidebar.j2 @@ -0,0 +1,39 @@ + + +{% if request.path == url_for('about') %} +
+{% else %} +
+{% endif %} + + + About +
\ No newline at end of file diff --git a/templates/home.j2 b/templates/home.j2 new file mode 100644 index 0000000..8a6ab10 --- /dev/null +++ b/templates/home.j2 @@ -0,0 +1,50 @@ +{% extends "bootstrap/base.html" %} +{% block title %}$REPO_NAME{% endblock %} + +{% block metas %} +{{super()}} + + + + + +{% endblock %} + +{% block styles %} +{{super()}} + +{% endblock %} + +{% block navbar %} + {% include "fragments/navbar.j2" %} +{% endblock %} + +{% block content %} +
+ + + + +
+
+
+
+ This is your home page, have fun! +
+
+
+
+
+{% endblock %} + +{% block scripts %} +{{ super() }} + +{% endblock %} \ No newline at end of file diff --git a/templates/login.j2 b/templates/login.j2 new file mode 100644 index 0000000..00fda09 --- /dev/null +++ b/templates/login.j2 @@ -0,0 +1,48 @@ +{% extends "bootstrap/base.html" %} +{% block title %}$REPO_NAME{% endblock %} + +{% block metas %} +{{super()}} + + + + + +{% endblock %} + +{% block styles %} +{{super()}} + +{% endblock %} + +{% block navbar %} + +{% endblock %} + +{% block content %} +
+
+
+

Sign in for our awesome service

+

Forgot your password? Too bad! We don't have emails working yet!

+
+
+ + {% if error is defined %} + + {% endif %} + +
+ +
+ +
+ +
+
+
+{% endblock %} \ No newline at end of file