order phase 2

This commit is contained in:
deflax 2018-01-09 13:05:45 +02:00
parent a27ed34ff7
commit ef57acb3cb
9 changed files with 127 additions and 54 deletions

View file

@ -7,7 +7,7 @@ from .forms import ChargeForm, Addr2PoolForm
from .. import db
from ..email import send_email
from ..models import User, Transaction, Deployment, Service, Region, Bridge, Router, Address, Domain, contact_proxmaster
from ..models import User, Transaction, Server, Deployment, Service, Region, Bridge, Router, Address, Domain, contact_proxmaster
from ..decorators import admin_required, permission_required
import base64
@ -65,6 +65,30 @@ def list_recyclebin():
domains = Domain.query.filter_by(deleted=True).all()
return render_template('admin/list_recyclebin.html', deployments=deployments, services=services, domains=domains)
@admin.route("/listusers", methods=['GET'])
@fresh_login_required
@admin_required
def list_users():
allusers = User.query.filter_by(active=True).order_by(User.last_seen.desc()).all()
return render_template('admin/list_users.html', users=allusers)
@admin.route("/charge/<int:user_pid>", methods=['GET', 'POST'])
@fresh_login_required
@admin_required
def charge(user_pid=0):
cuser = User.query.filter_by(pid=user_pid).first()
form = ChargeForm()
if form.validate_on_submit():
transaction = Transaction(user_id=int(cuser.pid), description='Account charged by staff', value=float(form.amount.data))
db.session.add(transaction)
db.session.commit()
cuser.wallet += float(form.amount.data)
db.session.add(cuser)
db.session.commit()
return redirect(url_for('admin.list_users'))
return render_template('admin/charge.html', form=form, usr=cuser)
@admin.route("/listaddresses", methods=['GET'])
@fresh_login_required
@admin_required
@ -94,29 +118,12 @@ def addr2pool():
return redirect(url_for('admin.list_addresses'))
return render_template('admin/addr2pool.html', form=form, alladdresses=alladdrlist)
@admin.route("/listusers", methods=['GET'])
@admin.route("/listservers", methods=['GET'])
@fresh_login_required
@admin_required
def list_users():
allusers = User.query.filter_by(active=True).order_by(User.last_seen.desc()).all()
return render_template('admin/list_users.html', users=allusers)
@admin.route("/charge/<int:user_pid>", methods=['GET', 'POST'])
@fresh_login_required
@admin_required
def charge(user_pid=0):
cuser = User.query.filter_by(pid=user_pid).first()
form = ChargeForm()
if form.validate_on_submit():
transaction = Transaction(user_id=int(cuser.pid), description='Account charged by staff', value=float(form.amount.data))
db.session.add(transaction)
db.session.commit()
cuser.wallet += float(form.amount.data)
db.session.add(cuser)
db.session.commit()
return redirect(url_for('admin.list_users'))
return render_template('admin/charge.html', form=form, usr=cuser)
def list_servers():
allservers = Server.query.all()
return render_template('admin/list_servers.html', servers=allservers)
@admin.route("/listtransactions", methods=['GET'])
@fresh_login_required

View file

@ -5,7 +5,7 @@ from flask_sqlalchemy import get_debug_queries
from . import main
from .. import db
from ..email import send_email
from ..models import User, Permission, Deployment, Service, Region, Address, Bridge, Router, Domain, contact_proxmaster
from ..models import User, Permission, Server, Deployment, Service, Region, Address, Bridge, Router, Domain, contact_proxmaster
import base64
@ -19,7 +19,8 @@ def after_request(response):
#STATIC PAGES
@main.route("/", methods=['GET'])
def index():
return render_template('main/index.html')
allservers = Server.query.all()
return render_template('main/index.html', servers=allservers)
@main.route("/chat", methods=['GET'])
def chat():

View file

@ -87,6 +87,7 @@ class User(db.Model, UserMixin):
wallet = db.Column(db.Float)
currency = db.Column(db.String, default='BGN')
inv_servers = db.relationship('Server', backref='owner', lazy='dynamic')
inv_routers = db.relationship('Router', backref='owner', lazy='dynamic')
inv_addresses = db.relationship('Address', backref='owner', lazy='dynamic')
inv_bridges = db.relationship('Bridge', backref='owner', lazy='dynamic')
@ -95,6 +96,7 @@ class User(db.Model, UserMixin):
inv_services = db.relationship('Service', backref='owner', lazy='dynamic')
inv_domains = db.relationship('Domain', backref='owner', lazy='dynamic')
inv_transactions = db.relationship('Transaction', backref='owner', lazy='dynamic')
def __init__(self, **kwargs):
@ -232,6 +234,7 @@ def contact_proxmaster(data, method):
class Region(db.Model):
__tablename__ = 'regions'
pid = db.Column(db.Integer, primary_key=True)
inv_servers = db.relationship('Server', backref='region', lazy='dynamic')
inv_addresses = db.relationship('Address', backref='region', lazy='dynamic')
inv_bridges = db.relationship('Bridge', backref='region', lazy='dynamic')
@ -240,6 +243,16 @@ class Region(db.Model):
description = db.Column(db.String)
extraprice = db.Column(db.Float)
class Server(db.Model):
__tablename__ = 'servers'
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
name = db.Column(db.String)
description = db.Column(db.String)
address = db.Column(db.String)
class Bridge(db.Model):
__tablename__ = 'bridges'
pid = db.Column(db.Integer, primary_key=True)

View file

@ -8,7 +8,8 @@
<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-usd" aria-hidden="true"></span> Transactions</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>
</div>

View file

@ -0,0 +1,46 @@
{% extends "base.html" %}
{% block page_content %}
<div class="row">
{% include "admin/admin_tasks.html" %}
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Transactions</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Address</th>
<th>Region</th>
<th>Seller</th>
</tr>
</thead>
<tbody>
{% for server in servers %}
<tr class="default">
<td>{{ server.name }}</td>
<td>{{ server.description }}</td>
<td>{{ server.address }}</td>
<td>{{ server.region.name }}</td>
<td><a href="{{ url_for('admin.dashboard', user_pid=server.owner.pid) }}">{{ server.owner.email }}</a></td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -81,6 +81,16 @@
</div>
{% for server in servers %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary panel-transparent">
<div class="panel-body">
</div>
</div>
</div>
</div>
{% endfor %}
<div class="container-fluid-index">
<div class="row">
@ -97,7 +107,7 @@
<div class="panel-body">
<img src="../../static/images/VPS-Support.png" width="128" height="128" />
<h2 class="media-heading">Поддръжка</h2>
<p>Ще Ви помогнем във всички неприятни ситуации, по всяко време. Независимо от нивото на умения Ви. Ние сме винаги насреща за въпроси.</p>
<p>Ще Ви помогнем във всички неприятни ситуации, по всяко време. </p>
<a href="/chat"><button type="button" class="btn btn-success">Support</button></a>
</div>
</div>
@ -124,15 +134,6 @@
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary panel-transparent">
<div class="panel-body">
<!--iframe src="https://datapoint.bg/kiwi/" style="border:0; width:100%; height:480px;"></iframe>-->
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -14,17 +14,17 @@ function getPeriod()
function calculateTotal()
{
var period = getPeriod();
var ppm = {{ ppm }};
var tpm = {{ tpm }};
var discount = {{ discount }};
var ppm = {{ ppm }};
var pricetotal = 0;
pricetotal = period * ppm;
var priceselect = document.getElementById('totalPrice');
priceselect.innerHTML = "Total Price: "+pricetotal+" {{ currency }}";
priceselect.innerHTML = "Total: " + period + " x " + ppm + " = " + pricetotal +" {{ currency }}";
var discounttotal = 0;
discounttotal = period * discount;
var discountselect = document.getElementById('totalDiscount');
discountselect.innerHTML = "Discount <font color=#ff0000>-{{ deploy.discount }}%</font>: "+discounttotal+" {{ currency }}";
@ -54,9 +54,10 @@ Storage: {{ deploy.machine_hdd }} GB<br />
{% endfor %}
---<br />
{% if deploy.discount != 0 %}
<div id="totalDiscount">Discount <font color=#ff0000>-{{ deploy.discount }}%</font>: {{ discount }} {{ currency }}</div>
<div id="totalDiscount">Discount <font color=#ff0000>-{{ deploy.discount }}%</font>: {{ deploy.period * discount }} {{ currency }}</div>
{% endif %}
<div id="totalPrice">{% if deploy.protected == False %}Total:{% else %}Previous Period:{% endif %} {{ total }} {{ currency }}</div>
<div id="totalPrice">Total: {{ deploy.period }} x {{ ppm }} = {{ total }} {{ currency }}</div>
</h3>
<p>

View file

@ -138,9 +138,9 @@ def activate(itemid=0):
cpu_cost = deploy.machine_cpu * current_app.config['CPU_RATIO']
mem_cost = ( deploy.machine_mem / 1024 ) * current_app.config['MEM_RATIO']
hdd_cost = deploy.machine_hdd * current_app.config['HDD_RATIO']
ppm = cpu_cost + mem_cost + hdd_cost
discount = round(( ppm * deploy.discount ) / 100)
ppm = round(ppm - discount)
tpm = cpu_cost + mem_cost + hdd_cost
discount = round(( tpm * deploy.discount ) / 100)
ppm = round(tpm - discount)
#default period = 1 for virgin deployments
if deploy.period is None:
@ -232,7 +232,7 @@ def activate(itemid=0):
return redirect(url_for('admin.list_deployments'))
else:
return redirect(url_for('main.dashboard'))
return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, ppm=ppm, discount=discount, total=total, currency=owner.currency)
return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, tpm=tpm, ppm=ppm, discount=discount, total=total, currency=owner.currency)
@vmanager.route('/vmremove/<int:unit_id>', methods=['GET', 'POST'])
@login_required

View file

@ -68,8 +68,8 @@ def autodisable():
expiry = lastcharge + relativedelta(lastcharge, months=+(deploy.period))
if today >= expiry:
email_content = '[!] Deployment "' + deploy.machine_alias + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')
print(str(email_content))
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content))
print(str(email_content) + " [mail sent]")
#send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content))
#send_email(str(deploy.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
deploy.warning = False
deploy.enabled = False
@ -83,8 +83,8 @@ def autodisable():
expiry = lastcharge + relativedelta(lastcharge, months=+(service.period))
if today >= expiry:
email_content = '[!] Service "' + service.description + '" is past expiration date and will be marked INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')
print(str(email_content))
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=service.owner, content=str(email_content))
print(str(email_content) + " [mail sent]")
#send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=service.owner, content=str(email_content))
#send_email(str(deploy.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
service.warning = False
service.enabled = False
@ -97,8 +97,8 @@ def autodisable():
expiry = domain.date_expire
if today >= expiry:
email_content = '[!] Domain "' + domain.fqdn + '" is past expiration date and will be marked as INACTIVE. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')
print(str(email_content))
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=domain.owner, content=str(email_content))
print(str(email_content) + " [mail sent]")
#send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=domain.owner, content=str(email_content))
#send_email(str(deploy.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
domain.warning = False
domain.enabled = False
@ -122,8 +122,9 @@ def autowarn():
db.session.commit()
warndays = deploy.period * 5
email_content = 'Deployment "' + deploy.machine_alias + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')
if daysleft.days == warndays or (daysleft.days / 2) == warndays:
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content))
if daysleft.days == warndays or round(daysleft.days / 2) == warndays:
print(str(email_content) + " [mail sent]")
#send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=deploy.owner, content=str(email_content))
#send_email(str(deploy.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
deploy.warning = True
if daysleft.days < warndays:
@ -141,7 +142,8 @@ def autowarn():
db.session.commit()
warndays = service.period * 5
email_content = 'Service "' + service.description + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')
if daysleft.days == warndays or (daysleft.days / 2) == warndays:
if daysleft.days == warndays or round(daysleft.days / 2) == warndays:
print(str(email_content) + " [mail sent]")
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=service.owner, content=str(email_content))
send_email(str(service.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
service.warning = True
@ -159,6 +161,7 @@ def autowarn():
warndays = domain.period * 5
email_content = 'Domain "' + domain.fqdn + '" is ' + str(daysleft.days)+ ' days until expiration. Expiry date: ' + expiry.strftime('%c')
if daysleft.days == warndays or (daysleft.days / 2) == warndays:
print(str(email_content) + " [mail sent]")
send_email(app.config['MAIL_USERNAME'], str(email_content), 'email/adm_logger', user=domain.owner, content=str(email_content))
send_email(str(domain.owner.email), str(email_content), 'email/client_logger', content=str(email_content))
domain.warning = True