HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //bin/lwdbprovd
#!/usr/bin/python

import argparse
import logging
import logging.config
import logging.handlers
import yaml
import hmac

from lwdbadmin import bottle
from lwdbadmin.bottle import request

with open('/etc/locaweb/lwdbadmin-log.yml', 'r') as f:
    configlog = yaml.safe_load(f.read())

logging.config.dictConfig(configlog)
logger = logging.getLogger(__name__)

# change config of log to file lwdbadmin-log.yml
#h = logging.handlers.SysLogHandler()
#l = logger = logging.getLogger()
#l.setLevel(logging.NOTSET)
#l.addHandler(h)

#def configure_logging(logfile='/var/log/lwdbadmin/lwdbadmin.log'):
#    format = '%(asctime)s.%(msecs)03d %(module)s[%(process)d] %(levelname)s %(message)s'
#    formatter = logging.Formatter(fmt=format, datefmt='%b %d %H:%M:%S')
#    # always put the log in /var/log
#    trace = logging.FileHandler(logfile)
#    trace.setFormatter(formatter)
#
#    with open('/etc/locaweb/lwdbadmin.yml', 'r') as locaconf:
#        config = yaml.safe_load(locaconf)
#    log_debug = codecs.encode(config['lwdbadmin_debug'])
#
#    if log_debug == 'True':
#        trace.setLevel(logging.DEBUG)
#    else:
#        trace.setLevel(logging.INFO)
#
#    l = logging.getLogger()
#    l.addHandler(trace)
#
#    # There is 2 levels: Handler level and Logger level
#    # use NOTSET to each handler choose it's own level
#    l.setLevel(logging.NOTSET)

app = application = bottle.Bottle()

@app.install
def authorize(callback):
    def wrapper(*args, **kwargs):
        if 'X-Auth' not in request.headers.keys():
            logger.warn("X-Auth Header not found")
            return bottle.abort(403)
        else:
            with open('/etc/locaweb/linuxadmin.yml', 'r') as locaconf:
                config = yaml.load(locaconf)
            digest_maker = hmac.new(config['hmac_key'])
            with open('/etc/locaweb/aka.key', 'r') as f:
                block = f.read()
                digest_maker.update(block)
                digest = digest_maker.hexdigest()
            if request.headers['X-Auth'] == digest:
                logger.debug("X-Auth Header accepted")
                return callback(*args, **kwargs)
            else:
                logger.debug("X-Auth Header found but content does not match")
                return bottle.abort(403)
    return wrapper

#configure_logging()

with app:
    try:
        import lwdbadmin.bottlelibs.bottlemysql
    except ImportError as e:
        logging.error('Could not find lwdbadmin.bottlelibs.bottlemysql')
    try:
        import lwdbadmin.bottlelibs.bottlepgsql
    except ImportError as e:
        logging.error('Could not find lwdbadmin.bottlelibs.bottlepgsql')


@app.error(500)
def error500(error):
    return error.body

class StripPathMiddleware(object):
    '''
    Get that slash out of the request
    '''
    def __init__(self, a):
        self.a = a
    def __call__(self, e, h):
        e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
        return self.a(e, h)

parser = argparse.ArgumentParser(description="lwdbprovd daemon")
parser.add_argument('-d', '--debug', action='store_true')
args = parser.parse_args()

app = StripPathMiddleware(app)

if __name__ == '__main__':
    logging.info('Starting lwdbprovd...')
    bottle.run(app=app,
        server='auto',
        host='0.0.0.0',
        port=8080,
        debug=args.debug)