Example #1
0
def init(cfgfn=_cfgfn):
    config = cfg.new(cfgfn)

    log.init(config.get('sadm', 'log', fallback='error'))
    log.debug(version.string('sadm-devops'))
    log.debug("read config %s" % cfgfn)

    log.debug("bottle config %s" % _wappcfg)
    wapp.config.load_config(_wappcfg)

    tpldir = libdir.fpath('devops', 'wapp', 'tpl')
    log.debug("templates dir %s" % tpldir)
    bottle.TEMPLATE_PATH = [tpldir]

    rmplugins = [
        p.strip() for p in wapp.config.get('plugins.uninstall', '').split(' ')
    ]
    for p in rmplugins:
        if p != '':
            log.debug("plugin uninstall %s" % p)
            wapp.uninstall(p)

    log.debug('install auth plugins')
    wapp.install(AuthPlugin(config))

    errors.init(wapp)
    handlers.init(wapp)

    session.init(config)

    log.debug("loaded handlers %s" % [r.name for r in wapp.routes])
    return wapp
Example #2
0
def _loadEnabled(env):
    fn = 'config.ini'
    cfgdir = env.settings.get('service', 'config.dir', fallback='service')
    for s in env.settings.getlist('service', 'enable'):
        env.log("enable %s" % s)
        libfn = libdir.fpath('service', s, fn)
        libok = _loadConfig(env, libfn)
        sfn = env.assets.rootdir(cfgdir, s, fn)
        sok = _loadConfig(env, sfn)
        if not sok and not libok:
            raise env.error("%s file not found" % sfn)
Example #3
0
def uwsgi():
    cmd = [
        'uwsgi',
        '--need-plugin',
        'python3',
        '--set-ph',
        "sadm-home=%s" % sys.exec_prefix,
        '--touch-reload',
        path.join(path.sep, 'etc', 'opt', 'sadm', 'listen.cfg'),
        '--touch-reload',
        libdir.fpath('listen', 'wsgi', 'uwsgi.ini'),
        '--safe-pidfile',
        path.join(path.sep, 'tmp', 'sadm.listen.uwsgi.pid'),
        '--ini',
        libdir.fpath('listen', 'wsgi', 'uwsgi.ini'),
    ]
    try:
        callCheck(cmd)
    except CommandError as err:
        return err.rc
    return 0
Example #4
0
def _buildListen(env):
	cfgfiles = (
		(libdir.fpath('listen', 'wsgi', 'uwsgi.ini'),
			path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'uwsgi.ini')),
		(libdir.fpath('listen', 'wsgi', 'uwsgi.service'),
			path.join(path.sep, 'etc', 'systemd', 'system', 'sadm-listen.service')),

		(libdir.fpath('listen', 'wsgi', 'apache.conf'),
			path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'apache.conf')),
		(libdir.fpath('listen', 'wsgi', 'nginx.conf'),
			path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'nginx.conf')),
		(libdir.fpath('listen', 'wsgi', 'lighttpd.conf'),
			path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'lighttpd.conf')),

		(libdir.fpath('listen', 'fail2ban', 'filter.d', 'sadm-listen.conf'),
			path.join(path.sep, 'etc', 'fail2ban', 'filter.d', 'sadm-listen.conf')),
		(libdir.fpath('listen', 'fail2ban', 'jail.d', 'sadm-listen.conf'),
			path.join(path.sep, 'etc', 'fail2ban', 'jail.d', 'sadm-listen.conf')),
	)
	for srcfn, dstfn in cfgfiles:
		env.log("create %s" % dstfn)
		with open(srcfn, 'r') as src:
			with builddir.create(env, dstfn) as dst:
				dst.write(src.read())
Example #5
0
 def __init__(self, pname, dist, sdir=None):
     if sdir is None:
         sdir = libdir.fpath('scripts', dist, pname.replace('.', path.sep))
     self._dir = sdir
     log.debug("%s" % self._dir)
     self._env = environ.copy()
Example #6
0
# Copyright (c) Jeremías Casteglione <*****@*****.**>
# See LICENSE file.

import bottle

from _sadm import libdir, log, version
from _sadm.devops.wapp import cfg, errors, handlers
from _sadm.devops.wapp.plugin.auth import AuthPlugin
from _sadm.devops.wapp.session import session
from _sadm.utils import path

__all__ = ['init']

_wappcfg = libdir.fpath('devops', 'wapp', 'wapp.conf')
_cfgfn = path.join(path.sep, 'etc', 'opt', 'sadm', 'devops.cfg')

wapp = bottle.Bottle()


def init(cfgfn=_cfgfn):
    config = cfg.new(cfgfn)

    log.init(config.get('sadm', 'log', fallback='error'))
    log.debug(version.string('sadm-devops'))
    log.debug("read config %s" % cfgfn)

    log.debug("bottle config %s" % _wappcfg)
    wapp.config.load_config(_wappcfg)

    tpldir = libdir.fpath('devops', 'wapp', 'tpl')
    log.debug("templates dir %s" % tpldir)
Example #7
0
# Copyright (c) Jeremías Casteglione <*****@*****.**>
# See LICENSE file.

import bottle

from os import path

from _sadm import libdir, log

__all__ = ['serve']

_rootdir = libdir.fpath('devops', 'wapp', 'static')
_serveExtension = {
    '.css': True,
    '.ico': True,
}


def serve(filename):
    filename = path.normpath(filename)
    ext = path.splitext(filename)[1]
    if ext == '' or filename.startswith('.') or \
     not _serveExtension.get(ext, False):
        log.warn("static file refuse %s" % filename)
        return bottle.HTTPError(404, "file not found")
    log.debug("serve %s" % filename)
    return bottle.static_file(filename, root=_rootdir)
Example #8
0
    # ~ for k, v in req.headers.items():
    # ~ log.debug("%s: %s" % (k, v))
    u = urlparse(req.url)
    scheme = u.scheme
    if not scheme:  # pragma: no cover
        scheme = 'http'
    port = u.port
    if not port:
        port = '3666'
    url = "%s://127.0.0.1:%s" % (scheme, port)
    log.debug("URL: %s" % url)
    return url


_pycmd = path.join(sys.exec_prefix, 'bin', 'python3')
_selfpath = libdir.fpath('listen', 'exec.py')


def _sched(taskfn):
    log.debug("exec prefix %s" % sys.exec_prefix)
    cmd = [_pycmd, _selfpath, taskfn]
    atcmd = "echo '%s' | at now" % ' '.join(cmd)
    log.debug("run: %s" % atcmd)
    callCheck(atcmd)


#
# task exec main (runs under a new process)
#

Example #9
0
# Copyright (c) Jeremías Casteglione <*****@*****.**>
# See LICENSE file.

import bottle
from configparser import ConfigParser, ExtendedInterpolation

from _sadm import libdir, log, version
from _sadm.listen import errors, handlers
from _sadm.utils import path

__all__ = ['wapp', 'config', 'init']

_wappcfg = libdir.fpath('listen', 'wapp.conf')
_cfgfn = path.join(path.sep, 'etc', 'opt', 'sadm', 'listen.cfg')

wapp = bottle.Bottle()
config = None

def _newConfig(fn):
	c = ConfigParser(
		defaults = None,
		allow_no_value = False,
		delimiters = ('=',),
		comment_prefixes = ('#',),
		strict = True,
		interpolation = ExtendedInterpolation(),
		default_section = 'default',
	)
	with open(fn, 'r') as fh:
		c.read_file(fh)
	return c
Example #10
0
# Copyright (c) Jeremías Casteglione <*****@*****.**>
# See LICENSE file.

import bottle

from _sadm import libdir

__all__ = ['wapp', 'view', 'run']

_cfgfn = libdir.fpath('web', 'app.conf')
_htmldir = libdir.fpath('web', 'html')
_staticdir = libdir.fpath('web', 'static')

bottle.TEMPLATE_PATH = [_htmldir]
view = bottle.view

wapp = bottle.Bottle()
wapp.config.load_config(_cfgfn)


@wapp.route('/static/<filename:path>')
def _static(filename):
    return bottle.static_file(filename, root=_staticdir, download=False)


def run(host, port, debug):
    import _sadm.web.load  # load views
    wapp.run(host=host,
             port=port,
             reloader=debug,
             quiet=not debug,