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
|
||||
|
||||
#if app.debug:
|
||||
if not app.debug:
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
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]'))
|
||||
app.logger.addHandler(file_handler)
|
||||
app.logger.setLevel(logging.INFO)
|
||||
app.logger.setLevel(logging.DEBUG)
|
||||
app.logger.info('Proxadmin started.')
|
||||
|
||||
@app.errorhandler(403)
|
||||
|
|
|
@ -56,43 +56,6 @@ def login():
|
|||
|
||||
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'])
|
||||
def twofactor():
|
||||
|
|
|
@ -20,7 +20,6 @@ class Permission:
|
|||
DEPLOY = 0x01
|
||||
ADMINISTER = 0x80
|
||||
|
||||
|
||||
class Role(db.Model):
|
||||
__tablename__ = 'roles'
|
||||
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_vatnum = db.Column(db.String(16))
|
||||
|
||||
wallet = db.Column(db.Float)
|
||||
wallet = db.Column(db.Float, default=0.0)
|
||||
credit = db.Column(db.Float)
|
||||
creditlimit = db.Column(db.Float, default=20.0)
|
||||
|
||||
|
@ -187,7 +186,6 @@ class User(db.Model, UserMixin):
|
|||
def __repr__(self):
|
||||
return '<User %r>' % self.email
|
||||
|
||||
|
||||
class AnonymousUser(AnonymousUserMixin):
|
||||
def can(self, permissions):
|
||||
return False
|
||||
|
@ -197,12 +195,10 @@ class AnonymousUser(AnonymousUserMixin):
|
|||
|
||||
lm.anonymous_user = AnonymousUser
|
||||
|
||||
|
||||
@lm.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
||||
|
||||
def contact_proxmaster(data, method, cubeid=0):
|
||||
url = current_app.config['PROXMASTER_URL']
|
||||
data['apikey'] = current_app.config['APIKEY']
|
||||
|
@ -223,7 +219,6 @@ def contact_proxmaster(data, method, cubeid=0):
|
|||
except:
|
||||
return None
|
||||
|
||||
|
||||
#TEMPLATE CLASSES
|
||||
class Product(db.Model):
|
||||
__tablename__ = 'products'
|
||||
|
@ -272,7 +267,7 @@ class Product(db.Model):
|
|||
'cpu': product.cpu,
|
||||
'mem': product.mem,
|
||||
'hdd': product.hdd,
|
||||
'recipe': product.recipe,
|
||||
'recipe': product.recipe
|
||||
}
|
||||
return products
|
||||
|
||||
|
@ -322,6 +317,7 @@ class Transaction(db.Model):
|
|||
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
|
||||
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||
currency = db.Column(db.String, default='BGN')
|
||||
value = db.Column(db.Float)
|
||||
|
||||
#PROFORMA INVOICE CLASS
|
||||
class Invoice(db.Model):
|
||||
|
@ -361,8 +357,7 @@ class InvoiceItem(db.Model):
|
|||
item_quantity = db.Column(db.Float)
|
||||
item_price = db.Column(db.Float)
|
||||
amount = db.Column(db.Float)
|
||||
|
||||
invoice = db.relationship(Invoice, backref=backref('items', order_by=item_number, cascade="delete"))
|
||||
invoice = db.relationship(Invoice, backref=db.backref('items', order_by=item_number, cascade="delete"))
|
||||
|
||||
def total(self):
|
||||
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']
|
||||
total = cpu_cost + mem_cost + hdd_cost
|
||||
|
||||
|
||||
|
||||
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))
|
||||
managed_user.credit += total
|
||||
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('')
|
||||
if datetime.utcnow.date() ==
|
||||
db.session.commit()
|
||||
if deploy.
|
||||
db.session.commit()
|
||||
|
||||
class Contract(db.Model):
|
||||
__tablename__ = 'contracts'
|
||||
|
@ -426,13 +417,13 @@ class Contract(db.Model):
|
|||
for contract in result:
|
||||
managed_user = User.query.get(contract.user_id)
|
||||
db.session.add(contract)
|
||||
if datetime.utcnow.date() > (contract.date_expire - timedelta(days=10)):
|
||||
if contract.enabled == True:
|
||||
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))
|
||||
order = Order(user_id=managed_user.id, units=contract.units, unitvalue=(current_service.unitprice * contract.units), description=current_service.name)
|
||||
db.session.add(order)
|
||||
contract.data_expire = datetime.utcnow.date() + timedelta(days=30)
|
||||
#if datetime.utcnow.date() > (contract.date_expire - timedelta(days=10)):
|
||||
if contract.enabled == True:
|
||||
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))
|
||||
transaction = Transaction(user_id=managed_user.id, units=contract.units, unitvalue=(current_service.unitprice * contract.units), description=current_service.name)
|
||||
db.session.add(transaction)
|
||||
contract.data_expire = datetime.utcnow.date() + timedelta(days=30)
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
|
@ -453,11 +444,11 @@ class Domain(db.Model):
|
|||
for domain in result:
|
||||
managed_user = User.query.get(domain.user_id)
|
||||
db.session.add(domain)
|
||||
if datetime.utcnow.date() > (domain.date_expire - timedelta(days=60)):
|
||||
if domain.enabled == True:
|
||||
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)
|
||||
db.session.add(order)
|
||||
#if datetime.utcnow.date() > (domain.date_expire - timedelta(days=60)):
|
||||
if domain.enabled == True:
|
||||
print('{}> Domain {} will expire in 60 days at {}. Creating new order...'.format(managed_user.email, domain.fqdn, domain.date_expire))
|
||||
transaction = Transaction(user_id=managed_user.id, unitvalue=25, description=domain.fqdn)
|
||||
db.session.add(transaction)
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from flask import Blueprint
|
||||
uinvoice = Blueprint('settings', __name__)
|
||||
settings = Blueprint('settings', __name__)
|
||||
from . import routes
|
||||
|
|
|
@ -3,11 +3,12 @@ from flask_login import login_required, login_user, logout_user, current_user
|
|||
from sqlalchemy import desc
|
||||
|
||||
from . import settings
|
||||
from .forms import EditProfileForm, EditProfileAdminForm, ChargeForm, PaymentForm
|
||||
from .forms import EditProfileForm, EditProfileAdminForm
|
||||
|
||||
from ..email import send_email
|
||||
from .. import db
|
||||
from ..models import User, Order
|
||||
from ..models import User
|
||||
import sys
|
||||
|
||||
#PROFILE
|
||||
@settings.route('/profile', methods=['GET', 'POST'])
|
||||
|
@ -19,8 +20,8 @@ def profile():
|
|||
ouruser = User.query.filter_by(email=currentmail).first()
|
||||
db.session.commit()
|
||||
|
||||
#wallet = "%.2f" % round(ouruser.wallet, 3)
|
||||
#print(wallet)
|
||||
wallet = "%.2f" % round(ouruser.wallet, 3)
|
||||
current_app.logger.info('wallet: ' + wallet)
|
||||
|
||||
form = EditProfileForm()
|
||||
if form.validate_on_submit():
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
{% block html_attribs %} lang="en"{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
{{ super() }}
|
||||
<link href="{{ url_for('static', filename='css/navbar.css') }}" rel="stylesheet">
|
||||
|
@ -16,7 +20,6 @@
|
|||
|
||||
{% block scripts %}
|
||||
{{ 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>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -34,7 +37,6 @@
|
|||
{% endfor %}
|
||||
|
||||
{% block page_content %}{% endblock %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<ul class="nav navbar-nav">
|
||||
|
||||
{% 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 %}
|
||||
<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>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block page_content %}
|
||||
<canvas id="canvas"></canvas>
|
||||
|
||||
|
||||
<div id="container">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
{% 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 %}
|
||||
|
||||
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 %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,11 +3,11 @@ from flask_login import login_required, login_user, logout_user, current_user
|
|||
from sqlalchemy import desc
|
||||
|
||||
from . import uinvoice
|
||||
from .forms import EditProfileForm, EditProfileAdminForm, ChargeForm, PaymentForm
|
||||
from .forms import ChargeForm, PaymentForm
|
||||
|
||||
from ..email import send_email
|
||||
from .. import db
|
||||
from ..models import User, Order
|
||||
from ..models import User, Invoice
|
||||
|
||||
#INVOICES
|
||||
#@uinvoice.route('/charge', methods=['GET', 'POST'])
|
||||
|
@ -30,8 +30,8 @@ from ..models import User, Order
|
|||
@uinvoice.route('/documents', methods=['GET'])
|
||||
@login_required
|
||||
def documents():
|
||||
page = { 'title': 'Order documents' }
|
||||
invoices = Order.query.filter_by(user_id=current_user.pid).order_by(desc(Order.date_created)).all()
|
||||
page = { 'title': 'Invoice documents' }
|
||||
invoices = Invoice.query.filter_by(user_id=current_user.pid).order_by(desc(Invoice.date_created)).all()
|
||||
db.session.commit()
|
||||
return render_template('uinvoice/documents.html', page=page, documents=invoices)
|
||||
|
||||
|
@ -40,7 +40,7 @@ def documents():
|
|||
@login_required
|
||||
def order(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()
|
||||
#check if document_id is owned by you.
|
||||
try:
|
||||
|
|
|
@ -123,7 +123,7 @@ def deploy(product_id=None):
|
|||
|
||||
if query is not None:
|
||||
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.commit()
|
||||
|
||||
|
@ -140,7 +140,6 @@ def deploy(product_id=None):
|
|||
@vmanager.route("/dashboard", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def dashboard():
|
||||
#if request.method == 'GET':
|
||||
deployments = current_user.inv_deployments.order_by(Deployment.date_created.desc()).all()
|
||||
|
||||
inv_deployments = []
|
||||
|
|
Loading…
Reference in a new issue