<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, 
																			 com.novell.emframe.dev.*,
																			 com.novell.admin.ns.AdminNamespace,
																			 com.novell.admin.ns.ObjectAttribute,
																			 com.novell.admin.ns.ValueComponent,
																			 com.novell.application.console.snapin.ObjectEntry,
																			 com.novell.nps.utils.Utils" %>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("BaseResources"); %>

<HTML>
<HEAD>
   <TITLE><%= c.string("ProductName") %></TITLE>

   <jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/XmlScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/ValidateIntegerScripts_inc.jsp") %>' flush="true" />

   <LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
   <jsp:include page='<%= c.getPath("dev/PageScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/OSScripts_inc.jsp") %>' flush="true" />
   <iman:calendarScripts/>
   <SCRIPT language="JavaScript">

      lmsTemp = "";
      var ENABLED_COLOR = "white";
      var DISABLED_COLOR = "#EFEEE9";

     /*
      *This function sets the last login time, using a localized string that 
      *uses the client timezone.
      */
	  function populateLastLoginTimestamp(localizedString){
	  	 var form = document.forms[0];
	  	 form._Login_Time.value = localizedString;
	  }
	
      function onInit()
      {
         var form=document.forms[0];

         <%-- -------------- --%>
         <%-- Login Disabled --%>
         <%-- -------------- --%>
         var xml="<%= c.toScript(c.var("eDir$target$accountDisabled")) %>";
         if(getValueFromXml(xml) == 'true')
            form._eDir$target$accountDisabled.checked=true;
         initMooMode("_accountDisabled", xml);

         <%-- ------------------------ --%>
         <%-- Password Expiration Time --%>
         <%-- ------------------------ --%>
         var strXml = "<%= c.toScript(c.var("eDir$target$accountDisabledUntil")) %>";
         secStr = getValueFromXml(strXml);
         msecs = parseInt(secStr);

         if(msecs>0)
         {
            var date = new Date(msecs);
            form.expDay.value = date.getDate();
            form.expMonth.options[date.getMonth()+1].selected = true;
            form.expYear.value = date.getFullYear();
            form.expHour.options[date.getHours()].selected = true;
            form.expMinute.value = date.getMinutes();
            if(form.expMinute.value.length == 1)
            {
               form.expMinute.value = "0"+form.expMinute.value;
            }
            form.hasExpiration.checked = true;
         }

         initMooMode("_accountDisabledUntil", strXml);

         // disable if no rights
         <% if (c.var("eDirRights$target$accountDisabledUntil").equals("R") || c.var("eDirRights$target$accountDisabledUntil").equals("NONE")){ %>
            disableControl(form.expDay);
            disableControl(form.expMonth);
            disableControl(form.expYear);
            disableControl(form.expHour);
            disableControl(form.expMinute);
         <% } %>

      }
      <%-- ---------------------------------------------------- --%>
      <%-- isPageValid                                          --%>
      <%-- called when user leaves this page or applys changes  --%>
      <%-- ---------------------------------------------------- --%>
      function isPageValid()
      {
         var form=document.forms[0];

         <%-- Login Disabled --%>
         form.eDir$target$accountDisabled.value = toXmlString((form._eDir$target$accountDisabled.checked?'true':'false')<% if (c.var("Task.moo").equals("true")) { %>, form._accountDisabled_mode.value<% } %>);

         <%-- Password Expiration Time --%>
         if((form.hasExpiration.checked)&&(form.expDay.value.length != 0))
         {
            var date = new Date(form.expYear.value, form.expMonth.value, form.expDay.value, form.expHour.value, form.expMinute.value);
            var milliSeconds = date.valueOf();

            if( isNaN(milliSeconds))
            {
               alert("<%= c.string("PasswordRestrictionsFormatError") %>");
               form.expDay.focus();
               return false;
            }

            form.eDir$target$accountDisabledUntil.value = toXmlString(""+milliSeconds <% if (c.var("Task.moo").equals("true")) { %>, form._accountDisabledUntil_mode.value<% } %>);
         }
         else
         {
            form.eDir$target$accountDisabledUntil.value = toXmlString(""<% if (c.var("Task.moo").equals("true")) { %>, form._accountDisabledUntil_mode.value<% } %>);
         }

          return true;
      }

      function disableControl(control)
      {
         control.disabled = true;
         control.style.backgroundColor = DISABLED_COLOR;
      }

      function enableControl(control)
      {
         control.disabled = false;
         control.style.backgroundColor = ENABLED_COLOR;
      }

      function EnableDisableControls()
      {
         with(document.forms[0])
         {
            if (_eDir$target$accountDisabled.checked)
            {
               disableControl(hasExpiration);
               disableControl(expDay);
               disableControl(expMonth);
               disableControl(expYear);
               disableControl(expHour);
               disableControl(expMinute);
            }
            else
            {
               enableControl(hasExpiration);

               if (hasExpiration.checked)
               {
                  enableControl(expDay);
                  enableControl(expMonth);
                  enableControl(expYear);
                  enableControl(expHour);
                  enableControl(expMinute);

                  if (expDay.value.length == 0)
                  {
                     // now default
                     var date = new Date();
                     expDay.value = date.getDate();
                     expMonth.options[date.getMonth()+1].selected = true;
                     expYear.value = date.getFullYear();
                     expMinute.value = "00";
                  }

                  if (expDay.disabled == false)
                  {
				        expDay.focus();
                  }
               }
               else
               {
                  disableControl(expDay);
                  disableControl(expMonth);
                  disableControl(expYear);
                  disableControl(expHour);
                  disableControl(expMinute);
               }

            }

            if (!_eDir$target$accountDisabled.checked && !hasExpiration.checked && !_eDir$target$accountDisabled.disabled)
            {
               _eDir$target$accountDisabled.focus();
            }
         }
      }
      
      /*callback function for calendar widget*/
      function getExpTime()
      {
         var form = document.form;
         if(form.hasExpiration.checked == true)
         {
            return new Date(form.expYear.value, form.expMonth.value, form.expDay.value, form.expHour.value, form.expMinute.value);
         }
         else
         {
            return new Date();
         }
      }
      
      /*callback function for calendar widget*/      
      function returnExpTime(date)
      {
         var form = document.form;
         if(form.hasExpiration.checked == true)
         {
            form.expDay.value = date.getDate();
            form.expMonth.options[date.getMonth()+1].selected = true;
            form.expYear.value = date.getFullYear();
            form.expHour.options[date.getHours()].selected = true;
            form.expMinute.value = date.getMinutes();
            if(form.expMinute.value.length == 1)
            {
               form.expMinute.value = "0"+form.expMinute.value;
            }
         }
      }
   </SCRIPT>
</HEAD>

<BODY onLoad="onInit();EnableDisableControls();">
<FORM name="form" method=post action="webacc">
   <jsp:include page='<%= c.getPath("dev/Messagebar_inc.jsp") %>' flush="true" />
	<jsp:include page='<%= c.getPath("dev/BookVars_inc.jsp") %>' flush="true" />


   <TABLE class="mediumtext" border="0" bgcolor='#FFFFFF' cellpadding="0" cellspacing="0">

      <%-- -------------- --%>
      <%-- Login Disabled --%>
      <%-- -------------- --%>
      <TR>
         <TD style="padding-right:4"align=left valign=middle>
            <INPUT name='_eDir$target$accountDisabled' onClick="EnableDisableControls()" type=checkbox <% if (c.var("eDirRights$target$accountDisabled").equals("R") || c.var("eDirRights$target$accountDisabled").equals("NONE")) { %>DISABLED<% } %> >
         </TD>
         <TD align=left valign=middle colspan=2>
            <INPUT name='eDir$target$accountDisabled' type=hidden><%= c.toDisplay(c.string("LoginRestriction.AcctDisabled")) %>
         </TD>
         <TD>
            <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_accountDisabled_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
         </TD>
      </TR>
      <TR><TD height=9></TD></TR>


      <%-- --------------------- --%>
      <%-- Login Expiration Time --%>
      <%-- --------------------- --%>
      <TR>
         <TD align=left valign=middle>
            <input type=Checkbox name="hasExpiration" value="" <% if (c.var("eDirRights$target$accountDisabledUntil").equals("RW")) {%> onClick="EnableDisableControls()" <%} %> <% if (c.var("eDirRights$target$accountDisabledUntil").equals("R") || c.var("eDirRights$target$accountDisabledUntil").equals("NONE")) { %>DISABLED<% } %> >
         </TD>
         <TD align=left valign=middle>
            <%= c.string("ModifyOrg.HasExpiration") %>
         </TD>
      </tr>
      <TR>
         <TD align=left></TD>
         <TD><NOBR><%= c.toDisplay(c.string("LoginExpir.DateTime")) %>:</NOBR></TD>
      </TR>

      <TR>
         <TD>&nbsp;</TD>

         <TD class=smalltext>
           &nbsp;&nbsp;&nbsp;<%= c.string("Date.Day") %>: <input type=text name=expDay size=2>&nbsp;
            <%= c.string("Date.Month") %>: <select name=expMonth size="1" style="width:130px">
                <option value=12></option>
                <option value=0><%= c.string("Date.Month.0") %>
                <option value=1><%= c.string("Date.Month.1") %>
                <option value=2><%= c.string("Date.Month.2") %>
                <option value=3><%= c.string("Date.Month.3") %>
                <option value=4><%= c.string("Date.Month.4") %>
                <option value=5><%= c.string("Date.Month.5") %>
                <option value=6><%= c.string("Date.Month.6") %>
                <option value=7><%= c.string("Date.Month.7") %>
                <option value=8><%= c.string("Date.Month.8") %>
                <option value=9><%= c.string("Date.Month.9") %>
                <option value=10><%= c.string("Date.Month.10") %>
                <option value=11><%= c.string("Date.Month.11") %>
            </select>&nbsp;
           <%= c.string("Date.Year") %>: <input type=text name=expYear size=4>&nbsp;
           <%= c.string("Date.Time") %>: <select name=expHour>
              <option value=00>00</option>
              <option value=01>01</option>
              <option value=02>02</option>
              <option value=03>03</option>
              <option value=04>04</option>
              <option value=05>05</option>
              <option value=06>06</option>
              <option value=07>07</option>
              <option value=08>08</option>
              <option value=09>09</option>
              <option value=10>10</option>
              <option value=11>11</option>
              <option value=12>12</option>
              <option value=13>13</option>
              <option value=14>14</option>
              <option value=15>15</option>
              <option value=16>16</option>
              <option value=17>17</option>
              <option value=18>18</option>
              <option value=19>19</option>
              <option value=20>20</option>
              <option value=21>21</option>
              <option value=22>22</option>
              <option value=23>23</option>
           </select>:<input type=text name=expMinute size=2 maxlength=2>&nbsp;
           <iman:calendar onLoadCallback="getExpTime" name="expTimeWidget" returnCallback="returnExpTime"/>

            <INPUT name='eDir$target$accountDisabledUntil' type=hidden value="<%= c.var("eDir$target$accountDisabledUntil") %>">
        </TD>

         <TD valign=top>
            <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_accountDisabledUntil_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
         </TD>
      </TR>
      <TR><TD height=9></TD></TR>
      
      <%-- ------------ --%>
      <%-- Login Policy --%>
      <%-- ------------ --%>
      <%
		      MContext taskContext = eMFrameFactory.getMContext(request);
		   
		      ObjectEntry treeOE = (ObjectEntry) taskContext.getAuthenticationBroker().getProtocolObject(AuthenticationBroker.PROTOCOL_ADMINNAMESPACE);
		      AdminNamespace ns = (AdminNamespace) treeOE.getNamespace(); 
		      ObjectEntry objectEntry = null;
		      ObjectAttribute policyAttr = null;
		      ObjectAttribute[] LPLAttrs = null;
	      	  ValueComponent[] vc = null;
		      ObjectAttribute tempAttr;
		      String[] attrNames = {"pwdFailureCountInterval",
										"pwdDelayReturnOnFailedLogin",
										"pwdLockoutDuration",
										"pwdLockout",
										"pwdMaxFailure"};
		      try
		      {
		      	 //get the object entry of the current target
		         //objectEntry = ns.getObjectEntry(eMFrameUtils.unpack((String)c.get("eDir$target"), taskContext)[0]);
		         objectEntry = ns.getObjectEntry(eMFrameUtils.unpack(c.var("eDir$target"), taskContext)[0]);
		         //now get the value of the login policy attribute
		         policyAttr = ns.getAttribute(objectEntry, "loginPolicyAdministrativeArea");
		         vc = policyAttr.getBeginningComponents();
			     StringBuffer policyDN = new StringBuffer();
		         for(int iv=0; iv<vc.length; iv++)
		         {
		            policyDN.append(vc[iv].toString());
		         }
		         
		         //the login policy attribute contains a DN to a policy object
		         //now we need to get the actual policy object
		         objectEntry = ns.getObjectEntry(policyDN.toString());
		         
		         //finally, get the policy data from the policy object attributes
		         //specifically named in the attrNames array and print them out
		         LPLAttrs = ns.getAttributes(objectEntry, attrNames);
		         out.println("<TR>");
         		 out.println("<TD align=left valign=middle colspan=4>");
            	 out.println("<div class='margintop1'><u>Login Policy</u></div>");
               	 out.println("<div class='marginleft2'>");
            
                 for(int i=0; i<LPLAttrs.length; i++)
	             {
	                tempAttr = LPLAttrs[i];
	                out.print(c.string("LoginRestriction."+tempAttr.getName())+": ");
	                vc = tempAttr.getBeginningComponents();
	                for(int j=0; j<vc.length; j++)
	                {
	                   out.print(vc[j].toString());
	                }
	                out.println("<br>");
	             }     
		      }
		      catch(Exception e)
		      {
		   	     D.log("Unable to find a password login policy");
		      }
            %>
            </div>
         </TD>
      </TR>
      <TR><TD height=9></TD></TR>
      
      

	  <IFRAME src="/nps/Empty.html" style="visibility: hidden" name="dateFrame" id="dateFrame" width="0" height="0" marginwidth="0" marginheight="0"></IFRAME>
   </TABLE>
</FORM>
</BODY>
</HTML>

