|
|
@@ -15,8 +15,8 @@ import markdown2
|
|
|
|
app = Flask(__name__, static_folder='static')
|
|
|
|
app = Flask(__name__, static_folder='static')
|
|
|
|
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev')
|
|
|
|
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev')
|
|
|
|
app.config['ALLOWED_IP_RANGES'] = os.getenv('ALLOWED_IP_RANGES', '192.168.0.0/16,10.0.0.0/8').split(',')
|
|
|
|
app.config['ALLOWED_IP_RANGES'] = os.getenv('ALLOWED_IP_RANGES', '192.168.0.0/16,10.0.0.0/8').split(',')
|
|
|
|
app.config['VERSION'] = '1.2.20'
|
|
|
|
app.config['VERSION'] = '1.2.21'
|
|
|
|
app.config['DATABASE'] = os.path.join(app.instance_path, 'customers.db')
|
|
|
|
app.config['DATABASE'] = 'data/customers.db'
|
|
|
|
app.config['DATABASE_TIMEOUT'] = 20
|
|
|
|
app.config['DATABASE_TIMEOUT'] = 20
|
|
|
|
app.config['DATABASE_POOL_SIZE'] = 5
|
|
|
|
app.config['DATABASE_POOL_SIZE'] = 5
|
|
|
|
|
|
|
|
|
|
|
@@ -51,6 +51,12 @@ def init_db():
|
|
|
|
c = conn.cursor()
|
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
# Prüfe, ob die Tabelle bereits existiert
|
|
|
|
|
|
|
|
c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='customers'")
|
|
|
|
|
|
|
|
if c.fetchone() is not None:
|
|
|
|
|
|
|
|
app.logger.info('Datenbank existiert bereits, überspringe Initialisierung')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Erstelle die Kunden-Tabelle
|
|
|
|
# Erstelle die Kunden-Tabelle
|
|
|
|
c.execute('''
|
|
|
|
c.execute('''
|
|
|
|
CREATE TABLE IF NOT EXISTS customers (
|
|
|
|
CREATE TABLE IF NOT EXISTS customers (
|
|
|
@@ -83,9 +89,57 @@ def init_db():
|
|
|
|
# Zusammengesetzter Index für die häufigste Suchkombination
|
|
|
|
# Zusammengesetzter Index für die häufigste Suchkombination
|
|
|
|
c.execute('CREATE INDEX IF NOT EXISTS idx_customers_search ON customers(name, ort, fachrichtung, tag)')
|
|
|
|
c.execute('CREATE INDEX IF NOT EXISTS idx_customers_search ON customers(name, ort, fachrichtung, tag)')
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('Datenbank initialisiert')
|
|
|
|
app.logger.info('Datenbank initialisiert')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Importiere die CSV-Daten
|
|
|
|
|
|
|
|
import_csv_data('data/medisoft.csv', 'MEDISOFT')
|
|
|
|
|
|
|
|
import_csv_data('data/mediconsult.csv', 'MEDICONSULT')
|
|
|
|
|
|
|
|
app.logger.info('CSV-Daten erfolgreich in die Datenbank importiert')
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f'Fehler bei der Datenbankinitialisierung: {str(e)}')
|
|
|
|
app.logger.error(f'Fehler bei der Datenbankinitialisierung: {str(e)}')
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def import_csv_data(file_path, tag):
|
|
|
|
|
|
|
|
"""Importiert die CSV-Datei in die Datenbank."""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if not os.path.exists(file_path):
|
|
|
|
|
|
|
|
app.logger.warning(f"CSV-Datei {file_path} nicht gefunden")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.logger.info(f"Importiere {tag}-Daten aus {file_path}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with get_db() as conn:
|
|
|
|
|
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Lese die CSV-Datei
|
|
|
|
|
|
|
|
df = pd.read_csv(file_path, encoding='iso-8859-1')
|
|
|
|
|
|
|
|
df.columns = df.columns.str.strip().str.replace('"', '')
|
|
|
|
|
|
|
|
df = df.apply(lambda x: x.str.strip().str.replace('"', '') if x.dtype == "object" else x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filtere Datensätze mit Fachrichtung "intern"
|
|
|
|
|
|
|
|
df = df[df['Fachrichtung'].str.lower() != 'intern']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bereite die Daten für den Batch-Insert vor
|
|
|
|
|
|
|
|
data = [(
|
|
|
|
|
|
|
|
row['VorNachname'], row['Nummer'], row['Strasse'], row['PLZ'], row['Ort'],
|
|
|
|
|
|
|
|
row['Tel'], row['Tel'], row['mail'], row['Fachrichtung'], tag,
|
|
|
|
|
|
|
|
row['Handy'], row['Tele Firma'], row['Kontakt1'], row['Kontakt2'], row['Kontakt3']
|
|
|
|
|
|
|
|
) for _, row in df.iterrows()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Führe Batch-Insert durch
|
|
|
|
|
|
|
|
c.executemany('''
|
|
|
|
|
|
|
|
INSERT INTO customers (
|
|
|
|
|
|
|
|
name, nummer, strasse, plz, ort, telefon, mobil, email,
|
|
|
|
|
|
|
|
fachrichtung, tag, handy, tele_firma, kontakt1, kontakt2, kontakt3
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
|
|
|
''', data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.logger.info(f"{tag}-Daten erfolgreich importiert")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
app.logger.error(f"Fehler beim Importieren der {tag}-Daten: {str(e)}")
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def isIPInSubnet(ip, subnet):
|
|
|
|
def isIPInSubnet(ip, subnet):
|
|
|
@@ -109,76 +163,6 @@ def isIPInSubnet(ip, subnet):
|
|
|
|
logger.error(f"Fehler bei der IP-Überprüfung: {str(e)}")
|
|
|
|
logger.error(f"Fehler bei der IP-Überprüfung: {str(e)}")
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def import_csv():
|
|
|
|
|
|
|
|
"""Importiert die CSV-Datei in die Datenbank"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with get_db() as conn:
|
|
|
|
|
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Lösche bestehende Daten
|
|
|
|
|
|
|
|
c.execute('DELETE FROM customers')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Importiere MEDISOFT-Daten
|
|
|
|
|
|
|
|
if os.path.exists('data/customers.csv'):
|
|
|
|
|
|
|
|
logger.info("Importiere MEDISOFT-Daten...")
|
|
|
|
|
|
|
|
df = pd.read_csv('data/customers.csv', encoding='iso-8859-1')
|
|
|
|
|
|
|
|
df.columns = df.columns.str.strip().str.replace('"', '')
|
|
|
|
|
|
|
|
df = df.apply(lambda x: x.str.strip().str.replace('"', '') if x.dtype == "object" else x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filtere Datensätze mit Fachrichtung "intern"
|
|
|
|
|
|
|
|
df = df[df['Fachrichtung'].str.lower() != 'intern']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bereite die Daten für den Batch-Insert vor
|
|
|
|
|
|
|
|
data = [(
|
|
|
|
|
|
|
|
row['VorNachname'], row['Nummer'], row['Strasse'], row['PLZ'], row['Ort'],
|
|
|
|
|
|
|
|
row['Tel'], row['Tel'], row['mail'], row['Fachrichtung'], 'medisoft',
|
|
|
|
|
|
|
|
row['Handy'], row['Tele Firma'], row['Kontakt1'], row['Kontakt2'], row['Kontakt3']
|
|
|
|
|
|
|
|
) for _, row in df.iterrows()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Führe Batch-Insert durch
|
|
|
|
|
|
|
|
c.executemany('''
|
|
|
|
|
|
|
|
INSERT INTO customers (
|
|
|
|
|
|
|
|
name, nummer, strasse, plz, ort, telefon, mobil, email,
|
|
|
|
|
|
|
|
fachrichtung, tag, handy, tele_firma, kontakt1, kontakt2, kontakt3
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
|
|
|
''', data)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.warning("MEDISOFT CSV-Datei nicht gefunden")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Importiere MEDICONSULT-Daten
|
|
|
|
|
|
|
|
if os.path.exists('data/customers_snk.csv'):
|
|
|
|
|
|
|
|
logger.info("Importiere MEDICONSULT-Daten...")
|
|
|
|
|
|
|
|
df_snk = pd.read_csv('data/customers_snk.csv', encoding='iso-8859-1')
|
|
|
|
|
|
|
|
df_snk.columns = df_snk.columns.str.strip().str.replace('"', '')
|
|
|
|
|
|
|
|
df_snk = df_snk.apply(lambda x: x.str.strip().str.replace('"', '') if x.dtype == "object" else x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filtere Datensätze mit Fachrichtung "intern"
|
|
|
|
|
|
|
|
df_snk = df_snk[df_snk['Fachrichtung'].str.lower() != 'intern']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bereite die Daten für den Batch-Insert vor
|
|
|
|
|
|
|
|
data = [(
|
|
|
|
|
|
|
|
row['VorNachname'], row['Nummer'], row['Strasse'], row['PLZ'], row['Ort'],
|
|
|
|
|
|
|
|
row['Tel'], row['Tel'], row['mail'], row['Fachrichtung'], 'mediconsult',
|
|
|
|
|
|
|
|
row['Handy'], row['Tele Firma'], row['Kontakt1'], row['Kontakt2'], row['Kontakt3']
|
|
|
|
|
|
|
|
) for _, row in df_snk.iterrows()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Führe Batch-Insert durch
|
|
|
|
|
|
|
|
c.executemany('''
|
|
|
|
|
|
|
|
INSERT INTO customers (
|
|
|
|
|
|
|
|
name, nummer, strasse, plz, ort, telefon, mobil, email,
|
|
|
|
|
|
|
|
fachrichtung, tag, handy, tele_firma, kontakt1, kontakt2, kontakt3
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
|
|
|
''', data)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.warning("MEDICONSULT CSV-Datei nicht gefunden")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("CSV-Daten erfolgreich in die Datenbank importiert")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logger.error(f"Fehler beim Importieren der CSV-Datei: {str(e)}")
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/login', methods=['GET', 'POST'])
|
|
|
|
@app.route('/login', methods=['GET', 'POST'])
|
|
|
|
def login():
|
|
|
|
def login():
|
|
|
|
# Überprüfe, ob die Client-IP in einem der erlaubten Bereiche liegt
|
|
|
|
# Überprüfe, ob die Client-IP in einem der erlaubten Bereiche liegt
|
|
|
@@ -422,8 +406,8 @@ def upload():
|
|
|
|
customers.save('data/customers.csv')
|
|
|
|
customers.save('data/customers.csv')
|
|
|
|
|
|
|
|
|
|
|
|
# Importiere die Daten in die Datenbank
|
|
|
|
# Importiere die Daten in die Datenbank
|
|
|
|
import_csv('data/customers_snk.csv', 'snk')
|
|
|
|
import_csv_data('data/customers_snk.csv', 'snk')
|
|
|
|
import_csv('data/customers.csv', 'medisoft')
|
|
|
|
import_csv_data('data/customers.csv', 'medisoft')
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('upload.html', success="Dateien erfolgreich hochgeladen und importiert", version=app.config['VERSION'])
|
|
|
|
return render_template('upload.html', success="Dateien erfolgreich hochgeladen und importiert", version=app.config['VERSION'])
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
@@ -453,18 +437,8 @@ def init_app(app):
|
|
|
|
# Stelle sicher, dass der data-Ordner existiert
|
|
|
|
# Stelle sicher, dass der data-Ordner existiert
|
|
|
|
os.makedirs('data', exist_ok=True)
|
|
|
|
os.makedirs('data', exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
# Lösche die alte Datenbank, falls sie existiert
|
|
|
|
|
|
|
|
if os.path.exists(app.config['DATABASE']):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.remove(app.config['DATABASE'])
|
|
|
|
|
|
|
|
logger.info(f"Alte Datenbank {app.config['DATABASE']} wurde gelöscht")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logger.error(f"Fehler beim Löschen der alten Datenbank: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Initialisiere die Datenbank
|
|
|
|
# Initialisiere die Datenbank
|
|
|
|
init_db()
|
|
|
|
init_db()
|
|
|
|
# Importiere die CSV-Daten
|
|
|
|
|
|
|
|
import_csv()
|
|
|
|
|
|
|
|
logger.info("Anwendung erfolgreich initialisiert")
|
|
|
|
logger.info("Anwendung erfolgreich initialisiert")
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Fehler bei der Initialisierung: {str(e)}")
|
|
|
|
logger.error(f"Fehler bei der Initialisierung: {str(e)}")
|
|
|
|