<%@ page language="VB" autoeventwireup="false" inherits="RCC_VPS_VMConsole, MachSol.MachPanel.Web" %>

<%-- for help go through https://msdn.microsoft.com/en-us/library/windows/desktop/aa383541%28v=vs.85%29.aspx --%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <title>Remote Desktop</title>
 <meta http-equiv="x-ua-compatible" content="IE=8"/>
     
     <script type="text/javascript" language="javascript">
         function ResizeWindow(width, hight) {
             //   alert(width + +hight);
             //  window.resizeBy(width, hight);
             //window.resizeTo(width, hight);
         }

     </script>
 <style type="text/css" media="screen">
     P {
         font-family: Verdana, Arial, Helvetica;
         color: #000000;
         font-size: 65%;
     }

     .Port {
         font-family: Verdana, Arial, Helvetica;
         color: #000000;
         font-size: 65%;
     }

     H1 {
         margin-top: 0em;
         font-family: verdana, arial, helvetica;
         font-size: 100%;
         font-weight: bold;
     }

     P.indent {
         line-height: 1.25em;
         margin: 0.5em 1em 0.2em 3em;
     }

     .button {
         border-bottom-color: #6699ff;
         background-color: #ffffff;
         margin-top: 6pt;
         border-top-color: #6699ff;
         font-family: Verdana, Helvetica, Arial, Sans-Serif;
         color: #000000;
         border-right-color: #6699ff;
         margin-left: 0.5em;
         font-size: 70%;
         border-left-color: #6699ff;
         font-weight: normal;
     }

     .topspace {
         margin-top: 0.08em;
     }

     .auto-style1 {
         width: 16px;
     }
 </style>
      <meta name="GENERATOR" content="MSHTML 8.00.7600.16625" />
    </head>

    <body bgcolor="#ffffff" > <%--onload="<% If (Me.IsPostBack = False And Not Request.QueryString("Auto").ToString().ToLower.Contains("false")) Then%> BtnConnect()  <% End If %>"--%>
   
        <script type="text/vbscript" language="vbscript">
<!--
           
const L_FullScreenWarn1_Text = "Your current security settings do not allow automatically switching to fullscreen mode."
const L_FullScreenWarn2_Text = "You can use ctrl-alt-pause to toggle your remote desktop session to fullscreen mode"
const L_FullScreenTitle_Text = "Remote Desktop Web Connection "
const L_ErrMsg_Text         = "Error connecting to remote computer: "
const L_ClientNotSupportedWarning_Text = "Remote Desktop 6.0 does not support CredSSP over TSWeb."

' error messages
const L_RemoteDesktopCaption_ErrorMessage =  "Remote Desktop Connection"
const L_InvalidServerName_ErrorMessage = "An invalid server name was specified."

sub window_onload()
   if not autoConnect() then
       Document.all.editServer.Focus
   end if
end sub

function autoConnect()
    Dim sServer
    Dim iFS, iAutoConnect

    sServer = getQS ("Server")
    iAutoConnect = getQS ("AutoConnect")
    iFS = getQS ("FS")

    if NOT IsNumeric ( iFS ) then
        iFS = 0
    else
        iFS = CInt ( iFS )
    end if

    if iAutoConnect <> 1 then
        autoConnect = false
        exit function
    else
        if iFS < 0 or iFS >= Document.all.comboResolution.options.length then
            iFS = 0
        end if

        if IsNull ( sServer ) or sServer = "" then
            sServer = window.location.hostname
        end if

        Document.all.comboResolution.selectedIndex    = iFS
        Document.all.Server.value = sServer

        btnConnect ()

        autoConnect = true
    end if

end function

function getQS ( sKey )
    Dim iKeyPos, iDelimPos, iEndPos
    Dim sURL, sRetVal
    iKeyPos = iDelimPos = iEndPos = 0
    sURL = window.location.href

    if sKey = "" Or Len(sKey) < 1 then
        getQS = ""
        exit function
    end if

    iKeyPos = InStr ( 1, sURL, sKey )

    if iKeyPos = 0 then
        sRetVal = ""
        exit function
    end if

    iDelimPos = InStr ( iKeyPos, sURL, "=" )
    iEndPos = InStr ( iDelimPos, sURL, "&" )

    if iEndPos = 0 then
        sRetVal = Mid ( sURL, iDelimPos + 1 )
    else
        sRetVal = Mid ( sURL, iDelimPos + 1, iEndPos - iDelimPos - 1 )
    end if

    getQS = sRetVal
end function

