add: management scripts to ease database deployement and upgrade

This commit is contained in:
ziirish 2016-07-14 23:03:02 +02:00
parent 4a2ed7dee7
commit 11487b11e1
3 changed files with 71 additions and 0 deletions

3
bui-manage Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
python ./burpui -m manage $@

66
burpui/manage.py Normal file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
# Try to load modules from our current env first
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
from burpui import create_app
config = os.getenv('BUI_CONFIG')
app = create_app(config)
db = app.db
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def create_user(name, backend='BASIC', password=None):
print('[*] Adding \'{}\' user...'.format(name))
try:
handler = getattr(app, 'uhandler')
except AttributeError:
handler = None
if not handler or len(handler.backends) == 0:
print('No authentication backend found')
sys.exit(1)
back = None
for bck in handler.backends:
if bck.name == backend:
back = bck
if not back:
print('No authentication backend found')
sys.exit(1)
if back.add_user is False:
print("The '{}' backend does not support user creation".format(backend))
sys.exit(2)
if not password:
import random
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pw_length = 8
mypw = ""
for i in range(pw_length):
next_index = random.randrange(len(alphabet))
mypw += alphabet[next_index]
password = mypw
print('[+] Generated password: {}'.format(password))
success, _, _ = back.add_user(name, password)
print('[+] Success: {}'.format(success))
if __name__ == '__main__':
manager.run()

View file

@ -214,6 +214,7 @@ setup(
'burp-ui=burpui.__main__:server',
'bui-agent=burpui.__main__:agent',
'bui-celery=burpui.__main__:celery',
'bui-manage=burpui.__main__:manage',
],
},
data_files=[
@ -236,6 +237,7 @@ setup(
'dev': dev_requires,
'debian_wheezy': ['functools32'],
'celery': ['Celery', 'redis'],
'sql': ['Flask-SQLAlchemy', 'Flask-Migrate'],
},
tests_require=test_requires,
classifiers=[