Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
aj.config.BaseConfig.__init__(self)
self.data = {
'bind': {
'mode': 'tcp',
'host': '0.0.0.0',
'port': 8000,
},
'color': 'blue',
'name': 'test',
'ssl': {
'enable': False
}
@url(r'/api/plugins/pypi/list')
@endpoint(api=True)
def handle_api_pypi_list(self, http_context):
r = {}
for l in subprocess.check_output(['pip', 'freeze']).splitlines():
if l:
package = l.decode().split('=')[0]
if package:
prefix = 'ajenti.plugin.'
if package.startswith(prefix):
name = package[len(prefix):]
r[name] = package
return r
import json
import os
from jadi import component
import aj
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager
from aj.api.endpoint import endpoint
@component(HttpPlugin)
class ResourcesHandler(HttpPlugin):
def __init__(self, http_context):
self.cache = {}
self.use_cache = not aj.debug
self.mgr = PluginManager.get(aj.context)
def __wrap_js(self, name, js):
return '''
try {
%s
} catch (err) {
console.warn('Plugin load error:');
console.warn(' * %s');
console.error(' ', err);
}
''' % (js, name)
import json
import os
from jadi import component
import aj
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager
from aj.api.endpoint import endpoint
@component(HttpPlugin)
class ResourcesHandler(HttpPlugin):
def __init__(self, http_context):
self.cache = {}
self.use_cache = not aj.debug
self.mgr = PluginManager.get(aj.context)
def __wrap_js(self, name, js):
return '''
try {
%s
} catch (err) {
console.warn('Plugin load error:');
console.warn(' * %s');
console.error(' ', err);
}
''' % (js, name)
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']
listener = socket.socket(
socket.AF_INET6 if ':' in host else socket.AF_INET, socket.SOCK_STREAM
)
if aj.platform not in ['freebsd', 'osx']:
try:
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
except socket.error:
logging.warn('Could not set TCP_CORK')
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
logging.info('Binding to [%s]:%s', host, port)
try:
listener.bind((host, port))
except socket.error as e:
logging.error('Could not bind: %s', str(e))
sys.exit(1)
import multiprocessing
import os
import subprocess
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class LoadAverageWidget(Widget):
id = 'loadavg'
name = _('Load average')
template = '/dashboard:resources/partial/widgets/loadavg.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
k = 1.0
if config and config.get('divide', False):
k /= multiprocessing.cpu_count()
if os.path.exists('/proc/loadavg'):
return [float(open('/proc/loadavg').read().split()[x]) * k for x in range(3)]
else:
tokens = subprocess.check_output(['uptime']).split()
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']
except socket.error:
logging.warn('Could not set TCP_CORK')
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
logging.info('Binding to [%s]:%s', host, port)
try:
listener.bind((host, port))
except socket.error as e:
logging.error('Could not bind: %s', str(e))
sys.exit(1)
# Fix stupid socketio bug (it tries to do *args[0][0])
socket.socket.__getitem__ = lambda x, y: None
listener.listen(10)
gateway = GateMiddleware.get(aj.context)
application = HttpRoot(HttpMiddlewareAggregator([gateway])).dispatch
aj.server = SocketIOServer(
listener,
log=open(os.devnull, 'w'),
application=application,
handler_class=RequestHandler,
policy_server=False,
transports=[
str('websocket'),
str('flashsocket'),
str('xhr-polling'),
str('jsonp-polling'),
],
)
def init(plugin_manager):
import aj
api.TZManager.any(aj.context)
from .main import ItemProvider
from .views import Handler