Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logging.warn('Dev mode')
try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error:
logging.warning('Couldn\'t set default locale')
# install a passthrough gettext replacement since all localization is handled in frontend
# and _() is here only for string extraction
__builtins__['_'] = lambda x: x
logging.info('Ajenti Core %s', aj.version)
logging.info('Detected platform: %s / %s', aj.platform, aj.platform_string)
# Load plugins
PluginManager.get(aj.context).load_all_from(aj.plugin_providers)
if len(PluginManager.get(aj.context)) == 0:
logging.warn('No plugins were loaded!')
if aj.config.data['bind']['mode'] == 'unix':
path = aj.config.data['bind']['socket']
if os.path.exists(path):
os.unlink(path)
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
listener.bind(path)
except OSError:
logging.error('Could not bind to %s', path)
sys.exit(1)
if aj.config.data['bind']['mode'] == 'tcp':
host = aj.config.data['bind']['host']
try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error:
logging.warning('Couldn\'t set default locale')
# install a passthrough gettext replacement since all localization is handled in frontend
# and _() is here only for string extraction
__builtins__['_'] = lambda x: x
logging.info('Ajenti Core %s', aj.version)
logging.info('Detected platform: %s / %s', aj.platform, aj.platform_string)
# Load plugins
PluginManager.get(aj.context).load_all_from(aj.plugin_providers)
if len(PluginManager.get(aj.context)) == 0:
logging.warn('No plugins were loaded!')
if aj.config.data['bind']['mode'] == 'unix':
path = aj.config.data['bind']['socket']
if os.path.exists(path):
os.unlink(path)
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
listener.bind(path)
except OSError:
logging.error('Could not bind to %s', path)
sys.exit(1)
if aj.config.data['bind']['mode'] == 'tcp':
host = aj.config.data['bind']['host']
port = aj.config.data['bind']['port']
def handle_api_list_installed(self, http_context):
r = []
manager = PluginManager.get(aj.context)
for name in manager:
plugin = manager[name]
r.append({
'name': plugin['info']['name'],
'imported': plugin['imported'],
'crash': self.__serialize_exception(manager.get_crash(plugin['info']['name'])),
'path': plugin['path'],
'author': plugin['info']['author'],
'author_email': plugin['info']['email'],
'url': plugin['info']['url'],
'icon': plugin['info']['icon'],
'version': plugin['info']['version'],
'title': plugin['info']['title'],
})
return r
def __init__(self, http_context):
self.cache = {}
self.use_cache = not aj.debug
self.mgr = PluginManager.get(aj.context)
def handle_api_languages(self, http_context):
mgr = PluginManager.get(aj.context)
languages = set()
for id in mgr:
locale_dir = mgr.get_content_path(id, 'locale')
if os.path.isdir(locale_dir):
for lang in os.listdir(locale_dir):
if lang != 'app.pot':
languages.add(lang)
return sorted(list(languages))
def get_augeas(self):
return Augeas(
modules=[{
'name': 'Supervisor',
'lens': 'Supervisor.lns',
'incl': [
self.path,
]
}],
loadpath=PluginManager.get(aj.context).get_content_path('supervisor', ''),
)
Library | Version
------- | -------
gevent | %s
greenlet | %s
psutil | %s
%s
""" % (
version,
platform, platform_unmapped, platform_string,
subprocess.check_output(['uname', '-mp']).strip(),
'.'.join([str(x) for x in _platform.python_version_tuple()]),
debug,
', '.join(sorted(PluginManager.get(aj.context).get_loaded_plugins_list())),
gevent.__version__,
greenlet.__version__,
psutil.__version__,
tb,
)
if rebuild_all:
cmd = ['ajenti-dev-multitool', '--rebuild']
else:
cmd = ['ajenti-dev-multitool', '--build']
p = subprocess.Popen(
cmd,
cwd=provider.path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
o, e = p.communicate()
if p.returncode != 0:
logging.error('Resource compilation failed')
logging.error(o + e)
manager = PluginManager.get(aj.context)
path = manager.get_content_path('core', 'content/pages/index.html')
content = open(path).read() % {
'prefix': http_context.prefix,
'plugins': json.dumps(
dict((manager[n]['info']['name'], manager[n]['info']['title']) for n in manager)
),
'config': json.dumps(aj.config.data),
'version': six.text_type(aj.version),
'platform': aj.platform,
'platformUnmapped': aj.platform_unmapped,
'bootstrapColor': aj.config.data.get('color', None),
}
http_context.add_header('Content-Type', 'text/html')
http_context.respond_ok()
return content
def handle_file(self, http_context, plugin=None, path=None):
if '..' in path:
return http_context.respond_not_found()
return http_context.file(PluginManager.get(aj.context).get_content_path(plugin, path))