forked from shaba/openuds
Backporting transport limitation by connecting os
This commit is contained in:
parent
7892a196ac
commit
49aaaedbe9
@ -36,6 +36,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
from uds.models import Transport, Network
|
||||
from uds.core.transports import factory
|
||||
from uds.core.util import permissions
|
||||
from uds.core.util import OsDetector
|
||||
|
||||
from uds.REST.model import ModelHandler
|
||||
|
||||
@ -48,14 +49,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class Transports(ModelHandler):
|
||||
model = Transport
|
||||
save_fields = ['name', 'comments', 'tags', 'priority', 'nets_positive']
|
||||
save_fields = ['name', 'comments', 'tags', 'priority', 'nets_positive', 'allowed_oss']
|
||||
|
||||
table_title = _('Current Transports')
|
||||
table_fields = [
|
||||
{'priority': {'title': _('Priority'), 'type': 'numeric', 'width': '6em'}},
|
||||
{'name': {'title': _('Name'), 'visible': True, 'type': 'iconType'}},
|
||||
{'comments': {'title': _('Comments')}},
|
||||
{'deployed_count': {'title': _('Used by'), 'type': 'numeric', 'width': '8em'}},
|
||||
{'allowed_oss': {'title': _('Devices'), 'width': '8em'}},
|
||||
{'tags': {'title': _('tags'), 'visible': False}},
|
||||
]
|
||||
|
||||
@ -65,22 +66,32 @@ class Transports(ModelHandler):
|
||||
def getGui(self, type_):
|
||||
try:
|
||||
return self.addField(
|
||||
self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments', 'tags', 'priority']), {
|
||||
'name': 'nets_positive',
|
||||
'value': True,
|
||||
'label': ugettext('Network access'),
|
||||
'tooltip': ugettext('If checked, the transport will be enabled for the selected networks.If unchecked, transport will be disabled for selected networks'),
|
||||
'type': 'checkbox',
|
||||
'order': 100, # At end
|
||||
}), {
|
||||
'name': 'networks',
|
||||
self.addField(
|
||||
self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments', 'tags', 'priority']), {
|
||||
'name': 'nets_positive',
|
||||
'value': True,
|
||||
'label': ugettext('Network access'),
|
||||
'tooltip': ugettext('If checked, the transport will be enabled for the selected networks.If unchecked, transport will be disabled for selected networks'),
|
||||
'type': 'checkbox',
|
||||
'order': 100, # At end
|
||||
}), {
|
||||
'name': 'networks',
|
||||
'value': [],
|
||||
'values': sorted([{'id': x.id, 'text': x.name} for x in Network.objects.all()], key=lambda x: x['text'].lower()), # TODO: We will fix this behavior after current admin client is fully removed
|
||||
'label': ugettext('Networks'),
|
||||
'tooltip': ugettext('Networks associated with this transport. If No network selected, will mean "all networks"'),
|
||||
'type': 'multichoice',
|
||||
'order': 101
|
||||
}), {
|
||||
'name': 'allowed_oss',
|
||||
'value': [],
|
||||
'values': sorted([{'id': x.id, 'text': x.name} for x in Network.objects.all()], key=lambda x: x['text'].lower()), # TODO: We will fix this behavior after current admin client is fully removed
|
||||
'label': ugettext('Networks'),
|
||||
'tooltip': ugettext('Networks associated with this transport. If No network selected, will mean "all networks"'),
|
||||
'values': sorted([{'id': x, 'text': x} for x in OsDetector.knownOss], key=lambda x: x['text'].lower()), # TODO: We will fix this behavior after current admin client is fully removed
|
||||
'label': ugettext('Allowed Devices'),
|
||||
'tooltip': ugettext('If empty, any kind of device compatible with this transport will be allowed. Else, only devices compatible with selected values will be allowed'),
|
||||
'type': 'multichoice',
|
||||
'order': 101
|
||||
'order': 102
|
||||
})
|
||||
|
||||
except Exception:
|
||||
self.invalidItemException()
|
||||
|
||||
@ -94,12 +105,17 @@ class Transports(ModelHandler):
|
||||
'priority': item.priority,
|
||||
'nets_positive': item.nets_positive,
|
||||
'networks': [{'id': n.id} for n in item.networks.all()],
|
||||
'allowed_oss': [{'id': x} for x in item.allowed_oss.split(',')] if item.allowed_oss != '' else [],
|
||||
'deployed_count': item.deployedServices.count(),
|
||||
'type': type_.type(),
|
||||
'protocol': type_.protocol,
|
||||
'permission': permissions.getEffectivePermission(self._user, item)
|
||||
}
|
||||
|
||||
def beforeSave(self, fields):
|
||||
fields['allowed_oss'] = ','.join(fields['allowed_oss'])
|
||||
|
||||
|
||||
def afterSave(self, item):
|
||||
try:
|
||||
networks = self._params['networks']
|
||||
@ -108,5 +124,13 @@ class Transports(ModelHandler):
|
||||
return
|
||||
if networks is None:
|
||||
return
|
||||
logger.debug('Params: {0}'.format(networks))
|
||||
logger.debug('Networks: {0}'.format(networks))
|
||||
item.networks = Network.objects.filter(id__in=networks)
|
||||
|
||||
# try:
|
||||
# oss = ','.join(self._params['allowed_oss'])
|
||||
# except:
|
||||
# oss = ''
|
||||
# logger.debug('Devices: {0}'.format(oss))
|
||||
# item.allowed_oss = oss
|
||||
# item.save() # Store correctly the allowed_oss
|
||||
|
@ -1,4 +1,4 @@
|
||||
# jshint strict: true
|
||||
# jshint strict: true
|
||||
gui.connectivity =
|
||||
transports: new GuiElement(api.transports, "trans")
|
||||
networks: new GuiElement(api.networks, "nets")
|
||||
@ -41,6 +41,14 @@ gui.connectivity.link = (event) ->
|
||||
# Load osmanager "info"
|
||||
gui.methods.typedShow gui.connectivity.transports, selected[0], '#transports-info-placeholder .well', gettext('Error accessing data')
|
||||
|
||||
onData: (data) ->
|
||||
$.each data, (undefined_, value) ->
|
||||
if value.allowed_oss != ''
|
||||
value.allowed_oss = (v.id for v in value.allowed_oss).toString()
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
buttons: [
|
||||
"new"
|
||||
"edit"
|
||||
@ -69,4 +77,4 @@ gui.connectivity.link = (event) ->
|
||||
|
||||
return
|
||||
|
||||
return
|
||||
return
|
||||
|
@ -105,7 +105,7 @@ def index(request):
|
||||
trans = []
|
||||
for t in svr.transports.all().order_by('priority'):
|
||||
typeTrans = t.getType()
|
||||
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']):
|
||||
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']) and t.validForOs(os['OS']):
|
||||
if typeTrans.ownLink is True:
|
||||
link = reverse('TransportOwnLink', args=('A' + svr.uuid, t.uuid))
|
||||
else:
|
||||
@ -147,7 +147,7 @@ def index(request):
|
||||
trans = []
|
||||
for t in svr.transports.all().order_by('priority'):
|
||||
typeTrans = t.getType()
|
||||
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']):
|
||||
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']) and t.validForOs(os['OS']):
|
||||
if typeTrans.ownLink is True:
|
||||
link = reverse('TransportOwnLink', args=('F' + svr.uuid, t.uuid))
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user