clean up documentation

This commit is contained in:
deflax 2017-09-28 14:10:19 +03:00
parent ddd07804ee
commit 96e62c8c4f
9 changed files with 53 additions and 3 deletions

View file

@ -8,6 +8,7 @@ from . import db, lm
import os import os
import random import random
import uuid
import base64 import base64
import hashlib import hashlib
import json import json
@ -65,6 +66,7 @@ class User(db.Model, UserMixin):
twofactor = db.Column(db.Boolean, default=False) #optional 2factor auth twofactor = db.Column(db.Boolean, default=False) #optional 2factor auth
otp_secret = db.Column(db.String) otp_secret = db.Column(db.String)
avatar_hash = db.Column(db.String) avatar_hash = db.Column(db.String)
uuid = db.Column(db.String)
name = db.Column(db.Unicode) name = db.Column(db.Unicode)
address = db.Column(db.Unicode) address = db.Column(db.Unicode)
@ -83,6 +85,7 @@ class User(db.Model, UserMixin):
wallet = db.Column(db.Float) wallet = db.Column(db.Float)
currency = db.Column(db.String, default='BGN') currency = db.Column(db.String, default='BGN')
inv_routers = db.relationship('Router', backref='owner', lazy='dynamic')
inv_deployments = db.relationship('Deployment', backref='owner', lazy='dynamic') inv_deployments = db.relationship('Deployment', backref='owner', lazy='dynamic')
inv_services = db.relationship('Service', backref='owner', lazy='dynamic') inv_services = db.relationship('Service', backref='owner', lazy='dynamic')
inv_domains = db.relationship('Domain', backref='owner', lazy='dynamic') inv_domains = db.relationship('Domain', backref='owner', lazy='dynamic')
@ -100,13 +103,17 @@ class User(db.Model, UserMixin):
#if role is stil not set, create default user role #if role is stil not set, create default user role
self.role = Role.query.filter_by(default=True).first() self.role = Role.query.filter_by(default=True).first()
if self.email is not None and self.avatar_hash is None: if self.avatar_hash is None and self.email is not None:
self.avatar_hash = hashlib.md5(self.email.encode('utf-8')).hexdigest() self.avatar_hash = hashlib.md5(self.email.encode('utf-8')).hexdigest()
if self.otp_secret is None: if self.otp_secret is None:
# generate a random secret # generate a random secret
self.otp_secret = base64.b32encode(os.urandom(10)).decode('utf-8') self.otp_secret = base64.b32encode(os.urandom(10)).decode('utf-8')
if self.uuid is None:
# generate uuid
self.uuid = uuid.uuid4()
@property @property
def password(self): def password(self):
raise AttributeError('password is not a readable attribute') raise AttributeError('password is not a readable attribute')
@ -222,6 +229,14 @@ def contact_proxmaster(data, method, cubeid=0):
except: except:
return None return None
class Router(db.Model):
__tablename__ = 'routers'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)
cancelled = db.Column(db.Boolean, default=False)
class Deployment(db.Model): class Deployment(db.Model):
__tablename__ = 'deployments' __tablename__ = 'deployments'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)

View file

@ -46,9 +46,29 @@ def createvm():
#flash('Region: {}'.format(str(selected_region.description))) #flash('Region: {}'.format(str(selected_region.description)))
#return redirect(url_for('main.dashboard')) #return redirect(url_for('main.dashboard'))
router = current_user.inv_routers.filter_by(cancelled=False).all()
if router == []:
#no router. creating...
data = { 'clientid': str(current_user.pid), data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email), 'clientemail': str(current_user.email),
'hostname': str(form.servername.data), 'hostname': 'c' + str(current_user.pid) + 'router',
'region': str(selected_region.name),
'type': 'kvm',
'cpu': '1',
'mem': '128',
'hdd': '1'
}
try:
query = contact_procmaster(data, 'vmcreate')
except:
flash('Region unreachable! Cannot create router. Please try again later...')
return redirect(url_for('main.dashboard'))
#exit 0
return redirect(url_for('main.dashboard'))
data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email),
'hostname': 'c' + str(current_user.pid) + str(form.servername.data),
'region': str(selected_region.name), 'region': str(selected_region.name),
'type': 'kvm', 'type': 'kvm',
'cpu': '1', 'cpu': '1',
@ -58,7 +78,7 @@ def createvm():
try: try:
query = contact_proxmaster(data, 'vmcreate') query = contact_proxmaster(data, 'vmcreate')
except: except:
flash('Region unreachable! Please try again later...') flash('Region unreachable! Cannot create deployment. Please try again later...')
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
if query is not None: if query is not None:
@ -82,6 +102,8 @@ def remove(itemid=0):
query = contact_proxmaster(data, 'vmremove', int(itemid)) query = contact_proxmaster(data, 'vmremove', int(itemid))
flash('Machine {} terminated'.format(itemid)) flash('Machine {} terminated'.format(itemid))
deploy.cancelled = True deploy.cancelled = True
deploy.enabled = False
deploy.warning = False
db.session.commit() db.session.commit()
except: except:
flash('Cannot delete machine {}'.format(itemid)) flash('Cannot delete machine {}'.format(itemid))

3
docs/TODO Normal file
View file

@ -0,0 +1,3 @@
1. remote router app pyqt/kivi
2. open ssh keyfile with decrypt dialog
3. open remote console button, make backup button (with possible schedule timer with checkbox?), route trafic through client machine button on/off

9
docs/posts.txt Normal file
View file

@ -0,0 +1,9 @@
templates/settings/profile.html:<form method="POST" action="{{ url_for('settings.profile') }}">
templates/dmanager/activate.html:<form method="POST" action"{{ url_for('dmanager.activate', itemid=itemid) }}">
templates/vmanager/create.html: <form method="POST" action="{{ url_for('vmanager.createvm') }}">
templates/vmanager/activate.html:<form method="POST" action="{{ url_for('vmanager.activate', itemid=deploy.machine_id) }}">
templates/vmanager/recipe.html:<form method="POST" action"{{ url_for('vmanager.recipe', itemid=deploy.machine_id) }}">
templates/admin/addr2pool.html: <form method="POST" action="{{ url_for('admin.addr2pool') }}">
templates/admin/charge.html: <form method="POST" action="{{ url_for('admin.charge', user_pid=usr.pid) }}">
templates/uinvoice/invoice.html: <form method="POST" action="{{ url_for('uinvoice.invoice', document_id=document.pid) }}">
templates/smanager/activate.html:<form method="POST" action"{{ url_for('smanager.activate', itemid=service.pid) }}">

View file

@ -1,3 +1,4 @@
uuid
alembic==0.9.2 alembic==0.9.2
appdirs==1.4.3 appdirs==1.4.3
Babel==2.4.0 Babel==2.4.0