sub checkClick
    if Document.all.Check1.Checked then
        Document.all.tableLogonInfo.style.display = ""
        Document.all.editUserName.Disabled = false
        Document.all.editDomain.Disabled = false
    else
        Document.all.tableLogonInfo.style.display = "none"
        Document.all.editUserName.Disabled = true
        Document.all.editDomain.Disabled = true
    end if
end sub

sub OnControlLoadError
    Document.all.cerrmsg.style.display = "block"
    Document.all.csafemsg.style.display = "none"
    Document.all.Server.disabled = TRUE
    Document.all.comboResolution.disabled = TRUE
end sub

sub OnControlLoad
   set Control = Document.getElementById("MsRdpClientForVM")
   if Not Control is Nothing then
      if Control.readyState = 4 then
         Document.all.connectButton.disabled = FALSE
      else
          Document.all.cerrmsg.style.display = "block"
          Document.all.csafemsg.style.display = "none"
          Document.all.Server.disabled = TRUE
          Document.all.comboResolution.disabled = TRUE
      end if
   else 
      Document.all.cerrmsg.style.display = "block"
      Document.all.csafemsg.style.display = "none"
      Document.all.Server.disabled = TRUE
      Document.all.comboResolution.disabled = TRUE
   end if
end sub


sub BtnConnect
           
   'alert("BtnConnect start")

   Dim serverName
            Dim portName
   'server
   if not Document.all.Server.value = "" then
      serverName = Document.all.Server.value
   else
      serverName = Document.location.hostname
   end if
   'msgbox serverName,0,L_RemoteDesktopCaption_ErrorMessage
   serverName = trim(serverName)

            if not Document.all.Port.value = "" then
            portName = Document.all.Port.value
            else
            portName = 3389
            end if

   On Error Resume Next
   MsRdpClientForVM.server = serverName

       
   If Err then 
      msgbox L_InvalidServerName_ErrorMessage,0,L_RemoteDesktopCaption_ErrorMessage
      Err.Clear
      exit sub
   end if
   On Error Goto 0
   
   'serverName name text
   Document.all.srvNameField.innerHtml = serverName
      
   'Resolution
   MsRdpClientForVM.FullScreen = FALSE
   select case document.all.comboResolution.value
   case "1"
     MsRdpClientForVM.FullScreen = TRUE
      resWidth  = screen.width
      resHeight = screen.height
    case "2"
      resWidth  = "640"
      resHeight = "480"
   case "3"
      resWidth  = "800"
      resHeight = "600"
      
   case "4"
      resWidth  = "1024"
      resHeight = "768"
   case "5"
      resWidth  = "1280"
      resHeight = "1024"
   case "6"
      resWidth  = "1600"
      resHeight = "1200"
   end select
            
  ' window.resizeTo resWidth+50,resHeight+100
      ' ResizeWindow resWidth,resHeight

   MsRdpClientForVM.DesktopWidth = resWidth
   MsRdpClientForVM.DesktopHeight = resHeight
   
   MsRdpClientForVM.Width = resWidth
   MsRdpClientForVM.Height = resHeight

   'Default to EnableCredSsp and negotiate authentication level
   'If functionality not supported, we ignore the error and continue
   'Admins: If Network Level Authentication(NLA) not required, you can safely
   '  delete from here to "End of CredSSP/NLA warning section" marker.
   'Server Admins: Start of CredSSP/NLA warning section
   On Error Resume Next
   
    MsRdpClientForVM.AdvancedSettings5.AuthenticationLevel = 2       
   MsRdpClientForVM.AdvancedSettings7.EnableCredSspSupport = TRUE
   
          'MsRdpClientForVM.AdvancedSettings2.EnableCredSspSupport= FALSE
          
    

''MsRdpClient.Domain="Domain";
'MsRdpClientForVM.UserName=""
'MsRdpClientForVM.AdvancedSettings2.ClearTextpassword=""
''        
   If Err then 
      msgbox L_ClientNotSupportedWarning_Text,48,L_RemoteDesktopCaption_ErrorMessage
      Err.Clear
   end if
   On Error Goto 0
   'Server Admins: End of CredSSP/NLA warning section
   
   'Device redirection options
            MsRdpClientForVM.AdvancedSettings2.RDPPort = portName
   MsRdpClientForVM.AdvancedSettings2.RedirectDrives     = FALSE
   MsRdpClientForVM.AdvancedSettings2.RedirectPrinters   = FALSE
   MsRdpClientForVM.AdvancedSettings2.RedirectPrinters   = FALSE
   MsRdpClientForVM.AdvancedSettings2.RedirectClipboard  = FALSE
   MsRdpClientForVM.AdvancedSettings2.RedirectSmartCards = FALSE

   'Set keyboard hook mode to "Always hook" - only works on XP.
   'MsRdpClientForVM.SecuredSettings2.KeyboardHookMode = 1

   'FullScreen title
   MsRdpClientForVM.FullScreenTitle = L_FullScreenTitle_Text & "(" & serverName & ")"
   
   'Display connect region
          
              
             Document.all.loginArea.style.display = "none"
             Document.all.connectArea.style.display = "block"

   'Connect
          
  ' alert("Hello before Connect command")
  
             MsRdpClientForVM.Connect
     
   'alert("Hello after Connect command")
           
end sub

-->

    </script>

<!--   
-->

<!-- =========================LOGIN AREA   ==========================-->
<div id="loginArea">
<%--<font size="4">
<img border="0" src="Images/hv.png" id=leftalign align="left" width="101" height="100" hspace="25"></font></font><font id=Tahoma1 face="Tahoma" size="1"><br>
</font><font size="6" id=Tahoma2 face="Tahoma">
<img border="0" src="Images/win2000r.png" hspace="0" vspace="7" width="145" height="45"></font><font id=Tahoma3 face="Tahoma" size="4"><br>
</font><b>
<font id=Tahoma4 face="Calibri" size="5"><ID id=bigtitle><span style="color: #db312d">MachPanel </span>Remote Desktop Web Connection </ID></font></b><p>&nbsp;</p>
--%><table>
    <tr>
     <th width="70%" height="45" align="center">
                    <asp:Image ID="Img_Logo" runat="server" ImageUrl="~/App_Themes/Default/Images/icons/logo.png"
                        class="width-500px" />
                </th>
        </tr>
    </table>
    <br/>
    <br/>
<table border="0" width="640" cellspacing="0" cellpadding=0 class="Graphic-bar" <%----%>>
<!-- Graphic bar row  -->
<tr>
    
<td colspan="4" <%--width="50%"--%>>
<img src="../../../../images/bluebarh.png" alt="blue bar graphic" height="8" class="width-324px"></td>
<td colspan=4 align="left" valign="middle">
    &nbsp;</td>
</tr> 
<!-- Row 1 -->
<tr>       
<!-- Column 2 spans 4 rows-->
	<td rowspan=4 valign="top" align="left" class="auto-style1">
    <img src="../../../../images/bluebarv.png" alt="blue bar graphic" border=0 width="8" height="330">
	</td>
	
<!-- Column 3 -->		
    <td id="ServerNameKeyWidth" align="left" class="width-10percent" valign="middle">     
         <label id=ServerNameKey accessKey="S" for="editServer">
         <br><p align="right">&nbsp;<ID id=ServerName><u>S</u>erver:</ID></label></p>
     </td>
		  
<!-- Column 4 -->		  
	<td id="ServerKeyWidth" width="40%" valign="bottom">
	<br>&nbsp;&nbsp;<input type="text" name="Server" size="30" id="editServer" value="<%= Me.ViewState("VMIP")%>"> 
        <span class="Port"><ID id=PortName><u>P</u>ort:</ID></span>&nbsp;&nbsp;<input type="text" name="Port" size="6" id="editPort" value="3389">
        <%--<asp:TextBox ID="editServer" size="41" runat="server"></asp:TextBox>--%>
	
	</td>
	</tr>
<!-- Row 2 -->
<tr>
<!-- Column 3 -->
<td valign="middle">
<p align="right"><label id=sizeKey accessKey="Z" for="comboRes" class="sizespace"><ID id=size>Si<u>z</u>e:</ID></p></td>
<!-- Column 4 -->
<td valign="bottom">&nbsp;&nbsp;
    <select size="1" name="comboResolution" id=comboRes class="topspace">
              <option selected value="1"><ID id=option1>Full-screen</ID></option>
              <option value="2"><ID id=option2>640 by 480</ID></option>
              <option value="3"><ID id=option3>800 by 600</ID></option>
              <option value="4"><ID id=option4>1024 by 768</ID></option>
              <option value="5"><ID id=option5>1280 by 1024</ID></option>
              <option value="6"><ID id=option6>1600 by 1200</ID></option>
   </select> </label>
</td>
</tr>
<!-- Row 3 -->
<tr>
<!-- Column 3 -->
<td></td>
<!-- Column 4 -->
<td align="bottom">			
	 <p class=topspace>&nbsp;<input type="checkbox" name="CheckBoxAutoLogon" ID="Check1" value="OFF" onclick = "checkClick()"><label for="Check1" ID=SendLogonKey accesskey="l"><ID id=logoninfo>Send <u>l</u>ogon information for this connection&nbsp;</ID></label><br>
	  
<span ID="tableLogonInfo" style="display: none">

            <p align="right" class=topspace>
			<br> 
			<ID id=usernamelabel><u>U</u>ser&nbsp;name:</ID>
                <label id=UserNameKey accessKey="U" for="editUserName"><input type="text" name="UserName" id=editUserName size="25"></label><br>
			<ID id=domainlabel><u>D</u>omain:</ID>
          <label id=editDomainKey accessKey="D" for="editDomain">
          <input type="text" name="Domain" id=editDomain size="25"></label></p></span>	
          <input type="submit" id=connectbutton value="Connect" disabled="TRUE" name="ButtonLogin"  OnClick="BtnConnect()" class="button">
         <%--<asp:Button ID="btnAutoConnect" runat="server" Text="Auto Connect" Visible="false" OnClick="BtnConnect()" />--%>
          <table>
      <tr><!-- Column 1 spans 4 rows -->
    <td  colspan="4" valign="top">
        <p <%--class=indent--%>><ID id=ID3><b><%= Me.ViewState("HelpandInstructions")%></b></ID></p>
        <p <%--class=indent--%>><ID id=ID4><%= Me.ViewState("VMConsoleButtonToolTip")%></ID></p>
    </td></tr>
  </table>
</td>
   
<!-- Row 4 -->
<tr>
<!-- Column 3 -->
<td height="150">&nbsp;</td>      
<!-- Column 4 -->
<td>&nbsp;</td>
</tr>
    <tr><!-- Column 1 spans 4 rows -->
    <td  colspan="4" valign="top">
     </td></tr>

</table>
 
   
</div>
<!-- ================================= LOGIN FORM =================-->

<!-- ================================= CONNECT ====================-->
<div style="display: none" id="connectArea">
        <center>
            <table>
                <tbody>
                    <tr>
                        <td>
                            <object 
                                id="MsRdpClientForVM" 
                                language="vbscript" 
                                onreadystatechange="OnControlLoad()" 
                                onerror="OnControlLoadError()"
                                classid="CLSID:4eb89ff4-7f78-4a0f-8b8d-2bf02e94e4b2" 
                                width="800" 
                                height="600">
                            </object>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br>
                            <font id="srvfontname" color="#000000" size="1" face="Verdana, Arial, Helvetica">
                                <div style="display: none" id="connectDisplay">

                                    <id id="loggedinsrv">Connected to</id>
                                    <i><span id="srvNameField"></span></i>
                                    <br>
                                     <input type="submit" size="4"  face="Verdana" id=DisConn value="Dis Connect" name="DisConn"  OnClick="ReturnToConnectPage()" class="button">
                                </div>
                            </font>
                        </td>
                    </tr>
 <script language="VBScript" type="text/vbscript">
<!--

sub ReturnToConnectPage()

  'alert("ReturnToConnectPage")
   'if(window.location

'     dim NewUrl 
'     NewUrl = window.location & "&Auto=false"
'     window.location.href(NewUrl)
    
    location.reload
     
 
'     Document.All.connectArea.style.display = "none"
'    Document.all.loginArea.style.display = "block"

'     Document.All.connectDisplay.style.display = "none"   
'     Document.all.tableLogonInfo.style.display = "block"

  
end sub

sub MsRdpClientForVM_OnConnected()
    ' alert("onConnected")
   Document.All.connectDisplay.style.display = "block"
end sub

sub MsRdpClientForVM_OnDisconnected(disconnectCode)
   
   extendedDiscReason = MsRdpClientForVM.ExtendedDisconnectReason
   majorDiscReason = disconnectCode And &hFF

   if (disconnectCode = &hB08 or majorDiscReason = 2 or majorDiscReason = 1) and not (extendedDiscReason = 5) then
     
      'Switch back to login area
'     alert(" OnDisconnected if body")
'     alert("disconnectCode" & disconnectCode & "majorDiscReason" & majorDiscReason & "extendedDiscReason" & extendedDiscReason)
    'window.open("VMConsoleRDP.aspx")'?VMIP=" & Me.ViewState("VMIP")", "VMConsole
   ' window.returnvalue=true
     
    
      ReturnToConnectPage
      exit sub
   end if

   errMsgText = MsRdpClientForVM.GetErrorDescription(disconnectCode, extendedDiscReason)
   if not errMsgText = "" then
         msgbox errMsgText,0,L_RemoteDesktopCaption_ErrorMessage
   end if

     'alert("OnDisconnected function end")
'  
'     dim NewUrl 
'     NewUrl = window.location & "&Auto=False"
'     window.location.href(NewUrl)

     ReturnToConnectPage

end sub



-->
                    </script>
                      
 
                </tbody>
            </table>
        </center>
    </div>
</body>

</html>
