Install-SecureMFA_RDG_WebPortal.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function Install-SecureMFA_RDG_WebPortal {

<#
     .DESCRIPTION
    Deploys SecureMFA RD Gateway Portal. It is a single HTML file which allows users to generate RDP file which allows to initiated RDP connection with OTP and RD Gateway server parameters.
  
    .PARAMETER GatewayHostname
    - GatewayHostname [Optional] � Sets RD Gateway default parameter for a website .
 
    .PARAMETER RDPortalPath
    - RDPortalPath [Optional] � Allows to change default website deployment path. Default path is 'C:\inetpub\wwwroot'
 
    .EXAMPLE
    # Deploys SecureMFA RD Gateway Portal into default location.
    Install-SecureMFA_RD_Gateway_Portal -GatewayHostname rdgateway.adatum.labnet
 
    .LINK
    https://www.securemfa.com/downloads/mfa-rds-otp
 
 
#>


[CmdletBinding()]
Param(
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][string]$GatewayHostname,      
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][string]$RDPortalPath = 'C:\inetpub\wwwroot'
)    
        

#HTML file Template
$htmlfile = @'
<!doctype html>
 
<html lang="en">
<head>
  <meta charset="utf-8">
 
  <title>SecureMFA RD Gateway Authentication Portal</title>
  <meta name="description" content="SecureMFA RD Gateway OTP Authentication Portal">
  <meta name="author" content="SecureMFA">
 
</head>
 
<body>
<style>
body {
  background-image: url('background.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: 100% 100%;
}
</style>
<center>
  <div style="background-color:white; width: 90%;" >
  <br /><b><label for="info">SecureMFA RD Gateway OTP Authentication Portal</label></B><br /><br />
  <textarea id="server" rows="1" placeholder="Server" autofocus cols="50"></textarea><br/>
  <textarea id="user" rows="1" placeholder="DOMAIN\USER" cols="50"></textarea><br/>
  <textarea id="otp" rows="1" placeholder="OTP" maxlength="6" cols="50"></textarea><br/>
  <textarea id="gatewayhostname" rows="1" placeholder="RD Gateway Server" cols="50">RDGatewayServerText</textarea><br/>
  <br /><input type="button" id="rdpconnect-btn" value="RDP Connect"/><br /><br />
  </div>
</center>
  <script>
    function download(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
 
        element.style.display = 'none';
        document.body.appendChild(element);
 
        element.click();
 
        document.body.removeChild(element);
    }
 
    // Start file download.
    document.getElementById("rdpconnect-btn").addEventListener("click", function(){
    // Generate download of hello.txt file with some content
    var otpvalue = document.getElementById("otp").value;
    var filename = document.getElementById("server").value + ".rdp";
    var anchordomain = "securemfa.com";
 
    var RDPSettings = [
        'screen mode id:i:2',
        'use multimon:i:0',
        'desktopwidth:i:1920',
        'desktopheight:i:1200',
        'session bpp:i:32',
        'winposstr:s:0,3,0,0,800,600',
        'compression:i:1',
        'keyboardhook:i:2',
        'audiocapturemode:i:0',
        'videoplaybackmode:i:1',
        'connection type:i:7',
        'networkautodetect:i:1',
        'bandwidthautodetect:i:1',
        'displayconnectionbar:i:1',
        'enableworkspacereconnect:i:0',
        'disable wallpaper:i:0',
        'allow font smoothing:i:0',
        'allow desktop composition:i:0',
        'disable full window drag:i:1',
        'disable menu anims:i:1',
        'disable themes:i:0',
        'disable cursor setting:i:0',
        'bitmapcachepersistenable:i:1',
        'audiomode:i:0',
        'redirectprinters:i:1',
        'redirectcomports:i:0',
        'redirectsmartcards:i:1',
        'redirectclipboard:i:1',
        'redirectposdevices:i:0',
        'autoreconnection enabled:i:1',
        'authentication level:i:2',
        'prompt for credentials:i:0',
        'negotiate security layer:i:1',
        'remoteapplicationmode:i:0',
        'alternate shell:s:',
        'shell working directory:s:',
        'gatewayusagemethod:i:1',
        'gatewayprofileusagemethod:i:1',
        'promptcredentialonce:i:0',
        'gatewaybrokeringtype:i:0',
        'use redirection server name:i:0',
        'rdgiskdcproxy:i:0',
        'kdcproxyname:s:',
        'gatewaycredentialssource:i:5',
        ('gatewayhostname:s:' + document.getElementById("gatewayhostname").value),
        ('gatewayaccesstoken:s:' + document.getElementById("user").value + ":" + document.getElementById("otp").value + ":" + anchordomain),
        ('full address:s:' + document.getElementById("server").value),
        ''].join('\n');
     
     
        download(filename, RDPSettings.replace(/\n/g, '\r\n'));
    }, false);
  </script>
   
   
</body>
</html>
'@


#Replace values with static params
$htmlfile = $htmlfile.Replace('AnchorDomainText', $AnchorDomain)
$htmlfile = $htmlfile.Replace('RDGatewayServerText', $GatewayHostname)

    Try {    
            
        $deploymentpath = Join-Path $RDPortalPath "index.html"
       
        if(Test-Path $RDPortalPath) {
        $htmlfile | Out-File $deploymentpath -Force
        write-host "SecureMFA RD Gateway Portal has been deployed $deploymentpath" -ForegroundColor Cyan
        }
        else {write-host "$RDPortalPath doesn't exist. Please choose a valid path." -ForegroundColor Red}


    } Catch {Write-host $_.Exception.message -ForegroundColor Red}
}