Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 12.19 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, and contact Dserv for a new version.
  46. echo.
  47.  
  48. echo MENU:
  49. echo [1] INSTALL OPENVPN
  50. %instp% echo [2] CHANGE CONNECTION CONFIG
  51. %instp% echo [3] CHANGE PASSWORD
  52. %instp% echo [4] STOP SERVICE
  53. %instp% echo [5] START SERVICE
  54. %instp% echo [6] KILLSWITCH
  55. echo [Q] EXIT
  56. echo ==========================
  57.  
  58. echo Enter selection and press ENTER key:
  59. set /P menuchoice=
  60. if /I "%menuchoice%" EQU "1" goto :installopenvpn
  61. if /I "%menuchoice%" EQU "2" goto :changeconfig
  62. if /I "%menuchoice%" EQU "3" goto :changepass
  63. if /I "%menuchoice%" EQU "4" goto :stop_sc
  64. if /I "%menuchoice%" EQU "5" goto :start_sc
  65. if /I "%menuchoice%" EQU "6" goto :killswitch
  66. if /I "%menuchoice%" EQU "Q" exit
  67.  
  68. :INSTALLOPENVPN
  69. cls
  70. IF EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn already installed. & pause & goto :installmenu
  71. echo Downloading and installing OpenVpn, this can take a couple minutes...
  72. bitsadmin.exe /transfer "ovpndowload" /priority high %openvpnpath% "%tempdir%\openvpninstall.exe" >nul
  73. if %ERRORLEVEL% NEQ 0 cls & echo ERROR: Can't find file. & pause & goto :installmenu
  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. if %ERRORLEVEL% NEQ 0 cls & echo ERROR: Can't find file. & pause & goto :installmenu
  108. icacls "*.ovpn" /setowner %username% /T /C >nul
  109.  
  110. setlocal enabledelayedexpansion
  111. for /f "tokens=1,* delims=¶" %%A in ( '"findstr /n ^^ %addrfile%"') do (
  112.    SET string=%%A
  113.    for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
  114.    if  "!string!" == "" (
  115.        echo.>>config.tmp
  116.    ) else (
  117.       SET modified=!string:auth-user-pass=auth-user-pass auth.txt!
  118.       echo !modified! >> config.tmp
  119.   )
  120. )
  121. del %addrfile%
  122. rename config.tmp %addrfile%
  123. endlocal
  124.  
  125. copy %addrfile% "%programfiles%\OpenVPN\config" >nul
  126. del %addrfile% >nul
  127.  
  128. if "%menuchoice%"=="1" goto :changepass
  129. if "%menuchoice%"=="2" %service_run% >nul & cls & echo Config changed to %addr%
  130. pause
  131. goto :installmenu
  132.  
  133.  
  134. :CHANGEPASS
  135. cls
  136. if "%menuchoice%"=="3" IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  137. if "%menuchoice%"=="3" %service_stop% >nul
  138. set /p usern= Input your vpn username:
  139. set /p passw= input your vpn password:
  140. cls
  141. echo Username:%usern% Password:%passw% is this correct? [Y] [N]
  142. set /P m=
  143. if /I "%m%" EQU "Y" echo Yes >nul
  144. if /I "%m%" EQU "N" goto :CHANGEPASS
  145. cls
  146. cd %tempdir% >nul
  147. echo %usern%>auth.txt
  148. echo %passw%>>auth.txt
  149. icacls "auth.txt" /setowner %username% /T /C >nul
  150. copy auth.txt "%programfiles%\OpenVPN\config" >nul
  151. del auth.txt >nul
  152. if "%menuchoice%"=="1" %service_auto% >nul & %service_run% >nul & echo OpenVpn is installed and running.
  153. if "%menuchoice%"=="3" %service_run% >nul & echo Password changed.
  154. pause
  155. goto :installmenu
  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%== 0 (
  162.   echo Service already stopped...
  163.   pause
  164.   goto :installmenu
  165. ) else (
  166.   echo not stopped >nul
  167. )
  168. %service_stop% >nul
  169. timeout 2 >nul
  170. :STOP_SC_CHECK
  171. sc query "openvpnservice" | findstr /i "STOPPED" >nul
  172.   if %errorlevel%== 1  (
  173.   timeout 5 >nul
  174.   goto :stop_sc_check
  175. ) else (
  176.   echo Service stopped...
  177.   pause
  178.   goto :installmenu
  179. )
  180.  
  181. :START_SC
  182. cls
  183. IF NOT EXIST "%programfiles%\openvpn\bin\openvpn.exe" echo OpenVpn is not installed. & pause & goto :installmenu
  184. sc query "openvpnservice" | findstr /i "RUNNING" >nul
  185.   if %errorlevel%== 0 (
  186.   echo Service already running...
  187.   pause
  188.   goto :installmenu
  189. ) else (
  190.   echo No running >nul
  191. )
  192. %service_run% >nul
  193. timeout 2 >nul
  194. :START_SC_CHECK
  195. sc query "openvpnservice" | findstr /i "RUNNING" >nul
  196.   if %errorlevel%== 1  (
  197.   timeout 5 >nul
  198.   goto :start_sc_check
  199. ) else (
  200.   echo Service started...
  201.   pause
  202.   goto :installmenu
  203. )
  204.  
  205. :KILLSWITCH
  206. cls
  207. echo This will set your network connection to private if it's public or domain.
  208. echo After that install two firewall rules.
  209. echo which prevent your torrent client to communicate as long as your vpn connection is lost.
  210. echo.
  211. echo Do you want to install these rules? [Y] [N]
  212. set /P killswitchyesno=
  213. if /I "%killswitchyesno%" EQU "Y" echo yes >nul
  214. if /I "%killswitchyesno%" EQU "N" goto :installmenu
  215.  
  216. :killswitch_menu
  217. cls
  218. echo KILLSWITCH MENU:
  219. echo [1] UTORRENT
  220. echo [2] RTORRENT
  221. echo [3] BITTORRENT
  222. echo [4] QBITTORRENT
  223. echo [5] OTHER CLIENT
  224. echo [6] BACK TO MAIN MENU
  225. echo [Q] EXIT
  226. echo ==========================
  227.  
  228. echo Enter selection and press ENTER key:
  229. set /P killswitch_menuchoice=
  230. if /I "%killswitch_menuchoice%" EQU "1" goto :killswitch_utorrent
  231. if /I "%killswitch_menuchoice%" EQU "2" goto :killswitch_rtorrent
  232. if /I "%killswitch_menuchoice%" EQU "3" goto :killswitch_bittorrent
  233. if /I "%killswitch_menuchoice%" EQU "4" goto :killswitch_qbittorrent
  234. if /I "%killswitch_menuchoice%" EQU "5" goto :killswitch_other
  235. if /I "%killswitch_menuchoice%" EQU "6" goto :installmenu
  236. if /I "%killswitch_menuchoice%" EQU "Q" exit
  237.  
  238. :killswitch_utorrent
  239. cls
  240. for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
  241. cls
  242. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
  243. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
  244. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
  245. for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
  246. goto :killswitch_installrules
  247.  
  248. :killswitch_rtorrent
  249. cls
  250. for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
  251. cls
  252. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
  253. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
  254. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
  255. for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
  256. goto :killswitch_installrules
  257.  
  258. :killswitch_bittorrent
  259. cls
  260. for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
  261. cls
  262. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
  263. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
  264. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
  265. for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
  266. goto :killswitch_installrules
  267.  
  268. :killswitch_qbittorrent
  269. cls
  270. for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
  271. cls
  272. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
  273. if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
  274. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
  275. for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
  276. goto :killswitch_installrules
  277.  
  278. :killswitch_other
  279. cls
  280. set /p torrentlocation= Input path: (example: C:\Program Files (x86)\uTorrent\uTorrent.exe)
  281. cls
  282. if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
  283. for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
  284. goto :killswitch_installrules
  285.  
  286. :killswitch_installrules
  287. for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
  288.  
  289. reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" /v Category | find "0x1">nul
  290.  
  291. IF %ERRORLEVEL%== 0 (
  292.     echo network is private >nul
  293. ) else (
  294. for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
  295. Reg Add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\%var%" /V Category /t REG_DWORD /d 1 /f >nul
  296. )
  297.  
  298. cls
  299. netsh advfirewall firewall show rule name="%torrentlocation_ext% (IN)" >nul
  300. if %errorlevel%== 0 (
  301.     echo Rules already installed.
  302. ) ELSE (
  303.     netsh advfirewall firewall add rule name="%torrentlocation_ext% (IN)" dir=in action=block program="%Torrentlocation%" profile=private,domain >nul
  304.     netsh advfirewall firewall add rule name="%torrentlocation_ext% (OUT)" dir=out action=block program="%Torrentlocation%" profile=private,domain >nul
  305.     echo Rules installed.
  306. )
  307. pause
  308. cls
  309. goto :installmenu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement