2017-03-31 16:24:10 +00:00
|
|
|
from flask import Flask, render_template, request, session, redirect, url_for, flash
|
2017-03-14 23:32:55 +00:00
|
|
|
from os import urandom as rand
|
|
|
|
import pprint
|
|
|
|
import ts3
|
|
|
|
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.secret_key = rand(24)
|
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
|
|
|
|
def teamspeakClientAdd(clientName):
|
2017-03-14 23:32:55 +00:00
|
|
|
with ts3.query.TS3Connection('magic.adam-ant.co.uk', '10011') as ts3conn:
|
|
|
|
try:
|
2017-03-31 20:11:09 +00:00
|
|
|
ts3conn.login(client_login_name='serveradmin', client_login_password='DE0xWKTx')
|
2017-03-14 23:32:55 +00:00
|
|
|
except ts3.query.TS3QueryError as err:
|
|
|
|
print(err)
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-14 23:32:55 +00:00
|
|
|
ts3conn.use(sid=1)
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-14 23:32:55 +00:00
|
|
|
try:
|
|
|
|
clientdbid = ts3conn.clientdbfind(pattern=clientName)[0]['cldbid']
|
|
|
|
except ts3.query.TS3QueryError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2017-03-31 20:11:09 +00:00
|
|
|
ts3conn.servergroupaddclient(sgid=9, cldbid=clientdbid)
|
|
|
|
ts3conn.servergroupaddclient(sgid=10, cldbid=clientdbid)
|
|
|
|
ts3conn.servergroupaddclient(sgid=11, cldbid=clientdbid)
|
|
|
|
ts3conn.servergroupaddclient(sgid=12, cldbid=clientdbid)
|
2017-03-14 23:32:55 +00:00
|
|
|
return True
|
|
|
|
except:
|
|
|
|
print("ERROR")
|
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-31 16:24:10 +00:00
|
|
|
def teamspeakClientCheck(clientName):
|
|
|
|
with ts3.query.TS3Connection('magic.adam-ant.co.uk', '10011') as ts3conn:
|
|
|
|
try:
|
2017-03-31 20:11:09 +00:00
|
|
|
ts3conn.login(client_login_name='serveradmin', client_login_password='DE0xWKTx')
|
2017-03-31 16:24:10 +00:00
|
|
|
except ts3.query.TS3QueryError as err:
|
|
|
|
print(err)
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-31 16:24:10 +00:00
|
|
|
ts3conn.use(sid=1)
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-31 16:24:10 +00:00
|
|
|
try:
|
|
|
|
print('before')
|
|
|
|
client = ts3conn.clientfind(pattern=clientName)
|
|
|
|
print('after')
|
|
|
|
clientid = client[0]['clid']
|
|
|
|
groups = ts3conn.clientinfo(clid=clientid)[0]['client_servergroups']
|
|
|
|
except ts3.query.TS3QueryError as ts3err:
|
|
|
|
if ts3err.resp.error['id'] == '512':
|
|
|
|
session.pop('username', None)
|
2017-03-31 20:11:09 +00:00
|
|
|
flash("ERROR: Username not found. Type it carefully cos Clockwork PLUS! is gonna cost ya...", "danger")
|
2017-03-31 16:24:10 +00:00
|
|
|
return redirect(url_for('index'))
|
|
|
|
return "Ooops! Tell Adam this: <br>" + ts3err.resp.error['msg']
|
|
|
|
if "9," in groups:
|
|
|
|
print("FeckOffMate!")
|
2017-03-31 20:11:09 +00:00
|
|
|
flash("ERROR: You already have Clockwork PLUS, ya dingus", "danger")
|
2017-03-31 16:24:10 +00:00
|
|
|
session.pop('username', None)
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
else:
|
|
|
|
return redirect(url_for("payment"))
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-31 16:24:10 +00:00
|
|
|
|
2017-03-14 23:32:55 +00:00
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2017-03-31 17:02:02 +00:00
|
|
|
if 'username' in session:
|
|
|
|
#No longer in the checkout flow, reset!
|
|
|
|
session.pop('username', None)
|
2017-03-14 23:32:55 +00:00
|
|
|
return render_template("index.html")
|
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-14 23:32:55 +00:00
|
|
|
@app.route("/collectsunlight")
|
|
|
|
def wait():
|
2017-03-31 16:24:10 +00:00
|
|
|
if "username" in session:
|
|
|
|
return render_template("wait.html")
|
|
|
|
else:
|
|
|
|
return redirect(url_for("buy"))
|
2017-03-31 11:13:02 +00:00
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-31 11:13:02 +00:00
|
|
|
@app.route("/pay")
|
|
|
|
def payment():
|
|
|
|
if "username" in session:
|
|
|
|
return render_template("payment.html")
|
|
|
|
else:
|
|
|
|
return redirect(url_for("buy"))
|
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
|
2017-03-14 23:32:55 +00:00
|
|
|
@app.route("/activate")
|
|
|
|
def activate():
|
|
|
|
if "username" in session:
|
|
|
|
if teamspeakClientAdd(session['username']):
|
2017-03-31 16:28:58 +00:00
|
|
|
session.pop('username', None)
|
2017-03-31 20:11:09 +00:00
|
|
|
flash("Success! You have been upgraded to Clockwork PLUS! Enjoy!", "success")
|
2017-03-14 23:32:55 +00:00
|
|
|
return redirect(url_for('index'))
|
|
|
|
else:
|
|
|
|
return "Adam fucked up! go nag him"
|
|
|
|
else:
|
|
|
|
return redirect(url_for("buy"))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/buy", methods=['GET', 'POST'])
|
|
|
|
def buy():
|
|
|
|
if request.method == 'POST':
|
|
|
|
session['username'] = request.form['username']
|
2017-03-31 16:24:10 +00:00
|
|
|
return teamspeakClientCheck(session['username'])
|
2017-03-14 23:32:55 +00:00
|
|
|
return render_template("buy.html")
|
|
|
|
|
|
|
|
|
2017-03-31 20:11:09 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', debug=True)
|