Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
import json
import datetime
from datetime import timedelta,date,datetime
engine = create_engine(app.config['DATABASE_URI_FK'],future=True)
class FCModel():
def __init__(self):
try:
self.meta = MetaData()
self.fc_sessions = Table("fc_sessions", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def getDataBysession_key(self,session_key,current_dt,conf_id,conf_key):
with engine.connect() as conn:
stmt = text("SELECT s.* from fc_sessions s where s.session_key = "+str(session_key)+ " and s.conf_id = "+ str(conf_id) + " and conf_key = '"+str(conf_key)+"' limit 1;")
result = conn.execute(stmt).fetchone()
if result :
return dict(result._mapping)
else:
return None
def insertFCScannedData1(self,session_id,delegate_no,del_table_name,fc_del_session_table_name,fc_session_entry_table_name,scan_system_name):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_save_fc_scanned_data",[session_id,delegate_no,del_table_name,fc_del_session_table_name,fc_session_entry_table_name,scan_system_name])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
#single result set store proc
def getFCReport(self,session_id,conf_id,conf_key,del_table_name,fc_session_entry_table_name,scan_system_name,role_wise_report):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_fc_reports",[session_id,conf_id,conf_key,del_table_name,fc_session_entry_table_name,scan_system_name,role_wise_report])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
# check session is open
def checkFCSessionIsOpen(self,session_id,current_dt):
with engine.connect() as conn:
stmt = text("select * from fc_sessions where session_id = "+str(session_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# call usp_get_kc_download_report(3,1,'fc_sessions_entry_selsi22','DELEGATE');
# GET SCANNED RECORDS FOR DOWNLOAD REPORT #single result set store proc
def getFcReportDownload(self,session_id,conf_id,fc_session_entry_table_name,role,del_table_name):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_fc_download_report",[session_id,conf_id,fc_session_entry_table_name,role,del_table_name])
# call usp_get_fc_download_report (30,2,'fc_sessions_entry_vrsi22','All', 'delegates_vrsi22')
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def insert_token_data(self,insert_stmt):
conn = engine.connect()
try:
stmt = text(insert_stmt)
results = conn.execute(stmt)
return "success"
except Exception as e:
conn.close()
return str(e)
# get completed sessions
def completedSessions(self,conf_id,current_dt_1):
with engine.connect() as conn:
stmt = text("SELECT s.* from fc_sessions s where s.conf_id = "+str(conf_id)+" and s.end_time < '"+current_dt_1+"' ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def getDataBysession_keyFrontEnd(self,session_key,current_dt,conf_id,conf_key):
with engine.connect() as conn:
stmt = text("SELECT s.* from fc_sessions s where s.session_key = "+str(session_key)+ " and s.conf_id = "+ str(conf_id) + " and conf_key = '"+str(conf_key)+"' and '"+current_dt+"' between s.start_time and s.end_time;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# view backup data start
#single result set store proc
def getFCReportbackup(self,session_id,conf_id,conf_key,del_table_name,fc_session_entry_table_name,system_wise_scan,scan_system_name,role_wise_report):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_fc_reports",[session_id,conf_id,conf_key,del_table_name,fc_session_entry_table_name,system_wise_scan,scan_system_name,role_wise_report])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists