# Ënnstatus
# Copyright (C) 2015 Dennis Fink
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from flask import (Blueprint,
render_template,
current_app,
request,
redirect,
url_for)
from ennstatus.status.functions import (all_servers_by_type, single_server,
split_all_servers_to_types)
from .forms import ServerTypeForm
status_page = Blueprint('status', __name__)
@status_page.route('/', methods=('GET', 'POST'))
def index():
current_app.logger.info('Handling status index!')
form = ServerTypeForm()
if request.method == 'POST':
current_app.logger.debug('Validating form')
if form.validate_on_submit():
servertype = form.servertype.data
if servertype != 'all':
return redirect(url_for('status.' + servertype))
servers = split_all_servers_to_types()
current_app.logger.info('Returning servers')
return render_template('status/index.html', exit=servers['exit'],
relay=servers['relay'], bridge=servers['bridge'],
form=form)
@status_page.route('/exit')
def exit():
servers = list(all_servers_by_type('exit'))
form = ServerTypeForm()
form.servertype.data = 'exit'
return render_template('status/index.html', exit=servers, form=form)
@status_page.route('/relay')
def relay():
servers = list(all_servers_by_type('relay'))
form = ServerTypeForm()
form.servertype.data = 'relay'
return render_template('status/index.html', relay=servers, form=form)
@status_page.route('/bridge')
def bridge():
servers = list(all_servers_by_type('bridge'))
form = ServerTypeForm()
form.servertype.data = 'bridge'
return render_template('status/index.html', bridge=servers, form=form)
@status_page.route('/single/<server_name>')
def single(server_name):
server = single_server(server_name.lower())
kwargs = {server['server_type'].lower(): [server]}
return render_template('status/index.html', **kwargs)