2017-09-19 07:36:39 +00:00
|
|
|
import datetime
|
2017-09-12 07:39:18 +00:00
|
|
|
import os
|
2017-09-20 10:13:14 +00:00
|
|
|
from flask import Flask, session, url_for, redirect, request, render_template, abort
|
2017-02-01 07:21:18 +00:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2017-09-12 09:41:13 +00:00
|
|
|
from sqlalchemy.exc import IntegrityError
|
2017-09-11 10:57:41 +00:00
|
|
|
import bcrypt
|
2017-09-13 10:48:41 +00:00
|
|
|
import random
|
2017-09-20 09:36:39 +00:00
|
|
|
import subprocess
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2017-09-15 06:31:45 +00:00
|
|
|
app.secret_key = os.environ["flask_secret_key"]
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
# SQL
|
2017-09-15 06:31:45 +00:00
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
|
2017-09-12 07:39:18 +00:00
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
2017-02-01 07:21:18 +00:00
|
|
|
db = SQLAlchemy(app)
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-09-20 09:36:39 +00:00
|
|
|
old_wd = os.getcwd()
|
|
|
|
try:
|
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
estus_version = str(subprocess.check_output(["git", "describe", "--tags"]), encoding="utf8").strip()
|
|
|
|
except Exception:
|
|
|
|
estus_version = "Unknown"
|
|
|
|
finally:
|
|
|
|
os.chdir(old_wd)
|
|
|
|
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
class User(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Utente per il login sul sito dell'inventario."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "website_users"
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
uid = db.Column(db.Integer, primary_key=True)
|
2017-09-14 12:55:39 +00:00
|
|
|
username = db.Column(db.String, unique=True, nullable=False)
|
|
|
|
passwd = db.Column(db.LargeBinary, nullable=False)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
def __init__(self, username, passwd):
|
|
|
|
self.username = username
|
|
|
|
self.passwd = passwd
|
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.username
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<User {}>".format(self.username, self.passwd)
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
class Ente(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Ente (Unione Terre di Castelli, Comune di Vignola...)."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "enti"
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
eid = db.Column(db.Integer, primary_key=True)
|
2017-09-12 07:40:47 +00:00
|
|
|
nomeente = db.Column(db.String)
|
|
|
|
nomebreveente = db.Column(db.String)
|
2017-09-14 09:20:12 +00:00
|
|
|
servizi = db.relationship("Servizio", backref='ente', lazy='dynamic', cascade="delete")
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
def __init__(self, nomeente, nomebreveente):
|
|
|
|
self.nomeente = nomeente
|
|
|
|
self.nomebreveente = nomebreveente
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.nomeente
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
def __repr__(self):
|
2017-02-01 09:37:53 +00:00
|
|
|
return "<Ente {}>".format(self.nomebreveente)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Servizio(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Servizio di un ente (Anagrafe, Ufficio Scuola, Sindaco)."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "servizi"
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
sid = db.Column(db.Integer, primary_key=True)
|
2017-09-12 07:39:18 +00:00
|
|
|
eid = db.Column(db.Integer, db.ForeignKey('enti.eid'))
|
2017-09-12 07:40:47 +00:00
|
|
|
nomeservizio = db.Column(db.String)
|
|
|
|
locazione = db.Column(db.String)
|
2017-09-14 09:20:12 +00:00
|
|
|
impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic', cascade="delete")
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-11 13:56:42 +00:00
|
|
|
def __init__(self, eid, nomeservizio, locazione):
|
2017-02-01 07:21:18 +00:00
|
|
|
self.eid = eid
|
2017-02-01 09:37:53 +00:00
|
|
|
self.nomeservizio = nomeservizio
|
2017-09-11 13:56:42 +00:00
|
|
|
self.locazione = locazione
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.nomeservizio
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
def __repr__(self):
|
2017-02-01 09:37:53 +00:00
|
|
|
return "<Servizio {}>".format(self.nomeservizio)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Impiegato(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Impiegato in uno dei servizi."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "impiegati"
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
iid = db.Column(db.Integer, primary_key=True)
|
2017-09-12 07:39:18 +00:00
|
|
|
sid = db.Column(db.Integer, db.ForeignKey('servizi.sid'))
|
2017-09-12 07:40:47 +00:00
|
|
|
nomeimpiegato = db.Column(db.String)
|
2017-09-14 12:55:39 +00:00
|
|
|
username = db.Column(db.String)
|
2017-09-12 07:40:47 +00:00
|
|
|
passwd = db.Column(db.String)
|
2017-09-14 09:20:12 +00:00
|
|
|
dispositivi = db.relationship("Accesso", backref='impiegato', lazy='dynamic', cascade="delete")
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
def __init__(self, sid, nomeimpiegato, username, passwd):
|
2017-02-01 07:21:18 +00:00
|
|
|
self.sid = sid
|
2017-02-01 09:37:53 +00:00
|
|
|
self.nomeimpiegato = nomeimpiegato
|
2017-02-01 07:21:18 +00:00
|
|
|
self.username = username
|
|
|
|
self.passwd = passwd
|
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.nomeimpiegato
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
def __repr__(self):
|
2017-09-18 15:27:19 +00:00
|
|
|
return "<Impiegato {}>".format(self.nomeimpiegato)
|
2017-02-02 08:33:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Dispositivo(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Dispositivo gestito dal CED registrato nell'inventario."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "dispositivi"
|
|
|
|
|
2017-02-02 08:33:54 +00:00
|
|
|
did = db.Column(db.Integer, primary_key=True)
|
2017-09-14 09:20:12 +00:00
|
|
|
accessi = db.relationship("Accesso", backref='dispositivo', lazy='dynamic', cascade="delete")
|
2017-09-12 07:40:47 +00:00
|
|
|
tipo = db.Column(db.String)
|
|
|
|
marca = db.Column(db.String)
|
|
|
|
modello = db.Column(db.String)
|
2017-09-18 12:54:52 +00:00
|
|
|
inv_ced = db.Column(db.Integer, unique=True)
|
|
|
|
inv_ente = db.Column(db.Integer, unique=True)
|
2017-09-12 07:40:47 +00:00
|
|
|
seriale = db.Column(db.String)
|
2017-09-13 06:19:08 +00:00
|
|
|
ip = db.Column(db.String)
|
2017-09-12 07:39:18 +00:00
|
|
|
nid = db.Column(db.Integer, db.ForeignKey('reti.nid'))
|
|
|
|
rete = db.relationship("Rete", backref='dispositivi')
|
2017-09-18 13:38:49 +00:00
|
|
|
hostname = db.Column(db.String, unique=True)
|
2017-09-18 14:07:04 +00:00
|
|
|
so = db.Column(db.String)
|
2017-09-19 08:29:57 +00:00
|
|
|
oid = db.Column(db.Integer, db.ForeignKey('ordini.oid'))
|
2017-02-02 08:33:54 +00:00
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
if self.marca != "" and self.modello != "":
|
|
|
|
return f"{self.marca} {self.modello}"
|
|
|
|
elif self.hostname != "":
|
|
|
|
return f"Dispositivo {self.hostname}"
|
|
|
|
elif self.seriale != "":
|
|
|
|
return f"Dispositivo {self.seriale}"
|
|
|
|
else:
|
|
|
|
return f"Dispositivo {self.did}"
|
|
|
|
|
2017-02-02 08:33:54 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<Dispositivo {}>".format(self.inv_ced)
|
|
|
|
|
|
|
|
|
|
|
|
class Accesso(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Tabella di associazione tra dispositivi e impiegati."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "assoc_accessi"
|
|
|
|
|
|
|
|
iid = db.Column(db.Integer, db.ForeignKey('impiegati.iid'), primary_key=True)
|
|
|
|
did = db.Column(db.Integer, db.ForeignKey('dispositivi.did'), primary_key=True)
|
2017-02-02 08:33:54 +00:00
|
|
|
|
|
|
|
def __init__(self, iid, did):
|
|
|
|
self.iid = iid
|
|
|
|
self.did = did
|
|
|
|
|
|
|
|
def __repr__(self):
|
2017-02-03 12:04:11 +00:00
|
|
|
return "<Accesso {} su {}>".format(self.iid, self.did)
|
2017-02-02 08:33:54 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-12 07:39:18 +00:00
|
|
|
class Rete(db.Model):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Configurazione di rete di uno o più computer."""
|
2017-09-12 07:39:18 +00:00
|
|
|
__tablename__ = "reti"
|
|
|
|
|
2017-09-11 14:55:23 +00:00
|
|
|
nid = db.Column(db.Integer, primary_key=True)
|
2017-09-12 07:40:47 +00:00
|
|
|
nome = db.Column(db.String)
|
|
|
|
network_ip = db.Column(db.String, unique=True, nullable=False)
|
2017-09-12 07:39:18 +00:00
|
|
|
subnet = db.Column(db.Integer, nullable=False)
|
2017-09-12 07:40:47 +00:00
|
|
|
primary_dns = db.Column(db.String)
|
|
|
|
secondary_dns = db.Column(db.String)
|
2017-09-11 14:55:23 +00:00
|
|
|
|
2017-09-12 07:39:18 +00:00
|
|
|
def __init__(self, nome, network_ip, subnet, primary_dns, secondary_dns):
|
2017-09-12 06:26:58 +00:00
|
|
|
self.nome = nome
|
2017-09-12 07:39:18 +00:00
|
|
|
self.network_ip = network_ip
|
|
|
|
self.subnet = subnet
|
|
|
|
self.primary_dns = primary_dns
|
|
|
|
self.secondary_dns = secondary_dns
|
2017-09-11 14:55:23 +00:00
|
|
|
|
2017-09-18 15:57:40 +00:00
|
|
|
def __str__(self):
|
|
|
|
return f"Rete {self.nome}"
|
|
|
|
|
2017-09-11 14:55:23 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<Rete {},{}>".format(self.nid, self.nome)
|
|
|
|
|
|
|
|
|
2017-09-19 07:36:39 +00:00
|
|
|
class Ordine(db.Model):
|
|
|
|
"""Ordine di uno o più dispositivi"""
|
|
|
|
__tablename__ = "ordini"
|
|
|
|
|
|
|
|
oid = db.Column(db.Integer, primary_key=True)
|
|
|
|
data = db.Column(db.Date)
|
|
|
|
numero_ordine = db.Column(db.String)
|
2017-09-19 08:29:57 +00:00
|
|
|
garanzia = db.Column(db.Date)
|
|
|
|
dispositivo = db.relationship("Dispositivo", backref='ordine', lazy='dynamic', cascade="delete")
|
2017-09-19 13:49:01 +00:00
|
|
|
fornitore = db.Column(db.String)
|
2017-09-19 07:36:39 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.numero_ordine is not None:
|
|
|
|
return f"Ordine {self.numero_ordine}"
|
|
|
|
return f"Ordine #{self.oid}"
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"<Ordine {self.oid}>"
|
|
|
|
|
|
|
|
|
2017-09-11 13:00:04 +00:00
|
|
|
class FakeAccesso:
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Hackerino usato nel caso in cui non ci sia nessun impiegato assegnato a un dispositivo.
|
|
|
|
Viva il duck typing!"""
|
2017-09-11 13:00:04 +00:00
|
|
|
def __init__(self, dispositivo):
|
|
|
|
self.did = dispositivo.did
|
|
|
|
self.iid = None
|
|
|
|
self.dispositivo = dispositivo
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if key == 0:
|
|
|
|
return self.dispositivo
|
|
|
|
|
2017-09-12 06:26:58 +00:00
|
|
|
|
2017-09-13 10:48:41 +00:00
|
|
|
class Pesce:
|
2017-09-14 07:44:04 +00:00
|
|
|
"""Un pesce? In un inventario!?"""
|
2017-09-18 15:57:40 +00:00
|
|
|
def __init__(self, origin_obj, avgsize=1.0, variation=0.1, link="#"):
|
|
|
|
self.name = str(origin_obj)
|
2017-09-14 07:44:04 +00:00
|
|
|
self.size = random.gauss(avgsize, variation)
|
|
|
|
self.color = "{:02x}".format(random.randrange(0, 16777216))
|
|
|
|
self.position = (random.randrange(0, 1423), random.randrange(52, 600))
|
|
|
|
self.link = link
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"<Pesce {self.name}, dimensioni {self.size}, colore #{self.color.hex()}>"
|
2017-09-13 10:48:41 +00:00
|
|
|
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
# Funzioni del sito
|
|
|
|
def login(username, password):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Controlla se l'username e la password di un utente del sito sono corrette."""
|
2017-02-01 07:21:18 +00:00
|
|
|
user = User.query.filter_by(username=username).first()
|
2017-09-12 09:39:21 +00:00
|
|
|
return user is not None and bcrypt.checkpw(bytes(password, encoding="utf-8"), user.passwd)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-09-12 07:39:18 +00:00
|
|
|
def subnet_to_string(integer):
|
|
|
|
"""Converte una subnet mask in numero in una stringa"""
|
|
|
|
still_int = (0xFFFFFFFF << (32 - integer)) & 0xFFFFFFFF
|
2017-09-18 14:43:30 +00:00
|
|
|
return f"{still_int >> 24}.{(still_int >> 16) & 0xFF}.{(still_int >> 8 & 0xFF)}.{still_int & 0xFF}"
|
2017-09-12 07:39:18 +00:00
|
|
|
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
# Sito
|
|
|
|
@app.route('/')
|
|
|
|
def page_home():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina principale del sito:
|
|
|
|
se non sei loggato reindirizza alla pagina del login,
|
|
|
|
se sei loggato effettua il logout e dopo reindirizza al login"""
|
2017-02-01 07:21:18 +00:00
|
|
|
if 'username' not in session:
|
2017-09-14 08:32:27 +00:00
|
|
|
return redirect(url_for('page_login'))
|
2017-02-01 07:21:18 +00:00
|
|
|
else:
|
2017-09-13 07:17:23 +00:00
|
|
|
return redirect(url_for('page_dashboard'))
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
@app.route('/login', methods=['GET', 'POST'])
|
|
|
|
def page_login():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di login:
|
|
|
|
accetta richieste GET per la visualizzazione della pagina
|
|
|
|
e richieste POST con form data per il login"""
|
2017-02-01 07:21:18 +00:00
|
|
|
if request.method == 'GET':
|
|
|
|
goldfish = url_for("static", filename="goldfish.png")
|
2017-09-12 09:11:19 +00:00
|
|
|
return render_template("login.htm", goldfish=goldfish)
|
2017-02-01 07:21:18 +00:00
|
|
|
else:
|
|
|
|
if login(request.form['username'], request.form['password']):
|
|
|
|
session['username'] = request.form['username']
|
2017-09-14 13:06:47 +00:00
|
|
|
session.permanent = request.form.get('remember')
|
2017-02-01 07:21:18 +00:00
|
|
|
return redirect(url_for('page_dashboard'))
|
|
|
|
else:
|
2017-09-13 07:14:56 +00:00
|
|
|
return render_template('error.htm', error="Username o password non validi.")
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-09-13 07:17:23 +00:00
|
|
|
@app.route('/logout')
|
|
|
|
def page_logout():
|
|
|
|
"""Pagina di logout:
|
|
|
|
slogga l'utente se visitata"""
|
|
|
|
if 'username' in session:
|
|
|
|
session.pop('username')
|
|
|
|
return redirect(url_for('page_login'))
|
|
|
|
|
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
@app.route('/dashboard')
|
|
|
|
def page_dashboard():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Dashboard del sito:
|
|
|
|
Conteggia i servizi e visualizza la navbar
|
|
|
|
Sì, è un po' inutile."""
|
2017-02-02 07:46:15 +00:00
|
|
|
enti = Ente.query.all()
|
|
|
|
conteggioservizi = dict()
|
2017-09-12 06:26:58 +00:00
|
|
|
goldfish = url_for("static", filename="goldfish.png")
|
2017-02-02 07:46:15 +00:00
|
|
|
for ente in enti:
|
|
|
|
conteggioservizi[ente.nomeente] = Servizio.query.join(Ente).filter_by(eid=ente.eid).count()
|
|
|
|
conteggioutenti = dict()
|
|
|
|
for ente in enti:
|
|
|
|
conteggioutenti[ente.nomeente] = Impiegato.query.join(Servizio).join(Ente).filter_by(eid=ente.eid).count()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("dashboard.htm", pagetype="main",
|
2017-09-12 09:15:36 +00:00
|
|
|
conteggioutenti=conteggioutenti, conteggioservizi=conteggioservizi, goldfish=goldfish)
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
@app.route('/ente_add', methods=['GET', 'POST'])
|
|
|
|
def page_ente_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuovo ente:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva."""
|
2017-02-01 07:21:18 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 07:21:18 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ente/show.htm", action="add", pagetype="ente")
|
2017-02-01 07:21:18 +00:00
|
|
|
else:
|
2017-02-01 09:37:53 +00:00
|
|
|
nuovoent = Ente(request.form['nomeente'], request.form['nomebreveente'])
|
2017-02-01 07:21:18 +00:00
|
|
|
db.session.add(nuovoent)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_ente_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
@app.route('/ente_del/<int:eid>')
|
|
|
|
def page_ente_del(eid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di cancellazione ente:
|
|
|
|
accetta richieste GET per cancellare l'ente specificato."""
|
2017-02-01 07:21:18 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-12 09:46:30 +00:00
|
|
|
ente = Ente.query.get_or_404(eid)
|
2017-02-01 09:37:53 +00:00
|
|
|
servizi = Servizio.query.filter_by(eid=ente.eid).all()
|
|
|
|
for serv in servizi:
|
|
|
|
impiegati = Impiegato.query.filter_by(sid=serv.sid).all()
|
|
|
|
for imp in impiegati:
|
|
|
|
db.session.delete(imp)
|
|
|
|
db.session.delete(serv)
|
2017-02-01 07:21:18 +00:00
|
|
|
db.session.delete(ente)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_ente_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
@app.route('/ente_list')
|
|
|
|
def page_ente_list():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco degli enti disponibili sul sito."""
|
2017-02-01 07:21:18 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
enti = Ente.query.order_by(Ente.nomeente).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ente/list.htm", enti=enti, pagetype="ente")
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
@app.route('/ente_show/<int:eid>', methods=['GET', 'POST'])
|
|
|
|
def page_ente_show(eid):
|
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 07:21:18 +00:00
|
|
|
if request.method == "GET":
|
2017-09-12 09:46:30 +00:00
|
|
|
ente = Ente.query.get_or_404(eid)
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ente/show.htm", action="show", ente=ente)
|
2017-02-01 07:21:18 +00:00
|
|
|
else:
|
2017-09-12 09:46:30 +00:00
|
|
|
ente = Ente.query.get_or_404(eid)
|
2017-02-01 09:37:53 +00:00
|
|
|
ente.nomeente = request.form["nomeente"]
|
|
|
|
ente.nomebreveente = request.form["nomebreveente"]
|
2017-02-01 07:21:18 +00:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_ente_list'))
|
2017-02-01 09:37:53 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/serv_add', methods=['GET', 'POST'])
|
|
|
|
def page_serv_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuovo servizio:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 09:37:53 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-18 07:06:44 +00:00
|
|
|
enti = Ente.query.order_by(Ente.nomeente).all()
|
2017-09-21 06:25:35 +00:00
|
|
|
servizi = db.engine.execute("SELECT locazione FROM servizi GROUP BY locazione;")
|
2017-09-20 10:31:54 +00:00
|
|
|
return render_template("servizio/show.htm", action="add", enti=enti, servizi=servizi, pagetype="serv")
|
2017-02-01 09:37:53 +00:00
|
|
|
else:
|
2017-09-11 13:56:42 +00:00
|
|
|
nuovoserv = Servizio(request.form['eid'], request.form['nomeservizio'], request.form['locazione'])
|
2017-02-01 09:37:53 +00:00
|
|
|
db.session.add(nuovoserv)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_serv_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/serv_del/<int:sid>')
|
|
|
|
def page_serv_del(sid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di cancellazione servizio:
|
|
|
|
accetta richieste GET per cancellare il servizio specificato."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-12 09:46:30 +00:00
|
|
|
serv = Servizio.query.get_or_404(sid)
|
2017-02-01 09:37:53 +00:00
|
|
|
impiegati = Impiegato.query.filter_by(sid=serv.sid).all()
|
|
|
|
for imp in impiegati:
|
|
|
|
db.session.delete(imp)
|
|
|
|
db.session.delete(serv)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_serv_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/serv_list')
|
|
|
|
def page_serv_list():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco dei servizi registrati sul sito."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
serv = Servizio.query.join(Ente).order_by(Ente.nomeente, Servizio.nomeservizio).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("servizio/list.htm", serv=serv, pagetype="serv")
|
2017-02-01 09:37:53 +00:00
|
|
|
|
|
|
|
|
2017-09-11 13:00:04 +00:00
|
|
|
@app.route('/serv_list/<int:eid>')
|
|
|
|
def page_serv_list_plus(eid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco dei servizi registrati sul sito, filtrati per ente."""
|
2017-09-11 13:00:04 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
serv = Servizio.query.join(Ente).filter_by(eid=eid).order_by(Servizio.nomeservizio).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("servizio/list.htm", serv=serv, pagetype="serv")
|
2017-09-11 13:00:04 +00:00
|
|
|
|
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/serv_show/<int:sid>', methods=['GET', 'POST'])
|
|
|
|
def page_serv_show(sid):
|
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 09:37:53 +00:00
|
|
|
if request.method == "GET":
|
2017-09-12 09:46:30 +00:00
|
|
|
serv = Servizio.query.get_or_404(sid)
|
2017-02-01 09:37:53 +00:00
|
|
|
enti = Ente.query.all()
|
2017-09-21 06:34:23 +00:00
|
|
|
servizi = db.engine.execute("SELECT locazione FROM servizi GROUP BY locazione;")
|
2017-09-20 10:36:38 +00:00
|
|
|
return render_template("servizio/show.htm", action="show", serv=serv, servizi=servizi, enti=enti)
|
2017-02-01 09:37:53 +00:00
|
|
|
else:
|
2017-09-12 09:46:30 +00:00
|
|
|
serv = Servizio.query.get_or_404(sid)
|
2017-02-01 09:37:53 +00:00
|
|
|
serv.eid = request.form["eid"]
|
|
|
|
serv.nomeservizio = request.form["nomeservizio"]
|
2017-09-11 13:56:42 +00:00
|
|
|
serv.locazione = request.form["locazione"]
|
2017-02-01 09:37:53 +00:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_serv_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/imp_add', methods=['GET', 'POST'])
|
|
|
|
def page_imp_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuovo impiegato:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 09:37:53 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-18 07:06:44 +00:00
|
|
|
servizi = Servizio.query.join(Ente).order_by(Ente.nomeente, Servizio.nomeservizio).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("impiegato/show.htm", action="add", servizi=servizi, pagetype="imp")
|
2017-02-01 09:37:53 +00:00
|
|
|
else:
|
2017-09-11 09:43:50 +00:00
|
|
|
nuovoimp = Impiegato(request.form['sid'], request.form['nomeimpiegato'], request.form['username'],
|
|
|
|
request.form['passwd'],)
|
2017-02-01 09:37:53 +00:00
|
|
|
db.session.add(nuovoimp)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_imp_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/imp_del/<int:iid>')
|
|
|
|
def page_imp_del(iid):
|
2017-09-18 07:06:44 +00:00
|
|
|
"""Pagina di cancellazione impiegato:
|
|
|
|
accetta richieste GET per cancellare l'impiegato specificato."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-12 09:46:30 +00:00
|
|
|
imp = Impiegato.query.get_or_404(iid)
|
2017-02-01 09:37:53 +00:00
|
|
|
db.session.delete(imp)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_imp_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/imp_list')
|
|
|
|
def page_imp_list():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco degli impiegati registrati nell'inventario."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-19 06:11:52 +00:00
|
|
|
impiegati = Impiegato.query.join(Servizio).join(Ente)\
|
|
|
|
.order_by(Ente.nomeente, Servizio.nomeservizio, Impiegato.nomeimpiegato).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("impiegato/list.htm", impiegati=impiegati, pagetype="imp")
|
2017-02-01 09:37:53 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/imp_list/<int:sid>')
|
|
|
|
def page_imp_list_plus(sid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco degli impiegati registrati nell'inventario, filtrati per servizio."""
|
2017-02-01 09:37:53 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
impiegati = Impiegato.query.join(Servizio).filter_by(sid=sid).join(Ente).order_by(Impiegato.nomeimpiegato).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("impiegato/list.htm", impiegati=impiegati)
|
2017-02-01 09:37:53 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-01 09:37:53 +00:00
|
|
|
@app.route('/imp_show/<int:iid>', methods=['GET', 'POST'])
|
|
|
|
def page_imp_show(iid):
|
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-01 09:37:53 +00:00
|
|
|
if request.method == "GET":
|
2017-09-12 09:46:30 +00:00
|
|
|
imp = Impiegato.query.get_or_404(iid)
|
2017-02-01 09:37:53 +00:00
|
|
|
servizi = Servizio.query.all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("impiegato/show.htm", action="show", imp=imp, servizi=servizi)
|
2017-02-01 09:37:53 +00:00
|
|
|
else:
|
2017-09-12 09:46:30 +00:00
|
|
|
imp = Impiegato.query.get_or_404(iid)
|
2017-02-01 09:37:53 +00:00
|
|
|
imp.sid = request.form["sid"]
|
|
|
|
imp.nomeimpiegato = request.form["nomeimpiegato"]
|
|
|
|
imp.username = request.form["username"]
|
|
|
|
imp.passwd = request.form["passwd"]
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_imp_list'))
|
2017-02-02 14:44:26 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-09-18 15:27:19 +00:00
|
|
|
@app.route('/imp_details/<int:iid>')
|
|
|
|
def page_imp_details(iid):
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
imp = Impiegato.query.filter_by(iid=iid).join(Servizio).join(Ente).first_or_404()
|
|
|
|
accessi = Accesso.query.filter_by(iid=imp.iid).join(Dispositivo).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("impiegato/details.htm", accessi=accessi, impiegato=imp)
|
2017-09-18 15:27:19 +00:00
|
|
|
|
|
|
|
|
2017-02-02 14:44:26 +00:00
|
|
|
@app.route('/disp_add', methods=['GET', 'POST'])
|
|
|
|
def page_disp_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuovo dispositivo:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva."""
|
2017-02-02 14:44:26 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-02 14:44:26 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-11 14:45:49 +00:00
|
|
|
serial = request.args.get("scanned_barcode")
|
2017-09-21 06:34:23 +00:00
|
|
|
opzioni = db.engine.execute("SELECT tipo FROM dispositivi GROUP BY tipo;")
|
|
|
|
sistemi = db.engine.execute("SELECT so FROM dispositivi GROUP BY so;")
|
2017-09-18 07:06:44 +00:00
|
|
|
reti = Rete.query.order_by(Rete.nome).all()
|
|
|
|
impiegati = Impiegato.query.order_by(Impiegato.nomeimpiegato).all()
|
2017-09-19 08:29:57 +00:00
|
|
|
ordini = Ordine.query.order_by(Ordine.data).all()
|
2017-09-18 14:15:44 +00:00
|
|
|
return render_template("dispositivo/show.htm", action="add", impiegati=impiegati, opzioni=opzioni, reti=reti,
|
2017-09-21 06:34:23 +00:00
|
|
|
pagetype="dev", serial=serial, sistemi=sistemi,
|
2017-09-19 08:29:57 +00:00
|
|
|
ordini=ordini)
|
2017-02-02 14:44:26 +00:00
|
|
|
else:
|
2017-09-12 10:04:45 +00:00
|
|
|
if request.form["inv_ced"]:
|
|
|
|
try:
|
|
|
|
int(request.form["inv_ced"])
|
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario CED deve contenere un numero.")
|
|
|
|
if request.form["inv_ente"]:
|
|
|
|
try:
|
|
|
|
int(request.form["inv_ente"])
|
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario ente deve contenere un numero.")
|
2017-09-19 15:30:14 +00:00
|
|
|
nuovodisp = Dispositivo(tipo=request.form['tipo'],
|
|
|
|
marca=request.form['marca'],
|
|
|
|
modello=request.form['modello'],
|
|
|
|
inv_ced=int(request.form['inv_ced']) if request.form['inv_ced'] else None,
|
|
|
|
inv_ente=int(request.form['inv_ente']) if request.form['inv_ente'] else None,
|
|
|
|
nid=request.form['rete'],
|
|
|
|
seriale=request.form['seriale'] if request.form['seriale'] else None,
|
|
|
|
ip=request.form['ip'],
|
|
|
|
hostname=request.form['hostname'] if request.form['hostname'] else None,
|
|
|
|
so=request.form['so'],
|
|
|
|
oid=int(request.form['ordine']) if request.form['ordine'] else None)
|
2017-02-02 14:44:26 +00:00
|
|
|
db.session.add(nuovodisp)
|
|
|
|
db.session.commit()
|
2017-02-03 12:04:11 +00:00
|
|
|
# Trova tutti gli utenti, edizione sporco hack in html
|
|
|
|
users = list()
|
|
|
|
while True:
|
|
|
|
# Trova tutti gli utenti esistenti
|
|
|
|
userstring = 'utente{}'.format(len(users))
|
|
|
|
if userstring in request.form:
|
|
|
|
users.append(request.form[userstring])
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
for user in users:
|
|
|
|
nuovologin = Accesso(int(user), nuovodisp.did)
|
|
|
|
db.session.add(nuovologin)
|
|
|
|
db.session.commit()
|
2017-02-02 14:44:26 +00:00
|
|
|
return redirect(url_for('page_disp_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-02 14:44:26 +00:00
|
|
|
@app.route('/disp_del/<int:did>')
|
|
|
|
def page_disp_del(did):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di cancellazione dispositivo:
|
|
|
|
accetta richieste GET per cancellare il dispositivo specificato."""
|
2017-02-02 14:44:26 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
disp = Dispositivo.query.get_or_404(did)
|
2017-09-12 10:04:45 +00:00
|
|
|
for accesso in disp.accessi:
|
|
|
|
db.session.delete(accesso)
|
2017-02-02 14:44:26 +00:00
|
|
|
db.session.delete(disp)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_disp_list'))
|
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-02-02 14:44:26 +00:00
|
|
|
@app.route('/disp_list')
|
|
|
|
def page_disp_list():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco dei dispositivi registrati nell'inventario."""
|
2017-02-02 14:44:26 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-02-03 12:04:11 +00:00
|
|
|
accessi = list()
|
2017-09-18 07:06:44 +00:00
|
|
|
dispositivi = Dispositivo.query.order_by(Dispositivo.inv_ced).all()
|
2017-02-03 12:04:11 +00:00
|
|
|
for dispositivo in dispositivi:
|
|
|
|
accesso = Accesso.query.join(Dispositivo).filter_by(did=dispositivo.did).join(Impiegato).all()
|
2017-09-11 13:00:04 +00:00
|
|
|
if not accesso:
|
2017-09-11 13:22:44 +00:00
|
|
|
# oh dio mio a cosa stavo pensando viva il duck typing
|
2017-09-11 13:00:04 +00:00
|
|
|
accessi.append([FakeAccesso(dispositivo)])
|
|
|
|
else:
|
|
|
|
accessi.append(accesso)
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("dispositivo/list.htm", accessi=accessi, pagetype="disp")
|
2017-02-02 14:44:26 +00:00
|
|
|
|
2017-09-11 09:43:50 +00:00
|
|
|
|
2017-09-11 13:00:04 +00:00
|
|
|
@app.route('/disp_details/<int:did>')
|
2017-09-12 09:39:21 +00:00
|
|
|
def page_disp_details(did):
|
|
|
|
"""Pagina di dettagli di un dispositivo, contenente anche gli utenti che vi hanno accesso."""
|
2017-09-11 13:00:04 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
disp = Dispositivo.query.get_or_404(did)
|
2017-09-19 08:44:55 +00:00
|
|
|
if disp.oid is not None:
|
|
|
|
disp = Dispositivo.query.filter_by(did=did).join(Ordine).first()
|
2017-09-11 13:22:44 +00:00
|
|
|
accessi = Accesso.query.filter_by(did=did).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("dispositivo/details.htm", disp=disp, accessi=accessi, pagetype="disp")
|
2017-09-11 10:47:52 +00:00
|
|
|
|
|
|
|
|
2017-09-12 10:50:28 +00:00
|
|
|
@app.route('/disp_show/<int:did>', methods=['GET', 'POST'])
|
|
|
|
def page_disp_show(did):
|
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-12 10:50:28 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-18 07:06:44 +00:00
|
|
|
disp = Dispositivo.query.get_or_404(did)
|
2017-09-12 13:11:23 +00:00
|
|
|
accessi = Accesso.query.filter_by(did=did).all()
|
2017-09-18 07:06:44 +00:00
|
|
|
impiegati = Impiegato.query.order_by(Impiegato.nomeimpiegato).all()
|
2017-09-19 08:29:57 +00:00
|
|
|
ordini = Ordine.query.order_by(Ordine.data).all()
|
2017-09-21 06:34:23 +00:00
|
|
|
opzioni = db.engine.execute("SELECT tipo FROM dispositivi GROUP BY tipo;")
|
|
|
|
sistemi = db.engine.execute("SELECT so FROM dispositivi GROUP BY so;")
|
2017-09-18 07:06:44 +00:00
|
|
|
reti = Rete.query.order_by(Rete.nome).all()
|
2017-09-19 06:11:52 +00:00
|
|
|
return render_template("dispositivo/show.htm", action="show", dispositivo=disp, accessi=accessi,
|
2017-09-20 09:36:39 +00:00
|
|
|
impiegati=impiegati, pagetype="disp", opzioni=opzioni,
|
2017-09-21 06:34:23 +00:00
|
|
|
reti=reti, sistemi=sistemi, ordini=ordini)
|
2017-09-12 10:50:28 +00:00
|
|
|
else:
|
2017-09-18 12:54:52 +00:00
|
|
|
disp = Dispositivo.query.get_or_404(did)
|
|
|
|
accessi = Accesso.query.filter_by(did=did).all()
|
2017-09-12 10:50:28 +00:00
|
|
|
if request.form["inv_ced"]:
|
|
|
|
try:
|
2017-09-18 12:54:52 +00:00
|
|
|
disp.inv_ced = int(request.form["inv_ced"])
|
2017-09-12 10:50:28 +00:00
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario CED deve contenere un numero.")
|
2017-09-18 12:54:52 +00:00
|
|
|
else:
|
|
|
|
disp.inv_ced = None
|
2017-09-12 10:50:28 +00:00
|
|
|
if request.form["inv_ente"]:
|
|
|
|
try:
|
2017-09-18 12:54:52 +00:00
|
|
|
disp.inv_ente = int(request.form["inv_ente"])
|
2017-09-12 10:50:28 +00:00
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario ente deve contenere un numero.")
|
2017-09-18 12:54:52 +00:00
|
|
|
else:
|
|
|
|
disp.inv_ente = None
|
2017-09-12 10:50:28 +00:00
|
|
|
disp.tipo = request.form['tipo']
|
|
|
|
disp.marca = request.form['marca']
|
|
|
|
disp.modello = request.form['modello']
|
2017-09-12 13:11:23 +00:00
|
|
|
disp.nid = int(request.form['rete'])
|
2017-09-13 06:19:08 +00:00
|
|
|
disp.ip = request.form['ip']
|
2017-09-19 08:29:57 +00:00
|
|
|
disp.hostname = request.form['hostname'] if request.form['hostname'] else None
|
2017-09-18 14:07:04 +00:00
|
|
|
disp.so = request.form['so']
|
2017-09-19 08:29:57 +00:00
|
|
|
disp.oid = int(request.form['ordine']) if request.form['ordine'] else None
|
2017-09-12 10:50:28 +00:00
|
|
|
# Trova tutti gli utenti, edizione sporco hack in html
|
|
|
|
users = list()
|
|
|
|
while True:
|
|
|
|
# Trova tutti gli utenti esistenti
|
|
|
|
userstring = 'utente{}'.format(len(users))
|
|
|
|
if userstring in request.form:
|
|
|
|
users.append(request.form[userstring])
|
|
|
|
else:
|
|
|
|
break
|
2017-09-12 13:11:23 +00:00
|
|
|
for accesso in accessi:
|
|
|
|
db.session.delete(accesso)
|
2017-09-12 10:50:28 +00:00
|
|
|
for user in users:
|
2017-09-12 13:11:23 +00:00
|
|
|
nuovologin = Accesso(int(user), disp.did)
|
2017-09-12 10:50:28 +00:00
|
|
|
db.session.add(nuovologin)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_disp_list'))
|
|
|
|
|
|
|
|
|
2017-09-18 13:04:22 +00:00
|
|
|
@app.route('/disp_clone/<int:did>', methods=['GET', 'POST'])
|
|
|
|
def page_disp_clone(did):
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
if request.method == 'GET':
|
|
|
|
disp = Dispositivo.query.get_or_404(did)
|
|
|
|
accessi = Accesso.query.filter_by(did=did).all()
|
|
|
|
impiegati = Impiegato.query.order_by(Impiegato.nomeimpiegato).all()
|
2017-09-21 06:34:23 +00:00
|
|
|
opzioni = db.engine.execute("SELECT tipo FROM dispositivi GROUP BY tipo;")
|
|
|
|
sistemi = db.engine.execute("SELECT so FROM dispositivi GROUP BY so;")
|
2017-09-19 08:29:57 +00:00
|
|
|
ordini = Ordine.query.order_by(Ordine.data).all()
|
2017-09-18 13:04:22 +00:00
|
|
|
reti = Rete.query.order_by(Rete.nome).all()
|
2017-09-19 06:11:52 +00:00
|
|
|
return render_template("dispositivo/show.htm", action="clone", dispositivo=disp, accessi=accessi,
|
2017-09-20 09:36:39 +00:00
|
|
|
impiegati=impiegati, pagetype="disp", opzioni=opzioni,
|
2017-09-21 06:34:23 +00:00
|
|
|
reti=reti, sistemi=sistemi, ordini=ordini)
|
2017-09-18 13:04:22 +00:00
|
|
|
else:
|
|
|
|
if request.form["inv_ced"]:
|
|
|
|
try:
|
|
|
|
int(request.form["inv_ced"])
|
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario CED deve contenere un numero.")
|
|
|
|
if request.form["inv_ente"]:
|
|
|
|
try:
|
|
|
|
int(request.form["inv_ente"])
|
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Inventario ente deve contenere un numero.")
|
2017-09-19 15:30:14 +00:00
|
|
|
nuovodisp = Dispositivo(tipo=request.form['tipo'],
|
|
|
|
marca=request.form['marca'],
|
|
|
|
modello=request.form['modello'],
|
|
|
|
inv_ced=int(request.form['inv_ced']) if request.form['inv_ced'] else None,
|
|
|
|
inv_ente=int(request.form['inv_ente']) if request.form['inv_ente'] else None,
|
|
|
|
nid=request.form['rete'],
|
|
|
|
seriale=request.form['seriale'] if request.form['seriale'] else None,
|
|
|
|
ip=request.form['ip'],
|
|
|
|
hostname=request.form['hostname'] if request.form['hostname'] else None,
|
|
|
|
so=request.form['so'],
|
|
|
|
oid=int(request.form['ordine']) if request.form['ordine'] else None)
|
2017-09-18 13:04:22 +00:00
|
|
|
db.session.add(nuovodisp)
|
|
|
|
db.session.commit()
|
|
|
|
# Trova tutti gli utenti, edizione sporco hack in html
|
|
|
|
users = list()
|
|
|
|
while True:
|
|
|
|
# Trova tutti gli utenti esistenti
|
|
|
|
userstring = 'utente{}'.format(len(users))
|
|
|
|
if userstring in request.form:
|
|
|
|
users.append(request.form[userstring])
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
for user in users:
|
|
|
|
nuovologin = Accesso(int(user), nuovodisp.did)
|
|
|
|
db.session.add(nuovologin)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_disp_list'))
|
|
|
|
|
|
|
|
|
2017-09-11 14:55:23 +00:00
|
|
|
@app.route('/net_add', methods=['GET', 'POST'])
|
|
|
|
def page_net_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuova rete:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva."""
|
2017-09-11 14:55:23 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-11 14:55:23 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("net/show.htm", action="add", pagetype="net")
|
2017-09-11 14:55:23 +00:00
|
|
|
else:
|
2017-09-13 09:36:20 +00:00
|
|
|
try:
|
|
|
|
int(request.form["subnet"])
|
|
|
|
except ValueError:
|
|
|
|
return render_template("error.htm", error="Il campo Subnet deve contenere il numero di bit della subnet. "
|
|
|
|
"(8, 16, 24...)")
|
2017-09-20 10:40:29 +00:00
|
|
|
nuovonet = Rete(nome=request.form["nome"], network_ip=request.form["network_ip"], subnet=request.form["subnet"].lstrip("/"),
|
2017-09-12 07:39:18 +00:00
|
|
|
primary_dns=request.form["primary_dns"], secondary_dns=request.form["secondary_dns"])
|
2017-09-11 14:55:23 +00:00
|
|
|
db.session.add(nuovonet)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_net_list'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/net_del/<int:nid>')
|
2017-09-12 07:39:18 +00:00
|
|
|
def page_net_del(nid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di cancellazione rete:
|
|
|
|
accetta richieste GET per cancellare la rete specificata."""
|
2017-09-11 14:55:23 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:14:56 +00:00
|
|
|
return abort(403)
|
2017-09-13 08:40:57 +00:00
|
|
|
if Rete.query.count() <= 1:
|
|
|
|
return render_template("error.htm", error="Non puoi cancellare l'ultima rete rimasta!")
|
2017-09-12 09:46:30 +00:00
|
|
|
rete = Rete.query.get_or_404(nid)
|
2017-09-13 08:53:29 +00:00
|
|
|
defaultrete = Rete.query.filter_by(network_ip="0.0.0.0").first()
|
|
|
|
dispositivi = Dispositivo.query.filter_by(nid=rete.nid).all()
|
|
|
|
for dispositivo in dispositivi:
|
|
|
|
dispositivo.nid = defaultrete.nid
|
2017-09-11 14:55:23 +00:00
|
|
|
db.session.delete(rete)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_net_list'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/net_list')
|
|
|
|
def page_net_list():
|
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
reti = Rete.query.order_by(Rete.nome).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("net/list.htm", reti=reti, pagetype="net")
|
2017-09-11 14:55:23 +00:00
|
|
|
|
|
|
|
|
2017-09-11 15:31:20 +00:00
|
|
|
@app.route('/net_details/<int:nid>')
|
2017-09-12 07:39:18 +00:00
|
|
|
def page_net_details(nid):
|
2017-09-11 15:31:20 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
net = Rete.query.get_or_404(nid)
|
2017-09-12 07:39:18 +00:00
|
|
|
dispositivi = Dispositivo.query.join(Rete).filter_by(nid=nid).all()
|
|
|
|
subnet = subnet_to_string(net.subnet)
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("net/details.htm", net=net, subnet=subnet, dispositivi=dispositivi, pagetype="net")
|
2017-09-11 15:31:20 +00:00
|
|
|
|
|
|
|
|
2017-09-13 09:36:20 +00:00
|
|
|
@app.route('/net_show/<int:nid>', methods=['GET', 'POST'])
|
|
|
|
def page_net_show(nid):
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
if request.method == 'GET':
|
|
|
|
net = Rete.query.filter_by(nid=nid).first_or_404()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("net/show.htm", action="show", net=net, pagetype="net")
|
2017-09-13 09:36:20 +00:00
|
|
|
else:
|
|
|
|
net = Rete.query.filter_by(nid=nid).first_or_404()
|
|
|
|
net.nome = request.form['nome']
|
|
|
|
net.network_ip = request.form['network_ip']
|
|
|
|
net.subnet = request.form['subnet']
|
|
|
|
net.primary_dns = request.form['primary_dns']
|
|
|
|
net.secondary_dns = request.form['secondary_dns']
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_net_list'))
|
|
|
|
|
|
|
|
|
2017-09-12 08:48:21 +00:00
|
|
|
@app.route('/user_list')
|
|
|
|
def page_user_list():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di elenco degli utenti che possono connettersi al sito.
|
|
|
|
Le password sono hashate."""
|
2017-09-12 08:48:21 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-18 07:06:44 +00:00
|
|
|
utenti = User.query.order_by(User.username).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("user/list.htm", utenti=utenti, pagetype="user")
|
2017-09-12 08:48:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/user_del/<int:uid>')
|
|
|
|
def page_user_del(uid):
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di cancellazione impiegato:
|
|
|
|
accetta richieste GET per cancellare l'utente specificato."""
|
2017-09-12 08:48:21 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-13 08:40:57 +00:00
|
|
|
if User.query.count() <= 1:
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("error.htm", error="Non puoi cancellare l'ultimo utente rimasto!")
|
2017-09-12 09:46:30 +00:00
|
|
|
utente = User.query.get_or_404(uid)
|
2017-09-13 08:43:38 +00:00
|
|
|
if utente.username == session["username"]:
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("error.htm", error="Non puoi cancellare l'utente con cui sei loggato!")
|
2017-09-12 08:48:21 +00:00
|
|
|
db.session.delete(utente)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_user_list'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/user_add', methods=['GET', 'POST'])
|
|
|
|
def page_user_add():
|
2017-09-12 09:39:21 +00:00
|
|
|
"""Pagina di creazione nuovo utente del sito:
|
|
|
|
come tutte le altre pagine di creazione del sito,
|
|
|
|
accetta GET per visualizzare la pagina
|
|
|
|
e POST con form data per l'aggiunta effettiva.
|
|
|
|
Le password vengono hashate con bcrypt."""
|
2017-09-12 08:48:21 +00:00
|
|
|
if 'username' not in session:
|
2017-09-13 07:23:26 +00:00
|
|
|
return abort(403)
|
2017-09-12 08:48:21 +00:00
|
|
|
if request.method == 'GET':
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("user/add.htm", pagetype="user")
|
2017-09-12 08:48:21 +00:00
|
|
|
else:
|
|
|
|
p = bytes(request.form["passwd"], encoding="utf-8")
|
|
|
|
cenere = bcrypt.hashpw(p, bcrypt.gensalt())
|
|
|
|
nuovo = User(request.form['username'], cenere)
|
|
|
|
db.session.add(nuovo)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_user_list'))
|
|
|
|
|
|
|
|
|
2017-09-19 07:36:39 +00:00
|
|
|
@app.route('/order_list')
|
|
|
|
def page_order_list():
|
|
|
|
"""Pagina di elenco degli ordini registrati nel database."""
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
2017-09-19 09:28:08 +00:00
|
|
|
ordini = Ordine.query.order_by(Ordine.data.desc()).all()
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ordine/list.htm", orders=ordini, pagetype="order",
|
2017-09-19 09:28:08 +00:00
|
|
|
today=datetime.date.today(), soon=datetime.date.today() + datetime.timedelta(7))
|
2017-09-19 07:36:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/order_add', methods=['GET', 'POST'])
|
|
|
|
def page_order_add():
|
|
|
|
"""Pagina di creazione nuovo ordine"""
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
if request.method == 'GET':
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ordine/show.htm", action="add", pagetype="order")
|
2017-09-19 07:36:39 +00:00
|
|
|
else:
|
|
|
|
if request.form["data"] != "":
|
|
|
|
yyyy, mm, dd = request.form["data"].split("-", 2)
|
|
|
|
data = datetime.date(int(yyyy), int(mm), int(dd))
|
|
|
|
else:
|
|
|
|
data = None
|
2017-09-19 08:29:57 +00:00
|
|
|
if request.form["garanzia"] != "":
|
|
|
|
yyyy, mm, dd = request.form["garanzia"].split("-", 2)
|
|
|
|
garanzia = datetime.date(int(yyyy), int(mm), int(dd))
|
|
|
|
else:
|
|
|
|
garanzia = None
|
2017-09-19 13:49:01 +00:00
|
|
|
nuovoordine = Ordine(data=data, numero_ordine=request.form["numero_ordine"], garanzia=garanzia,
|
|
|
|
fornitore=request.form['fornitore'])
|
2017-09-19 07:36:39 +00:00
|
|
|
db.session.add(nuovoordine)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for("page_order_list"))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/order_show/<int:oid>', methods=['GET', 'POST'])
|
|
|
|
def page_order_show(oid):
|
|
|
|
"""Pagina di modifica ordine"""
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
if request.method == 'GET':
|
|
|
|
order = Ordine.query.get_or_404(oid)
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("ordine/show.htm", order=order, action="show", pagetype="order")
|
2017-09-19 07:36:39 +00:00
|
|
|
else:
|
|
|
|
order = Ordine.query.get_or_404(oid)
|
|
|
|
if request.form["data"] != "":
|
|
|
|
yyyy, mm, dd = request.form["data"].split("-", 2)
|
|
|
|
order.data = datetime.date(int(yyyy), int(mm), int(dd))
|
|
|
|
else:
|
|
|
|
order.data = None
|
2017-09-19 08:29:57 +00:00
|
|
|
if request.form["garanzia"] != "":
|
|
|
|
yyyy, mm, dd = request.form["garanzia"].split("-", 2)
|
|
|
|
order.garanzia = datetime.date(int(yyyy), int(mm), int(dd))
|
|
|
|
else:
|
|
|
|
order.garanzia = None
|
2017-09-19 07:36:39 +00:00
|
|
|
order.numero_ordine = request.form["numero_ordine"]
|
2017-09-19 13:49:01 +00:00
|
|
|
order.fornitore = request.form['fornitore']
|
2017-09-19 07:36:39 +00:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for("page_order_list"))
|
|
|
|
|
|
|
|
|
2017-09-19 09:28:08 +00:00
|
|
|
@app.route('/order_del/<int:oid>')
|
|
|
|
def page_order_del(oid):
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
ordine = Ordine.query.get_or_404(oid)
|
|
|
|
dispositivi = Dispositivo.query.filter_by(oid=oid).all()
|
|
|
|
for dispositivo in dispositivi:
|
|
|
|
dispositivo.oid = None
|
|
|
|
db.session.delete(ordine)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('page_order_list'))
|
|
|
|
|
|
|
|
|
2017-09-19 08:57:53 +00:00
|
|
|
@app.route('/order_details/<int:oid>')
|
|
|
|
def page_order_details(oid):
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
ordine = Ordine.query.get_or_404(oid)
|
|
|
|
dispositivi = Dispositivo.query.join(Ordine).filter_by(oid=oid).all()
|
2017-09-19 09:28:08 +00:00
|
|
|
return render_template("ordine/details.htm", dispositivi=dispositivi, pagetype="order", today=datetime.date.today(),
|
2017-09-20 09:36:39 +00:00
|
|
|
ordine=ordine, soon=datetime.date.today() + datetime.timedelta(7))
|
2017-09-19 08:57:53 +00:00
|
|
|
|
|
|
|
|
2017-09-13 08:24:59 +00:00
|
|
|
@app.route('/query', methods=['GET', 'POST'])
|
|
|
|
def page_query():
|
|
|
|
"""Pagina delle query manuali:
|
|
|
|
in GET visualizza la pagina per fare una query,
|
|
|
|
mentre in POST visualizza i risultati."""
|
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
|
|
|
if request.method == 'GET':
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("query.htm", pagetype="query")
|
2017-09-13 08:24:59 +00:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
result = db.engine.execute("SELECT" + request.form["query"] + ";")
|
|
|
|
except Exception as e:
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("query.htm", query=request.form["query"], error=repr(e), pagetype="query")
|
|
|
|
return render_template("query.htm", query=request.form["query"], result=result,
|
2017-09-13 10:11:29 +00:00
|
|
|
pagetype="query")
|
2017-09-13 08:24:59 +00:00
|
|
|
|
|
|
|
|
2017-09-13 10:48:41 +00:00
|
|
|
@app.route('/smecds')
|
2017-09-12 13:11:23 +00:00
|
|
|
def page_smecds():
|
2017-09-12 10:50:04 +00:00
|
|
|
"""Pagina che visualizza i credits del sito"""
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("smecds.htm", pagetype="main")
|
2017-09-13 10:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/pheesh')
|
|
|
|
def page_pheesh():
|
|
|
|
"""Acquario del sito.
|
|
|
|
I pesci sono generati dinamicamente basandosi sui dati presenti nel database."""
|
2017-09-14 11:26:20 +00:00
|
|
|
if 'username' not in session:
|
|
|
|
return abort(403)
|
2017-09-13 10:48:41 +00:00
|
|
|
enti = Ente.query.all()
|
|
|
|
servizi = Servizio.query.all()
|
|
|
|
impiegati = Impiegato.query.all()
|
|
|
|
dispositivi = Dispositivo.query.all()
|
|
|
|
reti = Rete.query.all()
|
|
|
|
utenti = User.query.all()
|
2017-09-19 09:28:08 +00:00
|
|
|
ordini = Ordine.query.all()
|
2017-09-13 10:48:41 +00:00
|
|
|
pesci = []
|
|
|
|
for obj in enti:
|
2017-09-14 07:44:04 +00:00
|
|
|
random.seed(hash(obj.nomeente))
|
2017-09-18 15:57:40 +00:00
|
|
|
pesci.append(Pesce(obj, 3, 0.9, f"/ente_list"))
|
2017-09-13 10:48:41 +00:00
|
|
|
for obj in servizi:
|
2017-09-14 07:44:04 +00:00
|
|
|
random.seed(hash(obj.nomeservizio))
|
2017-09-18 15:57:40 +00:00
|
|
|
pesci.append(Pesce(obj, 2, 0.5, f"/serv_list"))
|
2017-09-13 10:48:41 +00:00
|
|
|
for obj in reti:
|
2017-09-14 07:44:04 +00:00
|
|
|
random.seed(hash(obj.nome))
|
2017-09-18 15:57:40 +00:00
|
|
|
pesci.append(Pesce(obj, 1.5, 0.4, f"/net_details/{obj.nid}"))
|
2017-09-13 10:48:41 +00:00
|
|
|
for obj in impiegati:
|
2017-09-14 07:44:04 +00:00
|
|
|
random.seed(hash(obj.nomeimpiegato))
|
2017-09-19 09:28:08 +00:00
|
|
|
pesci.append(Pesce(obj, 1, 0.3, f"/imp_details/{obj.iid}"))
|
2017-09-13 10:48:41 +00:00
|
|
|
for obj in dispositivi:
|
2017-09-14 13:11:07 +00:00
|
|
|
random.seed(hash(obj.did))
|
2017-09-19 09:28:08 +00:00
|
|
|
pesci.append(Pesce(obj, 0.8, 0.2, f"/disp_details/{obj.did}"))
|
2017-09-13 10:48:41 +00:00
|
|
|
for obj in utenti:
|
2017-09-14 07:44:04 +00:00
|
|
|
random.seed(hash(obj.username))
|
2017-09-18 15:57:40 +00:00
|
|
|
pesci.append(Pesce(obj, 1.5, 0.1, f"/user_list"))
|
2017-09-19 09:28:08 +00:00
|
|
|
for obj in ordini:
|
|
|
|
random.seed(hash(obj.numero_ordine))
|
|
|
|
pesci.append(Pesce(obj, 1.2, 0.4, f"/order_details/{obj.oid}"))
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template("pheesh.htm", pheesh=pesci, footer=False)
|
2017-09-12 10:50:04 +00:00
|
|
|
|
|
|
|
|
2017-09-14 12:55:39 +00:00
|
|
|
@app.errorhandler(400)
|
|
|
|
def page_400(_):
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template('400.htm')
|
2017-09-14 12:55:39 +00:00
|
|
|
|
|
|
|
|
2017-09-13 07:06:59 +00:00
|
|
|
@app.errorhandler(403)
|
|
|
|
def page_403(_):
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template('403.htm')
|
2017-09-13 07:06:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def page_404(_):
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template('404.htm')
|
2017-09-13 07:06:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
|
|
|
def page_500(e):
|
2017-09-20 09:36:39 +00:00
|
|
|
return render_template('500.htm', e=e)
|
|
|
|
|
|
|
|
|
|
|
|
@app.context_processor
|
|
|
|
def inject_vars():
|
|
|
|
return {
|
|
|
|
"user": session.get("username"),
|
|
|
|
"estus_version": estus_version
|
|
|
|
}
|
2017-09-13 07:06:59 +00:00
|
|
|
|
|
|
|
|
2017-09-11 10:47:52 +00:00
|
|
|
if __name__ == "__main__":
|
2017-09-12 09:39:21 +00:00
|
|
|
# Se non esiste il database, crealo e inizializzalo!
|
2017-09-18 07:11:44 +00:00
|
|
|
if not os.path.isfile("db.sqlite"):
|
2017-09-12 07:39:18 +00:00
|
|
|
db.create_all()
|
|
|
|
try:
|
2017-09-12 09:39:21 +00:00
|
|
|
# L'utente predefinito è "stagista" "smecds".
|
2017-09-12 07:39:18 +00:00
|
|
|
nuovapassword = bcrypt.hashpw(b"smecds", bcrypt.gensalt())
|
|
|
|
nuovouser = User('stagista', nuovapassword)
|
|
|
|
db.session.add(nuovouser)
|
2017-09-12 09:39:21 +00:00
|
|
|
# Crea una rete nulla da utilizzare quando non ci sono altre reti disponibili
|
2017-09-12 07:39:18 +00:00
|
|
|
retenulla = Rete(nome="Sconosciuta", network_ip="0.0.0.0", subnet=0, primary_dns="0.0.0.0",
|
|
|
|
secondary_dns="0.0.0.0")
|
|
|
|
db.session.add(retenulla)
|
|
|
|
db.session.commit()
|
2017-09-12 09:41:13 +00:00
|
|
|
except IntegrityError:
|
2017-09-12 09:39:21 +00:00
|
|
|
# Se queste operazioni sono già state compiute in precedenza, annullale
|
2017-09-12 07:39:18 +00:00
|
|
|
db.session.rollback()
|
2017-09-14 08:01:28 +00:00
|
|
|
app.run()
|