diff --git a/app/admin/forms.py b/app/admin/forms.py index 9fa39a1..63626d7 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -1,6 +1,8 @@ import string import random -from ..models import User, Role + +from .. import db +from ..models import User, Role, Region from flask_wtf import FlaskForm, RecaptchaField from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField @@ -11,3 +13,14 @@ class ChargeForm(FlaskForm): amount = DecimalField('Стойност:', [validators.DataRequired(), validators.NumberRange(min=1, max=500)]) submit = SubmitField('Зареди') +class Addr2PoolForm(FlaskForm): + #regions = Region.query.all() + #region_choices = [] + #for region in regions: + # region_choices.expand((region.pid, str(region.description))) + region_choices = [(1, 'Plovdiv, Bulgaria')] + ip = StringField('IP Address:', [validators.DataRequired(), validators.Regexp(message='172.16.0.1', regex='^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')]) + region = SelectField('Region', choices=region_choices, coerce=int) + reserved = BooleanField('Reserved:') + submit = SubmitField('Add IP') + diff --git a/app/admin/routes.py b/app/admin/routes.py index 0152a2b..3531ec8 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -3,7 +3,7 @@ from flask_login import login_required, login_user, logout_user from flask_sqlalchemy import get_debug_queries from . import admin -from .forms import ChargeForm +from .forms import ChargeForm, Addr2PoolForm from .. import db from ..email import send_email @@ -68,7 +68,26 @@ def charge(user_pid=0): return redirect(url_for('admin.list_users')) return render_template('admin/charge.html', form=form, usr=cuser) - +@admin.route("/addr2pool", methods=['GET', 'POST']) +@login_required +@admin_required +def addr2pool(): + alladdrlist = [] + alladdr = Address.query.all() + for addr in alladdr: + alladdrlist.append(str(addr.ip)) + current_app.logger.info('Current IP pool: {}'.format(alladdrlist)) + form = Addr2PoolForm() + if form.validate_on_submit(): + if form.ip.data in alladdrlist: + flash('IP address {} is already in the pool!'.format(form.ip.data)) + return redirect(url_for('admin.addr2pool')) + address = Address(ip=form.ip.data, region_id=form.region.data, enabled=True, reserved=form.reserved.data) + db.session.add(address) + db.session.commit() + flash('Address {} added to region {}'.format(form.ip.data, form.region.data)) + return redirect(url_for('admin.list_items')) + return render_template('admin/addr2pool.html', form=form, alladdresses=alladdrlist) @admin.route("/dashboard/", methods=['GET']) @login_required diff --git a/app/models.py b/app/models.py index 28438af..64703a3 100644 --- a/app/models.py +++ b/app/models.py @@ -282,15 +282,16 @@ class Address(db.Model): 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): + def __init__(self, **kwargs): + super(Address, self).__init__(**kwargs) if self.mac is None: self.mac = self.genmac() def genmac(self): - addr = Address.query.all() + alladdr = Address.query.all() allmacs = [] for addr in alladdr: - allmacs.expand(str(addr.mac)) + allmacs.append(str(addr.mac)) while True: mac = [ random.randint(0, 255) for x in range(0, 6) ] mac[0] = (mac[0] & 0xfc) | 0x02 diff --git a/app/smanager/routes.py b/app/smanager/routes.py index 53bc447..3b79b4c 100644 --- a/app/smanager/routes.py +++ b/app/smanager/routes.py @@ -67,5 +67,5 @@ def activate(itemid=0): return redirect(url_for('admin.list_items')) else: return redirect(url_for('main.dashboard')) - return render_template('smanager/activate.html', form=form, service=service, ppm=ppm, total=(ppm * service.period)) + return render_template('smanager/activate.html', form=form, service=service, ppm=ppm, total=(ppm * service.period), currency=owner.currency) diff --git a/app/templates/admin/addr2pool.html b/app/templates/admin/addr2pool.html new file mode 100644 index 0000000..6b5e0b2 --- /dev/null +++ b/app/templates/admin/addr2pool.html @@ -0,0 +1,61 @@ +{% extends "base.html" %} + +{% block title %}Add IP address to ip pool{% endblock %} + +{% block page_content %} +
+
+ {% include "admin/admin_tasks.html" %} +
+
+
Add IP address to the pool
+
+ +
+

+ {{ form.ip.label }} {{ form.ip }}
+ {% for error in form.ip.errors %} + {{ error }}
+ {% endfor %} +

+

+ {{ form.region.label }} {{ form.region }}
+ {% for error in form.region.errors %} + {{ error }}
+ {% endfor %} +

+

+ {{ form.reserved.label }} {{ form.reserved }}
+ {% for error in form.reserved.errors %} + {{ error }}
+ {% endfor %} +

+ +

+ {{ form.csrf_token() }} + {{ form.submit }} +

+ +
+
+
+ +
+
+
Current IP Pool
+
+ {% for addr in alladdresses %} + {{ addr }}
+ {% endfor %} +
+
+
+ + + + +
+
+ +{% endblock %} + diff --git a/app/templates/admin/admin_tasks.html b/app/templates/admin/admin_tasks.html index 7df91ec..cf74d32 100644 --- a/app/templates/admin/admin_tasks.html +++ b/app/templates/admin/admin_tasks.html @@ -6,7 +6,7 @@ - + diff --git a/app/templates/admin/list_items.html b/app/templates/admin/list_items.html index e8d487e..3e8c45b 100644 --- a/app/templates/admin/list_items.html +++ b/app/templates/admin/list_items.html @@ -138,7 +138,6 @@ - @@ -148,7 +147,6 @@ {% for address in addresses %} {% if address.enabled == False %}{% else %}{% endif %} - @@ -156,6 +154,7 @@
Owner IP MAC Addr. Reverse DNS
{{ address.owner.email }} {{ address.ip }} {{ address.mac }} {{ address.rdns }}
+ diff --git a/app/templates/smanager/activate.html b/app/templates/smanager/activate.html index 8c98153..140de35 100644 --- a/app/templates/smanager/activate.html +++ b/app/templates/smanager/activate.html @@ -18,7 +18,7 @@ function calculateTotal() var total = 0; total = period * ppm; var divobj = document.getElementById('totalPrice'); - divobj.innerHTML = "Total Price: "+total; + divobj.innerHTML = "Total Price: "+total+" {{ currency }}"; } {% endblock %} @@ -42,7 +42,7 @@ function calculateTotal() {% endfor %}

---
-
Previous Period: {{ total }}
+
Previous Period: {{ total }} {{ currency }}

{{ form.csrf_token() }} diff --git a/app/templates/vmanager/activate.html b/app/templates/vmanager/activate.html index 7a347de..edcf486 100644 --- a/app/templates/vmanager/activate.html +++ b/app/templates/vmanager/activate.html @@ -18,7 +18,7 @@ function calculateTotal() var total = 0; total = period * ppm; var divobj = document.getElementById('totalPrice'); - divobj.innerHTML = "Total Price: "+total; + divobj.innerHTML = "Total Price: "+total+" {{ currency }}"; } {% endblock %} @@ -44,7 +44,7 @@ Storage: {{ deploy.machine_hdd }} GB
{{ error }}
{% endfor %} ---
-
Previous Period: {{ total }}
+
Previous Period: {{ total }} {{ currency }}

diff --git a/app/vmanager/routes.py b/app/vmanager/routes.py index d4bb571..a93ef8c 100644 --- a/app/vmanager/routes.py +++ b/app/vmanager/routes.py @@ -171,7 +171,7 @@ def activate(itemid=0): return redirect(url_for('admin.list_items')) 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, total=(ppm * deploy.period)) + return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, ppm=ppm, total=(ppm * deploy.period), currency=owner.currency) @vmanager.route('//') @login_required diff --git a/manage.py b/manage.py index 95a1037..6957927 100644 --- a/manage.py +++ b/manage.py @@ -91,7 +91,7 @@ def autowarn(): lastcharge = deploy.date_last_charge expiry = lastcharge + relativedelta(lastcharge, months=+(deploy.period)) daysleft = expiry - today - deploy.daysleft = daysleft.days + deploy.daysleft = daysleft.days + 1 db.session.commit() warndays = deploy.period * 5 if daysleft.days < warndays: @@ -107,7 +107,7 @@ def autowarn(): lastcharge = service.date_last_charge expiry = lastcharge + relativedelta(lastcharge, months=+(service.period)) daysleft = expiry - today - service.daysleft = daysleft.days + service.daysleft = daysleft.days + 1 db.session.commit() warndays = service.period * 5 if daysleft.days < warndays: @@ -122,7 +122,7 @@ def autowarn(): for domain in domains_ena: expiry = domain.date_expire daysleft = expiry - today - domain.daysleft = daysleft.days + domain.daysleft = daysleft.days + 1 db.session.commit() warndays = service.period * 5