%!
import logging
# uiHelper requires splunk.util to be imported.
import splunk.util
#needed for views page
import lxml.etree as et
from xml.sax.saxutils import quoteattr
import re
logger = logging.getLogger('splunk.appserver.templates.admin._helpers')
sharing_names = {'user' : _("Private"),
'app' : _("App"),
'global' : _("Global"),
'system' : _("Global")}
action_names = {'disable' : _("Disable"),
'enable' : _("Enable"),
'remove' : _("Delete")}
%>
<%def name="renderBreadcrumbs(breadcrumb)">
% if breadcrumb:
\
% for i, (title, url) in enumerate(breadcrumb):
% if i:
»
% endif
% if url:
${title|h}
% else:
${title|h}
% endif
% endfor
% endif
%def>
<%def name="message(content=None, level='info')">
% if content:
% if isinstance(content, basestring):
- ${content|h}
% elif isinstance(content, list):
% for x in content:
- ${x|h}
% endfor
% else:
- ${_('Invalid message type:')} ${content|h}
% endif
% endif
%def>
<%def name="generateFormRow(element, eaiAttributes, form_defaults)">
<%
widget = element['type'] if 'type' in element else 'textfield'
widgetstyle = ''
depends = element.get('hideUnlessFieldSet')
hidetype = 'hideUnlessFieldSet' if element.has_key('hideUnlessFieldSet') else None
if not hidetype:
hidetype = 'nullUnlessFieldSet' if element.has_key('nullUnlessFieldSet') else None
if hidetype:
depends = element[hidetype]
depends = depends if isinstance(depends, list) else [ depends ]
for depend in depends:
if not form_defaults.get(depend, ''):
if hidetype == 'nullUnlessFieldSet':
widget = 'hidden'
else:
widgetstyle = 'style="display: none"'
%>
<%include file="/admin/widgets/${widget}.html" args="element=element, eaiAttributes=eaiAttributes, widgetstyle=widgetstyle" />
%def>
<%def name="makeSortHeading(elementLabel, elementName, kwargs)">
<%
sort_key = kwargs.get("sort_key", None)
sort_dir = kwargs.get("sort_dir", None)
import copy
qs = copy.deepcopy(kwargs)
qs['sort_key'] = elementName
isSorted = (sort_key == elementName)
if sort_dir == None :
sort_dir = "asc"
sort_class = "splSortNone"
elif sort_dir == "desc":
sort_dir = "asc"
sort_class = "splSortDesc"
else:
sort_dir = "desc"
sort_class = "splSortAsc"
qs['sort_dir'] = sort_dir
%>
${elementLabel}
% if isSorted:
% else :
% endif
%def>
<%def name="genListRows(namespace, uiHelper, entities, endpoint_path, kwargs=None)">
<%
from urllib import quote
from lib.eai import cpQuoteEntity
countRows = 0
try:
hasCreateLink = filter((lambda x: x[0] == 'create'), entities.links)
except:
hasCreateLink = False
%>
<%def name="genDataCells(elements, entity_endpoint_path, headerRow=False)">
% for element in elements:
% if headerRow:
% if "list" in element.get("showInView", []):
% if "elements" in element:
<%call expr="genDataCells(element['elements'], entity_endpoint_path, headerRow)"/>
% endif
<%
elementLabel = None
if "labelList" in element:
elementLabel = _(element["labelList"])
elif "label" in element:
elementLabel = _(element["label"])
elif element["type"] != "fieldset":
elementLabel = element["elementName"]
else:
continue
%>
<%call expr="makeSortHeading(elementLabel, element['elementName'], kwargs)"/>
|
% endif
% else:
% if "list" in element.get("showInView", []):
% if "elements" in element:
<%call expr="genDataCells(element['elements'], entity_endpoint_path, headerRow)"/>
% endif
% if element.get("type") != "fieldset":
% if element.get("elementName") == "name":
<%
qs = {'action':'edit'}
if entity['eai:acl']['app']:
qs['ns'] = entity['eai:acl']['app']
list_links = filter((lambda x: x[0] == 'list'), entity.links)
%>
% if list_links:
<% qs['uri'] = list_links[0][1] %>
${entity.name | h}
% else:
${entity.name | h}
% endif
% else:
<%
# apply any transformations defined in uiHelper
value = entity.get(element['elementName'], '')
processed_value = None
if element.has_key('processValueList'):
try:
processed_value = eval(element['processValueList'])
except Exception, e:
logger.error('uiHelper processValueList operator failed for endpoint_path=%s elementName=%s: %s' % (endpoint_path, element['elementName'], str(e)))
processed_value = '[PROCESSING ERROR]'
%>
% if element.has_key('showRSSLink'):
% if value == "1":
% endif
% elif processed_value is None:
${value|h}
% else:
${processed_value|h}
% endif
% endif
|
% endif
% endif
% endif
% endfor
%def>
% if len(entities) == 0:
<%doc>TRANS: Displayed if no admin entities exist to list%doc>${_('There are no configurations of this type.')} ${hasCreateLink and _('Click the "New" button to create a new configuration.') or ""} |
% endif
<%
isAppList = True if endpoint_path == 'apps/local' else False
isDeploymentserverclass = True if endpoint_path == 'deployment/serverclass' else False
isSavedsearches = True if endpoint_path == 'saved/searches' else False
isClonable = False if endpoint_path in ['data/outputs/tcp/group','admin/win-event-log-collections','data/lookup-table-files'] else True
isEnablable = False if endpoint_path in ['admin/win-wmi-collections'] else True
showEnabledColumn = False if uiHelper.get('hideEnabledColumn') else True
showPermissionsColumn = False if uiHelper.get('hidePermissionsColumn') else True
showActionsColumn = False if uiHelper.get('hideActionsColumn') else True
%>
% for entity in entities.values():
<%
isDeletable = False if ( (endpoint_path in ['admin/win-wmi-collections']) or (endpoint_path in ['admin/win-event-log-collections'] and entity.name=='localhost') ) else True
%>
% if "elements" in uiHelper:
<%
headerRow = False
if countRows == 0:
headerRow = True
isModifiable = True if entity['eai:acl']['modifiable']=="1" else False
isScheduled = True if entity.get('is_scheduled')=="1" else False
%>
% if headerRow:
<%call expr="genDataCells(uiHelper['elements'], endpoint_path, headerRow)"/>
% if showPermissionsColumn:
% if isModifiable:
<%call expr="makeSortHeading(_('Sharing'), 'eai:acl.sharing', kwargs)"/>
|
% endif
%endif
% if showEnabledColumn:
<%call expr="makeSortHeading(_('Enabled'), 'disabled', kwargs)"/>
|
% endif
% if showActionsColumn:
${_('Actions')} |
% endif
<%
## the header has been created, proceed...
headerRow = False
%>
% endif
<% entity_endpoint_path = entity.get('endpoint_base', endpoint_path) %>
<%call expr="genDataCells(uiHelper['elements'], entity_endpoint_path, headerRow)"/>
% if showPermissionsColumn:
% if isModifiable:
<% list_links = filter((lambda x: x[0] == 'list'), entity.links) %>
${sharing_names.get(entity['eai:acl']['sharing'], "")}
% if list_links and (entity['eai:acl'].get('sharing', None) != 'user' or entity['eai:acl'].get('can_share_app', None) == '1'):
<% qs = {'uri': list_links[0][1]} %>
| ${_("Permissions")}
% endif
|
% endif
%endif
% if showEnabledColumn:
% if isEnablable:
<%
if not splunk.util.normalizeBoolean(entity.get('disabled',None)):
enabledState = _("Enabled")
else:
enabledState = _("Disabled")
endif
%>
${enabledState}
% endif
|
% endif
% if showActionsColumn:
% if isEnablable:
% if entity['eai:acl']['can_write']=='1':
% for ctrl in ('disable', 'enable'):
<% ctrl_links = filter((lambda x: x[0] == ctrl), entity.links) %>
% if ctrl_links:
<% jscall = "doObjectAction('%s', '%s', '%s'); return false;" % ( ctrl.replace("'","\\'"), ctrl_links[0][1].replace("'","\\'"), entity.name.replace("'","\\'") ) %>
${_(action_names[ctrl])}
|
% endif
% endfor
% endif
% endif
% if (isSavedsearches and isScheduled):
${_("View recent")}
|
% endif
% if isDeploymentserverclass:
<%
link_url = filter((lambda x: x[0] == "status"), entity.links)[0][1]
link_url_parts = link_url.split('/')
status_link = ""
if link_url_parts[1] == "servicesNS":
# for servicesNS, remove the app and user parts + deployment since that is where we are.
status_link = "/".join(link_url_parts[5:])
else:
# for services, there are no app and user parts to remove
status_link = "/".join(link_url_parts[2:])
%>
status
% endif
% if isAppList:
% if filter((lambda x: x[0] == 'setup'), entity.links):
<% qs = {'action':'edit'} %>
${_("Setup")}
|
% endif
% if entity['disabled'] == '0':
<% qs = {'ns':entity.name, 'app_only':'1'} %>
${_("View configurations")}
% endif
% else:
<% needs_sep = False %>
<% list_links = filter((lambda x: x[0] == 'list'), entity.links) %>
% if isClonable and list_links and hasCreateLink:
% if needs_sep:
|
% endif
<% needs_sep = True %>
<%doc>TRANS: Clicked to clone an existing enity%doc>${_('Clone')}
% endif
% if entity['eai:acl']['can_write']=='1':
<% ctrl_links = filter((lambda x: x[0] == 'remove'), entity.links) %>
% if isDeletable and ctrl_links:
% if needs_sep:
|
% endif
<% jscall = "doObjectAction('remove', '%s', '%s');" % ( ctrl_links[0][1].replace("'","\\'"), entity.name.replace("'","\\'") ) %>
${_(action_names['remove'])}
% endif
% endif
% endif
|
% endif
% endif
<% countRows += 1 %>
% endfor
%def>
<%def name="menulist(namespace, menuDict)">
<%
label = menuDict.get("label", None)
menuItems = menuDict.get("menuItems",[]) # menu items is a list of dicts.
%>
% if label:
${_(label)}
% endif
% for item in menuItems:
<%
itemLabel = item.get("label", "A label is required for this item.")
itemUrl = item.get("url", None)
itemDescription = item.get("description", None)
links = item.get("links", None)
%>
-
% if itemUrl:
${_(itemLabel)}
% else:
${_(itemLabel)}
% endif
% if links:
% for link in links:
<%
label = link.get("label", "label is required and not provided")
url = "#"
localUrl = link.get("local-url", None)
remoteUrl = link.get("remote-url", None)
if remoteUrl != None:
url = remoteUrl
target = "_blank"
## local url's win if both are defined
if localUrl != None:
url = make_url(localUrl % dict(namespace=namespace))
target = "_top"
%>
|${_(label)}
% endfor
% endif
% if itemDescription:
- ${_(itemDescription)}
% endif
% endfor
%def>
## used by admin/EAI to hook events into widgets
<%def name="wireElementEvents(element, eltype=None)">
<%
eltype = eltype if eltype else element['type']
%>
% if element.has_key('onChange') and eltype in ('select', 'multiselect', 'hidden'):
onchange="${'Splunk.EAI.getInstance().doElementOnChange(this, %s)' % (jsonify(element['elementName']).replace('"', "'"))}"
% endif
% if element.has_key('onChange') and eltype in ('radio','checkbox','button') :
onclick="${'Splunk.EAI.getInstance().doElementOnChange(this, %s)' % (jsonify(element['elementName']).replace('"', "'"))}"
% endif
%def>
<%def name="header(namespace)">
%def>
<%def name="displayrestartbutton(displayRestartButton=True)">
% if displayRestartButton:
<%doc>TRANS: Clicked to restart splunkd%doc>${_('Restart Splunk')}
% endif
%def>