Last active
October 5, 2020 15:44
-
-
Save monaboiste/2d2167c43c1895aef6459dc72a2e0403 to your computer and use it in GitHub Desktop.
Remote connection to SAS server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Set up proxy and ssh connection to UZ server. | |
.DESCRIPTION | |
Set up proxy and ssh connection to UZ server. There one can | |
access SAS tools for data analysis. | |
.PARAMETER User | |
User name provided by academic teacher. | |
.INPUTS | |
None. You cannot pipe objects to this script. | |
.OUTPUTS | |
None. This script does not generate any output. | |
.LINK | |
None. | |
.EXAMPLE | |
.\Connect-SASServer.ps1 -User "saslab75" | |
#> | |
# ssh -D 1080 -L 1080:sas.issi.uz.zgora.pl:1080 saslab75@dendrit.issi.uz.zgora.pl -p 10000 | |
Param ( | |
[Parameter(Mandatory=$True)] | |
[ValidateNotNullOrEmpty()] | |
[String]$User | |
) | |
$HostAddr = "dendrit.issi.uz.zgora.pl" | |
$ServerAddr = "sas.issi.uz.zgora.pl" | |
$ForwardPort = 1080 | |
$SshServerPort = 10000 | |
$SasURL = "http://sas.issi.uz.zgora.pl:7980/SASStudio/" | |
# Checks if host is already added, otherwise adds the host to etc\hosts | |
$HostAdded = ((Get-Content $Env:windir\System32\drivers\etc\hosts) -replace " ", "" | Select-String -Pattern "127.0.0.1$ServerAddr") | |
If (-not $HostAdded) { | |
Add-Content -Path $Env:windir\System32\drivers\etc\hosts -Value "`n# Analiza Danych`n127.0.0.1 $ServerAddr" -Force | |
} | |
# Open browser | |
Start-Process "microsoft-edge:$SasURL" | |
# Open SSH connection in new window | |
Invoke-Expression "cmd /c start powershell -NoExit -Command { ssh -D $ForwardPort -L $ForwardPort`:$ServerAddr`:$ForwardPort $User`@$HostAddr -p $SshServerPort }" | |
# Set up proxy | |
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Value "socks=127.0.0.1:$ForwardPort;" -Type String | |
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 1 | |
Write-Host "You can now access SAS at: $SasURL" | |
Write-Host "Please refresh your browser." | |
Write-Host "`tNote:`tIf you experience internet connection issues, please" | |
Write-Host "`t`twait briefly. It's take time to set up proxy." | |
Read-Host "`nPress any key to quit..." | |
# Clean up proxy | |
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 0 | |
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Value "" -Type String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment