Advertisement
Guest User

Untitled

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