Commits

Michael K committed 6e1f8cc

Web-based ops generation and cleanup. still needs UI tweaks

  • Participants
  • Parent commits 7abf3e7
  • Branches feature/mumble-temporary-ops

Comments (0)

Files changed (6)

File config/mumble-pizza-auth.py

 					user_info = literal_eval(mumblehash[name])
 					# is the op still valid?
 					if user_info['op_hash'] in operationshash:
+						displayname = user_info['display_name']
 						if user_info['password'] == pw:
-							return (random.choice(range(500000,1000000)) + cfg.user.id_offset, 'GUEST - %s' % (user_info['display_name']), [])
+							if user_info.get('corporationid', None):
+
+								if corporation not in CORPORATIONS_TICKER:
+									try:
+										api = eveapi.EVEAPIConnection()
+										corporation_sheet = api.corp.CorporationSheet(corporationID=userinfo['corporationid'])
+										ticker = CORPORATIONS_TICKER[corporation] = corporation_sheet.ticker
+									except Exception, e:
+										warning('Could not retrieve Ticker for corporation {corporation}'.format(corporation=corporation))
+										ticker = 'GUEST'
+								else:
+									ticker = CORPORATIONS_TICKER[corporation]
+							display_name = "%s - %s" % (ticker, display_name)
+							return (random.choice(range(500000,1000000)) + cfg.user.id_offset, 'G - %s' % (display_name,), [])
 
 				# It was actually a bad login
 				warning("User " + name + " failed with wrong password")

File pizza_auth/main.py

 import json
+import ast
 from flask import Flask, flash, session, render_template, redirect, request, abort, url_for, escape
 from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user
 import ts3tools, announce
 from keytools import KeyTools
 from emailtools import EmailTools
 from reddittools import RedditTools
+from redisutils import *
 from authutils import groups_required, group_required, api_key_required
 from collections import namedtuple
 from ldap import ALREADY_EXISTS
 			user = user.__dict__
 	return render_template("admintools.html", user=user)
 
+@app.route("/mumble")
+@login_required
+@group_required("mumble")
+def mumbleopslist():
+	ops = operationshash.keys()
+	operations = []
+	for opkey in ops:
+		op_data = literal_eval(operationshash[opkey])
+		op_data.update({'op_hash': opkey})
+		operations.append(op_data)
+
+	return render_template("mumbleopslist.html", operations=operations)
+
+@app.route("/mumble/admin/add", methods=["POST"])
+@login_required
+@group_required("mumble")
+def generateop():
+	form = request.form
+	op_name = form["op_name"]
+	op_fc = form.get("op_fc", None)
+	op_info = {}
+	if op_fc:
+		op_info.update({'op_fc': op_fc})
+	
+	generate_op(op_name, **op_info)
+	flash("Generated Operation.", "success")
+	return redirect("/mumble")
+
+@app.route("/mumble/generateuser/<opkey>")
+def generateuser(opkey):
+	hdrs = request.headers
+	if hdrs.get('Eve-Trusted', 'empty').lower() == 'no':
+		flash("You must trust this site to use this feature.", "danger")
+		return render_template("trustneeded.html")
+	charactername = hdrs.get('Eve-Charname', "BAD KITTY")
+	user_info = {
+			'charactername': charactername,
+			'corporationid': hdrs.get('Eve-Corpid', 0),
+			'allianceid':	 hdrs.get('Eve-Allianceid', 0)
+			}
+
+	user_hash = generate_user(opkey, charactername,**user_info)
+
+	return render_template("mumblegenerate.html", userhash = user_hash)
+
+@app.route("/mumble/remove/<opkey>")
+@login_required
+@group_required("mumble")
+def removemumbleop(opkey):
+	users = get_op_users(opkey)
+	if destroy_op(opkey):
+		flash("Successful delete for operation %s." % (opkey,), "success")
+		flash("Deleted users: %s" % (", ".join(users),), "success")
+	else:
+		flash("Something went wrong deleting operation %s." % (opkey,), "danger")
+	return redirect("/mumble")
+
 @app.route("/admin/deleteuser", methods=["POST"])
 @login_required
 @group_required("admin")

File pizza_auth/redisutils.py

 def confirm_user(username):
 	return username in mumblehash
 
+def get_op_users(op_hash):
+	user_list = []
+	if confirm_op(op_hash):
+		for username in mumblehash.keys():
+			tmp_dict = literal_eval(mumblehash[username])
+			if 'op_hash' in tmp_dict:
+				if tmp_dict['op_hash'] == op_hash:
+					user_list.append(username)
+	return user_list
+
 def destroy_user(username):
 	if confirm_user(username):
 		del(mumblehash[username])

File pizza_auth/templates/mumblegenerate.html

+{% extends "base.html" %}
+{% block title %}Mumble Op Generator {% endblock %}
+{% block header %}Mumble Op Access {% endblock %}
+{% block body %}
+<div class="row">
+	<div class="col-md-8">
+		<div class="panel panel-primary">
+			<div class="panel-heading"><h3 class="panel-title">Mumble Op Login</h3></div>
+			<div class="panel-body">
+				<p>Mumble Username: <span class="text-info">{{ userhash.username }}</span></p>
+				<p>Mumble Password: <span class="text-info">{{ userhash.password }}</span></p>
+				<p>Server: <span class="text-info">{{ config["mumble"]["server"] }}</span></p>
+				
+			</div>
+		</div>
+	</div>
+</div>
+{% endblock %}

File pizza_auth/templates/mumbleopslist.html

+{% extends "base.html" %}
+{% block title %}Mumble Op List - {{ group }}{% endblock %}
+{% block header %}Mumble Op List - {{ group }}{% endblock %}
+{% block body %}
+<div class="row">
+	<div class="col-md-4 panel panel-primary">
+			<div class="panel-heading"><h3 class="panel-title">Add Op</h3></div>
+			<div class="panel-body form-group">
+				<form role="form" class="panel-body form-inline span8 custom-form" name="form" action="/mumble/admin/add" method="post">
+					<label for="op_name">Op Name (req'd)</label><br />
+					<input class="form-control" style="width:100%" type="text" name="op_name" placeholder="Generic Op"></input>
+					<label for="op_fc">Op FC (optional)</label><br />
+					<input class="form-control" style="width:100%" type="text" name="op_fc" placeholder="Fleet Commander X"></input>
+					<div class="controls form-group">
+						<button type="submit" class="btn btn-primary" value="submit">Create</button>
+					</div>
+				</form>
+			</div>
+	</div>
+</div>
+<div class="row">
+	<div class="col-md-12">
+		<table class="table table-striped">
+			<tr>
+				<th>Op Name</th><th>Op FC</th><th>Mumble Channel</th><th>Fleet URL</th><th>Actions</th>
+			</tr>
+			{% for op in operations %}
+			<tr>
+				<td>{{ op.op_name }}</td>
+				<td>{{ op.op_fc }}</td>
+				<td>{{ op.op_channel }}</td>
+				<td>http://auth.talkinlocal.org/mumble/generateuser/{{ op.op_hash }}</td>
+				<td>
+					<div class="btn-group pull-right">
+						<a class="btn btn-xs btn-danger" href="/mumble/remove/{{ op.op_hash }}">Remove</a>
+					</div>
+				</td>
+			</tr>
+			{% endfor %}
+		</table>
+	</div>
+</div class="row">
+{% endblock %}

File pizza_auth/templates/trustneeded.html

+{% extends "base.html" %}
+{% block title %}Mumble Op Access - Trust Generation {% endblock %}
+{% block header %}Mumble Op Access {% endblock %}
+{% block body %}
+<div class="row">
+	<div class="col-md-8">
+		<div class="panel panel-primary">
+			<div class="panel-heading"><h3 class="panel-title">Trust Request</h3></div>
+			<div class="panel-body">
+			<p>
+			Trust is required to use this auth feature. After trusting the site, click the refresh button at the top of the in-game browers window.
+			<br/>
+			<br/><a href="javascript:CCPEVE.requestTrust('http://dev.{{ config["auth"]["domain"] }}:8090');" class="btn btn-info">Request Trust</a>
+			</p>
+			</div>
+		</div>
+	</div>
+</div>
+{% endblock %}