2024-07-01 12:56:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_HOME'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from update.bin.ail_updater import AIL_Updater
|
2024-09-03 14:54:24 +00:00
|
|
|
from lib import ail_orgs
|
2024-07-01 12:56:35 +00:00
|
|
|
from lib import ail_users
|
2024-08-27 13:48:11 +00:00
|
|
|
from lib import Investigations
|
2024-07-01 12:56:35 +00:00
|
|
|
from lib.ConfigLoader import ConfigLoader
|
2024-07-09 15:15:27 +00:00
|
|
|
from lib import chats_viewer
|
2024-08-28 14:47:44 +00:00
|
|
|
from lib import Tracker
|
2024-07-01 12:56:35 +00:00
|
|
|
|
|
|
|
class Updater(AIL_Updater):
|
|
|
|
"""default Updater."""
|
|
|
|
|
|
|
|
def __init__(self, version):
|
|
|
|
super(Updater, self).__init__(version)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
config_loader = ConfigLoader()
|
|
|
|
r_serv_db = config_loader.get_db_conn("Kvrocks_DB")
|
|
|
|
config_loader = None
|
|
|
|
date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
2024-08-27 13:48:11 +00:00
|
|
|
# USERS
|
|
|
|
print('Updating Users ...')
|
2024-09-03 14:54:24 +00:00
|
|
|
# Create Default Org
|
|
|
|
org = ail_orgs.create_default_org()
|
|
|
|
org_uuid = org.get_uuid()
|
|
|
|
|
2024-09-05 12:41:13 +00:00
|
|
|
for user_id in ail_users.get_users():
|
|
|
|
if ail_users.get_user_role(user_id) == 'analyst':
|
|
|
|
ail_users.set_user_role(user_id, 'user')
|
2024-09-03 14:54:24 +00:00
|
|
|
ail_users.edit_user('admin@admin.test', user_id, org_uuid=org_uuid)
|
2024-07-01 12:56:35 +00:00
|
|
|
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'creator', 'admin@admin.test')
|
|
|
|
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'created_at', date)
|
|
|
|
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'last_edit', date)
|
2024-09-05 12:41:13 +00:00
|
|
|
r_serv_db.srem(f'ail:users:role:analyst', user_id)
|
|
|
|
user_role = ail_users.get_user_role(user_id)
|
|
|
|
ail_users.set_user_role(user_id, user_role)
|
2024-09-03 14:54:24 +00:00
|
|
|
# ADD User to ORG
|
|
|
|
org.add_user(user_id)
|
2024-07-01 12:56:35 +00:00
|
|
|
|
2024-08-27 13:48:11 +00:00
|
|
|
# INVESTIGATIONS
|
|
|
|
print('Updating Investigations ...')
|
2024-09-03 14:54:24 +00:00
|
|
|
for inv_uuid in Investigations.get_all_investigations():
|
2024-08-27 13:48:11 +00:00
|
|
|
inv = Investigations.Investigation(inv_uuid)
|
|
|
|
inv.set_level(1, None)
|
2024-09-03 14:54:24 +00:00
|
|
|
inv._set_field('creator_org', org_uuid)
|
2024-08-27 13:48:11 +00:00
|
|
|
|
2024-09-03 14:54:24 +00:00
|
|
|
print('Updating Trackers ...')
|
|
|
|
for tracker_uuid in Tracker.get_trackers():
|
|
|
|
tracker = Tracker.Tracker(tracker_uuid)
|
|
|
|
tracker._set_field('creator_org', org_uuid)
|
2024-08-28 14:47:44 +00:00
|
|
|
|
|
|
|
print('Updating Retro Hunts ...')
|
2024-09-03 14:54:24 +00:00
|
|
|
for retro_hunt_uuid in Tracker.get_all_retro_hunt_tasks():
|
2024-08-28 14:47:44 +00:00
|
|
|
retro = Tracker.RetroHunt(retro_hunt_uuid)
|
|
|
|
retro.set_level(1, None)
|
2024-09-03 14:54:24 +00:00
|
|
|
retro._set_field('creator_org', org_uuid)
|
2024-08-28 14:47:44 +00:00
|
|
|
|
2024-07-09 15:15:27 +00:00
|
|
|
chats_viewer.fix_chats_with_messages()
|
|
|
|
|
2024-07-01 12:56:35 +00:00
|
|
|
updater = Updater('v5.7')
|
|
|
|
updater.run_update()
|
|
|
|
|