mirror of
https://github.com/ziirish/burp-ui.git
synced 2026-05-15 14:16:08 -06:00
refactor tests to avoid having to setup a real burp server
This commit is contained in:
parent
2ede65fe85
commit
b08abb3b3a
27 changed files with 88 additions and 1363 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,6 +5,7 @@ burpui-dev.cfg*
|
|||
burpui/RELEASE
|
||||
devel.sh
|
||||
*.egg*
|
||||
.tox
|
||||
.coverage
|
||||
.coveragerc
|
||||
.pylintrc
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ stages:
|
|||
|
||||
test:lint:
|
||||
stage: test
|
||||
image: ziirish/python:2.7
|
||||
image: python:2.7
|
||||
script:
|
||||
- pip install flake8 pylint
|
||||
- make flake8
|
||||
|
|
@ -19,9 +19,10 @@ test:lint:
|
|||
|
||||
test:py2.7:
|
||||
stage: test
|
||||
image: ziirish/python:2.7
|
||||
image: python:2.7
|
||||
script:
|
||||
- /bin/bash tests/run_tests.sh
|
||||
- pip install tox
|
||||
- tox -e py27
|
||||
tags:
|
||||
- docker
|
||||
except:
|
||||
|
|
@ -29,9 +30,21 @@ test:py2.7:
|
|||
|
||||
test:py3.4:
|
||||
stage: test
|
||||
image: ziirish/python:3.4
|
||||
image: python:3.4
|
||||
script:
|
||||
- /bin/bash tests/run_tests.sh
|
||||
- pip install tox
|
||||
- tox -e py34
|
||||
tags:
|
||||
- docker
|
||||
except:
|
||||
- tags
|
||||
|
||||
test:py3.6:
|
||||
stage: test
|
||||
image: python:3.6
|
||||
script:
|
||||
- pip install tox
|
||||
- tox -e py34
|
||||
tags:
|
||||
- docker
|
||||
except:
|
||||
|
|
@ -53,7 +66,7 @@ build:py2:
|
|||
|
||||
build:py3:
|
||||
stage: build
|
||||
image: ziirish/python:3.4
|
||||
image: python:3.6
|
||||
script:
|
||||
- /bin/bash tests/run_build.sh
|
||||
tags:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ include CONTRIBUTORS
|
|||
include burpui/VERSION
|
||||
include burpui/RELEASE
|
||||
include requirements.txt
|
||||
include test-requirements.txt
|
||||
include share/burpui/etc/burpui.sample.cfg
|
||||
include babel.cfg
|
||||
graft contrib
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from ...utils import human_readable as _hr, BUIcompress, sanitize_string, \
|
|||
from ...exceptions import BUIserverException
|
||||
from ..._compat import unquote, PY3, to_unicode, to_bytes
|
||||
|
||||
if PY3:
|
||||
if PY3: # pragma: no cover
|
||||
from shlex import quote
|
||||
else:
|
||||
from pipes import quote
|
||||
|
|
@ -242,7 +242,7 @@ class Burp(BUIbackend):
|
|||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
try: # pragma: no cover
|
||||
cmd = [self.burpbin, '-a', 'l']
|
||||
if self.burpconfcli:
|
||||
cmd += ['-c', self.burpconfcli]
|
||||
|
|
|
|||
|
|
@ -43,4 +43,22 @@ To do so, run the following commands:
|
|||
git submodule update --init
|
||||
|
||||
|
||||
Before submitting your code, make sure the tests still run.
|
||||
To do that, you can use `tox <https://tox.readthedocs.io/en/latest/>`_ like
|
||||
this:
|
||||
|
||||
::
|
||||
|
||||
pip install tox
|
||||
tox
|
||||
|
||||
|
||||
By defaults, it will run tests against python 2.7, 3.4 and 3.6. However, you can
|
||||
choose the versions specifically like this:
|
||||
|
||||
::
|
||||
|
||||
tox -e py27
|
||||
|
||||
|
||||
.. _Burp-UI: https://git.ziirish.me/ziirish/burp-ui
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ provides-extra =
|
|||
agent
|
||||
celery
|
||||
limit
|
||||
ci
|
||||
requires-dist =
|
||||
ldap3; extra == 'ldap_authentication'
|
||||
gevent; extra in ['agent', 'gunicorn']
|
||||
|
|
|
|||
18
setup.py
18
setup.py
|
|
@ -210,10 +210,20 @@ url = __url__
|
|||
with open(os.path.join(ROOT, 'requirements.txt')) as f:
|
||||
requires = [x.strip() for x in f if x.strip()]
|
||||
|
||||
with open(os.path.join(ROOT, 'test-requirements.txt')) as f:
|
||||
test_requires = [x.strip() for x in f if x.strip()]
|
||||
|
||||
dev_requires = ['flake8', 'pylint']
|
||||
test_requires = [
|
||||
'Flask-Testing',
|
||||
'nose',
|
||||
'coverage',
|
||||
'mock',
|
||||
'mockredispy',
|
||||
'Flask-Session',
|
||||
'Celery',
|
||||
'redis',
|
||||
'Flask-SQLAlchemy',
|
||||
'Flask-Migrate',
|
||||
'sqlalchemy_utils',
|
||||
]
|
||||
|
||||
datadir = os.path.join('share', 'burpui')
|
||||
confdir = os.path.join(datadir, 'etc')
|
||||
|
|
@ -262,7 +272,7 @@ setup(
|
|||
'gunicorn': ['gevent', 'gunicorn'],
|
||||
'gunicorn-extra': ['redis', 'Flask-Session==0.3.0'],
|
||||
'agent': ['gevent'],
|
||||
'test': test_requires,
|
||||
'ci': test_requires,
|
||||
'dev': dev_requires,
|
||||
'debian_wheezy': ['functools32'],
|
||||
'celery': ['Celery', 'redis'],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Flask-Testing==0.5.0
|
||||
Flask-Testing
|
||||
nose
|
||||
coverage
|
||||
mock
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
# simple config for burp_ca
|
||||
|
||||
RANDFILE = /dev/urandom
|
||||
CA_DIR = @WORKING_DIR@/CA
|
||||
|
||||
|
||||
[ ca ]
|
||||
dir = $ENV::CA_DIR
|
||||
database = $dir/index.txt
|
||||
serial = $dir/serial.txt
|
||||
certs = $dir/certs
|
||||
new_certs_dir = $dir/newcerts
|
||||
crlnumber = $dir/crlnumber.txt
|
||||
|
||||
unique_subject = no
|
||||
|
||||
default_md = sha256
|
||||
default_days = 7300
|
||||
default_crl_days = 7300
|
||||
|
||||
#????
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
x509_extensions = usr_cert
|
||||
copy_extensions = copy
|
||||
policy = policy_anything
|
||||
|
||||
[ usr_cert ]
|
||||
basicConstraints = CA:FALSE
|
||||
|
||||
[ policy_anything ]
|
||||
commonName = supplied
|
||||
|
|
@ -1,208 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright: Patrick Koppen
|
||||
# License: GPLv3
|
||||
# Version: 1.2
|
||||
# Date: 29.12.2012
|
||||
|
||||
set -e
|
||||
|
||||
etc=/etc/burp
|
||||
dir=${etc}/CA
|
||||
conf=${etc}/CA.cnf
|
||||
|
||||
name=$(hostname -f)
|
||||
ca_days=7300
|
||||
size=2048
|
||||
|
||||
def_umask=022
|
||||
sec_umask=077
|
||||
|
||||
function help() {
|
||||
cat <<EOF
|
||||
$0: Help:
|
||||
-h|--help show help
|
||||
-i|--init inititalize CA
|
||||
-k|--key generate new key
|
||||
-K|--keypath <path> path to new key
|
||||
-r|--request generate certificate sign request
|
||||
-R|--requestpath <path> path to certificate sign request
|
||||
-s|--sign sign csr (use --ca <ca> and --name <name>)
|
||||
--batch do not prompt for anything
|
||||
--revoke <number> revoke certificate with serial number
|
||||
--crl generate certificate revoke list
|
||||
-d|--dir <dir> ca output dir (default: $dir)
|
||||
-c|--config config file (default: $conf)
|
||||
-n|--name name (default: $name)
|
||||
-D|--days valid days for certificate (default in config file)
|
||||
--ca_days valid days for CA certificate (default: $ca_days)
|
||||
-S|--size key size (default: $size)
|
||||
-a|--ca ca name if different from name
|
||||
-f|--dhfile <path> generate Diffie-Hellman file
|
||||
-A|--altname subjectAltName
|
||||
EOF
|
||||
}
|
||||
|
||||
check_second_arg()
|
||||
{
|
||||
if [ "$1" -eq 0 ] ; then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help) help; exit 0 ;;
|
||||
-i|--init) init=yes ;;
|
||||
-k|--key) key=yes ;;
|
||||
-K|--keypath) check_second_arg $#; keypath=$2; shift ;;
|
||||
-r|--request) request=yes ;;
|
||||
-R|--requestpath) check_second_arg $#; requestpath=$2; shift ;;
|
||||
-s|--sign) sign=yes ;;
|
||||
--batch) batch="-batch" ;;
|
||||
--revoke) check_second_arg $#; revoke=$2; shift ;;
|
||||
--crl) crl=yes ;;
|
||||
-d|--dir) check_second_arg $#; dir=$2; shift ;;
|
||||
-c|--config) check_second_arg $#; conf=$2; shift ;;
|
||||
-n|--name) check_second_arg $#; name=$2; shift ;;
|
||||
-D|--days) check_second_arg $#; days="-days $2"; shift ;;
|
||||
--ca_days) check_second_arg $#; ca_days=$2; shift ;;
|
||||
-S|--size) check_second_arg $#; size=$2; shift ;;
|
||||
-a|--ca) check_second_arg $#; ca=$2; shift ;;
|
||||
-f|--dhfile) check_second_arg $#; dhfile=$2; shift ;;
|
||||
-A|--altname) check_second_arg $#; altname=$2; shift ;;
|
||||
--) shift; break;;
|
||||
-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -n "$dhfile" ] ; then
|
||||
openssl dhparam -out "$dhfile" 1024
|
||||
r=$?
|
||||
chmod 600 "$dhfile"
|
||||
exit $r
|
||||
fi
|
||||
|
||||
if [ -z "$ca" ]; then
|
||||
ca=${name}
|
||||
fi
|
||||
|
||||
if [ -n "$altname" ]; then
|
||||
altname="subjectAltName=$altname"
|
||||
fi
|
||||
|
||||
# init CA
|
||||
if [ "$init" = "yes" ]; then
|
||||
echo "Init... ${ca}"
|
||||
if [ ! -f ${conf} ]; then
|
||||
echo "$0: error - config ${conf} missing" 1>&2; exit 1
|
||||
fi
|
||||
if [ -d ${dir} ]; then
|
||||
echo "$0: error - ${dir} exists, ca initialized" 1>&2; exit 1
|
||||
fi
|
||||
|
||||
mkdir ${dir}
|
||||
mkdir ${dir}/certs
|
||||
mkdir ${dir}/newcerts
|
||||
|
||||
umask ${sec_umask}
|
||||
openssl genrsa -out ${dir}/CA_${ca}.key ${size}
|
||||
umask ${def_umask}
|
||||
TEMP=$(mktemp /tmp/burp_ca.tmp.XXXXXXXX || echo /tmp/burp_ca.tmp.$$)
|
||||
cat <<-EOF > ${TEMP}
|
||||
RANDFILE = /dev/urandom
|
||||
|
||||
[ req ]
|
||||
distinguished_name = req_distinguished_name
|
||||
prompt = no
|
||||
|
||||
[ v3_ca ]
|
||||
basicConstraints=CA:true
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid,issuer:always
|
||||
|
||||
[ req_distinguished_name ]
|
||||
commonName = ${ca}
|
||||
EOF
|
||||
CA_DIR=${dir} openssl req -config ${TEMP} -new -x509 -days $ca_days \
|
||||
-key ${dir}/CA_${ca}.key -out ${dir}/CA_${ca}.crt -extensions v3_ca
|
||||
rm -f $TEMP
|
||||
|
||||
: > ${dir}/index.txt
|
||||
echo "00" > ${dir}/serial.txt
|
||||
echo "00" > ${dir}/crlnumber.txt
|
||||
|
||||
fi
|
||||
|
||||
[ -z "$keypath" ] && keypath=${dir}/${name}.key
|
||||
|
||||
# generate key
|
||||
if [ "$key" = "yes" ]; then
|
||||
echo "generating key ${name}: ${keypath}"
|
||||
umask ${sec_umask}
|
||||
openssl genrsa -out "${keypath}" ${size}
|
||||
umask ${def_umask}
|
||||
fi
|
||||
|
||||
# generate signing request
|
||||
[ -z "$requestpath" ] && requestpath=${dir}/${name}.csr
|
||||
if [ "$request" = "yes" ]; then
|
||||
echo "generating request ${name}"
|
||||
TEMP=$(mktemp /tmp/burp_ca.tmp.XXXXXXXX || echo /tmp/burp_ca.tmp.$$)
|
||||
cat <<-EOF > ${TEMP}
|
||||
RANDFILE = /dev/urandom
|
||||
req_extensions = v3_req
|
||||
|
||||
[ req ]
|
||||
distinguished_name = req_distinguished_name
|
||||
prompt = no
|
||||
|
||||
[ v3_req ]
|
||||
basicConstraints=CA:false
|
||||
$altname
|
||||
|
||||
[ req_distinguished_name ]
|
||||
commonName = ${name}
|
||||
|
||||
EOF
|
||||
openssl req -config ${TEMP} -new -key "${keypath}" \
|
||||
-out "${requestpath}" -extensions v3_req
|
||||
rm -f $TEMP
|
||||
fi
|
||||
|
||||
|
||||
# sign
|
||||
if [ "$sign" = "yes" ]; then
|
||||
serial=$(cat ${dir}/serial.txt)
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-in ${dir}/${name}.csr -out $dir/${name}.crt ${days} \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt \
|
||||
${batch}
|
||||
if [ ! -f ${dir}/newcerts/${serial}.pem ]; then
|
||||
exit 0
|
||||
fi
|
||||
mv ${dir}/newcerts/${serial}.pem ${dir}/certs/${serial}.pem
|
||||
#rehash the certificates
|
||||
for file in ${dir}/certs/*.pem; do ln -s -f $file ${dir}/certs/`openssl x509 -hash -noout -in $file`.0; done
|
||||
fi
|
||||
|
||||
#revoke
|
||||
if [ -n "$revoke" ]; then
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-revoke ${dir}/certs/${revoke}.pem \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt \
|
||||
${batch}
|
||||
fi
|
||||
|
||||
#crl
|
||||
if [ -n "$crl" ]; then
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-gencrl -out ${dir}/CA_${ca}.crl \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
# This is an example config file for the burp server.
|
||||
|
||||
mode = server
|
||||
port = 5071
|
||||
status_port = 5072
|
||||
directory = @WORKING_DIR@/spool
|
||||
clientconfdir = @WORKING_DIR@/config/clientconfdir
|
||||
pidfile = @WORKING_DIR@/config/burp.server.pid
|
||||
hardlinked_archive = 0
|
||||
working_dir_recovery_method = delete
|
||||
max_children = 5
|
||||
max_status_children = 5
|
||||
umask = 0022
|
||||
syslog = 0
|
||||
stdout = 1
|
||||
# The following options can restrict what the client can do.
|
||||
# Note that restore_clients will still be able to do all of these operations,
|
||||
# except for force_backup.
|
||||
client_can_delete = 1
|
||||
# Set client_can_force_backup to 0 to only allow timed backups.
|
||||
client_can_force_backup = 1
|
||||
client_can_list = 1
|
||||
# Set client_can_restore to 0 if you want restores to only be initialised by
|
||||
# the server.
|
||||
client_can_restore = 1
|
||||
client_can_verify = 1
|
||||
# Ratelimit throttles the send speed. Specified in Megabits per second (Mb/s).
|
||||
# ratelimit = 1.5
|
||||
# Network timeout defaults to 7200 seconds (2 hours).
|
||||
# network_timeout = 7200
|
||||
|
||||
# When the client version does not match the server version, log a warning.
|
||||
# Set to 0 to turn it off.
|
||||
version_warn = 1
|
||||
|
||||
# More configuration files can be read, using syntax like the following
|
||||
# (without the leading '# ').
|
||||
# . path/to/more/conf
|
||||
|
||||
# Location of autoupgrade files to serve to clients. Leave it commented out
|
||||
# to not autoupgrade clients.
|
||||
# autoupgrade_dir = /etc/burp/autoupgrade/server
|
||||
|
||||
# You can have as many 'keep' lines as you like.
|
||||
# For example, if running backups daily, setting 7, 4, 6 will keep
|
||||
# 7 daily backups, 4 weekly, and 6 four-weekly backups.
|
||||
keep = 7
|
||||
# keep = 4
|
||||
# keep = 6
|
||||
|
||||
# Run as different user/group.
|
||||
# user=graham
|
||||
# group=nogroup
|
||||
|
||||
# CA options.
|
||||
# If you want your server to be a certificate authority and generate its own
|
||||
# certificates, uncomment the following lines. If the directory specified in
|
||||
# ca_conf does not exist, the server will create, populate it, and the paths
|
||||
# indicated by ssl_cert_ca, ssl_cert, ssl_key and ssl_dhfile below will be
|
||||
# overwritten. See docs/burp_ca.txt for more information.
|
||||
ca_conf = @WORKING_DIR@/config/CA/CA.cnf
|
||||
ca_name = burpCA
|
||||
ca_server_name = burpserver
|
||||
ca_burp_ca = @WORKING_DIR@/config/CA/burp_ca
|
||||
|
||||
# SSL certificate authority - same file on both server and client
|
||||
ssl_cert_ca = @WORKING_DIR@/config/ssl_cert_ca.pem
|
||||
|
||||
# Server SSL certificate
|
||||
ssl_cert = @WORKING_DIR@/config/ssl_cert-server.pem
|
||||
|
||||
# Server SSL key
|
||||
ssl_key = @WORKING_DIR@/config/ssl_cert-server.key
|
||||
|
||||
# Server SSL ciphers
|
||||
#ssl_ciphers =
|
||||
|
||||
# SSL key password
|
||||
ssl_key_password = password
|
||||
|
||||
# Server DH file.
|
||||
ssl_dhfile = @WORKING_DIR@/config/dhfile.pem
|
||||
|
||||
timer_script = @WORKING_DIR@/config/timer_script
|
||||
# Ensure that 20 hours elapse between backups
|
||||
# Available units:
|
||||
# s (seconds), m (minutes), h (hours), d (days), w (weeks), n (months)
|
||||
timer_arg = 20h
|
||||
# Allow backups to start in the evenings and nights during weekdays
|
||||
timer_arg = Mon,Tue,Wed,Thu,Fri,00,01,02,03,04,05,19,20,21,22,23
|
||||
# Allow more hours at the weekend.
|
||||
timer_arg = Sat,Sun,00,01,02,03,04,05,06,07,08,17,18,19,20,21,22,23
|
||||
# Note that, if you specify no timebands, the default timer script will never
|
||||
# allow backups.
|
||||
|
||||
# Uncomment the notify_success_* lines for email notifications of backups that
|
||||
# succeeded.
|
||||
# In the subject line, the following are substituted:
|
||||
# %b - "backup"/"restore"/"verify"
|
||||
# %c - client name
|
||||
# %w - number of warnings, if any
|
||||
#notify_success_script = /etc/burp/notify_script
|
||||
#notify_success_arg = sendmail -t
|
||||
#notify_success_arg = To: youremail@example.com
|
||||
#notify_success_arg = From: burp
|
||||
#notify_success_arg = Subject: %b succeeded: %c %w
|
||||
# Uncomment the following to have success notifications only if there were
|
||||
# warnings.
|
||||
#notify_success_warnings_only = 1
|
||||
# Uncomment the following to have success notifications only if there were
|
||||
# new or changed files.
|
||||
#notify_success_changes_only = 1
|
||||
|
||||
# Uncomment the following for email notifications of backups that failed.
|
||||
#notify_failure_script = /etc/burp/notify_script
|
||||
#notify_failure_arg = sendmail -t
|
||||
#notify_failure_arg = To: youremail@example.com
|
||||
#notify_failure_arg = From: burp
|
||||
#notify_failure_arg = Subject: %b failed: %c %w
|
||||
|
||||
# The server can run scripts on each connection after authentication and before
|
||||
# disconnecting.
|
||||
#server_script_pre = /etc/burp/ssl_extra_checks_script
|
||||
#server_script_pre_arg = /etc/burp/crl
|
||||
#server_script_pre_arg = /etc/burp/burp-server.conf
|
||||
#server_script_pre_arg = /etc/burp/server-pre-script.local
|
||||
# Set server_script_pre_notify to 1 to have notifications on server_script_pre
|
||||
# returning non-zero. Most people will want to leave this off - it could
|
||||
# result in a lot of emails because clients normally connect once every 20
|
||||
# minutes. Requires notify_failure_script to be set above.
|
||||
#server_script_pre_notify = 0
|
||||
#server_script_post =
|
||||
#server_script_post_arg =
|
||||
#server_script_post_arg =
|
||||
#server_script_post_run_on_fail=0
|
||||
# As for server_script_pre_notify, but for post.
|
||||
#server_script_post_notify = 0
|
||||
|
||||
# Clients that are able to list and restore files belonging to any other
|
||||
# client. If this is too permissive, you may set a restore_client for
|
||||
# individual original clients in the individual clientconfdir files.
|
||||
# restore_client = someclient
|
||||
# restore_client = someotherclient
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# If you add at least one 'include=' line, the server will override the
|
||||
# rest of the client options below, which define exactly what to backup.
|
||||
# Setting any of the other options here will then also take effect on the
|
||||
# client.
|
||||
# (This file needs to be included in the clientconfdir file for the client,
|
||||
# using the '. path/to/this/file' syntax. Alternatively, these options can
|
||||
# be added to the clientconfdir file directly).
|
||||
|
||||
# include=/home
|
||||
# exclude=/home/dontwant
|
||||
# exclude_ext=vdi
|
||||
# exclude_regex=/\.cache/
|
||||
# exclude_fs=tmpfs
|
||||
# exclude_comp=gz
|
||||
# min_file_size=0
|
||||
# max_file_size=0
|
||||
# cross_filesystem=/some/path
|
||||
# cross_all_filesystems=0
|
||||
# nobackup=.nobackup
|
||||
# read_fifo=/some/path/to/a/fifo
|
||||
# read_all_fifos=0
|
||||
# split_vss=1
|
||||
# strip_vss=0
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
password = abcdefgh
|
||||
|
||||
# More configuration files can be read, using syntax like the following
|
||||
# (without the leading '# ').
|
||||
. incexc/example
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script that determines whether it is time to run a backup.
|
||||
|
||||
echo "Running timer script: $@"
|
||||
|
||||
client="$1" ; shift
|
||||
current="$1" ; shift
|
||||
storage_dir="$1" ; shift
|
||||
reserved1="$1" ; shift
|
||||
reserved2="$1" ; shift
|
||||
interval="$1" ; shift
|
||||
timestamp="$current/timestamp"
|
||||
|
||||
# A 'backup' file placed in the storage directory tells this script that
|
||||
# a backup needs to be done right now.
|
||||
# This gives the 'server initiates a manual backup' feature.
|
||||
|
||||
manual_file="$storage_dir/$client/backup"
|
||||
if [ -f "$manual_file" ] ; then
|
||||
echo "Found $manual_file"
|
||||
echo "Do a backup of $client now"
|
||||
rm -f "$manual_file"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# The rest of the arguments, if any, should be timebands.
|
||||
# Set LANG=C and LC_TIME=C so that 'date' returns English day names.
|
||||
curdayhour=$(LANG=C LC_TIME=C date +"*%a*%H*")
|
||||
intimeband=0 # If no timebands given, default to not OK.
|
||||
while [ "$#" -gt 0 ] ; do
|
||||
intimeband=0
|
||||
timeband="$1"
|
||||
case "$timeband" in
|
||||
$curdayhour)
|
||||
echo "In timeband: $timeband"
|
||||
intimeband=1
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Out of timeband: $timeband"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
get_intervals()
|
||||
{
|
||||
if [ ! -e "$current" ] ; then
|
||||
echo "No prior backup of $client"
|
||||
return 0
|
||||
fi
|
||||
if [ ! -f "$timestamp" ] ; then
|
||||
echo "$0: Timestamp file missing for $client."
|
||||
return 0
|
||||
fi
|
||||
if [ -z "$interval" ] ; then
|
||||
echo "$0: No time interval given for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "$interval" in
|
||||
[0-9]*s) i=${interval%s*} ; intervalsecs=$i ;;
|
||||
[0-9]*m) i=${interval%m*} ; intervalsecs=$((i*60)) ;;
|
||||
[0-9]*h) i=${interval%h*} ; intervalsecs=$((i*60*60)) ;;
|
||||
[0-9]*d) i=${interval%d*} ; intervalsecs=$((i*60*60*24)) ;;
|
||||
[0-9]*w) i=${interval%w*} ; intervalsecs=$((i*60*60*24*7)) ;;
|
||||
[0-9]*n) i=${interval%n*} ; intervalsecs=$((i*60*60*24*7*30)) ;;
|
||||
*) echo "$0: interval $interval not understood for $client."
|
||||
return 0 ;;
|
||||
esac
|
||||
|
||||
if [ -z "$intervalsecs" ] ; then
|
||||
echo "$0: interval $interval not understood for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
read junk ts < "$timestamp"
|
||||
|
||||
if ! secs=$(LANG=C LC_TIME=C date +%s -d "$ts") \
|
||||
|| ! now=$(LANG=C LC_TIME=C date +"%Y-%m-%d %H:%M:%S") \
|
||||
|| ! nowsecs=$(LANG=C LC_TIME=C date +%s -d "$now")
|
||||
then
|
||||
echo "$0: Date command returned error for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
min_timesecs=$((secs+intervalsecs))
|
||||
|
||||
# GNU coreutils 'date' command should accept the following (even
|
||||
# slightly old versions).
|
||||
if ! min_time=$(LANG=C LC_TIME=C date -d "Jan 1, 1970 00:00:00 +0000 + $min_timesecs seconds" +"%Y-%m-%d %H:%M:%S")
|
||||
then
|
||||
# FreeBSD 'date' will return an error with the above, so try
|
||||
# a version that FreeBSD 'date' should be happy with.
|
||||
if ! min_time=$(LANG=C LC_TIME=C date -r $min_timesecs +"%Y-%m-%d %H:%M:%S")
|
||||
then
|
||||
echo "$0: Date command returned error for $client."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Last backup: $ts"
|
||||
echo "Next after : $min_time (interval $interval)"
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "$intimeband" = "0" ] ; then
|
||||
get_intervals
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if get_intervals ; then
|
||||
echo "Do a backup of $client now."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$min_timesecs" -lt "$nowsecs" ] ; then
|
||||
echo "$min_time < $now."
|
||||
echo "Do a backup of $client now."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Not yet time for a backup of $client"
|
||||
|
||||
exit 1
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
# simple config for burp_ca
|
||||
|
||||
RANDFILE = /dev/urandom
|
||||
CA_DIR = @WORKING_DIR@/CA
|
||||
|
||||
|
||||
[ ca ]
|
||||
dir = $ENV::CA_DIR
|
||||
database = $dir/index.txt
|
||||
serial = $dir/serial.txt
|
||||
certs = $dir/certs
|
||||
new_certs_dir = $dir/newcerts
|
||||
crlnumber = $dir/crlnumber.txt
|
||||
|
||||
unique_subject = no
|
||||
|
||||
default_md = sha256
|
||||
default_days = 7300
|
||||
default_crl_days = 7300
|
||||
|
||||
#????
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
x509_extensions = usr_cert
|
||||
copy_extensions = copy
|
||||
policy = policy_anything
|
||||
|
||||
[ usr_cert ]
|
||||
basicConstraints = CA:FALSE
|
||||
|
||||
[ policy_anything ]
|
||||
commonName = supplied
|
||||
|
|
@ -1,208 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright: Patrick Koppen
|
||||
# License: GPLv3
|
||||
# Version: 1.2
|
||||
# Date: 29.12.2012
|
||||
|
||||
set -e
|
||||
|
||||
etc=/etc/burp
|
||||
dir=${etc}/CA
|
||||
conf=${etc}/CA.cnf
|
||||
|
||||
name=$(hostname -f)
|
||||
ca_days=7300
|
||||
size=2048
|
||||
|
||||
def_umask=022
|
||||
sec_umask=077
|
||||
|
||||
function help() {
|
||||
cat <<EOF
|
||||
$0: Help:
|
||||
-h|--help show help
|
||||
-i|--init inititalize CA
|
||||
-k|--key generate new key
|
||||
-K|--keypath <path> path to new key
|
||||
-r|--request generate certificate sign request
|
||||
-R|--requestpath <path> path to certificate sign request
|
||||
-s|--sign sign csr (use --ca <ca> and --name <name>)
|
||||
--batch do not prompt for anything
|
||||
--revoke <number> revoke certificate with serial number
|
||||
--crl generate certificate revoke list
|
||||
-d|--dir <dir> ca output dir (default: $dir)
|
||||
-c|--config config file (default: $conf)
|
||||
-n|--name name (default: $name)
|
||||
-D|--days valid days for certificate (default in config file)
|
||||
--ca_days valid days for CA certificate (default: $ca_days)
|
||||
-S|--size key size (default: $size)
|
||||
-a|--ca ca name if different from name
|
||||
-f|--dhfile <path> generate Diffie-Hellman file
|
||||
-A|--altname subjectAltName
|
||||
EOF
|
||||
}
|
||||
|
||||
check_second_arg()
|
||||
{
|
||||
if [ "$1" -eq 0 ] ; then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help) help; exit 0 ;;
|
||||
-i|--init) init=yes ;;
|
||||
-k|--key) key=yes ;;
|
||||
-K|--keypath) check_second_arg $#; keypath=$2; shift ;;
|
||||
-r|--request) request=yes ;;
|
||||
-R|--requestpath) check_second_arg $#; requestpath=$2; shift ;;
|
||||
-s|--sign) sign=yes ;;
|
||||
--batch) batch="-batch" ;;
|
||||
--revoke) check_second_arg $#; revoke=$2; shift ;;
|
||||
--crl) crl=yes ;;
|
||||
-d|--dir) check_second_arg $#; dir=$2; shift ;;
|
||||
-c|--config) check_second_arg $#; conf=$2; shift ;;
|
||||
-n|--name) check_second_arg $#; name=$2; shift ;;
|
||||
-D|--days) check_second_arg $#; days="-days $2"; shift ;;
|
||||
--ca_days) check_second_arg $#; ca_days=$2; shift ;;
|
||||
-S|--size) check_second_arg $#; size=$2; shift ;;
|
||||
-a|--ca) check_second_arg $#; ca=$2; shift ;;
|
||||
-f|--dhfile) check_second_arg $#; dhfile=$2; shift ;;
|
||||
-A|--altname) check_second_arg $#; altname=$2; shift ;;
|
||||
--) shift; break;;
|
||||
-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -n "$dhfile" ] ; then
|
||||
openssl dhparam -out "$dhfile" 1024
|
||||
r=$?
|
||||
chmod 600 "$dhfile"
|
||||
exit $r
|
||||
fi
|
||||
|
||||
if [ -z "$ca" ]; then
|
||||
ca=${name}
|
||||
fi
|
||||
|
||||
if [ -n "$altname" ]; then
|
||||
altname="subjectAltName=$altname"
|
||||
fi
|
||||
|
||||
# init CA
|
||||
if [ "$init" = "yes" ]; then
|
||||
echo "Init... ${ca}"
|
||||
if [ ! -f ${conf} ]; then
|
||||
echo "$0: error - config ${conf} missing" 1>&2; exit 1
|
||||
fi
|
||||
if [ -d ${dir} ]; then
|
||||
echo "$0: error - ${dir} exists, ca initialized" 1>&2; exit 1
|
||||
fi
|
||||
|
||||
mkdir ${dir}
|
||||
mkdir ${dir}/certs
|
||||
mkdir ${dir}/newcerts
|
||||
|
||||
umask ${sec_umask}
|
||||
openssl genrsa -out ${dir}/CA_${ca}.key ${size}
|
||||
umask ${def_umask}
|
||||
TEMP=$(mktemp /tmp/burp_ca.tmp.XXXXXXXX || echo /tmp/burp_ca.tmp.$$)
|
||||
cat <<-EOF > ${TEMP}
|
||||
RANDFILE = /dev/urandom
|
||||
|
||||
[ req ]
|
||||
distinguished_name = req_distinguished_name
|
||||
prompt = no
|
||||
|
||||
[ v3_ca ]
|
||||
basicConstraints=CA:true
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid,issuer:always
|
||||
|
||||
[ req_distinguished_name ]
|
||||
commonName = ${ca}
|
||||
EOF
|
||||
CA_DIR=${dir} openssl req -config ${TEMP} -new -x509 -days $ca_days \
|
||||
-key ${dir}/CA_${ca}.key -out ${dir}/CA_${ca}.crt -extensions v3_ca
|
||||
rm -f $TEMP
|
||||
|
||||
: > ${dir}/index.txt
|
||||
echo "00" > ${dir}/serial.txt
|
||||
echo "00" > ${dir}/crlnumber.txt
|
||||
|
||||
fi
|
||||
|
||||
[ -z "$keypath" ] && keypath=${dir}/${name}.key
|
||||
|
||||
# generate key
|
||||
if [ "$key" = "yes" ]; then
|
||||
echo "generating key ${name}: ${keypath}"
|
||||
umask ${sec_umask}
|
||||
openssl genrsa -out "${keypath}" ${size}
|
||||
umask ${def_umask}
|
||||
fi
|
||||
|
||||
# generate signing request
|
||||
[ -z "$requestpath" ] && requestpath=${dir}/${name}.csr
|
||||
if [ "$request" = "yes" ]; then
|
||||
echo "generating request ${name}"
|
||||
TEMP=$(mktemp /tmp/burp_ca.tmp.XXXXXXXX || echo /tmp/burp_ca.tmp.$$)
|
||||
cat <<-EOF > ${TEMP}
|
||||
RANDFILE = /dev/urandom
|
||||
req_extensions = v3_req
|
||||
|
||||
[ req ]
|
||||
distinguished_name = req_distinguished_name
|
||||
prompt = no
|
||||
|
||||
[ v3_req ]
|
||||
basicConstraints=CA:false
|
||||
$altname
|
||||
|
||||
[ req_distinguished_name ]
|
||||
commonName = ${name}
|
||||
|
||||
EOF
|
||||
openssl req -config ${TEMP} -new -key "${keypath}" \
|
||||
-out "${requestpath}" -extensions v3_req
|
||||
rm -f $TEMP
|
||||
fi
|
||||
|
||||
|
||||
# sign
|
||||
if [ "$sign" = "yes" ]; then
|
||||
serial=$(cat ${dir}/serial.txt)
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-in ${dir}/${name}.csr -out $dir/${name}.crt ${days} \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt \
|
||||
${batch}
|
||||
if [ ! -f ${dir}/newcerts/${serial}.pem ]; then
|
||||
exit 0
|
||||
fi
|
||||
mv ${dir}/newcerts/${serial}.pem ${dir}/certs/${serial}.pem
|
||||
#rehash the certificates
|
||||
for file in ${dir}/certs/*.pem; do ln -s -f $file ${dir}/certs/`openssl x509 -hash -noout -in $file`.0; done
|
||||
fi
|
||||
|
||||
#revoke
|
||||
if [ -n "$revoke" ]; then
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-revoke ${dir}/certs/${revoke}.pem \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt \
|
||||
${batch}
|
||||
fi
|
||||
|
||||
#crl
|
||||
if [ -n "$crl" ]; then
|
||||
CA_DIR=${dir} openssl ca -config ${conf} -name ca \
|
||||
-gencrl -out ${dir}/CA_${ca}.crl \
|
||||
-keyfile ${dir}/CA_${ca}.key -cert ${dir}/CA_${ca}.crt
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
# This is an example config file for the burp server.
|
||||
|
||||
mode = server
|
||||
port = 4973
|
||||
status_port = 4974
|
||||
directory = @WORKING_DIR@/spool
|
||||
clientconfdir = @WORKING_DIR@/config/clientconfdir
|
||||
pidfile = @WORKING_DIR@/config/burp.server.pid
|
||||
hardlinked_archive = 0
|
||||
working_dir_recovery_method = delete
|
||||
max_children = 5
|
||||
max_status_children = 5
|
||||
umask = 0022
|
||||
syslog = 0
|
||||
stdout = 1
|
||||
# The following options can restrict what the client can do.
|
||||
# Note that restore_clients will still be able to do all of these operations,
|
||||
# except for force_backup.
|
||||
client_can_delete = 1
|
||||
# Set client_can_force_backup to 0 to only allow timed backups.
|
||||
client_can_force_backup = 1
|
||||
client_can_list = 1
|
||||
# Set client_can_restore to 0 if you want restores to only be initialised by
|
||||
# the server.
|
||||
client_can_restore = 1
|
||||
client_can_verify = 1
|
||||
# Ratelimit throttles the send speed. Specified in Megabits per second (Mb/s).
|
||||
# ratelimit = 1.5
|
||||
# Network timeout defaults to 7200 seconds (2 hours).
|
||||
# network_timeout = 7200
|
||||
|
||||
# When the client version does not match the server version, log a warning.
|
||||
# Set to 0 to turn it off.
|
||||
version_warn = 1
|
||||
|
||||
# More configuration files can be read, using syntax like the following
|
||||
# (without the leading '# ').
|
||||
# . path/to/more/conf
|
||||
|
||||
# Location of autoupgrade files to serve to clients. Leave it commented out
|
||||
# to not autoupgrade clients.
|
||||
# autoupgrade_dir = /etc/burp/autoupgrade/server
|
||||
|
||||
# You can have as many 'keep' lines as you like.
|
||||
# For example, if running backups daily, setting 7, 4, 6 will keep
|
||||
# 7 daily backups, 4 weekly, and 6 four-weekly backups.
|
||||
keep = 7
|
||||
# keep = 4
|
||||
# keep = 6
|
||||
|
||||
# Run as different user/group.
|
||||
# user=graham
|
||||
# group=nogroup
|
||||
|
||||
# CA options.
|
||||
# If you want your server to be a certificate authority and generate its own
|
||||
# certificates, uncomment the following lines. If the directory specified in
|
||||
# ca_conf does not exist, the server will create, populate it, and the paths
|
||||
# indicated by ssl_cert_ca, ssl_cert, ssl_key and ssl_dhfile below will be
|
||||
# overwritten. See docs/burp_ca.txt for more information.
|
||||
ca_conf = @WORKING_DIR@/config/CA/CA.cnf
|
||||
ca_name = burpCA
|
||||
ca_server_name = burpserver
|
||||
ca_burp_ca = @WORKING_DIR@/config/CA/burp_ca
|
||||
|
||||
# SSL certificate authority - same file on both server and client
|
||||
ssl_cert_ca = @WORKING_DIR@/config/ssl_cert_ca.pem
|
||||
|
||||
# Server SSL certificate
|
||||
ssl_cert = @WORKING_DIR@/config/ssl_cert-server.pem
|
||||
|
||||
# Server SSL key
|
||||
ssl_key = @WORKING_DIR@/config/ssl_cert-server.key
|
||||
|
||||
# Server SSL ciphers
|
||||
#ssl_ciphers =
|
||||
|
||||
# SSL key password
|
||||
ssl_key_password = password
|
||||
|
||||
# Server DH file.
|
||||
ssl_dhfile = @WORKING_DIR@/config/dhfile.pem
|
||||
|
||||
timer_script = @WORKING_DIR@/config/timer_script
|
||||
# Ensure that 20 hours elapse between backups
|
||||
# Available units:
|
||||
# s (seconds), m (minutes), h (hours), d (days), w (weeks), n (months)
|
||||
timer_arg = 20h
|
||||
# Allow backups to start in the evenings and nights during weekdays
|
||||
timer_arg = Mon,Tue,Wed,Thu,Fri,00,01,02,03,04,05,19,20,21,22,23
|
||||
# Allow more hours at the weekend.
|
||||
timer_arg = Sat,Sun,00,01,02,03,04,05,06,07,08,17,18,19,20,21,22,23
|
||||
# Note that, if you specify no timebands, the default timer script will never
|
||||
# allow backups.
|
||||
|
||||
# Uncomment the notify_success_* lines for email notifications of backups that
|
||||
# succeeded.
|
||||
# In the subject line, the following are substituted:
|
||||
# %b - "backup"/"restore"/"verify"
|
||||
# %c - client name
|
||||
# %w - number of warnings, if any
|
||||
#notify_success_script = /etc/burp/notify_script
|
||||
#notify_success_arg = sendmail -t
|
||||
#notify_success_arg = To: youremail@example.com
|
||||
#notify_success_arg = From: burp
|
||||
#notify_success_arg = Subject: %b succeeded: %c %w
|
||||
# Uncomment the following to have success notifications only if there were
|
||||
# warnings.
|
||||
#notify_success_warnings_only = 1
|
||||
# Uncomment the following to have success notifications only if there were
|
||||
# new or changed files.
|
||||
#notify_success_changes_only = 1
|
||||
|
||||
# Uncomment the following for email notifications of backups that failed.
|
||||
#notify_failure_script = /etc/burp/notify_script
|
||||
#notify_failure_arg = sendmail -t
|
||||
#notify_failure_arg = To: youremail@example.com
|
||||
#notify_failure_arg = From: burp
|
||||
#notify_failure_arg = Subject: %b failed: %c %w
|
||||
|
||||
# The server can run scripts on each connection after authentication and before
|
||||
# disconnecting.
|
||||
#server_script_pre = /etc/burp/ssl_extra_checks_script
|
||||
#server_script_pre_arg = /etc/burp/crl
|
||||
#server_script_pre_arg = /etc/burp/burp-server.conf
|
||||
#server_script_pre_arg = /etc/burp/server-pre-script.local
|
||||
# Set server_script_pre_notify to 1 to have notifications on server_script_pre
|
||||
# returning non-zero. Most people will want to leave this off - it could
|
||||
# result in a lot of emails because clients normally connect once every 20
|
||||
# minutes. Requires notify_failure_script to be set above.
|
||||
#server_script_pre_notify = 0
|
||||
#server_script_post =
|
||||
#server_script_post_arg =
|
||||
#server_script_post_arg =
|
||||
#server_script_post_run_on_fail=0
|
||||
# As for server_script_pre_notify, but for post.
|
||||
#server_script_post_notify = 0
|
||||
|
||||
# Clients that are able to list and restore files belonging to any other
|
||||
# client. If this is too permissive, you may set a restore_client for
|
||||
# individual original clients in the individual clientconfdir files.
|
||||
# restore_client = someclient
|
||||
# restore_client = someotherclient
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# If you add at least one 'include=' line, the server will override the
|
||||
# rest of the client options below, which define exactly what to backup.
|
||||
# Setting any of the other options here will then also take effect on the
|
||||
# client.
|
||||
# (This file needs to be included in the clientconfdir file for the client,
|
||||
# using the '. path/to/this/file' syntax. Alternatively, these options can
|
||||
# be added to the clientconfdir file directly).
|
||||
|
||||
# include=/home
|
||||
# exclude=/home/dontwant
|
||||
# exclude_ext=vdi
|
||||
# exclude_regex=/\.cache/
|
||||
# exclude_fs=tmpfs
|
||||
# exclude_comp=gz
|
||||
# min_file_size=0
|
||||
# max_file_size=0
|
||||
# cross_filesystem=/some/path
|
||||
# cross_all_filesystems=0
|
||||
# nobackup=.nobackup
|
||||
# read_fifo=/some/path/to/a/fifo
|
||||
# read_all_fifos=0
|
||||
# split_vss=1
|
||||
# strip_vss=0
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
password = abcdefgh
|
||||
|
||||
# More configuration files can be read, using syntax like the following
|
||||
# (without the leading '# ').
|
||||
. incexc/example
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script that determines whether it is time to run a backup.
|
||||
|
||||
echo "Running timer script: $@"
|
||||
|
||||
client="$1" ; shift
|
||||
current="$1" ; shift
|
||||
storage_dir="$1" ; shift
|
||||
reserved1="$1" ; shift
|
||||
reserved2="$1" ; shift
|
||||
interval="$1" ; shift
|
||||
timestamp="$current/timestamp"
|
||||
|
||||
# A 'backup' file placed in the storage directory tells this script that
|
||||
# a backup needs to be done right now.
|
||||
# This gives the 'server initiates a manual backup' feature.
|
||||
|
||||
manual_file="$storage_dir/$client/backup"
|
||||
if [ -f "$manual_file" ] ; then
|
||||
echo "Found $manual_file"
|
||||
echo "Do a backup of $client now"
|
||||
rm -f "$manual_file"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# The rest of the arguments, if any, should be timebands.
|
||||
# Set LANG=C and LC_TIME=C so that 'date' returns English day names.
|
||||
curdayhour=$(LANG=C LC_TIME=C date +"*%a*%H*")
|
||||
intimeband=0 # If no timebands given, default to not OK.
|
||||
while [ "$#" -gt 0 ] ; do
|
||||
intimeband=0
|
||||
timeband="$1"
|
||||
case "$timeband" in
|
||||
$curdayhour)
|
||||
echo "In timeband: $timeband"
|
||||
intimeband=1
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Out of timeband: $timeband"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
get_intervals()
|
||||
{
|
||||
if [ ! -e "$current" ] ; then
|
||||
echo "No prior backup of $client"
|
||||
return 0
|
||||
fi
|
||||
if [ ! -f "$timestamp" ] ; then
|
||||
echo "$0: Timestamp file missing for $client."
|
||||
return 0
|
||||
fi
|
||||
if [ -z "$interval" ] ; then
|
||||
echo "$0: No time interval given for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "$interval" in
|
||||
[0-9]*s) i=${interval%s*} ; intervalsecs=$i ;;
|
||||
[0-9]*m) i=${interval%m*} ; intervalsecs=$((i*60)) ;;
|
||||
[0-9]*h) i=${interval%h*} ; intervalsecs=$((i*60*60)) ;;
|
||||
[0-9]*d) i=${interval%d*} ; intervalsecs=$((i*60*60*24)) ;;
|
||||
[0-9]*w) i=${interval%w*} ; intervalsecs=$((i*60*60*24*7)) ;;
|
||||
[0-9]*n) i=${interval%n*} ; intervalsecs=$((i*60*60*24*7*30)) ;;
|
||||
*) echo "$0: interval $interval not understood for $client."
|
||||
return 0 ;;
|
||||
esac
|
||||
|
||||
if [ -z "$intervalsecs" ] ; then
|
||||
echo "$0: interval $interval not understood for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
read junk ts < "$timestamp"
|
||||
|
||||
if ! secs=$(LANG=C LC_TIME=C date +%s -d "$ts") \
|
||||
|| ! now=$(LANG=C LC_TIME=C date +"%Y-%m-%d %H:%M:%S") \
|
||||
|| ! nowsecs=$(LANG=C LC_TIME=C date +%s -d "$now")
|
||||
then
|
||||
echo "$0: Date command returned error for $client."
|
||||
return 0
|
||||
fi
|
||||
|
||||
min_timesecs=$((secs+intervalsecs))
|
||||
|
||||
# GNU coreutils 'date' command should accept the following (even
|
||||
# slightly old versions).
|
||||
if ! min_time=$(LANG=C LC_TIME=C date -d "Jan 1, 1970 00:00:00 +0000 + $min_timesecs seconds" +"%Y-%m-%d %H:%M:%S")
|
||||
then
|
||||
# FreeBSD 'date' will return an error with the above, so try
|
||||
# a version that FreeBSD 'date' should be happy with.
|
||||
if ! min_time=$(LANG=C LC_TIME=C date -r $min_timesecs +"%Y-%m-%d %H:%M:%S")
|
||||
then
|
||||
echo "$0: Date command returned error for $client."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Last backup: $ts"
|
||||
echo "Next after : $min_time (interval $interval)"
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "$intimeband" = "0" ] ; then
|
||||
get_intervals
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if get_intervals ; then
|
||||
echo "Do a backup of $client now."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$min_timesecs" -lt "$nowsecs" ] ; then
|
||||
echo "$min_time < $now."
|
||||
echo "Do a backup of $client now."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Not yet time for a backup of $client"
|
||||
|
||||
exit 1
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
FROM python:2.7
|
||||
MAINTAINER hi+burpui@ziirish.me
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y locales wget curl uthash-dev g++ make libssl-dev librsync-dev python2.7-dev \
|
||||
&& update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
|
||||
&& locale-gen en_US.UTF-8 \
|
||||
&& dpkg-reconfigure -f noninteractive locales \
|
||||
&& echo "Europe/Paris" >/etc/timezone \
|
||||
&& dpkg-reconfigure -f noninteractive tzdata \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
CMD ["/usr/bin/python"]
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
FROM python:3.4
|
||||
MAINTAINER hi+burpui@ziirish.me
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y locales wget curl uthash-dev g++ make libssl-dev librsync-dev python3.4-dev \
|
||||
&& update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
|
||||
&& locale-gen en_US.UTF-8 \
|
||||
&& dpkg-reconfigure -f noninteractive locales \
|
||||
&& echo "Europe/Paris" >/etc/timezone \
|
||||
&& dpkg-reconfigure -f noninteractive tzdata \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
CMD ["/usr/bin/python"]
|
||||
|
|
@ -12,7 +12,6 @@ echo "test requirements"
|
|||
exit 1
|
||||
}
|
||||
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install wheel
|
||||
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Absolute path to this script, e.g. /home/user/bin/foo.sh
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
# Absolute path this script is in, thus /home/user/bin
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
me=$(basename $0)
|
||||
|
||||
# prints error in all cases
|
||||
function myerror() {
|
||||
echo "[e] $*" >&2
|
||||
}
|
||||
|
||||
# prints the help menu and exit
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
$me [options...]
|
||||
usage:
|
||||
-u, --user User prefix for images
|
||||
-t, --test List of tests to run separated by a coma
|
||||
-h, --help Print this menu and exit
|
||||
EOF
|
||||
ret=${1:-0}
|
||||
exit $ret
|
||||
}
|
||||
|
||||
# options may be followed by one colon to indicate they have a required argument
|
||||
options=$(getopt -n "$me" -o "hu:t::" -l "help,user:,test::" -- "$@") || {
|
||||
# something went wrong, getopt will put out an error message for us
|
||||
usage 1
|
||||
}
|
||||
|
||||
set -- $options
|
||||
|
||||
if [ "$(getopt --version)" = " --" ]; then
|
||||
# bsd getopt - skip configuration declarations
|
||||
nb_delims_to_remove=2
|
||||
while [ $# -gt 0 ]; do
|
||||
if [ $1 = "--" ]; then
|
||||
shift
|
||||
nb_delims_to_remove=$(expr $nb_delims_to_remove - 1)
|
||||
if [ $nb_delims_to_remove -lt 1 ]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
|
||||
shift
|
||||
done
|
||||
fi
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help) usage ;;
|
||||
# for options with required arguments, an additional shift is required
|
||||
-u|--user) user=$(sed "s/^.//;s/.$//" <<<$2) ; shift ;;
|
||||
-t|--test) [ -z "$tests" ] && tests=$(sed "s/,/ /g;s/^.//;s/.$//" <<<$2) || tests="$tests $(sed 's/,/ /g;s/^.//;s/.$//' <<<$2)" ; shift ;;
|
||||
(--) shift; break ;;
|
||||
(-*) myerror "$me: error - unrecognized option $1"; usage 1 ;;
|
||||
(*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
for arg; do [ -z "${tests}" ] && tests=$(sed "s/,/ /g;s/^.//;s/.$//" <<<$arg) || tests="$tests $(sed 's/,/ /g;s/^.//;s/.$//' <<<$arg)"; done
|
||||
|
||||
USR=${user:-${USER}}
|
||||
IMAGES="${tests:-2.7 3.4}"
|
||||
|
||||
echo "[+] Building docker images..."
|
||||
for img in $IMAGES
|
||||
do
|
||||
[ -d ${SCRIPTPATH}/docker/py${img} ] || continue
|
||||
echo "[-] ${img}"
|
||||
docker build -t ${USR}/py${img}:${img} ${SCRIPTPATH}/docker/py${img}
|
||||
done
|
||||
|
||||
echo "[+] Running tests..."
|
||||
for img in $IMAGES
|
||||
do
|
||||
[ -d ${SCRIPTPATH}/docker/py${img} ] || continue
|
||||
echo "[-] ${img}"
|
||||
docker run -it --rm -v ${SCRIPTPATH}/..:/home/burp-ui ${USR}/py${img}:${img} /bin/bash -c "cd /home/burp-ui && /home/burp-ui/tests/run_tests.sh"
|
||||
done
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
PIP=$(which pip)
|
||||
PYTHON=$(which python)
|
||||
VERSION=$($PYTHON -V | cut -d' ' -f2)
|
||||
ISROOT=0
|
||||
UPDATED=0
|
||||
BURP="https://git.ziirish.me/ziirish/burp.git"
|
||||
BURP_VERSION="1.4.40"
|
||||
BURP2_VERSION="2.0.28"
|
||||
|
||||
function update() {
|
||||
[ $UPDATED -eq 0 ] && [ $ISROOT -eq 1 ] && {
|
||||
apt-get update
|
||||
UPDATED=1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
echo "test requirements"
|
||||
[ $UID -eq 0 ] && ISROOT=1
|
||||
|
||||
#[ $ISROOT -eq 1 ] && apt-get update
|
||||
|
||||
[ -x "$PIP" ] && {
|
||||
echo "python-pip seems to be installed"
|
||||
} || {
|
||||
echo "python-pip is missing..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$PYTHON" ] && {
|
||||
echo "python seems to be installed"
|
||||
} || {
|
||||
echo "python is missing..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
#echo "install build requirements"
|
||||
#update
|
||||
#[ $ISROOT -eq 1 ] && apt-get install -y uthash-dev g++ make libssl-dev librsync-dev nodejs nodejs-legacy npm python$(perl -pe "s/\.\d+$//" <<<$VERSION)-dev
|
||||
|
||||
#echo "installing bower"
|
||||
#npm install -g bower
|
||||
|
||||
|
||||
echo "downloading and compiling burp v${BURP_VERSION}"
|
||||
ROOT_PWD=`pwd`
|
||||
BURP_DIR=$(mktemp -d)
|
||||
cd $BURP_DIR
|
||||
|
||||
cat >/etc/apt/sources.list.d/ziirish.list<<EOF
|
||||
deb http://ziirish.info/debian/ zi-stable main
|
||||
EOF
|
||||
|
||||
cat >>/etc/apt/preferences<<EOF
|
||||
Explanation: Ziirish's packages should be preferred
|
||||
Package: *
|
||||
Pin: release o=Ziirish, c=main
|
||||
Pin-Priority: 900
|
||||
EOF
|
||||
|
||||
wget http://ziirish.info/debian/debian.gpg -O- | apt-key add -
|
||||
|
||||
apt-get update
|
||||
apt-get install -y -t zi-stable burp
|
||||
|
||||
cd $ROOT_PWD
|
||||
WORKING_DIR=$(mktemp -d)
|
||||
|
||||
echo "copying configuration files"
|
||||
cp -a test/burp/config $WORKING_DIR/
|
||||
sed -i "s|@WORKING_DIR@|${WORKING_DIR}|" $WORKING_DIR/config/burp.conf
|
||||
sed -i "s|@WORKING_DIR@|${WORKING_DIR}|" $WORKING_DIR/config/CA/CA.cnf
|
||||
|
||||
echo "launching background burp-server"
|
||||
LOGFILE=$(mktemp)
|
||||
LOGFILE2=$(mktemp)
|
||||
burp -F -c $WORKING_DIR/config/burp.conf -g >$LOGFILE 2>&1
|
||||
(burp -F -c $WORKING_DIR/config/burp.conf >>$LOGFILE 2>&1) &
|
||||
BURP_PID=$!
|
||||
|
||||
#echo "downloading and compiling burp v${BURP2_VERSION}"
|
||||
#BURP2_DIR=$(mktemp -d)
|
||||
#cd $BURP2_DIR
|
||||
|
||||
#git clone $BURP
|
||||
#cd burp
|
||||
#git checkout tags/${BURP2_VERSION}
|
||||
#./configure
|
||||
#make
|
||||
|
||||
#cd $ROOT_PWD
|
||||
#WORKING_DIR2=$(mktemp -d)
|
||||
|
||||
#echo "copying configuration files"
|
||||
#cp -a test/burp2/config $WORKING_DIR2/
|
||||
#sed -i "s|@WORKING_DIR@|${WORKING_DIR2}|" $WORKING_DIR2/config/burp.conf
|
||||
#sed -i "s|@WORKING_DIR@|${WORKING_DIR2}|" $WORKING_DIR2/config/CA/CA.cnf
|
||||
|
||||
#echo "launching background burp-server"
|
||||
#LOGFILE2=$(mktemp)
|
||||
#$BURP2_DIR/burp/src/burp -F -c $WORKING_DIR2/config/burp.conf -g >$LOGFILE2 2>&1
|
||||
#($BURP2_DIR/burp/src/burp -F -c $WORKING_DIR2/config/burp.conf >>$LOGFILE2 2>&1) &
|
||||
#BURP2_PID=$!
|
||||
|
||||
echo "install virtualenv"
|
||||
$PIP install virtualenv
|
||||
mkdir py$VERSION
|
||||
VIRTUALENV=$(which virtualenv)
|
||||
|
||||
echo "test python$VERSION"
|
||||
$VIRTUALENV -p $PYTHON py$VERSION
|
||||
source py${VERSION}/bin/activate
|
||||
pip install --upgrade pip
|
||||
pip install --upgrade -r requirements.txt
|
||||
pip install --upgrade -r test-requirements.txt
|
||||
|
||||
mkdir -p /etc/burp
|
||||
cp share/burpui/etc/burpui.sample.cfg /etc/burp/burpui.cfg
|
||||
nosetests --with-coverage --cover-package=burpui tests/test_burpui.py 2>&1 >$LOGFILE2
|
||||
ret=$?
|
||||
rm /etc/burp/burpui.cfg
|
||||
|
||||
echo "cleanup"
|
||||
deactivate
|
||||
rm -rf py$VERSION
|
||||
|
||||
echo "Killing burp-server"
|
||||
kill $BURP_PID || echo "Ooops KILL"
|
||||
cat $LOGFILE
|
||||
|
||||
#echo "Killing burp2-server"
|
||||
#kill $BURP2_PID || echo "Ooops KILL"
|
||||
#cat $LOGFILE2
|
||||
|
||||
cat $LOGFILE2
|
||||
|
||||
echo "removing temp files/dirs"
|
||||
rm -rf $LOGFILE $LOGFILE2 $BURP2_DIR $BURP_DIR $WORKING_DIR $WORKING_DIR2 || echo "Ooops RM"
|
||||
|
||||
echo "That's it!"
|
||||
|
||||
echo "Return: $ret"
|
||||
|
||||
exit $ret
|
||||
|
|
@ -219,6 +219,14 @@ class BurpuiAPITestCase(TestCase):
|
|||
self.assert500(response)
|
||||
|
||||
|
||||
def mock_status(query='\n', timeout=None, agent=None):
|
||||
answers = {
|
||||
'': ['testclient 2 i 0'],
|
||||
'\n': ['testclient 2 i 0'],
|
||||
}
|
||||
return answers.get(query, [])
|
||||
|
||||
|
||||
class BurpuiRoutesTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -228,23 +236,26 @@ class BurpuiRoutesTestCase(TestCase):
|
|||
print ('\nTest 4 Finished!\n')
|
||||
|
||||
def create_app(self):
|
||||
conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test4.cfg')
|
||||
bui = BUIinit(conf, gunicorn=False, unittest=True)
|
||||
bui.setup(conf, True)
|
||||
bui.config['TESTING'] = True
|
||||
bui.config['LOGIN_DISABLED'] = True
|
||||
bui.config['LIVESERVER_PORT'] = 5001
|
||||
bui.config['SECRET_KEY'] = 'toto'
|
||||
bui.login_manager.init_app(bui)
|
||||
return bui
|
||||
with patch('socket.socket'):
|
||||
conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test4.cfg')
|
||||
bui = BUIinit(conf, gunicorn=False, unittest=True)
|
||||
bui.setup(conf, True)
|
||||
bui.config['TESTING'] = True
|
||||
bui.config['LOGIN_DISABLED'] = True
|
||||
bui.config['LIVESERVER_PORT'] = 5001
|
||||
bui.config['SECRET_KEY'] = 'toto'
|
||||
bui.login_manager.init_app(bui)
|
||||
return bui
|
||||
|
||||
def test_live_monitor(self):
|
||||
response = self.client.get(url_for('view.live_monitor'), follow_redirects=True)
|
||||
assert 'Sorry, there are no running backups' in response.data.decode('utf-8')
|
||||
with patch('burpui.misc.backend.burp1.Burp.status', side_effect=mock_status):
|
||||
response = self.client.get(url_for('view.live_monitor'), follow_redirects=True)
|
||||
assert 'Sorry, there are no running backups' in response.data.decode('utf-8')
|
||||
|
||||
def test_get_clients(self):
|
||||
response = self.client.get(url_for('api.clients_stats'))
|
||||
self.assertEqual(response.json, [{u'state': u'idle', u'last': u'never', u'human': u'never', u'name': u'testclient', u'phase': None, u'percent': 0}])
|
||||
with patch('burpui.misc.backend.burp1.Burp.status', side_effect=mock_status):
|
||||
response = self.client.get(url_for('api.clients_stats'))
|
||||
self.assertEqual(sorted(response.json), sorted([{u'state': u'idle', u'last': u'never', u'human': u'never', u'name': u'testclient', u'phase': None, u'percent': 0}]))
|
||||
|
||||
|
||||
class BurpuiLoginTestCase(TestCase):
|
||||
|
|
@ -334,8 +345,8 @@ class BurpuiACLTestCase(TestCase):
|
|||
rv = self.login('admin', 'admin')
|
||||
response = self.client.get(url_for('api.auth_users'))
|
||||
response2 = self.client.get(url_for('api.auth_backends'))
|
||||
self.assertEqual(response.json, [{u'id': u'admin', u'name': u'admin', u'backend': u'BASIC'}, {u'id': u'user1', u'name': u'user1', u'backend': u'BASIC'}])
|
||||
self.assertEqual(response2.json, [{u'add': True, u'del': True, u'name': u'BASIC', u'mod': True}])
|
||||
self.assertEqual(sorted(response.json), sorted([{u'id': u'admin', u'name': u'admin', u'backend': u'BASIC'}, {u'id': u'user1', u'name': u'user1', u'backend': u'BASIC'}]))
|
||||
self.assertEqual(sorted(response2.json), sorted([{u'add': True, u'del': True, u'name': u'BASIC', u'mod': True}]))
|
||||
|
||||
def test_config_render_ko(self):
|
||||
with self.client:
|
||||
|
|
|
|||
6
tox.ini
Normal file
6
tox.ini
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[tox]
|
||||
envlist = py{27,34,36}
|
||||
|
||||
[testenv]
|
||||
commands = nosetests --with-coverage --cover-package=burpui tests/test_burpui.py
|
||||
deps = .[ci]
|
||||
Loading…
Add table
Add a link
Reference in a new issue