diff --git a/app/__init__.py b/app/__init__.py
index d84d953..683ee20 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -12,8 +12,8 @@ from werkzeug.contrib.fixers import ProxyFix
from config import config
app = Flask(__name__)
-app.config.from_object(config['default'])
-config['default'].init_app(app)
+app.config.from_object(config['dev'])
+config['dev'].init_app(app)
app.wsgi_app = ProxyFix(app.wsgi_app)
db = SQLAlchemy(session_options = { "autoflush": False })
@@ -76,8 +76,7 @@ class CustomJSONEncoder(JSONEncoder):
app.json_encoder = CustomJSONEncoder
-#TODO: if app.debug:
-if not app.debug:
+if app.config['DEBUG'] == 1:
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('/home/proxadmin/appserver/proxadmin/log/proxadmin.log', 'a', 1 * 1024 * 1024, 10)
@@ -137,7 +136,7 @@ def get_locale():
# g.request_time = lambda: '%.5fs' % (time.time() - g.request_start_time)
# g.pjax = 'X-PJAX' in request.headers
-if not app.debug and app.config['MAIL_SERVER'] != '':
+if not app.config['DEBUG'] == 1 and app.config['MAIL_SERVER'] != '':
import logging
from logging.handlers import SMTPHandler
credentials = None
diff --git a/app/admin/routes.py b/app/admin/routes.py
index 3d1dc0a..dad6b08 100644
--- a/app/admin/routes.py
+++ b/app/admin/routes.py
@@ -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, Address, Domain, contact_proxmaster
+from ..models import User, Transaction, Deployment, Service, Region, Bridge, Router, Address, Domain, contact_proxmaster
from ..decorators import admin_required, permission_required
import base64
@@ -70,7 +70,8 @@ def list_recyclebin():
@admin_required
def list_addresses():
alladdresses = Address.query.order_by(Address.ip.asc()).all()
- return render_template('admin/list_addresses.html', addresses=alladdresses)
+ allrouters = Router.query.all()
+ return render_template('admin/list_addresses.html', addresses=alladdresses, routers=allrouters)
@admin.route("/addr2pool", methods=['GET', 'POST'])
@fresh_login_required
@@ -156,27 +157,28 @@ def dashboard(user_pid=0):
inv_deploycubeids = []
inv_deployments_list = []
for invcls in inv_deployments:
- if invcls.user_id == cuser.pid:
- inv_deploycubeids.extend([invcls.machine_id])
- inv_deployments_list.extend([invcls.machine_alias])
+ inv_deploycubeids.extend([invcls.machine_id])
+ inv_deployments_list.extend([invcls.machine_alias])
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
inv_services_list = []
for invcls in inv_services:
- if invcls.user_id == cuser.pid:
- inv_services_list.extend([invcls.description])
+ inv_services_list.extend([invcls.description])
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
inv_domains_list = []
for invcls in inv_domains:
- if invcls.user_id == cuser.pid:
- inv_domains_list.extend([invcls.fqdn])
+ inv_domains_list.extend([invcls.fqdn])
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
inv_addresses_list = []
for invcls in inv_addresses:
- if invcls.user_id == cuser.pid:
- inv_addresses_list.extend([invcls.ip])
+ inv_addresses_list.extend([invcls.ip])
+
+ inv_bridges = cuser.inv_bridges.order_by(Bridge.bridge_id.asc()).all()
+ inv_bridges_list = []
+ for invcls in inv_bridges:
+ inv_bridges_list.extend([invcls.bridge_id])
sys_regions = Region.query.all()
regions = {}
@@ -202,6 +204,7 @@ def dashboard(user_pid=0):
rrd[unit_id][graph] = base64.b64encode(raw).decode()
status = { unit_id : query['status'] }
statuses.update(status)
- return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)
+ current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, bridges: {}, addresses: {}'.format(cuser.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_bridges_list, inv_addresses_list))
+ return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_bridges=inv_bridges, inv_addresses=inv_addresses, region=regions)
diff --git a/app/auth/routes.py b/app/auth/routes.py
index 647916b..8f85ca4 100644
--- a/app/auth/routes.py
+++ b/app/auth/routes.py
@@ -69,8 +69,9 @@ def login():
user.last_ip = lastip
db.session.add(user)
db.session.commit()
- #send_email(current_app.config['MAIL_USERNAME'], user.email + ' logged in.', 'auth/email/adm_loginnotify', user=user, ipaddr=lastip )
- flash('Last Login: {} from {}'.format(user.last_seen.strftime("%a %d %B %Y %H:%M"), previp))
+ send_email(current_app.config['MAIL_USERNAME'], user.email + ' logged in.', 'auth/email/adm_loginnotify', user=user, ipaddr=lastip )
+ #flash('Last Login: {} from {}'.format(user.last_seen.strftime("%a %d %B %Y %H:%M"), previp))
+ flash('Last Login: {}'.format(user.last_seen.strftime("%a %d %B %Y %H:%M")))
return redirect(request.args.get('next') or url_for('main.dashboard'))
else:
flash('Invalid username or password.')
diff --git a/app/main/routes.py b/app/main/routes.py
index ade13c8..2770494 100644
--- a/app/main/routes.py
+++ b/app/main/routes.py
@@ -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, Domain, contact_proxmaster
+from ..models import User, Permission, Deployment, Service, Region, Address, Bridge, Router, Domain, contact_proxmaster
import base64
@@ -58,33 +58,15 @@ def market(group_id=0):
@login_required
def dashboard():
cuser = current_user
-
inv_deployments = cuser.inv_deployments.filter_by(deleted=False).order_by(Deployment.date_created.desc()).all()
inv_deploycubeids = []
- inv_deployments_list = []
for invcls in inv_deployments:
if invcls.user_id == cuser.pid:
inv_deploycubeids.extend([invcls.machine_id])
- inv_deployments_list.extend([invcls.machine_alias])
-
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
- inv_services_list = []
- for invcls in inv_services:
- if invcls.user_id == cuser.pid:
- inv_services_list.extend([invcls.description])
-
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
- inv_domains_list = []
- for invcls in inv_domains:
- if invcls.user_id == cuser.pid:
- inv_domains_list.extend([invcls.fqdn])
-
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
- inv_addresses_list = []
- for invcls in inv_addresses:
- if invcls.user_id == cuser.pid:
- inv_addresses_list.extend([invcls.ip])
-
+ inv_bridges = cuser.inv_bridges.order_by(Bridge.bridge_id.asc()).all()
sys_regions = Region.query.all()
regions = {}
for region in sys_regions:
@@ -102,9 +84,9 @@ def dashboard():
query = contact_proxmaster(data, 'vmrrd')
except Exception as e:
current_app.logger.error(e)
- flash('Deploy #{} unreachable. Support is notified'.format(str(unit_id)))
+ flash('Support is notified.'.format(str(unit_id)))
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
- 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id)
+ 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e))
#current_app.logger.info('debug query:')
#current_app.logger.info(query)
@@ -117,10 +99,8 @@ def dashboard():
statuses.update(status)
except Exception as e:
current_app.logger.error(e)
- flash('Deploy #{} unreachable. Support is notified'.format(str(unit_id)))
+ flash('Support is notified.'.format(str(unit_id)))
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
- 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id )
-
- #current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list ))
- return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)
+ 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e))
+ return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_bridges=inv_bridges, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)
diff --git a/app/models.py b/app/models.py
index 014c8d9..73781ae 100644
--- a/app/models.py
+++ b/app/models.py
@@ -220,7 +220,8 @@ def contact_proxmaster(data, method):
try:
db_result = requests.post( url, data=data_json, headers={"content-type": "application/json"}, timeout=30 )
proxjson = db_result.json()
- current_app.logger.info('grid> {}'.format(str(proxjson)))
+ if current_app.config['DEBUG'] == 1:
+ current_app.logger.info('API> {}'.format(str(proxjson)))
return proxjson
except:
return { 'status': 'UNREACHABLE' }
@@ -232,6 +233,8 @@ class Router(db.Model):
date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False)
+ inv_addresses = db.relationship('Address', backref='router', lazy='dynamic')
+
machine_id = db.Column(db.BigInteger) #unit_id
class Bridge(db.Model):
@@ -286,6 +289,8 @@ class Region(db.Model):
pid = db.Column(db.Integer, primary_key=True)
enabled = db.Column(db.Boolean)
+ inv_addresses = db.relationship('Address', backref='region', lazy='dynamic')
+
name = db.Column(db.String)
description = db.Column(db.String)
extraprice = db.Column(db.Float)
@@ -294,11 +299,10 @@ class Address(db.Model):
__tablename__ = 'address'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
- date_assigned = db.Column(db.DateTime, default=datetime.utcnow)
- enabled = db.Column(db.Boolean)
-
region_id = db.Column(db.Integer, db.ForeignKey('regions.pid')) #FK
router_id = db.Column(db.Integer, db.ForeignKey('routers.pid')) #FK
+ date_assigned = db.Column(db.DateTime, default=datetime.utcnow)
+ enabled = db.Column(db.Boolean)
ip = db.Column(db.String)
mac = db.Column(db.String)
diff --git a/app/templates/admin/list_addresses.html b/app/templates/admin/list_addresses.html
index c397fff..860eea4 100644
--- a/app/templates/admin/list_addresses.html
+++ b/app/templates/admin/list_addresses.html
@@ -17,8 +17,10 @@
IP
- MAC Addr.
Reverse DNS
+ Region
+ Router
+ Owner
{{ user.email }}.
+
+{{ content }}
+
Regards, +Proxadmin
diff --git a/app/templates/email/adm_logger.txt b/app/templates/email/adm_logger.txt new file mode 100644 index 0000000..91a289b --- /dev/null +++ b/app/templates/email/adm_logger.txt @@ -0,0 +1,6 @@ +User {{ user.email }} + +{{ content }} + +Regards, +Proxadmin diff --git a/app/templates/main/dashboard.html b/app/templates/main/dashboard.html index 3139043..8a4790a 100644 --- a/app/templates/main/dashboard.html +++ b/app/templates/main/dashboard.html @@ -26,25 +26,25 @@ @media only screen and (max-width: 768px) { /* Force table to not be like tables anymore */ - #no-more-tables table, - #no-more-tables thead, - #no-more-tables tbody, - #no-more-tables th, - #no-more-tables td, - #no-more-tables tr { + .no-more-tables table, + .no-more-tables thead, + .no-more-tables tbody, + .no-more-tables th, + .no-more-tables td, + .no-more-tables tr { display: block; } /* Hide table headers (but not display: none;, for accessibility) */ - #no-more-tables thead tr { + .no-more-tables thead tr { position: absolute; top: -9999px; left: -9999px; } - #no-more-tables tr { border: 1px solid #ccc; } + .no-more-tables tr { border: 1px solid #ccc; } - #no-more-tables td { + .no-more-tables td { /* Behave like a "row" */ border: none; border-bottom: 1px solid #eee; @@ -54,23 +54,23 @@ text-align:left; } - #no-more-tables td:before { + .no-more-tables td:before { /* Now like a table header */ - position: absolute; + /* position: absolute; */ /* Top/left values mimic padding */ top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; - text-align:left; + text-align: left; font-weight: bold; } /* Label the data */ - #no-more-tables td:before { content: attr(data-title); } + .no-more-tables td:before { content: attr(data-title); } } {% endblock %} @@ -233,7 +233,7 @@ addEventListener("DOMContentLoaded", function() {
- ID: {{ deploy.machine_id }}
+ Unit: {{ deploy.machine_id }}
State: {{ status[deploy.machine_id] }}
Protected: {{ deploy.protected }}
Unit | +Network | +
---|---|
{{ bridge.bridge_id }} | +192.168.9.0 | +
IP | Region | -MAC Addr. | Reverse DNS |
---|---|---|---|
{{ address.ip }} | {{ region[address.region_id] }} | -{{ address.mac }} | {{ address.rdns }} | - {% endfor %}
{{ user.email }} encountered an error working with id: {{ unit_id }}
+debug:
+{{ error }}
Regards, +
Regards,
Proxadmin