# Path: beeswarm/shared/asciify.py
# def asciify(data):
#     if isinstance(data, list):
#         return _asciify_list(data)
#     elif isinstance(data, dict):
#         return _asciify_dict(data)
#     elif isinstance(data, unicode):
#         data = _remove_accents(data)
#         return data.encode('utf-8')
#     elif isinstance(data, str):
#         return data
#     else:
#         raise TypeError('Input must be dict, list, str or unicode')
# 
# Path: beeswarm/shared/message_enum.py
# class Messages(Enum):
#     STOP = 'STOP'
#     START = 'START'
#     CONFIG = 'CONFIG'
#     # dump of all configuration elements known to the sender
#     CONFIG_FULL = 'CONFIG_FULL'
#     # mapping between clients, honeypots, capabilities and bait users
#     CONFIG_ARCHITECTURE = 'CONFIG_ARCHITECTURE'
#     BROADCAST = 'BROADCAST'
# 
#     OK = 'OK'
#     FAIL = 'FAIL'
#     # KEY DRONE_ID DRONE_PRIVATE_KEY
#     KEY = 'KEY'
#     # CERT DRONE_ID DRONE_CERT
#     CERT = 'CERT'
# 
#     # All data on an entire session, this also indicates session end.
#     SESSION_HONEYPOT = 'SESSION_HONEYPOT'
#     # Network connect to a honeypot, data format is as in SESSION_HONEYPOT, but not all fields has data.
#     SESSION_PART_HONEYPOT_SESSION_START = 'SESSION_PART_HONEYPOT_SESSION_START'
#     # Authentication attempt, format is as in self.login_attempts list SESSION_HONEYPOT
#     SESSION_PART_HONEYPOT_AUTH = 'SESSION_PART_HONEYPOT_AUTH'
#     SESSION_CLIENT = 'SESSION_CLIENT'
# 
#     SET_CONFIG_ITEM = 'SET'
#     GET_CONFIG_ITEM = 'GET'
#     GET_ZMQ_KEYS = 'GET_ZMQ_KEYS'
#     DELETE_ZMQ_KEYS = 'DELETE_ZMQ_KEYS'
#     PING = 'PING'
#     PONG = 'PING'
#     IP = 'IP'
# 
#     DRONE_WANT_CONFIG = 'DRONE_WANT_CONFIG'
#     DRONE_CONFIG = 'DRONE_CONFIG'
#     # ID USERNAME PASSWORD
#     BAIT_USER_ADD = 'BAIT_USER_ADD'
#     BAIT_USER_DELETE = 'BAIT_USER_DELETE'
#     GET_BAIT_USERS = 'GET_BAIT_USERS'
#     DRONE_DELETE = 'DRONE_DELETE'
#     DRONE_ADD = 'DRONE_ADD'
# 
#     # Session was deleted because it was matched with an existing session
#     # This happens when a bait session is matched with a honeypot session.
#     # ID_OF_DELETED_SESSION ID_OF_THE_MERGED_SESSION
#     DELETED_DUE_TO_MERGE = "DELETED_DUE_TO_MERGE"
# 
#     # A classified session is transmitted
#     # Parameters is data in json.
#     SESSION = "SESSION"
# 
#     # Database requests
#     GET_DB_STATS = 'GET_DB_STATS'
#     # TODO: Following three should have to/from params to facilitate pagination
#     GET_SESSIONS_ALL = 'GET_SESSIONS_ALL'
#     GET_SESSIONS_BAIT = 'GET_SESSIONS_BAIT'
#     GET_SESSIONS_ATTACKS = 'GET_SESSIONS_ATTACKS'
# 
#     # Param: session id
#     GET_SESSION_TRANSCRIPT = 'GET_SESSION_TRANSCRIPT'
#     # Param: session id
#     GET_SESSION_CREDENTIALS = 'GET_SESSION_CREDENTIALS'
#     # Param dronetype
#     GET_DRONE_LIST = 'GET_DRONE_LIST'
#     # Param: clientId config
#     CONFIG_DRONE = 'CONFIG_DRONE'
# 
#     # Param: clientId config
#     PING_ALL_DRONES = 'PING_ALL_DRONES'


import urlparse
import os
import pwd
import grp
import platform
import logging
import json
import shutil
import sys
import sqlalchemy as sa
import netifaces
import zmq.green as zmq
import gevent
import requests
import beeswarm
import beeswarm.shared
from OpenSSL import crypto
from Crypto.PublicKey import RSA
from sqlalchemy.exc import ProgrammingError, OperationalError
from sqlalchemy.engine.url import make_url
from copy import copy
from beeswarm.shared.asciify import asciify
from beeswarm.shared.message_enum import Messages
        config_file.truncate(0)
        config_file.write(json.dumps(config, indent=4))


def get_config_dict(configfile):
    config = json.load(open(configfile, 'r'))
    return config


# for occasional req/resp
def send_zmq_request(actor_url, request):
    context = beeswarm.shared.zmq_context
    socket = context.socket(zmq.REQ)
    socket.connect(actor_url)
    socket.send(request)
    gevent.sleep()
    result = socket.recv()
    if result.split(' ', 1)[0] != Messages.OK.value:
        socket.close()
        assert False
    else:
        socket.close()
        return json.loads(result.split(' ', 1)[1])
    gevent.sleep()


def send_zmq_request_socket(socket, request):
    socket.send(request)
    result = socket.recv()
    status, data = result.split(' ', 1)

# Path: beeswarm/shared/asciify.py
# def asciify(data):
#     if isinstance(data, list):
#         return _asciify_list(data)
#     elif isinstance(data, dict):
#         return _asciify_dict(data)
#     elif isinstance(data, unicode):
#         data = _remove_accents(data)
#         return data.encode('utf-8')
#     elif isinstance(data, str):
#         return data
#     else:
#         raise TypeError('Input must be dict, list, str or unicode')
# 
# Path: beeswarm/shared/message_enum.py
# class Messages(Enum):
#     STOP = 'STOP'
#     START = 'START'
#     CONFIG = 'CONFIG'
#     # dump of all configuration elements known to the sender
#     CONFIG_FULL = 'CONFIG_FULL'
#     # mapping between clients, honeypots, capabilities and bait users
#     CONFIG_ARCHITECTURE = 'CONFIG_ARCHITECTURE'
#     BROADCAST = 'BROADCAST'
# 
#     OK = 'OK'
#     FAIL = 'FAIL'
#     # KEY DRONE_ID DRONE_PRIVATE_KEY
#     KEY = 'KEY'
#     # CERT DRONE_ID DRONE_CERT
#     CERT = 'CERT'
# 
#     # All data on an entire session, this also indicates session end.
#     SESSION_HONEYPOT = 'SESSION_HONEYPOT'
#     # Network connect to a honeypot, data format is as in SESSION_HONEYPOT, but not all fields has data.
#     SESSION_PART_HONEYPOT_SESSION_START = 'SESSION_PART_HONEYPOT_SESSION_START'
#     # Authentication attempt, format is as in self.login_attempts list SESSION_HONEYPOT
#     SESSION_PART_HONEYPOT_AUTH = 'SESSION_PART_HONEYPOT_AUTH'
#     SESSION_CLIENT = 'SESSION_CLIENT'
# 
#     SET_CONFIG_ITEM = 'SET'
#     GET_CONFIG_ITEM = 'GET'
#     GET_ZMQ_KEYS = 'GET_ZMQ_KEYS'
#     DELETE_ZMQ_KEYS = 'DELETE_ZMQ_KEYS'
#     PING = 'PING'
#     PONG = 'PING'
#     IP = 'IP'
# 
#     DRONE_WANT_CONFIG = 'DRONE_WANT_CONFIG'
#     DRONE_CONFIG = 'DRONE_CONFIG'
#     # ID USERNAME PASSWORD
#     BAIT_USER_ADD = 'BAIT_USER_ADD'
#     BAIT_USER_DELETE = 'BAIT_USER_DELETE'
#     GET_BAIT_USERS = 'GET_BAIT_USERS'
#     DRONE_DELETE = 'DRONE_DELETE'
#     DRONE_ADD = 'DRONE_ADD'
# 
#     # Session was deleted because it was matched with an existing session
#     # This happens when a bait session is matched with a honeypot session.
#     # ID_OF_DELETED_SESSION ID_OF_THE_MERGED_SESSION
#     DELETED_DUE_TO_MERGE = "DELETED_DUE_TO_MERGE"
# 
#     # A classified session is transmitted
#     # Parameters is data in json.
#     SESSION = "SESSION"
# 
#     # Database requests
#     GET_DB_STATS = 'GET_DB_STATS'
#     # TODO: Following three should have to/from params to facilitate pagination
#     GET_SESSIONS_ALL = 'GET_SESSIONS_ALL'
#     GET_SESSIONS_BAIT = 'GET_SESSIONS_BAIT'
#     GET_SESSIONS_ATTACKS = 'GET_SESSIONS_ATTACKS'
# 
#     # Param: session id
#     GET_SESSION_TRANSCRIPT = 'GET_SESSION_TRANSCRIPT'
#     # Param: session id
#     GET_SESSION_CREDENTIALS = 'GET_SESSION_CREDENTIALS'
#     # Param dronetype
#     GET_DRONE_LIST = 'GET_DRONE_LIST'
#     # Param: clientId config
#     CONFIG_DRONE = 'CONFIG_DRONE'
# 
#     # Param: clientId config
#     PING_ALL_DRONES = 'PING_ALL_DRONES'


# Path: beeswarm/shared/helpers.py
import urlparse
import os
import pwd
import grp
import platform
import logging
import json
import shutil
import sys
import sqlalchemy as sa
import netifaces
import zmq.green as zmq
import gevent
import requests
import beeswarm
import beeswarm.shared
from OpenSSL import crypto
from Crypto.PublicKey import RSA
from sqlalchemy.exc import ProgrammingError, OperationalError
from sqlalchemy.engine.url import make_url
from copy import copy
from beeswarm.shared.asciify import asciify
from beeswarm.shared.message_enum import Messages

        config_file.truncate(0)
        config_file.write(json.dumps(config, indent=4))


def get_config_dict(configfile):
    config = json.load(open(configfile, 'r'))
    return config


# for occasional req/resp
def send_zmq_request(actor_url, request):
    context = beeswarm.shared.zmq_context
    socket = context.socket(zmq.REQ)
    socket.connect(actor_url)
    socket.send(request)
    gevent.sleep()
    result = socket.recv()
    if result.split(' ', 1)[0] != Messages.OK.value:
        socket.close()
        assert False
    else:
        socket.close()
        return json.loads(result.split(' ', 1)[1])
    gevent.sleep()


def send_zmq_request_socket(socket, request):
    socket.send(request)
    result = socket.recv()
    status, data = result.split(' ', 1)

    if status != Messages.OK.value: