Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Script by Dserv
- @echo off
- ::check if run as admin
- openfiles > NUL 2>&1
- if %ERRORLEVEL% EQU 1 echo You need to run this script as Administrator. & pause & exit
- ::check processor architecture and set variable for program folder and openvpn-location.
- if not "%processor_architecture%"=="AMD64" echo This is a 64-bit installer. & pause & exit
- ::check internet connection
- echo Checking internet connection...
- ping -4 www.google.se >nul
- if %ERRORLEVEL% EQU 1 cls & ping www.google.se >nul
- if %ERRORLEVEL% EQU 1 cls echo No internet connection & pause & exit
- ::Set tempdir
- set tempdir=%userprofile%\desktop
- cd %tempdir%
- ::Set paths and filenames and service variables.
- set openvpnpath=https://swupdate.openvpn.org/community/releases/openvpn-install-2.3.10-I604-x86_64.exe
- set swedenudp=https://files.ovpn.se/windows/ovpn-se.ovpn
- set swedentcp=https://files.ovpn.se/windows/ovpn-se-tcp.ovpn
- set germanyudp=https://files.ovpn.se/windows/ovpn-de.ovpn
- set germanytcp=https://files.ovpn.se/windows/ovpn-de-tcp.ovpn
- set netherlandudp=https://files.ovpn.se/windows/ovpn-nl.ovpn
- set netherlandtcp=https://files.ovpn.se/windows/ovpn-nl-tcp.ovpn
- set canadaudp=https://files.ovpn.se/windows/ovpn-ca.ovpn
- set canadatcp=https://files.ovpn.se/windows/ovpn-ca-tcp.ovpn
- set service_run=SC Start "Openvpnservice"
- set service_stop=SC Stop "Openvpnservice"
- set service_auto=SC Config "Openvpnservice" start= AUTO
- ::Choices are connected to installopenvpn (keep in mind when adding choices betweeen 1-3.)
- :INSTALLMENU
- ::Only for menu verification.
- set instp=if exist "%programfiles%\openvpn\bin\openvpn.exe" >nul
- cls
- echo OpenVpn version: %openvpnpath%
- echo.
- echo Note: This script relies on the availability of Openvpn version 2.3.10.
- echo If installation process (application install or configuration change)
- echo takes more then 5 minutes terminate script, and contact Dserv for a new version.
- echo.
- :installmenu_ws
- echo MENU:
- echo [1] INSTALL OPENVPN
- %instp% echo [2] CHANGE CONNECTION CONFIG
- %instp% echo [3] CHANGE PASSWORD
- %instp% echo [4] STOP SERVICE
- %instp% echo [5] START SERVICE
- %instp% echo [6] KILLSWITCH
- echo [Q] EXIT
- echo ==========================
- set /P menuchoice=Enter selection and press ENTER key:
- if /I "%menuchoice%" EQU "1" goto :installopenvpn
- if /I "%menuchoice%" EQU "2" goto :changeconfig
- if /I "%menuchoice%" EQU "3" goto :changepass
- if /I "%menuchoice%" EQU "4" goto :stop_sc
- if /I "%menuchoice%" EQU "5" goto :start_sc
- if /I "%menuchoice%" EQU "6" goto :killswitch
- if /I "%menuchoice%" EQU "Q" exit
- echo Invalid selection.
- pause
- cls & goto :installmenu
- :INSTALLOPENVPN
- cls
- IF EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn already installed. & pause & goto :installmenu
- echo Downloading and installing OpenVpn, this can take a couple minutes...
- bitsadmin.exe /transfer "ovpndowload" /priority high %openvpnpath% "%tempdir%\openvpninstall.exe" >nul
- if %ERRORLEVEL% NEQ 0 cls & echo ERROR: Can't find file. & pause & goto :installmenu
- openvpninstall.exe /S /D=%programfiles%\openvpn
- del openvpninstall.exe
- del "%public%\desktop\openvpn gui.lnk"
- cls
- :CHANGECONFIG
- cls
- if "%menuchoice%"=="2" IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
- if "%menuchoice%"=="2" %service_stop% >nul
- IF EXIST "%programfiles%\openvpn\config\*.ovpn" del "%programfiles%\openvpn\config\*.ovpn" >nul
- echo [1] Sweden servers UDP
- echo [2] Sweden servers TCP
- echo [3] Germany servers UDP
- echo [4] Germany servers TCP
- echo [5] Netherland servers UDP
- echo [6] Netherland servers TCP
- echo [7] Canada servers UDP
- echo [8] Canada servers TCP
- echo Select serverconfig and press ENTER key:
- set /P confchoice=
- if /I "%confchoice%" EQU "1" set addr=%swedenudp% & set addrfile=ovpn-se.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "2" set addr=%swedentcp% & set addrfile=ovpn-se-tcp.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "3" set addr=%germanyudp% & set addrfile=ovpn-de.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "4" set addr=%germanytcp% & set addrfile=ovpn-de-tcp.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "5" set addr=%netherlandudp% & set addrfile=ovpn-nl.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "6" set addr=%netherlandtcp% & set addrfile=ovpn-nl-tcp.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "7" set addr=%canadaudp% & set addrfile=ovpn-ca.ovpn >nul & goto :changeconfig_install
- if /I "%confchoice%" EQU "8" set addr=%canadatcp% & set addrfile=ovpn-ca-tcp.ovpn >nul & goto :changeconfig_install
- echo Invalid selection.
- pause
- cls & goto :changeconfig
- :changeconfig_install
- cls
- echo Installing server configuration wait...
- bitsadmin.exe /transfer "ovpndowload" %addr% "%tempdir%\%addrfile%" >nul
- if %ERRORLEVEL% NEQ 0 cls & echo ERROR: Can't find file. & pause & goto :installmenu
- icacls "*.ovpn" /setowner %username% /T /C >nul
- setlocal enabledelayedexpansion
- for /f "tokens=1,* delims=ΒΆ" %%A in ( '"findstr /n ^^ %addrfile%"') do (
- SET string=%%A
- for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
- if "!string!" == "" (
- echo.>>config.tmp
- ) else (
- SET modified=!string:auth-user-pass=auth-user-pass auth.txt!
- echo !modified! >> config.tmp
- )
- )
- del %addrfile%
- rename config.tmp %addrfile%
- endlocal
- copy %addrfile% "%programfiles%\OpenVPN\config" >nul
- del %addrfile% >nul
- if "%menuchoice%"=="1" goto :changepass
- if "%menuchoice%"=="2" %service_run% >nul & cls & echo Config changed to %addr%
- pause
- goto :installmenu
- :CHANGEPASS
- cls
- if "%menuchoice%"=="3" IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
- if "%menuchoice%"=="3" %service_stop% >nul
- set /p usern= Input your vpn username:
- set /p passw= input your vpn password:
- cls
- :changepass_yn
- echo Username:%usern% Password:%passw% is this correct? [Y] [N]
- set /P m=
- if /I "%m%" EQU "Y" goto :changepass_install
- if /I "%m%" EQU "N" goto :CHANGEPASS
- echo Invalid selection.
- pause
- cls & goto :changepass_yn
- :changepass_install
- cls
- cd %tempdir% >nul
- echo %usern%>auth.txt
- echo %passw%>>auth.txt
- icacls "auth.txt" /setowner %username% /T /C >nul
- copy auth.txt "%programfiles%\OpenVPN\config" >nul
- del auth.txt >nul
- if "%menuchoice%"=="1" %service_auto% >nul & %service_run% >nul & echo OpenVpn is installed and running.
- if "%menuchoice%"=="3" %service_run% >nul & echo Password changed.
- pause
- goto :installmenu
- :STOP_SC
- cls
- IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
- sc query "openvpnservice" | findstr /i "STOPPED" >nul
- if %errorlevel%== 0 (
- echo Service already stopped...
- pause
- goto :installmenu
- ) else (
- echo not stopped >nul
- )
- %service_stop% >nul
- timeout 2 >nul
- :STOP_SC_CHECK
- sc query "openvpnservice" | findstr /i "STOPPED" >nul
- if %errorlevel%== 1 (
- timeout 5 >nul
- goto :stop_sc_check
- ) else (
- echo Service stopped...
- pause
- goto :installmenu
- )
- :START_SC
- cls
- IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
- sc query "openvpnservice" | findstr /i "RUNNING" >nul
- if %errorlevel%== 0 (
- echo Service already running...
- pause
- goto :installmenu
- ) else (
- echo No running >nul
- )
- %service_run% >nul
- timeout 2 >nul
- :START_SC_CHECK
- sc query "openvpnservice" | findstr /i "RUNNING" >nul
- if %errorlevel%== 1 (
- timeout 5 >nul
- goto :start_sc_check
- ) else (
- echo Service started...
- pause
- goto :installmenu
- )
- :KILLSWITCH
- cls
- echo This will set your network connection to private if it's public or domain.
- echo After that install two firewall rules.
- echo which prevent your torrent client to communicate as long as your vpn connection is lost.
- echo.
- echo Do you want to install these rules? [Y] [N]
- set /P killswitchyesno=
- if /I "%killswitchyesno%" EQU "Y" goto :killswitch_install
- if /I "%killswitchyesno%" EQU "N" goto :installmenu
- echo Invalid selection.
- pause
- cls & goto :killswitch
- :killswitch_install
- cls
- set /p torrentlocation= Input path: (example: C:\Program Files (x86)\uTorrent\uTorrent.exe)
- cls
- if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch
- for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
- reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" /v Category | find "0x1">nul
- IF %ERRORLEVEL%== 0 (
- goto :torrent_installrules
- ) else (
- for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
- Reg Add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\%var%" /V Category /t REG_DWORD /d 1 /f >nul
- )
- :torrent_installrules
- cls
- netsh advfirewall firewall show rule name="Private torrent (IN)" >nul
- if %errorlevel%== 0 (
- echo Rules already installed.
- ) ELSE (
- netsh advfirewall firewall add rule name="Private torrent (IN)" dir=in action=block program="%Torrentlocation%" profile=private,domain >nul
- netsh advfirewall firewall add rule name="Private torrent (OUT)" dir=out action=block program="%Torrentlocation%" profile=private,domain >nul
- echo Rules installed.
- )
- pause
- cls
- goto :installmenu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement