mirror of
https://github.com/Pennyw0rth/NetExec
synced 2026-06-06 16:34:30 +00:00
add exist function to cmedb
This commit is contained in:
committed by
Marshall Hallenbeck
parent
5521037b24
commit
cb8d080dcf
@@ -425,6 +425,65 @@ class CMEDBMenu(cmd.Cmd):
|
||||
"""
|
||||
print_help(help_string)
|
||||
|
||||
def create_workspace(workspace_name, p_loader, protocols):
|
||||
os.mkdir(os.path.join(WORKSPACE_DIR, workspace_name))
|
||||
|
||||
for protocol in protocols.keys():
|
||||
try:
|
||||
protocol_object = p_loader.load_protocol(protocols[protocol]['dbpath'])
|
||||
except KeyError:
|
||||
continue
|
||||
proto_db_path = os.path.join(WORKSPACE_DIR, workspace_name, protocol + '.db')
|
||||
|
||||
if not os.path.exists(proto_db_path):
|
||||
print('[*] Initializing {} protocol database'.format(protocol.upper()))
|
||||
conn = sqlite3.connect(proto_db_path)
|
||||
c = conn.cursor()
|
||||
|
||||
# try to prevent some weird sqlite I/O errors
|
||||
c.execute('PRAGMA journal_mode = OFF')
|
||||
c.execute('PRAGMA foreign_keys = 1')
|
||||
|
||||
getattr(protocol_object, 'database').db_schema(c)
|
||||
|
||||
# commit the changes and close everything off
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def delete_workspace(workspace_name):
|
||||
shutil.rmtree(os.path.join(WORKSPACE_DIR, workspace_name))
|
||||
|
||||
|
||||
def create_workspace(workspace_name, p_loader, protocols):
|
||||
os.mkdir(os.path.join(WORKSPACE_DIR, workspace_name))
|
||||
|
||||
for protocol in protocols.keys():
|
||||
try:
|
||||
protocol_object = p_loader.load_protocol(protocols[protocol]['dbpath'])
|
||||
except KeyError:
|
||||
continue
|
||||
proto_db_path = os.path.join(WORKSPACE_DIR, workspace_name, protocol + '.db')
|
||||
|
||||
if not os.path.exists(proto_db_path):
|
||||
print('[*] Initializing {} protocol database'.format(protocol.upper()))
|
||||
conn = sqlite3.connect(proto_db_path)
|
||||
c = conn.cursor()
|
||||
|
||||
# try to prevent some weird sqlite I/O errors
|
||||
c.execute('PRAGMA journal_mode = OFF')
|
||||
c.execute('PRAGMA foreign_keys = 1')
|
||||
|
||||
getattr(protocol_object, 'database').db_schema(c)
|
||||
|
||||
# commit the changes and close everything off
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def delete_workspace(workspace_name):
|
||||
shutil.rmtree(os.path.join(WORKSPACE_DIR, workspace_name))
|
||||
|
||||
|
||||
def create_workspace(workspace_name, p_loader, protocols):
|
||||
os.mkdir(os.path.join(WORKSPACE_DIR, workspace_name))
|
||||
|
||||
Reference in New Issue
Block a user