Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 8.79 KB | None | 0 0
  1. :: Script by Dserv
  2.  
  3. @echo off
  4.  
  5. ::check if run as admin
  6. openfiles > NUL 2>&1
  7. if %ERRORLEVEL% EQU 1 echo You need to run this script as Administrator. & pause & exit
  8.  
  9. ::check processor architecture and set variable for program folder and openvpn-location.
  10. if not "%processor_architecture%"=="AMD64" echo This is a 64-bit installer. & pause & exit
  11.  
  12. ::check internet connection
  13. echo Checking internet connection...
  14. ping -4 www.google.se >nul
  15. if %ERRORLEVEL% EQU 1 cls & ping www.google.se >nul
  16. if %ERRORLEVEL% EQU 1 cls echo No internet connection & pause & exit
  17.  
  18. ::Set tempdir
  19. set tempdir=%userprofile%\desktop
  20. cd %tempdir%
  21.  
  22. ::Set paths and filenames and service variables.
  23. set openvpnpath=https://swupdate.openvpn.org/community/releases/openvpn-install-2.3.10-I604-x86_64.exe
  24. set swedenudp=https://files.ovpn.se/windows/ovpn-se.ovpn
  25. set swedentcp=https://files.ovpn.se/windows/ovpn-se-tcp.ovpn
  26. set germanyudp=https://files.ovpn.se/windows/ovpn-de.ovpn
  27. set germanytcp=https://files.ovpn.se/windows/ovpn-de-tcp.ovpn
  28. set netherlandudp=https://files.ovpn.se/windows/ovpn-nl.ovpn
  29. set netherlandtcp=https://files.ovpn.se/windows/ovpn-nl-tcp.ovpn
  30. set canadaudp=https://files.ovpn.se/windows/ovpn-ca.ovpn
  31. set canadatcp=https://files.ovpn.se/windows/ovpn-ca-tcp.ovpn
  32. set service_run=SC Start "Openvpnservice"
  33. set service_stop=SC Stop "Openvpnservice"
  34. set service_auto=SC Config "Openvpnservice" start= AUTO
  35.  
  36. ::Choices are connected to installopenvpn (keep in mind when adding choices betweeen 1-3.)
  37. :INSTALLMENU
  38. ::Only for menu verification.
  39. set instp=if exist "%programfiles%\openvpn\bin\openvpn.exe" >nul
  40. cls
  41. echo OpenVpn version: %openvpnpath%
  42. echo.
  43. echo Note: This script relies on the availability of Openvpn version 2.3.10.
  44. echo If installation process (application install or configuration change)
  45. echo takes more then 5 minutes terminate script,
  46. echo and contact Dserv for a new version.
  47. echo.
  48.  
  49. echo MENU:
  50. echo [1] INSTALL OPENVPN
  51. %instp% echo [2] CHANGE CONNECTION CONFIG
  52. %instp% echo [3] CHANGE PASSWORD
  53. %instp% echo [4] STOP SERVICE
  54. %instp% echo [5] START SERVICE
  55. %instp% echo [6] KILLSWITCH
  56. echo [Q] EXIT
  57. echo ==========================
  58.  
  59. echo Enter selection and press ENTER key:
  60. set /P menuchoice=
  61. if /I "%menuchoice%" EQU "1" goto :installopenvpn
  62. if /I "%menuchoice%" EQU "2" goto :changeconfig
  63. if /I "%menuchoice%" EQU "3" goto :changepass
  64. if /I "%menuchoice%" EQU "4" goto :stop_sc
  65. if /I "%menuchoice%" EQU "5" goto :start_sc
  66. if /I "%menuchoice%" EQU "6" goto :killswitch
  67. if /I "%menuchoice%" EQU "Q" exit
  68.  
  69. :INSTALLOPENVPN
  70. cls
  71. IF EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn already installed. & pause & goto :installmenu
  72. echo Downloading and installing OpenVpn, this can take a couple minutes...
  73. bitsadmin.exe /transfer "ovpndowload" /priority high %openvpnpath% "%tempdir%\openvpninstall.exe" >nul
  74. openvpninstall.exe /S /D=%programfiles%\openvpn
  75. del openvpninstall.exe
  76. del "%public%\desktop\openvpn gui.lnk"
  77. cls
  78.  
  79. :CHANGECONFIG
  80. cls
  81. if "%menuchoice%"=="2" IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  82. if "%menuchoice%"=="2" %service_stop% >nul
  83. IF EXIST "%programfiles%\openvpn\config\*.ovpn" del "%programfiles%\openvpn\config\*.ovpn" >nul
  84. echo [1] Sweden servers UDP
  85. echo [2] Sweden servers TCP
  86. echo [3] Germany servers UDP
  87. echo [4] Germany servers TCP
  88. echo [5] Netherland servers UDP
  89. echo [6] Netherland servers TCP
  90. echo [7] Canada servers UDP
  91. echo [8] Canada servers TCP
  92.  
  93. echo Select serverconfig and press ENTER key:
  94. set /P confchoice=
  95. if /I "%confchoice%" EQU "1" set addr=%swedenudp% & set addrfile=ovpn-se.ovpn >nul
  96. if /I "%confchoice%" EQU "2" set addr=%swedentcp% & set addrfile=ovpn-se-tcp.ovpn >nul
  97. if /I "%confchoice%" EQU "3" set addr=%germanyudp% & set addrfile=ovpn-de.ovpn >nul
  98. if /I "%confchoice%" EQU "4" set addr=%germanytcp% & set addrfile=ovpn-de-tcp.ovpn >nul
  99. if /I "%confchoice%" EQU "5" set addr=%netherlandudp% & set addrfile=ovpn-nl.ovpn >nul
  100. if /I "%confchoice%" EQU "6" set addr=%netherlandtcp% & set addrfile=ovpn-nl-tcp.ovpn >nul
  101. if /I "%confchoice%" EQU "7" set addr=%canadaudp% & set addrfile=ovpn-ca.ovpn >nul
  102. if /I "%confchoice%" EQU "8" set addr=%canadatcp% & set addrfile=ovpn-ca-tcp.ovpn >nul
  103.  
  104. cls
  105. echo Installing server configuration wait...
  106. bitsadmin.exe /transfer "ovpndowload" %addr% "%tempdir%\%addrfile%" >nul
  107. icacls "*.ovpn" /setowner %username% /T /C >nul
  108.  
  109. setlocal enabledelayedexpansion
  110. for /f "tokens=1,* delims=ΒΆ" %%A in ( '"findstr /n ^^ %addrfile%"') do (
  111.    SET string=%%A
  112.    for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
  113.    if  "!string!" == "" (
  114.        echo.>>config.tmp
  115.    ) else (
  116.       SET modified=!string:auth-user-pass=auth-user-pass auth.txt!
  117.       echo !modified! >> config.tmp
  118.   )
  119. )
  120. del %addrfile%
  121. rename config.tmp %addrfile%
  122. endlocal
  123.  
  124. copy %addrfile% "%programfiles%\OpenVPN\config" >nul
  125. del %addrfile% >nul
  126.  
  127. if "%menuchoice%"=="1" goto :changepass
  128. if "%menuchoice%"=="2" %service_run% >nul & cls & echo Config changed to %addr%
  129. pause
  130. goto :installmenu
  131.  
  132.  
  133. :CHANGEPASS
  134. cls
  135. if "%menuchoice%"=="3" IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  136. if "%menuchoice%"=="3" %service_stop% >nul
  137. set /p usern= Input your vpn username:
  138. set /p passw= input your vpn password:
  139. cls
  140. echo Username:%usern% Password:%passw% is this correct? [Y] [N]
  141. set /P m=
  142. if /I "%m%" EQU "Y" echo Yes >nul
  143. if /I "%m%" EQU "N" goto :CHANGEPASS
  144. cls
  145. cd %tempdir% >nul
  146. echo %usern%>auth.txt
  147. echo %passw%>>auth.txt
  148. icacls "auth.txt" /setowner %username% /T /C >nul
  149. copy auth.txt "%programfiles%\OpenVPN\config" >nul
  150. del auth.txt >nul
  151. if "%menuchoice%"=="1" %service_auto% >nul & %service_run% >nul & echo OpenVpn is installed and running.
  152. if "%menuchoice%"=="3" %service_run% >nul & echo Password changed.
  153. pause
  154. goto :installmenu
  155.  
  156.  
  157. :STOP_SC
  158. cls
  159. IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  160. sc query "openvpnservice" | findstr /i "STOPPED" >nul
  161. if errorlevel 1 (
  162.     %service_stop% >nul
  163.     echo Stopping service...
  164.     timeout 5 >nul
  165.     cls
  166.     sc query "openvpnservice" | findstr /i "STOPPED" >nul & if errorlevel 1 echo ERROR: Can't stop service & pause & goto :installmenu
  167.     cls
  168.     echo Openvpn service is now stopped.
  169.     pause
  170.     goto :installmenu
  171. ) else (
  172.     echo Service already stopped.
  173.     pause
  174.     goto :installmenu
  175. )
  176.  
  177. :START_SC
  178. cls
  179. IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  180. sc query "openvpnservice" | findstr /i "RUNNING" >nul
  181. if errorlevel 1 (
  182.     %service_run% >nul
  183.     echo Starting service...
  184.     timeout 5 >nul
  185.     cls
  186.     sc query "openvpnservice" | findstr /i "RUNNING" >nul & if errorlevel 1 echo ERROR: Can't start service & pause & goto :installmenu
  187.     cls
  188.     echo Openvpn service is now running.
  189.     pause
  190.     goto :installmenu
  191. ) else (
  192.     echo Service already running.
  193.     pause
  194.     goto :installmenu
  195. )
  196.  
  197. :KILLSWITCH
  198. cls
  199. echo This will set your network connection to private if it's public or domain.
  200. echo After that install two firewall rules.
  201. echo which prevent your torrent client to communicate as long as your vpn connection is lost.
  202. echo.
  203. echo Do you want to install these rules? [Y] [N]
  204. set /P killswitchyesno=
  205. if /I "%killswitchyesno%" EQU "Y" echo yes >nul
  206. if /I "%killswitchyesno%" EQU "N" goto :installmenu
  207. cls
  208. set /p torrentlocation= Input path: (example: C:\Program Files (x86)\uTorrent\uTorrent.exe)
  209. cls
  210. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch
  211.  
  212. for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
  213.  
  214. reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" /v Category | find "0x1">nul
  215.  
  216. IF %ERRORLEVEL%== 0 (
  217.     goto :torrent_installrules
  218. ) else (
  219. for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
  220. Reg Add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\%var%" /V Category /t REG_DWORD /d 1 /f >nul
  221. )
  222.  
  223. :torrent_installrules
  224. cls
  225. netsh advfirewall firewall show rule name="Private torrent (IN)" >nul
  226. if %errorlevel%== 0 (
  227.     echo Rules already installed.
  228. ) ELSE (
  229.     netsh advfirewall firewall add rule name="Private torrent (IN)" dir=in action=block program="%Torrentlocation%" profile=private,domain >nul
  230.     netsh advfirewall firewall add rule name="Private torrent (OUT)" dir=out action=block program="%Torrentlocation%" profile=private,domain >nul
  231.     echo Rules installed.
  232. )
  233. pause
  234. cls
  235. goto :installmenu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement