2016-04-24 19:17:40 +02:00
|
|
|
from freeposte import dockercli
|
2016-08-29 19:35:09 +02:00
|
|
|
from freeposte.admin import app, db, models, forms, access
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
import flask
|
2016-08-13 20:51:54 +02:00
|
|
|
import flask_login
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/', methods=["GET"])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.authenticated
|
2016-03-19 21:37:48 +02:00
|
|
|
def index():
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.user_settings'))
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/login', methods=['GET', 'POST'])
|
|
|
|
def login():
|
|
|
|
form = forms.LoginForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
user = models.User.login(form.email.data, form.pw.data)
|
|
|
|
if user:
|
|
|
|
flask_login.login_user(user)
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.index'))
|
2016-03-19 21:37:48 +02:00
|
|
|
else:
|
2016-05-01 20:04:40 +02:00
|
|
|
flask.flash('Wrong e-mail or password', 'error')
|
2016-03-19 21:37:48 +02:00
|
|
|
return flask.render_template('login.html', form=form)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/logout', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.authenticated
|
2016-03-19 21:37:48 +02:00
|
|
|
def logout():
|
|
|
|
flask_login.logout_user()
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.index'))
|
2016-04-24 19:17:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/services', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.global_admin
|
2016-04-24 19:17:40 +02:00
|
|
|
def services():
|
|
|
|
containers = {}
|
|
|
|
for brief in dockercli.containers(all=True):
|
|
|
|
if brief['Image'].startswith('freeposte/'):
|
|
|
|
container = dockercli.inspect_container(brief['Id'])
|
|
|
|
container['Image'] = dockercli.inspect_image(container['Image'])
|
|
|
|
name = container['Config']['Labels']['com.docker.compose.service']
|
|
|
|
containers[name] = container
|
|
|
|
return flask.render_template('services.html', containers=containers)
|