Advertisement
Guest User

Untitled

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