polishing things
This commit is contained in:
parent
3261c0a96d
commit
567b75682b
11 changed files with 45 additions and 83 deletions
|
@ -57,14 +57,15 @@ class CustomJSONEncoder(JSONEncoder):
|
||||||
|
|
||||||
app.json_encoder = CustomJSONEncoder
|
app.json_encoder = CustomJSONEncoder
|
||||||
|
|
||||||
|
#if app.debug:
|
||||||
if not app.debug:
|
if not app.debug:
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
file_handler = RotatingFileHandler('/home/proxadmin/appserver/proxadmin/log/proxadmin.log', 'a', 1 * 1024 * 1024, 10)
|
file_handler = RotatingFileHandler('/home/proxadmin/appserver/proxadmin/log/proxadmin.log', 'a', 1 * 1024 * 1024, 10)
|
||||||
file_handler.setLevel(logging.INFO)
|
file_handler.setLevel(logging.DEBUG)
|
||||||
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
|
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
|
||||||
app.logger.addHandler(file_handler)
|
app.logger.addHandler(file_handler)
|
||||||
app.logger.setLevel(logging.INFO)
|
app.logger.setLevel(logging.DEBUG)
|
||||||
app.logger.info('Proxadmin started.')
|
app.logger.info('Proxadmin started.')
|
||||||
|
|
||||||
@app.errorhandler(403)
|
@app.errorhandler(403)
|
||||||
|
|
|
@ -56,43 +56,6 @@ def login():
|
||||||
|
|
||||||
return render_template('auth/login.html', page=page, form=form)
|
return render_template('auth/login.html', page=page, form=form)
|
||||||
|
|
||||||
#PROFILE
|
|
||||||
@auth.route('/profile', methods=['GET', 'POST'])
|
|
||||||
@login_required
|
|
||||||
def profile():
|
|
||||||
page = { 'title': 'Edit Profile' }
|
|
||||||
|
|
||||||
currentmail = current_user.email
|
|
||||||
ouruser = User.query.filter_by(email=currentmail).first()
|
|
||||||
db.session.commit()
|
|
||||||
wallet = "%.2f" % round(ouruser.wallet, 3)
|
|
||||||
print(wallet)
|
|
||||||
form = EditProfileForm()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
current_user.name = form.name.data
|
|
||||||
current_user.address = form.address.data
|
|
||||||
current_user.city = form.city.data
|
|
||||||
current_user.postcode = form.postcode.data
|
|
||||||
current_user.country = form.country.data
|
|
||||||
current_user.phone = form.phone.data
|
|
||||||
current_user.org_responsible = form.org_responsible.data
|
|
||||||
current_user.org_bulstat = form.org_bulstat.data
|
|
||||||
current_user.twofactor = form.twofactor.data
|
|
||||||
db.session.add(current_user)
|
|
||||||
db.session.commit()
|
|
||||||
flash('Info Updated!')
|
|
||||||
|
|
||||||
form.twofactor.data = current_user.twofactor
|
|
||||||
form.name.data = current_user.name
|
|
||||||
form.address.data = current_user.address
|
|
||||||
form.city.data = current_user.city
|
|
||||||
form.postcode.data = current_user.postcode
|
|
||||||
form.country.data = current_user.country
|
|
||||||
form.phone.data = current_user.phone
|
|
||||||
form.org_responsible.data = current_user.org_responsible
|
|
||||||
form.org_bulstat.data = current_user.org_bulstat
|
|
||||||
|
|
||||||
return render_template('auth/profile.html', page=page, form=form)
|
|
||||||
|
|
||||||
@auth.route('/twofactor', methods=['GET', 'POST'])
|
@auth.route('/twofactor', methods=['GET', 'POST'])
|
||||||
def twofactor():
|
def twofactor():
|
||||||
|
|
|
@ -20,7 +20,6 @@ class Permission:
|
||||||
DEPLOY = 0x01
|
DEPLOY = 0x01
|
||||||
ADMINISTER = 0x80
|
ADMINISTER = 0x80
|
||||||
|
|
||||||
|
|
||||||
class Role(db.Model):
|
class Role(db.Model):
|
||||||
__tablename__ = 'roles'
|
__tablename__ = 'roles'
|
||||||
pid = db.Column(db.Integer, primary_key=True)
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -78,7 +77,7 @@ class User(db.Model, UserMixin):
|
||||||
org_vat = db.Column(db.Boolean, default=False)
|
org_vat = db.Column(db.Boolean, default=False)
|
||||||
org_vatnum = db.Column(db.String(16))
|
org_vatnum = db.Column(db.String(16))
|
||||||
|
|
||||||
wallet = db.Column(db.Float)
|
wallet = db.Column(db.Float, default=0.0)
|
||||||
credit = db.Column(db.Float)
|
credit = db.Column(db.Float)
|
||||||
creditlimit = db.Column(db.Float, default=20.0)
|
creditlimit = db.Column(db.Float, default=20.0)
|
||||||
|
|
||||||
|
@ -187,7 +186,6 @@ class User(db.Model, UserMixin):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User %r>' % self.email
|
return '<User %r>' % self.email
|
||||||
|
|
||||||
|
|
||||||
class AnonymousUser(AnonymousUserMixin):
|
class AnonymousUser(AnonymousUserMixin):
|
||||||
def can(self, permissions):
|
def can(self, permissions):
|
||||||
return False
|
return False
|
||||||
|
@ -197,12 +195,10 @@ class AnonymousUser(AnonymousUserMixin):
|
||||||
|
|
||||||
lm.anonymous_user = AnonymousUser
|
lm.anonymous_user = AnonymousUser
|
||||||
|
|
||||||
|
|
||||||
@lm.user_loader
|
@lm.user_loader
|
||||||
def load_user(user_id):
|
def load_user(user_id):
|
||||||
return User.query.get(int(user_id))
|
return User.query.get(int(user_id))
|
||||||
|
|
||||||
|
|
||||||
def contact_proxmaster(data, method, cubeid=0):
|
def contact_proxmaster(data, method, cubeid=0):
|
||||||
url = current_app.config['PROXMASTER_URL']
|
url = current_app.config['PROXMASTER_URL']
|
||||||
data['apikey'] = current_app.config['APIKEY']
|
data['apikey'] = current_app.config['APIKEY']
|
||||||
|
@ -223,7 +219,6 @@ def contact_proxmaster(data, method, cubeid=0):
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
#TEMPLATE CLASSES
|
#TEMPLATE CLASSES
|
||||||
class Product(db.Model):
|
class Product(db.Model):
|
||||||
__tablename__ = 'products'
|
__tablename__ = 'products'
|
||||||
|
@ -272,7 +267,7 @@ class Product(db.Model):
|
||||||
'cpu': product.cpu,
|
'cpu': product.cpu,
|
||||||
'mem': product.mem,
|
'mem': product.mem,
|
||||||
'hdd': product.hdd,
|
'hdd': product.hdd,
|
||||||
'recipe': product.recipe,
|
'recipe': product.recipe
|
||||||
}
|
}
|
||||||
return products
|
return products
|
||||||
|
|
||||||
|
@ -322,6 +317,7 @@ class Transaction(db.Model):
|
||||||
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
|
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
|
||||||
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||||
currency = db.Column(db.String, default='BGN')
|
currency = db.Column(db.String, default='BGN')
|
||||||
|
value = db.Column(db.Float)
|
||||||
|
|
||||||
#PROFORMA INVOICE CLASS
|
#PROFORMA INVOICE CLASS
|
||||||
class Invoice(db.Model):
|
class Invoice(db.Model):
|
||||||
|
@ -361,8 +357,7 @@ class InvoiceItem(db.Model):
|
||||||
item_quantity = db.Column(db.Float)
|
item_quantity = db.Column(db.Float)
|
||||||
item_price = db.Column(db.Float)
|
item_price = db.Column(db.Float)
|
||||||
amount = db.Column(db.Float)
|
amount = db.Column(db.Float)
|
||||||
|
invoice = db.relationship(Invoice, backref=db.backref('items', order_by=item_number, cascade="delete"))
|
||||||
invoice = db.relationship(Invoice, backref=backref('items', order_by=item_number, cascade="delete"))
|
|
||||||
|
|
||||||
def total(self):
|
def total(self):
|
||||||
return self.item_quantity * self.item_price
|
return self.item_quantity * self.item_price
|
||||||
|
@ -395,17 +390,13 @@ class Deployment(db.Model):
|
||||||
hdd_cost = deploy.machine_hdd * current_app.config['HDD_RATIO']
|
hdd_cost = deploy.machine_hdd * current_app.config['HDD_RATIO']
|
||||||
total = cpu_cost + mem_cost + hdd_cost
|
total = cpu_cost + mem_cost + hdd_cost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if managed_user.wallet - managed_user.credit > managed_user.creditlimit:
|
if managed_user.wallet - managed_user.credit > managed_user.creditlimit:
|
||||||
print('{}> Deployment #{} costs {} today. Credit is now {}'.format(managed_user.email, deploy.machine_id, total, managed_user.credit))
|
print('{}> Deployment #{} costs {} today. Credit is now {}'.format(managed_user.email, deploy.machine_id, total, managed_user.credit))
|
||||||
managed_user.credit += total
|
managed_user.credit += total
|
||||||
else:
|
else:
|
||||||
print('{}> Deployment #{} costs {} today. Credit now is {} and its lower than the credit limit {}.'.format(managed_user.email, deploy.machine_id, total, managed_user.credit, managed_user.creditlimit)
|
print('{}> Deployment #{} costs {} today. Credit now is {} and its lower than the credit limit {}.'.format(managed_user.email, deploy.machine_id, total, managed_user.credit, managed_user.creditlimit))
|
||||||
print('')
|
print('')
|
||||||
if datetime.utcnow.date() ==
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if deploy.
|
|
||||||
|
|
||||||
class Contract(db.Model):
|
class Contract(db.Model):
|
||||||
__tablename__ = 'contracts'
|
__tablename__ = 'contracts'
|
||||||
|
@ -426,12 +417,12 @@ class Contract(db.Model):
|
||||||
for contract in result:
|
for contract in result:
|
||||||
managed_user = User.query.get(contract.user_id)
|
managed_user = User.query.get(contract.user_id)
|
||||||
db.session.add(contract)
|
db.session.add(contract)
|
||||||
if datetime.utcnow.date() > (contract.date_expire - timedelta(days=10)):
|
#if datetime.utcnow.date() > (contract.date_expire - timedelta(days=10)):
|
||||||
if contract.enabled == True:
|
if contract.enabled == True:
|
||||||
print('{}> Contract {} will expire in 10 days at {}. Creating new order...'.format(managed_user.email, contract.pid, contract.date_expire))
|
print('{}> Contract {} will expire in 10 days at {}. Creating new order...'.format(managed_user.email, contract.pid, contract.date_expire))
|
||||||
current_service = Service.query.get(int(contract.product_id))
|
current_service = Service.query.get(int(contract.product_id))
|
||||||
order = Order(user_id=managed_user.id, units=contract.units, unitvalue=(current_service.unitprice * contract.units), description=current_service.name)
|
transaction = Transaction(user_id=managed_user.id, units=contract.units, unitvalue=(current_service.unitprice * contract.units), description=current_service.name)
|
||||||
db.session.add(order)
|
db.session.add(transaction)
|
||||||
contract.data_expire = datetime.utcnow.date() + timedelta(days=30)
|
contract.data_expire = datetime.utcnow.date() + timedelta(days=30)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return True
|
return True
|
||||||
|
@ -453,11 +444,11 @@ class Domain(db.Model):
|
||||||
for domain in result:
|
for domain in result:
|
||||||
managed_user = User.query.get(domain.user_id)
|
managed_user = User.query.get(domain.user_id)
|
||||||
db.session.add(domain)
|
db.session.add(domain)
|
||||||
if datetime.utcnow.date() > (domain.date_expire - timedelta(days=60)):
|
#if datetime.utcnow.date() > (domain.date_expire - timedelta(days=60)):
|
||||||
if domain.enabled == True:
|
if domain.enabled == True:
|
||||||
print('{}> Domain {} will expire in 60 days at {}. Creating new order...'.format(managed_user.email, domain.fqdn, domain.date_expire))
|
print('{}> Domain {} will expire in 60 days at {}. Creating new order...'.format(managed_user.email, domain.fqdn, domain.date_expire))
|
||||||
order = Order(user_id=managed_user.id, unitvalue=25, description=domain.fqdn)
|
transaction = Transaction(user_id=managed_user.id, unitvalue=25, description=domain.fqdn)
|
||||||
db.session.add(order)
|
db.session.add(transaction)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
uinvoice = Blueprint('settings', __name__)
|
settings = Blueprint('settings', __name__)
|
||||||
from . import routes
|
from . import routes
|
||||||
|
|
|
@ -3,11 +3,12 @@ from flask_login import login_required, login_user, logout_user, current_user
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
from .forms import EditProfileForm, EditProfileAdminForm, ChargeForm, PaymentForm
|
from .forms import EditProfileForm, EditProfileAdminForm
|
||||||
|
|
||||||
from ..email import send_email
|
from ..email import send_email
|
||||||
from .. import db
|
from .. import db
|
||||||
from ..models import User, Order
|
from ..models import User
|
||||||
|
import sys
|
||||||
|
|
||||||
#PROFILE
|
#PROFILE
|
||||||
@settings.route('/profile', methods=['GET', 'POST'])
|
@settings.route('/profile', methods=['GET', 'POST'])
|
||||||
|
@ -19,8 +20,8 @@ def profile():
|
||||||
ouruser = User.query.filter_by(email=currentmail).first()
|
ouruser = User.query.filter_by(email=currentmail).first()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
#wallet = "%.2f" % round(ouruser.wallet, 3)
|
wallet = "%.2f" % round(ouruser.wallet, 3)
|
||||||
#print(wallet)
|
current_app.logger.info('wallet: ' + wallet)
|
||||||
|
|
||||||
form = EditProfileForm()
|
form = EditProfileForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
{% block html_attribs %} lang="en"{% endblock %}
|
{% block html_attribs %} lang="en"{% endblock %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<link href="{{ url_for('static', filename='css/navbar.css') }}" rel="stylesheet">
|
<link href="{{ url_for('static', filename='css/navbar.css') }}" rel="stylesheet">
|
||||||
|
@ -16,7 +20,6 @@
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script type=text/javascript src="{{ url_for('static', filename='js/jquery.js') }}"></script>
|
|
||||||
<script type=text/javascript src="{{ url_for('static', filename='js/nouislider.min.js') }}"></script>
|
<script type=text/javascript src="{{ url_for('static', filename='js/nouislider.min.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -34,7 +37,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% block page_content %}{% endblock %}
|
{% block page_content %}{% endblock %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<li><a href="/deploy/7"><span class="glyphicon glyphicon-send"></span> Deploy Application</a></li>
|
<li><a href="#"><span class="glyphicon glyphicon-send"></span> Deploy Application</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-send"></span> Deploy Application</a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-send"></span> Deploy Application</a>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
|
||||||
|
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
|
|
||||||
<iframe src="https://kiwiirc.com/client/irc.datapoint.bg:+6697/?nick=client|?&theme=relaxed#support" style="border:0; width:100%; height:640px;"></iframe>
|
<iframe src="https://kiwiirc.com/client/irc.datapoint.bg:+6697/?&theme=relaxed#support" style="border:0; width:100%; height:640px;"></iframe>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
To permanently stay connected to our chat network you could use an client like <a href="https://hexchat.github.io/downloads.html">HexChan</a> and use the following URL <a href="irc://irc.datapoint.bg:+6697/#support">irc://irc.datapoint.bg:+6697/#support</a>
|
||||||
|
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,11 +3,11 @@ from flask_login import login_required, login_user, logout_user, current_user
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from . import uinvoice
|
from . import uinvoice
|
||||||
from .forms import EditProfileForm, EditProfileAdminForm, ChargeForm, PaymentForm
|
from .forms import ChargeForm, PaymentForm
|
||||||
|
|
||||||
from ..email import send_email
|
from ..email import send_email
|
||||||
from .. import db
|
from .. import db
|
||||||
from ..models import User, Order
|
from ..models import User, Invoice
|
||||||
|
|
||||||
#INVOICES
|
#INVOICES
|
||||||
#@uinvoice.route('/charge', methods=['GET', 'POST'])
|
#@uinvoice.route('/charge', methods=['GET', 'POST'])
|
||||||
|
@ -30,8 +30,8 @@ from ..models import User, Order
|
||||||
@uinvoice.route('/documents', methods=['GET'])
|
@uinvoice.route('/documents', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def documents():
|
def documents():
|
||||||
page = { 'title': 'Order documents' }
|
page = { 'title': 'Invoice documents' }
|
||||||
invoices = Order.query.filter_by(user_id=current_user.pid).order_by(desc(Order.date_created)).all()
|
invoices = Invoice.query.filter_by(user_id=current_user.pid).order_by(desc(Invoice.date_created)).all()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return render_template('uinvoice/documents.html', page=page, documents=invoices)
|
return render_template('uinvoice/documents.html', page=page, documents=invoices)
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def documents():
|
||||||
@login_required
|
@login_required
|
||||||
def order(document_id):
|
def order(document_id):
|
||||||
page = { 'title': 'Preview ' + str(document_id) }
|
page = { 'title': 'Preview ' + str(document_id) }
|
||||||
order = Order.query.filter_by(pid=document_id).first()
|
order = Invoice.query.filter_by(pid=document_id).first()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
#check if document_id is owned by you.
|
#check if document_id is owned by you.
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -123,7 +123,7 @@ def deploy(product_id=None):
|
||||||
|
|
||||||
if query is not None:
|
if query is not None:
|
||||||
cubeid = query['cube']
|
cubeid = query['cube']
|
||||||
deployment = Deployment(user_id=client_id, product_id=product_id, machine_alias=form.servername.data, machine_id=cubeid, machine_cpu=form.cpu.data, machine_mem=form.mem.data, machine_hdd=form.hdd.data, credit=0, date_expire=(datetime.utcnow() + timedelta(days=30)), enabled=True)
|
deployment = Deployment(user_id=client_id, product_id=product_id, machine_alias=form.servername.data, machine_id=cubeid, machine_cpu=form.cpu.data, machine_mem=form.mem.data, machine_hdd=form.hdd.data, date_expire=(datetime.utcnow() + timedelta(days=30)), enabled=True)
|
||||||
db.session.add(deployment)
|
db.session.add(deployment)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -140,7 +140,6 @@ def deploy(product_id=None):
|
||||||
@vmanager.route("/dashboard", methods=['GET', 'POST'])
|
@vmanager.route("/dashboard", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
#if request.method == 'GET':
|
|
||||||
deployments = current_user.inv_deployments.order_by(Deployment.date_created.desc()).all()
|
deployments = current_user.inv_deployments.order_by(Deployment.date_created.desc()).all()
|
||||||
|
|
||||||
inv_deployments = []
|
inv_deployments = []
|
||||||
|
|
Loading…
Reference in a new issue