diff --git a/app/admin/forms.py b/app/admin/forms.py index 6d7ce52..9fa39a1 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -8,6 +8,6 @@ from wtforms import validators, ValidationError from wtforms.fields.html5 import EmailField class ChargeForm(FlaskForm): - amount = DecimalField('Стойност:', [validators.DataRequired(), validators.NumberRange(min=0, max=6)]) + amount = DecimalField('Стойност:', [validators.DataRequired(), validators.NumberRange(min=1, max=500)]) submit = SubmitField('Зареди') diff --git a/app/admin/routes.py b/app/admin/routes.py index ad5c03e..d91cbdc 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -7,7 +7,7 @@ from .forms import ChargeForm from .. import db from ..email import send_email -from ..models import User, Role, Deployment, Service, Region, Address, Domain, contact_proxmaster +from ..models import User, Deployment, Service, Region, Address, Domain, contact_proxmaster from ..decorators import admin_required, permission_required import base64 @@ -31,6 +31,16 @@ def after_request(response): @admin.route("/", methods=['GET']) @login_required @admin_required +def index(): + alldeployments = Deployment.query.order_by(Deployment.date_created.desc()).all() + alldomains = Domain.query.order_by(Domain.date_created.desc()).all() + allservices = Service.query.order_by(Service.date_created.desc()).all() + alladdresses = Address.query.order_by(Address.date_assigned.desc()).all() + return render_template('admin/index.html', deployments=alldeployments, domains=alldomains, services=allservices, addresses=alladdresses) + +@admin.route("/users", methods=['GET']) +@login_required +@admin_required def users(): allusers = User.query.order_by(User.pid.asc()).all() return render_template('admin/users.html', users=allusers) @@ -42,7 +52,7 @@ def charge(user_pid=0): cuser = User.query.filter_by(pid=user_pid).first() form = ChargeForm() if form.validate_on_submit(): - cuser.wallet += form.amount.data + cuser.wallet += float(form.amount.data) db.session.add(cuser) db.session.commit() return redirect(url_for('admin.users')) diff --git a/app/models.py b/app/models.py index 29d796b..eff2db6 100644 --- a/app/models.py +++ b/app/models.py @@ -160,7 +160,10 @@ class User(db.Model, UserMixin): return self.role is not None and (self.role.permissions & permissions) == permissions def is_administrator(self): - return self.can(Permission.ADMINISTER) + if self.can(Permission.ADMINISTER): + return True + else: + return False def ping(self): self.last_seen = datetime.utcnow() @@ -288,6 +291,7 @@ class Address(db.Model): ip = db.Column(db.String(64)) rdns = db.Column(db.String(256)) macaddr = db.Column(db.String(128)) + reserved = db.Column(db.Boolean, default=False) class Domain(db.Model): __tablename__ = 'domains' diff --git a/app/templates/admin/admin_tasks.html b/app/templates/admin/admin_tasks.html new file mode 100644 index 0000000..c438a55 --- /dev/null +++ b/app/templates/admin/admin_tasks.html @@ -0,0 +1,10 @@ +
+
+
Admin Pages
+
+ + +
+
+
+ diff --git a/app/templates/admin/charge.html b/app/templates/admin/charge.html index 5c78a2f..1e11328 100644 --- a/app/templates/admin/charge.html +++ b/app/templates/admin/charge.html @@ -4,21 +4,18 @@ {% block page_content %}
-
+ {% include "admin/admin_tasks.html" %} -{% block sidebar %} -{% include "/settings/acc_avatar.html" %} -{% endblock %} - -
+
Зареждане на сметка

- {{ form.charge_amount.label }} {{ form.charge_amount }}
- {% for error in form.charge_amount.errors %} + Current Value: {{ usr.wallet }}
+ {{ form.amount.label }} {{ form.amount }}
+ {% for error in form.amount.errors %} {{ error }}
{% endfor %}

@@ -35,7 +32,6 @@
-
diff --git a/app/templates/admin/dashboard.html b/app/templates/admin/dashboard.html index 9c88751..ef0928a 100644 --- a/app/templates/admin/dashboard.html +++ b/app/templates/admin/dashboard.html @@ -105,7 +105,7 @@ addEventListener("DOMContentLoaded", function() { request.open("GET", "/vmanager/" + command + "/" + vmid, true); // and then we send it off request.send(); - //alert("command " + command + " executed."); + alert("command " + command + " executed."); window.location.reload(); } }); @@ -118,8 +118,7 @@ addEventListener("DOMContentLoaded", function() {

- - Return to user list
+ {% include "admin/admin_tasks.html" %}
@@ -241,13 +240,10 @@ addEventListener("DOMContentLoaded", function() { -
- Return to user list
-
diff --git a/app/templates/admin/index.html b/app/templates/admin/index.html new file mode 100644 index 0000000..8877936 --- /dev/null +++ b/app/templates/admin/index.html @@ -0,0 +1,132 @@ +{% extends "base.html" %} + +{% block styles %} +{{ super() }} + +{% endblock %} + +{% block page_content %} +
+
+
+ {% include "admin/admin_tasks.html" %} + +
+
+
Deployments
+

+ + + + + + + + + + + + {% for deploy in deployments %} + + + + + + + + {% endfor %} + +
Cube IDAliasCPUMemHDDOwner
{% if deploy.enabled == True %}{% else %}{% endif %}{{ deploy.machine_id }}{{ deploy.machine_alias }}{{ deploy.machine_cpu }} Cores{{ deploy.machine_mem }} MB{{ deploy.machine_hdd }} GB{{ deploy.owner.email }}
+

+
+
+ +
+
+
Domains
+

+ + + + + + + + + {% for domain in domains %} + + + + + + {% endfor %} + +
NameExpiry DateOwner
{{ domain.fqdn }}{{ domain.date_expire }}{{ domain.owner.email }}
+

+
+
+ +
+
+
Addresses
+

+ + + + + + + + + + {% for address in addresses %} + + + + + + {% endfor %} + + +
IPReverse DNSMAC Addr.Owner
{{ address.ip }}{{ address.rdns }}{{ address.macaddr }}{{ address.owner.email }}
+

+
+
+ +
+
+
Services
+

+ + + + + + + + + + {% for service in services %} + + + + + + + + {% endfor %} + +
NameDescriptionUnitPrice
{{ service.name }}{{ service.description }}{{ service.unit }}{{ service.unitprice }}{{ service.owner.email }}
+

+
+
+ +
+ + +
+
+
+ +{% endblock %} + diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index 6d2d86d..b2a209a 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -2,6 +2,7 @@ {% block page_content %}
+ {% include "admin/admin_tasks.html" %}
@@ -30,11 +31,14 @@ {% endfor %} - +
+
+
+ {% endblock %} diff --git a/app/templates/nav.html b/app/templates/nav.html index 8619fa4..2e2bc78 100644 --- a/app/templates/nav.html +++ b/app/templates/nav.html @@ -24,8 +24,8 @@ {% endif %} {% if current_user.is_authenticated %} -
  • Deploy Application
  • -