Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Mar 23, 2015
1 parent 1c94aa6 commit 01274b5
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 54 deletions.
11 changes: 4 additions & 7 deletions ajenti-core/aj/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ def run(config=None, plugin_providers=None, product_name='ajenti', dev_mode=Fals
:type config: :class:`aj.config.BaseConfig`
:param plugin_providers: list of plugin providers to load plugins from
:type plugin_providers: list(:class:`aj.plugins.PluginProvider`)
:param product_name: a product name to use
:param dev_mode: enables dev mode (automatic resource recompilation)
:type dev_mode: bool
:param debug_mode: enables debug mode (verbose and extra logging)
:type debug_mode: bool
:param autologin: disables authentication and logs everyone in as the user running the panel. This is EXTREMELY INSECURE.
:type autologin: bool
:param str product_name: a product name to use
:param bool dev_mode: enables dev mode (automatic resource recompilation)
:param bool debug_mode: enables debug mode (verbose and extra logging)
:param bool autologin: disables authentication and logs everyone in as the user running the panel. This is EXTREMELY INSECURE.
"""
if config is None:
raise TypeError('`config` can\'t be None')
Expand Down
9 changes: 9 additions & 0 deletions ajenti-core/aj/gate/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self, context):
log_tag='restricted'
)
self.restricted_gate.start()
aj.config.data.setdefault('max_sessions', None)

def generate_session_key(self, env):
h = str(random.random())
Expand All @@ -121,6 +122,14 @@ def open_session(self, env, **kwargs):
"""
Creates a new session for the :class:`aj.http.HttpContext`
"""
max_sessions = aj.config.data['max_sessions']
if max_sessions and len(self.sessions) >= max_sessions:
candidates = sorted(self.sessions.keys(), key=lambda k: -self.sessions[k].get_age())
victim = self.sessions[candidates[0]]
logging.info("Closing session %s due to pool overflow" % victim.id)
victim.deactivate()
self.vacuum()

client_info = {
'address': env.get('REMOTE_ADDR', None),
}
Expand Down
5 changes: 4 additions & 1 deletion ajenti-core/aj/gate/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ def touch(self):
"""
self.timestamp = time.time()

def get_age(self):
return time.time() - self.timestamp

def is_dead(self):
return not self.active or (time.time() - self.timestamp) > 3600
return not self.active or self.get_age() > 3600

def set_cookie(self, http_context):
"""
Expand Down
1 change: 1 addition & 0 deletions ajenti-panel/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ ssl:
enable: true
force: false
enable: false
max_sessions: 1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ angular.module('core').controller 'CoreRootController', ($scope, $rootScope, $lo
$rootScope.ajentiVersion = ajentiVersion
$rootScope.ajentiPlugins = ajentiPlugins

# todo figure this out, used in settings template
$rootScope.keys = (x) -> Object.keys(x)

console.group('Welcome')
console.log('Ajenti', ajentiVersion)
if urlPrefix
Expand Down
30 changes: 27 additions & 3 deletions plugins/dashboard/resources/js/controllers/index.controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,33 @@ angular.module('ajenti.dashboard').controller 'DashboardIndexController', ($scop

settings.getUserConfig().then (userConfig) ->
$scope.userConfig = userConfig
$scope.userConfig.dashboard ?= {}
$scope.userConfig.dashboard.widgetsLeft ?= []
$scope.userConfig.dashboard.widgetsRight ?= []
$scope.userConfig.dashboard ?= {
widgetsLeft: [
{
id: 'w1'
typeId: 'hostname'

}
{
id: 'w2'
typeId: 'cpu'
}
{
id: 'w3'
typeId: 'loadavg'
}
]
widgetsRight: [
{
id: 'w4'
typeId: 'uptime'
}
{
id: 'w5'
typeId: 'memory'
}
]
}

updateInterval = $interval () ->
$scope.refresh()
Expand Down
45 changes: 28 additions & 17 deletions plugins/dashboard/resources/partial/widgets/cpu.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
<div ng:controller="CPUWidgetController" class="row">
<div class="col-xs-4">
<div class="widget-header">
CPU usage
<div ng:controller="CPUWidgetController">
<div class="row">
<div class="col-xs-4">
<div class="widget-header">
Active cores
</div>
<smart-progress value="cores" max="values.length"></smart-progress>
</div>
<div class="widget-value">
{{avgPercent}}%
<sup ng:show="avgPercent > 95">
<span class="label label-danger">
<i class="fa fa-warning"></i>
</span>
</sup>
<div class="col-xs-8">
<div class="widget-header">
CPU usage
</div>
<smart-progress value="avgPercent" max="100"></smart-progress>
</div>
<smart-progress value="avgPercent" max="100"></smart-progress>
</div>
<div class="col-xs-3">
<div class="widget-header">
Active cores
<div>
</div>
<div class="row">
<div class="col-xs-4">
<div class="widget-value">
{{cores}}/{{values.length}}
</div>
</div>
<div class="widget-value">
{{cores}}/{{values.length}}
<div class="col-xs-8">
<div class="widget-value">
{{avgPercent}}%
<sup ng:show="avgPercent > 95">
<span class="label label-danger">
<i class="fa fa-warning"></i>
</span>
</sup>
</div>
</div>
</div>
</div>
43 changes: 26 additions & 17 deletions plugins/dashboard/resources/partial/widgets/memory.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<div ng:controller="MemoryWidgetController" class="row">
<div class="col-xs-4">
<div class="widget-header">
Memory usage
<div ng:controller="MemoryWidgetController">
<div class="row">
<div class="col-xs-4">
<div class="widget-header">
Total
</div>
<smart-progress max="1"></smart-progress>
</div>
<div class="widget-value">
{{usage}}%
<sup ng:show="usage > 90">
<span class="label label-danger">
<i class="fa fa-warning"></i>
</span>
</sup>
<div class="col-xs-8">
<div class="widget-header">
Memory usage
</div>
<smart-progress value="usage" max="100"></smart-progress>
</div>
<smart-progress value="usage" max="100"></smart-progress>
</div>
<div class="col-xs-3">
<div class="widget-header">
Total
<div class="row">
<div class="col-xs-4">
<div class="widget-value">
{{total|bytes}}
</div>
</div>
<div class="widget-value">
{{total|bytes}}
<div class="col-xs-8">
<div class="widget-value">
{{usage}}%
<sup ng:show="usage > 90">
<span class="label label-danger">
<i class="fa fa-warning"></i>
</span>
</sup>
</div>
</div>
</div>
</div>
8 changes: 8 additions & 0 deletions plugins/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def __init__(self, manager):
self.running = None


class ServiceOperationError(Exception):
def __init__(self, inner):
self.inner = inner

def __unicode__(self):
return '[ServiceOperationError %s]' % self.inner


@interface
class ServiceManager(object):
id = None
Expand Down
18 changes: 14 additions & 4 deletions plugins/services/managers/upstart_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dbus.exceptions import DBusException
from upstart.system import UpstartSystem, DirectUpstartBus
from upstart.job import UpstartJob

from aj.api import *
from aj.plugins.services.api import ServiceManager, Service
from aj.plugins.services.api import ServiceManager, Service, ServiceOperationError


@component(ServiceManager)
Expand Down Expand Up @@ -50,10 +51,19 @@ def get(self, _id):
return svc

def start(self, _id):
UpstartJob(_id).start()
try:
UpstartJob(_id).start()
except DBusException as e:
raise ServiceOperationError(e)

def stop(self, _id):
UpstartJob(_id).stop()
try:
UpstartJob(_id).stop()
except DBusException as e:
raise ServiceOperationError(e)

def restart(self, _id):
UpstartJob(_id).restart()
try:
UpstartJob(_id).restart()
except DBusException as e:
raise ServiceOperationError(e)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('ajenti.services').controller 'ServiceWidgetController', ($scope, services) ->
angular.module('ajenti.services').controller 'ServiceWidgetController', ($scope, services, notify) ->
$scope.$on 'widget-update', ($event, id, data) ->
if id != $scope.widget.id
return
Expand All @@ -8,7 +8,8 @@ angular.module('ajenti.services').controller 'ServiceWidgetController', ($scope,
svc =
managerId: $scope.widget.config.manager_id
id: $scope.widget.config.service_id
services.runOperation(svc, o)
services.runOperation(svc, o).catch (e) ->
notify.error 'Service operation failed', e.message


angular.module('ajenti.services').controller 'ServiceWidgetConfigController', ($scope, services) ->
Expand Down
9 changes: 6 additions & 3 deletions plugins/services/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from aj.api import *
from aj.api.http import url, HttpPlugin

from aj.plugins.core.api.endpoint import endpoint
from aj.plugins.services.api import ServiceManager
from aj.plugins.core.api.endpoint import endpoint, EndpointError
from aj.plugins.services.api import ServiceManager, ServiceOperationError


@component(HttpPlugin)
Expand Down Expand Up @@ -45,4 +45,7 @@ def handle_api_get(self, http_context, manager_id=None, service_id=None):
def handle_api_operate(self, http_context, manager_id=None, operation=None, service_id=None):
if operation not in ['start', 'stop', 'restart']:
return
getattr(self.managers[manager_id], operation)(service_id)
try:
getattr(self.managers[manager_id], operation)(service_id)
except ServiceOperationError as e:
raise EndpointError(e)
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ angular.module('ajenti.settings').controller 'SettingsIndexController', ($scope,
$scope.newClientCertificate.generating = false
$scope.newClientCertificateDialogVisible = false
notify.error 'Certificate generation failed', err.message

$scope.addEmail = (email, username) ->
$scope.config.emails[email] = username
$scope.newEmailDialogVisible = false

$scope.removeEmail = (email) ->
delete $scope.config.emails[email]
52 changes: 52 additions & 0 deletions plugins/settings/resources/partial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,58 @@ <h4>Generating certificate</h4>
</dialog>
</div>
</div>

<hr />

<div class="form-group">
<label>E-mail authentication</label>
<div class="help-text">
Allows login with a confirmed e-mail address via <a href="https://login.persona.org/about" target="_blank">Mozilla Persona</a> auth service. Requires server-side internet access.
</div>
<div class="alert alert-warning" ng:show="keys(config.emails).length == 0">
<i class="fa fa-warning"></i> No e-mail addresses added yet.
</div>
<div class="list-group">
<div ng:repeat="(email, username) in config.emails" class="list-group-item list-group-item-large">
<a class="list-group-btn" ng:click="removeEmail(email)" title="Remove">
<i class="fa fa-trash-o"></i>
</a>
<div class="list-group-main">
<div class="list-group-icon">
<i class="fa fa-envelope"></i>
</div>
<h4 class="list-group-item-heading">
{{email}}
</h4>
<p class="list-group-item-text">
<i class="fa fa-user"></i> {{username}}
</p>
</div>
</div>
</div>
<a ng:click="newEmailDialogVisible = true" class="btn btn-default">
<i class="fa fa-plus"></i> New address
</a>
<dialog ng:show="newEmailDialogVisible">
<div class="modal-header">
<h4>New e-mail address</h4>
</div>
<div class="modal-body" ng:form="form">
<div class="form-group">
<label>E-mail address</label>
<input ng:model="newEmailAddress" required class="form-control" type="email" />
</div>
<div class="form-group">
<label>User to log in</label>
<select ng:model="newEmailUsername" required ng:options="x.name as x.name for x in availableUsers|orderBy:'name'" class="form-control"></select>
</div>
</div>
<div class="modal-footer">
<a ng:click="addEmail(newEmailAddress, newEmailUsername)" ng:disabled="!form.$valid" class="btn btn-default btn-flat">Add</a>
<a ng:click="$parent.newEmailDialogVisible = false" class="btn btn-default btn-flat">Cancel</a>
</div>
</dialog>
</div>
</div>

<div class="floating-toolbar-padder"></div>
Expand Down

0 comments on commit 01274b5

Please sign in to comment.