redesign admin pages

This commit is contained in:
deflax 2018-01-25 19:48:50 +02:00
parent 426143a5cc
commit d7246f30ed
8 changed files with 93 additions and 66 deletions

View file

@ -258,60 +258,64 @@ class Deployment(db.Model):
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.ForeignKey('users.pid')) #FK
server_id = db.Column(db.ForeignKey('servers.pid')) #FK
date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=True)
warning = db.Column(db.Boolean, default=False)
protected = db.Column(db.Boolean, default=False) #machines with this False will be autodeleted after the warning period is over.
date_last_charge = db.Column(db.DateTime)
discount = db.Column(db.Integer)
period = db.Column(db.Integer)
daysleft = db.Column(db.Integer)
vlan = db.Column(db.Integer)
machine_id = db.Column(db.BigInteger) #unit_id
machine_alias = db.Column(db.String) #dns name
machine_cpu = db.Column(db.Integer)
machine_mem = db.Column(db.Integer)
machine_hdd = db.Column(db.Integer)
discount = db.Column(db.Integer)
inv_addresses = db.relationship('Address', backref='assignee', lazy='dynamic')
inv_pubvlans = db.relationship('PubVLAN', backref='deploy', lazy='dynamic')
class PubVLAN(db.Model):
__tablename__ = 'pubvlans'
pid = db.Column(db.Integer, primary_key=True)
deploy_id = db.Column(db.ForeignKey('deployments.pid')) #FK
vlan_id = db.Column(db.Integer)
pubaddr = db.relationship('Address', uselist=False, backref='assignee')
class Address(db.Model):
__tablename__ = 'address'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.ForeignKey('users.pid')) #FK
region_id = db.Column(db.ForeignKey('regions.pid')) #FK
deployment_id = db.Column(db.ForeignKey('deployments.pid')) #FK
date_assigned = db.Column(db.DateTime, default=datetime.utcnow)
pubvlan_id = db.Column(db.ForeignKey('pubvlans.pid')) #FK
enabled = db.Column(db.Boolean)
ip = db.Column(db.String)
mac = db.Column(db.String)
#mac = db.Column(db.String)
rdns = db.Column(db.String)
reserved = db.Column(db.Boolean, default=False) #this ip SHOULD NOT be listed as available to assign even if its not currently owned by anyone
def __init__(self, **kwargs):
super(Address, self).__init__(**kwargs)
if self.mac is None:
self.mac = self.genmac()
#def __init__(self, **kwargs):
# super(Address, self).__init__(**kwargs)
# if self.mac is None:
# self.mac = self.genmac()
def genmac(self):
alladdr = Address.query.all()
allmacs = []
current_app.logger.info('populating mac addr pool')
for addr in alladdr:
allmacs.append(str(addr.mac))
while True:
mac = [ random.randint(0, 255) for x in range(0, 6) ]
mac[0] = (mac[0] & 0xfc) | 0x02
mac = ':'.join([ '{0:02x}'.format(x) for x in mac ])
if mac in allmacs:
current_app.logger.warning('mac address {} is in the pool. regenerating...'.format(mac))
continue
else:
return mac
#def genmac(self):
# alladdr = Address.query.all()
# allmacs = []
# current_app.logger.info('populating mac addr pool')
# for addr in alladdr:
# allmacs.append(str(addr.mac))
# while True:
# mac = [ random.randint(0, 255) for x in range(0, 6) ]
# mac[0] = (mac[0] & 0xfc) | 0x02
# mac = ':'.join([ '{0:02x}'.format(x) for x in mac ])
# if mac in allmacs:
# current_app.logger.warning('mac address {} is in the pool. regenerating...'.format(mac))
# continue
# else:
# return mac
#MISC ITEMS
class Service(db.Model):

View file

@ -0,0 +1,7 @@
<center>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_servers') }}','_self')"><span class="glyphicon glyphicon-off" aria-hidden="true"></span> Servers</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
<button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_recyclebin') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button>
</center>

View file

@ -0,0 +1,7 @@
<center>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-btc" aria-hidden="true"></span> Transactions</button>
</center>

View file

@ -1,17 +1,17 @@
<div class="col-md-12">
<div class="panel panel-warning" id="prxadmin">
<div class="panel-heading">Admin Pages</div>
<div class="col-md-6">
<div class="panel panel-warning" id="prxadmincloud">
<div class="panel-heading">Cloud Manager</div>
<div class="panel-body">
<center>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
<button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_recyclebin') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-btc" aria-hidden="true"></span> Transactions</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_servers') }}','_self')"><span class="glyphicon glyphicon-off" aria-hidden="true"></span> Servers</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
</center>
{% include "admin/admin_cloud.html" %}
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-warning" id="prxadminmisc">
<div class="panel-heading">Misc</div>
<div class="panel-body">
{% include "admin/admin_misc.html" %}
</div>
</div>
</div>

View file

@ -17,9 +17,9 @@
<thead>
<tr>
<th>IP</th>
<th>Assignee</th>
<th>VLAN</th>
<th>Slave</th>
<th>Deploy</th>
<th>Server</th>
<th>Region</th>
<th>rDNS</th>
</tr>
@ -27,19 +27,23 @@
<tbody>
{% for address in addresses %}
<tr>
{% if address.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
{% if address.reserved == True %}<tr class="danger">{% else %}<tr>{% endif %}
<td>{{ address.ip }}</td>
{% if address.assignee != None %}
<td>{{ address.assignee.machine_alias }}</td>
<td>{{ address.assignee.vlan }}</td>
<td>{{ address.assignee.server.name }}</td>
<td>{{ address.assignee.vlan_id }}</td>
<td>{{ address.assignee.deploy.machine_alias }}</td>
<td>{{ address.assignee.deploy.server.name }}</td>
{% else %}
<td>None</td>
<td></td>
<td></td>
<td></td>
{% endif %}
<td>{{ address.region.name }}</td>
{% if address.rdns != None %}
<td>{{ address.rdns }}</td>
{% else %}
<td></td>
{% endif %}
{% endfor %}
</tr>
</tbody>

View file

@ -21,7 +21,6 @@
<th>CPU</th>
<th>Mem</th>
<th>HDD</th>
<th>Price</th>
<th>Last Charged</th>
<th>Days Left</th>
</tr>
@ -42,7 +41,6 @@
<td>{{ deploy.machine_cpu }}</td>
<td>{{ deploy.machine_mem }} MB</td>
<td>{{ deploy.machine_hdd }} GB</td>
<td>{{ deploy.price }}</td>
{% if deploy.date_last_charge == None %}
<td>Never</td>
{% else %}

View file

@ -4,11 +4,12 @@ from flask_sqlalchemy import get_debug_queries
from . import vmanager
from .forms import CreateForm, ActivateForm
from .. import db
from .. import db, csrf
from ..email import send_email
from ..models import User, Permission, Transaction, Deployment, Service, Region, Address, Domain, contact_proxmaster
from ..models import User, Permission, Transaction, Deployment, Service, Region, Server, Address, Domain, contact_proxmaster
from ..decorators import admin_required, permission_required
import json
import base64
import string
import random
@ -27,20 +28,24 @@ def after_request(response):
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response
@vmanager.route('/slavetables/<int:regionid>', methods=['GET'])
def slavetables(regionid):
selected_region = Region.query.filter_by(pid=int(regionid)).first()
if selected_region == None:
return jsonify({})
addresses = selected_region.inv_addresses.filter_by(enabled=True).all()
regionlist = {}
for address in addresses:
regionlist[str(address.pid)] = { 'ipv4': str(address.ip), 'mac': str(address.mac) }
data = { 'region_id': str(selected_region.pid),
'addresses': regionlist }
return jsonify(data)
@vmanager.route('/slavetables', methods=['POST'])
@csrf.exempt
def slavetables():
postdata = request.get_json()
if postdata['passphrase'] == 'batkataisthebest1':
selected_slave = Server.query.filter_by(name=str(postdata['slavename'])).first()
if selected_slave == None:
return jsonify({'status': 'slave_not_found'})
deploylist = selected_slave.inv_deployments.all()
addresslist = {}
for deploy in deploylist:
addresslist[str(deploy.machine_id)] = {}
addresses = deploy.inv_addresses.first()
deploy_address_list = []
for address in addresses:
deploy_address_list.append(address.ip)
addresslist[deploy.vlan] = deploy_address_list
return jsonify(addresslist)
@vmanager.route('/createvm', methods=['GET', 'POST'])
@login_required
@ -78,7 +83,8 @@ def createvm():
return redirect(url_for('panel.dashboard'))
if query['status'] == 'kvm_created':
deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0, bridge_id=int(selected_bridge.pid))
selected_slave = Server.query.filter_by(name=query['slave']).first()
deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0, server_id=int(selected_slave.pid), vlan=query['vlanid'])
db.session.add(deployment)
db.session.commit()
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description)))

View file

@ -39,6 +39,7 @@ requests==2.17.3
schedule==0.4.2
six==1.10.0
sortedcontainers==1.5.7
speaklater==1.3
SQLAlchemy==1.1.10
traits==4.6.0
Unipath==1.1