def __init__(self, options): super(Sniffer, self).__init__() self.parser_options = options self.plugins = {} self._status = False self._interface = self.parser_options.interface self._filter = self.parser_options.filter self.config = Settings()
from tornado.web import RequestHandler from tornado.gen import * import simplejson as json import jwt from config.config import Settings from api.core.user import UserHelper settings=Settings() class BaseHandler(RequestHandler): def __init__(self, application , request, **kwargs): super().__init__(application, request, **kwargs) self.jwt_options = { 'verify_signature': True, 'verify_exp': True, 'verify_nbf': False, 'verify_iat': True, 'verify_aud': False } self.db = self.settings['db'] self._uh = UserHelper(db=self.db) @coroutine def create_auth_token(self, id): print(settings.JwtAlgorithm) jwt_token = jwt.encode({"id": str(id)}, key=settings.CookieSecret, algorithm=settings.JwtAlgorithm) raise Return(jwt_token) @coroutine
try: from config.config import Settings except: from config import Settings #import sys; sys.exit() '''env_root = os.path.abspath(os.path.dirname(__file__)).rsplit('/', 3)[0] + os.sep print(os.path.abspath(os.path.dirname(__file__)).rsplit('/', 3)[0] + os.sep) # env = env_root + 'office.env' env = env_root + '.env' ''' env_root = os.path.abspath(os.path.dirname(__file__)).rsplit('/', 2)[0] + os.sep env = env_root + '.env' # print(f"env: {env}") config = Settings(_env_file=env, _env_file_encoding='utf-8') # Configure API key authorization: app_id configuration = swagger_client.Configuration() # configuration.host = 'http://192.168.7.249:8088/ari' # configuration.api_key['api_key'] = 'pbxuser:e07026d612c56a4ec8f62273ed366e48' configuration.host = config.URLARI configuration.api_key['api_key'] = config.API_KEY def create_channels_with_id(_phone, _channel_id): api_instance = swagger_client.ChannelsApi( swagger_client.ApiClient(configuration)) endpoint = 'PJSIP/' + str(_phone) channel_id = _channel_id # { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } } (optional)
import os import logging import connection.client_core import connection.server_core from config.config import Settings # change working dir to this directory os.chdir(os.path.dirname(os.path.abspath(__file__))) settings = Settings(str(os.path.join('config', 'config.ini'))) log_level = getattr(logging, settings.log_level) logging.basicConfig(level=log_level, handlers=[ logging.FileHandler('mini-mt.log', mode='w'), logging.StreamHandler() ]) if settings.is_server: logging.info('Starting Server') connection.server_core.main(settings) else: logging.info('Starting Client') connection.client_core.main(settings)
class Sniffer(Thread): def __init__(self, options): super(Sniffer, self).__init__() self.parser_options = options self.plugins = {} self._status = False self._interface = self.parser_options.interface self._filter = self.parser_options.filter self.config = Settings() def checkIface(self, iface): if (iface in netifaces.interfaces()): return True return False def getStatus(self): return self._status def setInterface(self, iface): self.config.setValue("interface", iface) self._interface = iface def getInterface(self): return self._interface def setStatus(self, status): self._status = status def getStringFilter(self): return self._filter def setStringfilter(self, value): self._filter = value def exit_no_ifacesfound(self): print('[!] interface not found!') sys.exit(0) def sniffer(self, q): while not self.getStatus(): try: sniff(iface=self.getInterface(), filter=self.getStringFilter(), prn=lambda x: q.put(x), store=0) except Exception: pass if self.getStatus(): break def run(self): if not self.checkIface(self.getInterface()): return self.exit_no_ifacesfound() self.all_plugins = base.BasePlugin.__subclasses__() for p in self.all_plugins: print('[-] plugin:: {} ativo '.format(p.getName())) self.plugins[p.getName()] = p() self.plugins[p.getName()].setActivated(True) q = queue.Queue() sniff = Thread(target=self.sniffer, args=(q, )) sniff.deamon = True sniff.start() self.setStatus(False) while not self.getStatus(): try: pkt = q.get(timeout=1) for plugin in list(self.plugins.keys()): if self.plugins[plugin].getActivated(): self.plugins[plugin].ParserPackets(pkt) except queue.Empty: pass def stop(self): self.setStatus(True)