mirror of
https://github.com/ziirish/burp-ui.git
synced 2026-05-21 06:45:24 -06:00
add: compat module with some tricks
This commit is contained in:
parent
87ad493293
commit
051b70cfde
11 changed files with 84 additions and 36 deletions
|
|
@ -87,11 +87,14 @@ def init(conf=None, debug=0, logfile=None, gunicorn=True, unittest=False):
|
|||
from .server import BUIServer as BurpUI
|
||||
from .routes import view
|
||||
from .api import api, apibp
|
||||
from ._compat import patch_json
|
||||
|
||||
if gunicorn:
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
patch_json()
|
||||
|
||||
# We initialize the core
|
||||
app = BurpUI()
|
||||
app.gunicorn = gunicorn
|
||||
|
|
@ -191,6 +194,8 @@ def init(conf=None, debug=0, logfile=None, gunicorn=True, unittest=False):
|
|||
'CACHE_REDIS_DB': 1
|
||||
}
|
||||
)
|
||||
# clear cache at startup in case we removed or added servers
|
||||
api.cache.clear()
|
||||
else:
|
||||
api.cache.init_app(app)
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ def server(options=None):
|
|||
|
||||
def agent(options=None):
|
||||
from burpui.agent import BUIAgent as Agent
|
||||
from burpui._compat import patch_json
|
||||
|
||||
patch_json()
|
||||
|
||||
if not options:
|
||||
options = parse_args(mode=False, name='bui-agent')
|
||||
|
|
|
|||
66
burpui/_compat.py
Normal file
66
burpui/_compat.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf8 -*-
|
||||
"""
|
||||
.. module:: burpui._compat
|
||||
:platform: Unix
|
||||
:synopsis: Burp-UI compatibility module.
|
||||
|
||||
.. moduleauthor:: Ziirish <ziirish@ziirish.info>
|
||||
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
|
||||
IS_GUNICORN = 'gunicorn' in os.environ.get('SERVER_SOFTWARE', '')
|
||||
|
||||
if IS_GUNICORN:
|
||||
from gevent.local import local
|
||||
else:
|
||||
local = object
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
PY3 = True
|
||||
else:
|
||||
PY3 = False
|
||||
|
||||
# maps module name -> attribute name -> original item
|
||||
# e.g. "time" -> "sleep" -> built-in function sleep
|
||||
saved = {}
|
||||
|
||||
|
||||
# Borrowed from gevent in order to patch json
|
||||
def patch_item(module, attr, newitem, newmodule=None):
|
||||
NONE = object()
|
||||
olditem = getattr(module, attr, NONE)
|
||||
if olditem is not NONE:
|
||||
saved.setdefault(module.__name__, {}).setdefault(attr, olditem)
|
||||
if newmodule:
|
||||
setattr(newmodule, 'ori_' + attr, olditem)
|
||||
setattr(module, attr, newitem)
|
||||
|
||||
|
||||
def patch_module(name, items=None):
|
||||
toimport = items or []
|
||||
replace_module = __import__('burpui._' + name, fromlist=toimport)
|
||||
module_name = name
|
||||
module = __import__(module_name)
|
||||
if items is None:
|
||||
items = getattr(replace_module, '__implements__', None)
|
||||
if items is None:
|
||||
raise AttributeError('%r does not have __implements__' % replace_module)
|
||||
for attr in items:
|
||||
patch_item(module, attr, getattr(replace_module, attr), replace_module)
|
||||
|
||||
|
||||
def patch_json():
|
||||
try:
|
||||
import ujson
|
||||
except ImportError:
|
||||
# ujson is not available, we won't patch anything
|
||||
return
|
||||
patch_module('json', ['dumps', 'loads'])
|
||||
|
|
@ -16,10 +16,6 @@ try:
|
|||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
try:
|
||||
import SocketServer
|
||||
except ImportError:
|
||||
|
|
@ -28,6 +24,7 @@ except ImportError:
|
|||
from logging.handlers import RotatingFileHandler
|
||||
from .exceptions import BUIserverException
|
||||
from .misc.backend.interface import BUIbackend
|
||||
from ._compat import ConfigParser
|
||||
|
||||
from Queue import Queue
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
# -*- coding: utf8 -*-
|
||||
from .interface import BUIacl, BUIaclLoader
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError: # pragma: no cover
|
||||
import configparser as ConfigParser
|
||||
import json
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
# -*- coding: utf8 -*-
|
||||
from .interface import BUIhandler, BUIuser
|
||||
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
|
||||
class BasicLoader:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf8 -*-
|
||||
from six import viewitems
|
||||
|
||||
from .interface import BUIhandler, BUIuser
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
import ssl
|
||||
|
||||
|
|
@ -9,12 +11,6 @@ try:
|
|||
except ImportError:
|
||||
raise ImportError('Unable to load \'ldap3\' module')
|
||||
|
||||
# python 3 compatibility
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
|
||||
|
||||
class LdapLoader:
|
||||
"""The :class:`burpui.misc.auth.ldap.LdapLoader` handles searching for and
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ try:
|
|||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError: # pragma: no cover
|
||||
import configparser as ConfigParser
|
||||
|
||||
from six import iteritems
|
||||
from pipes import quote
|
||||
|
|
@ -33,6 +29,7 @@ from .interface import BUIbackend
|
|||
from ..parser.burp1 import Parser
|
||||
from ...utils import human_readable as _hr, BUIcompress
|
||||
from ...exceptions import BUIserverException
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
if sys.version_info >= (3, 0): # pragma: no cover
|
||||
from urllib.parse import unquote
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ try:
|
|||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
|
||||
from six import iteritems
|
||||
from select import select
|
||||
|
|
@ -22,6 +18,7 @@ from .burp1 import Burp as Burp1
|
|||
from ..parser.burp2 import Parser
|
||||
from ...utils import human_readable as _hr
|
||||
from ...exceptions import BUIserverException
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
if sys.version_info < (3, 3):
|
||||
TimeoutError = OSError
|
||||
|
|
|
|||
|
|
@ -7,13 +7,10 @@
|
|||
.. moduleauthor:: Ziirish <ziirish@ziirish.info>
|
||||
|
||||
"""
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
from ...utils import BUIlogging
|
||||
from ..._compat import ConfigParser
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
|
|
|
|||
|
|
@ -7,15 +7,12 @@
|
|||
.. moduleauthor:: Ziirish <ziirish@ziirish.info>
|
||||
|
||||
"""
|
||||
try:
|
||||
import ConfigParser
|
||||
except ImportError:
|
||||
import configparser as ConfigParser
|
||||
import traceback
|
||||
import sys
|
||||
import os
|
||||
|
||||
from .misc.auth.handler import UserAuthHandler
|
||||
from ._compat import ConfigParser
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue