<%!
    title = 'Splunk Admin Authentication Control'
%>
<%namespace name="lib" file="//lib.html" import="*"/>
<%namespace name="helpers" file="_helpers.html"/>
<%inherit file="//layout/admin.html"/>
<%
import splunk
from splunk.appserver.mrsparkle.lib import util, i18n
sessionId = cherrypy.session.id
selected = ""
%>

<style>
    .jmFormActions {
        margin-top:20px; 
        width:660px;  
    }
</style>
% if message:
    <%helpers:message content="${message}" level="info"/>
% endif
 <div id="ldapTabs" class="tabsWrapper">
         <ul class="tabs">        
            <li>
                <a href="#ldapConfiguration">LDAP configuration</a>
            </li>
            <li> 
                <a href="#roleMapping">Role mapping</a>
            </li>
        </ul>
    </div> 
    
<div class="licenseWrapper">
         
            
    <h1>${_('LDAP mapping')}</h1>
    
    <div>${_('First save your initial configuration, then login as failsafe user and use this screen to set up your role mappings.')}</div>
    <form method="post" action="${make_url(['manager', namespace, 'authentication', 'providers', 'LDAP', 'LDAP'])}">
    <div id="ldapConfiguration">
        
        <h2>${_('LDAP configuration:')}</h2>
        <table>
        % for property in LDAPEntity.properties:
            % if not property.startswith("roleMap_") and not property == 'eai:acl':
            <tr>
                <td>${property}:</td>
                <td>
                    <%
                    if property.lower().count("password") > 0:
                        type = 'type="password"'
                    else:
                        type = 'type="text"'
                    endif
                    propVal = "" if LDAPEntity[property] == None else LDAPEntity[property]
                    %>
                    <input ${type} size="50" name="${property}" value="${propVal}"/></td>
            </tr>
            % endif
        % endfor
        </table>
    </div>    
    
    <div id="roleMapping">    
        <h2>${_('Role mapping:')}</h2>
        <table>
            % for role in splunkroles:
            <tr>
                <td valign="top">${role}:</td>
                <td valign="top"><select multiple="multiple" name="roleMap_${role}" size="5">
                    <option value="">None mapped</option>
                    % for extRole in externalRoles:
                        % if extRole != "eai:acl":
                            <%
                            selected = ""
                            if extRole in LDAPEntity.get('roleMap_' + role, []):
                                selected = "selected='selected'"
                            endif
                            %>
                            <option value="${extRole}" ${selected}>${extRole}</option>
                        % endif
                    % endfor
                </select></td>
            % endfor
            </tr>
        </table>
    </div>
        
    
    <div class="jmFormActions">
        <button type="submit" class="splButton-primary" onclick="updateEntity(false)">
            <span>${_('Save')}</span>
        </span>
    </div>
    
    <input type="hidden" name="spl-ctrl_redirectionPath" value="ldapmapping" />
    ${csrf_hidden_input()}
    </form>
    
</div>
<script type="text/javascript">
    adminTabify("ldapTabs", "ldapConfiguration");
 </script>



