mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 15:02:19 +00:00
Flask app
This commit is contained in:
parent
a5b9bfba45
commit
372d1c4c5d
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
dist
|
||||
build
|
||||
__pycache__
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.swp
|
||||
*.egg-info
|
||||
_build
|
||||
.tox
|
||||
.coverage
|
||||
coverage
|
||||
|
||||
# Virtualenv
|
||||
venv
|
2
MANIFEST.in
Normal file
2
MANIFEST.in
Normal file
@ -0,0 +1,2 @@
|
||||
recursive-include ghostream/templates *
|
||||
recursive-include ghostream/static *
|
46
ghostream/__init__.py
Normal file
46
ghostream/__init__.py
Normal file
@ -0,0 +1,46 @@
|
||||
from flask import Flask, request, redirect, render_template
|
||||
import ldap
|
||||
|
||||
app = Flask(__name__)
|
||||
app.logger.setLevel(20) # log info
|
||||
app.config.from_object('ghostream.default_settings')
|
||||
app.config.from_envvar('GHOSTREAM_SETTINGS')
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Welcome page"""
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def viewer(path):
|
||||
"""Show stream that match this path"""
|
||||
return render_template('viewer.html', path=path)
|
||||
|
||||
@app.route('/auth', methods=['POST'])
|
||||
def auth():
|
||||
"""Authentication on stream start"""
|
||||
# Limit to NGINX auth
|
||||
if request.remote_addr != '127.0.0.1':
|
||||
return "Permission denied", 403
|
||||
|
||||
name = request.form.get('name')
|
||||
password = request.form.get('pass')
|
||||
|
||||
# Stream need a name and password
|
||||
if name is None or password is None:
|
||||
# When login success, the RTMP is redirected to remove the "?pass=xxx"
|
||||
# so just ignore login here, and NGINX will still allow streaming.
|
||||
return "Malformed request", 400
|
||||
|
||||
bind_dn = f"cn={name},{app.config.LDAP_USER_DN}"
|
||||
try:
|
||||
# Try to bind LDAP as the user
|
||||
connect = ldap.initialize(app.config.LDAP_URI)
|
||||
connect.bind_s(bind_dn, password)
|
||||
connect.unbind_s()
|
||||
app.logger.info("%s logged in successfully", name)
|
||||
# Remove "?pass=xxx" from RTMP URL
|
||||
return redirect(f"rtmp://127.0.0.1:1925/app/{name}", code=302)
|
||||
except:
|
||||
app.logger.warning("%s failed to log in", name)
|
||||
return 'Incorrect credentials', 401
|
9
ghostream/default_settings.py
Normal file
9
ghostream/default_settings.py
Normal file
@ -0,0 +1,9 @@
|
||||
# Default configuration
|
||||
|
||||
# LDAP
|
||||
LDAP_URI = "ldap://127.0.0.1:389"
|
||||
LDAP_USER_DN = "cn=users,dc=example,dc=com"
|
||||
|
||||
# Web page
|
||||
SITE_NAME = "Ghostream"
|
||||
FAVICON = "/favicon.ico"
|
17
ghostream/static/style.css
Normal file
17
ghostream/static/style.css
Normal file
@ -0,0 +1,17 @@
|
||||
body, html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #3b4b5b;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.text-select {
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.my-row {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
}
|
13
ghostream/templates/base.html
Normal file
13
ghostream/templates/base.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}{{ config.SITE_NAME }}{% endblock %}</title>
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
|
||||
<link rel="shortcut icon" href="{{ config.FAVICON }}">
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user