Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.53 KB | None | 0 0
  1. #!/bin/bash
  2. #Author: Sebastijan Bandur
  3. #Email: seba.bandur@gmail.com
  4. #Licecnce: GPL v2
  5. SELECTED_PROFILE=""
  6. PASSWORD=""
  7. USERNAME=""
  8. USER_BOOK="vpnbook"
  9. USER_KEYS="vpnkeys"
  10. URL_VPNBOOK="http://www.vpnbook.com/freevpn"
  11. URL_VPNBOOK_PROFILES="http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-Euro1.zip http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-Euro2.zip http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-US2.zip http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-CA1.zip http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-DE1.zip"
  12. URL_VPNKEYS="https://www.vpnkeys.com/get-free-vpn-instantly/"
  13. URL_VPNKEYS_PROFILES="https://www.vpnkeys.com/us1.zip https://www.vpnkeys.com/uk1.zip https://www.vpnkeys.com/nl1.zip https://www.vpnkeys.com/sg1.zip"
  14. IMPORTANT="IMPORTANT! Press CTRL+C to end when in connection!"
  15. INFO=$IMPORTANT
  16. PROFILES_DIR="PROFILES"
  17. PASSWORD_FILE="vpnuserpass"
  18.  
  19. #clear screen
  20. function CLS
  21. {
  22. printf "\033c" # clear screen
  23. }
  24.  
  25. function PrintTopMenuInfo()
  26. {
  27. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  28. echo "––––––––––––––––––----– Free VPN Connect for linux --------–––––––––––––––––––––"
  29. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  30. echo "––––– Supported services: www.FreeVPN.me, www.VPNbook.com, www.VPNkeys.com –––––"
  31. echo "––––––––––– Please donate to continue supporting free VPN services –––––––––––––"
  32. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  33. }
  34.  
  35.  
  36.  
  37. #usage: ChangeColor $COLOR text/background
  38. function ChangeColor()
  39. {
  40. TYPE=""
  41. case "$2" in
  42. "text") TYPE="setaf"
  43. ;;
  44. "back") TYPE="setab"
  45. ;;
  46. *) TYPE="setaf"
  47. esac
  48.  
  49.  
  50.  
  51. case "$1" in
  52. "red") tput "$TYPE" 1
  53. ;;
  54. "orange") tput "$TYPE" 3
  55. ;;
  56. "blue") tput "$TYPE" 4
  57. ;;
  58. "green") tput "$TYPE" 2
  59. ;;
  60. "black") tput "$TYPE" 0
  61. ;;
  62. "white") tput "$TYPE" 7
  63. ;;
  64. "magenta") tput "$TYPE" 5
  65. ;;
  66. "cyan") tput "$TYPE" 7
  67. ;;
  68. *) tput "$TYPE" 0
  69. esac
  70. }
  71.  
  72. #usage: DownloadProfile $URL
  73. function DownloadProfile()
  74. {
  75. #current dir
  76. DIR=$(pwd)
  77. #if profiles dir does not exist create it and enter
  78. if [ ! -d "$DIR/$PROFILES_DIR" ]
  79. then mkdir "$DIR/$PROFILES_DIR"
  80. fi
  81. cd "$DIR/$PROFILES_DIR"
  82. wget $1
  83. FILE=$(ls *.zip)
  84. unzip -j "$FILE"
  85. rm $FILE
  86. INFO="Profiles added: $FILE"
  87. cd $DIR
  88.  
  89. }
  90.  
  91. function ClearProfiles()
  92. {
  93. #current dir
  94. DIR=$(pwd)
  95. cd $PROFILES_DIR
  96. rm *.ovpn
  97. cd $DIR
  98. INFO="All profiles removed!"
  99. SELECTED_PROFILE=""
  100. PASSWORD=""
  101. USERNAME=""
  102. }
  103.  
  104. #USAGE: UpdatePassword $URL_ $USER_
  105. function UpdatePassword()
  106. {
  107. URL=$1
  108. USERNAME=$2
  109. local DIR=$(pwd)
  110. ## SCRIPT FOR GETTING PASSWORD FROM VPNBOOK - FREE VPN
  111. local SAVE_TO="$DIR/$PROFILES_DIR/$PASSWORD_FILE"
  112.  
  113. PASSWORD_LINE_PHARSE="Password"
  114.  
  115. ## get page with password | find line with pass | get last line | remove white spaces
  116. local PWD=$(wget -T 2 -q -O - "$@" "$url" | grep -n "$PASSWORD_LINE_PHARSE" | tail -1 | tr -d ' ')
  117.  
  118. ### for PWD we get: 154: <li>Password:<strong>fra4agaV</strong></li>
  119. local PWD=${PWD%<*} # remove text after last '<'
  120. # repeat only if extracting vpnbook password
  121. if [ "$USERNAME" = "vpnbook" ]
  122. then local PWD=${PWD%<*}
  123. fi
  124. local PWD=${PWD##*>} # remove text before last '>'
  125.  
  126. #remove Password: from string in case of vpnkeys service
  127. if [ "$USERNAME" = "vpnkeys" ]
  128. then local PWD=${PWD##*:}
  129. fi
  130.  
  131. PASSWORD=$PWD
  132. if [ -f $SAVE_TO ]
  133. then rm $SAVE_TO;
  134. fi
  135. touch $SAVE_TO
  136. echo $USERNAME > $SAVE_TO # replace file and add username to first line
  137. echo $PWD >> $SAVE_TO # add password to new line
  138. }
  139.  
  140.  
  141. function ConnectProfile()
  142. {
  143. DIR=$(pwd)
  144. L=$(echo $SELECTED_PROFILE | grep -c ".ovpn")
  145. if [ $L = "0" ]
  146. then
  147. INFO="Connection error! Profile not selected."
  148. else
  149. sudo openvpn --config "$DIR/$PROFILES_DIR/$SELECTED_PROFILE" --auth-user-pass "$DIR/$PROFILES_DIR/$PASSWORD_FILE"
  150. INFO="Disconnected from $SELECTED_PROFILE";
  151. fi
  152. }
  153.  
  154. # usage: TestPortOut port tcp/udp / returns 1 if port is open
  155. function TestPortOut()
  156. {
  157. Port="$1"
  158. NC=""
  159. if [ "$2" = "udp" ]
  160. then netcat -z -u -v -q 2 -w 2 portquiz.net $Port &> /dev/null; NC=$?
  161. else netcat -z -v -q 2 -w 2 portquiz.net $Port &> /dev/null; NC=$?
  162. fi
  163.  
  164. if [ $NC -eq 0 ]
  165. then return 1 #open
  166. else return 0 #closed
  167. fi
  168. }
  169.  
  170. #############################################
  171. #############################################
  172. ### MAIN MENU FUNCTIONS #####################
  173. #############################################
  174.  
  175. function MENU_SelectProfile()
  176. {
  177. DIR=$(pwd)
  178. CLS
  179. PrintTopMenuInfo
  180. echo "$(ChangeColor orange text)SELECT VPN PROFILE$(ChangeColor white text)"
  181. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  182. cd "$DIR/$PROFILES_DIR"
  183. PROFILES=$(ls *.ovpn)
  184. HAVE_PROFILES=$?
  185. cd $DIR
  186. if [ "$HAVE_PROFILES" = "2" ]
  187. then INFO="No profiles available! Download profiles!"; PASSWORD=""; USERNAME=""; return
  188. fi
  189.  
  190. select opt in $PROFILES; do
  191. SELECTED_PROFILE=$opt
  192. INFO="Profile selected: $opt"
  193. break
  194. done
  195.  
  196. PROVIDER=""
  197. VPNBOOK=$(echo $SELECTED_PROFILE | grep -c "vpnbook")
  198. if [ $VPNBOOK = "1" ]; then PROVIDER="vpnbook"; fi
  199.  
  200. VPNKEY=$(echo $SELECTED_PROFILE | grep -c "vpnkeys")
  201. if [ $VPNKEY = "1" ]; then PROVIDER="vpnkeys"; fi
  202.  
  203.  
  204. echo "WAIT! Reading password from web ..."
  205.  
  206. # update password for selected profile
  207. case "$PROVIDER" in
  208. "vpnbook") UpdatePassword $URL_VPNBOOK $USER_BOOK; break
  209. ;;
  210. "vpnkeys") UpdatePassword $URL_VPNKEYS $USER_KEYS; break
  211. ;;
  212. *) INFO="No profile selected!"; PASSWORD=""; USERNAME=""; return
  213. ;;
  214. esac
  215. INFO="Password updated."
  216.  
  217. }
  218.  
  219. function MENU_DownloadProfiles()
  220. {
  221. SERVICE_PROFILES=""
  222. SERVICE=""
  223. SERVICES="VPNbook.com VPNkeys.com"
  224. CLS
  225. PrintTopMenuInfo
  226. echo "$(ChangeColor orange text)DOWNLOAD VPN PROFILES$(ChangeColor white text)"
  227. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  228.  
  229. select opt in $SERVICES; do
  230. SERVICE=$opt
  231. case $opt in
  232. "VPNbook.com") SERVICE_PROFILES=$URL_VPNBOOK_PROFILES; break
  233. ;;
  234. "VPNkeys.com") SERVICE_PROFILES=$URL_VPNKEYS_PROFILES; break
  235. ;;
  236. *) INFO="No service selected for download"; return
  237. ;;
  238. esac
  239. done
  240.  
  241.  
  242. CLS
  243. PrintTopMenuInfo
  244. echo "$(ChangeColor orange text)DOWNLOAD $SERVICE PROFILES$(ChangeColor white text)"
  245. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  246.  
  247. select opt in $SERVICE_PROFILES; do
  248. DownloadProfile $opt
  249. break
  250. done
  251.  
  252.  
  253. }
  254.  
  255. function MENU_Credits()
  256. {
  257. local SELECT="Licence Back"
  258. CLS
  259. PrintTopMenuInfo
  260. echo "$(ChangeColor orange text)CREDITS$(ChangeColor white text)"
  261. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  262. echo "Author of script: Sebastijan Bandur"
  263. echo "Authors email: seba.bandur@gmail.com"
  264. echo "Licence: GPL v2"
  265. echo "Powered by free VPN services: www.VPNbook.com www.FreeVPN.me www.VPNkeys.com"
  266. echo "Please DONATE to www.VPNbook.com www.FreeVPN.me www.VPNkeys.com"
  267. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  268. select opt in $SELECT; do
  269. case $opt in
  270. "Licence") CLS; cat Licence.txt; echo ""
  271. select o in "Back"; do
  272. return
  273. done
  274. ;;
  275. *) return
  276. ;;
  277. esac
  278. done
  279.  
  280. }
  281. function MENU_Help()
  282. {
  283. local SELECT="Back"
  284. CLS
  285. PrintTopMenuInfo
  286. echo "$(ChangeColor orange text)HELP$(ChangeColor white text)"
  287. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  288. cat Help.txt; echo ""
  289. select opt in $SELECT; do
  290. return
  291. done
  292.  
  293. }
  294.  
  295. function MENU_Install()
  296. {
  297. local OK_DEB=""
  298. local OK_RPM=""
  299. local SELECTED=""
  300. local SELECT="Deb Rpm Back"
  301. CLS
  302. PrintTopMenuInfo
  303. echo "$(ChangeColor orange text)OpenVPN INSTALATION. Select your package type: Rpm/Deb$(ChangeColor white text)"
  304. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  305. select sel in $SELECT; do
  306. SELECTED=$sel
  307. case "$sel" in
  308. "Rpm")OK_RPM=$(rpm -qa | grep -c openvpn); break
  309. ;;
  310. "Deb")OK_DEB=$(dpkg -s openvpn | grep Status | grep -c "installed"); break
  311. ;;
  312. *) return
  313. ;;
  314. esac
  315. done
  316.  
  317. if [ $SELECTED = "Deb" ]
  318. then
  319. if [ $OK_DEB = "1" ]
  320. then INFO="OpenVPN is alredy installed!"; return
  321. fi
  322. fi
  323. if [ $SELECTED = "Rpm" ]
  324. then
  325. if [ $OK_RPM = "1" ]
  326. then INFO="OpenVPN is alredy installed!"; return
  327. fi
  328. fi
  329.  
  330.  
  331. SEL="Install Back"
  332. CLS
  333. PrintTopMenuInfo
  334. echo "$(ChangeColor orange text)INSTALL OpenVPN$(ChangeColor white text)"
  335. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  336. select opt in $SEL; do
  337. if [ $opt = "Install" ]
  338. then
  339. if [ $SELECTED = "Deb" ]
  340. then sudo apt-get install openvpn
  341. else sudo yum install openvpn
  342. fi
  343. INFO="OpenVPN is now installed."
  344. else
  345. return
  346. fi
  347. break
  348. done
  349.  
  350. }
  351. function MENU_TestPort()
  352. {
  353. PORT=""
  354. STATUS=""
  355. CONN=""
  356. MENU="tcp udp Back"
  357. while true; do
  358. CLS
  359. PrintTopMenuInfo
  360. echo "$(ChangeColor blue text)TEST OUTGOING PORTS$(ChangeColor white text)"
  361. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  362. echo "$(ChangeColor red text)Port: $CONN $PORT $STATUS$(ChangeColor white text)"
  363. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  364. select sel in $MENU;
  365. do
  366. if [ "$sel" = "Back" ]
  367. then return
  368. fi
  369. read -p "Enter port $sel 1-65535 or range >from-to<: " PORT
  370. IS_RANGE=$( echo $PORT | grep -c "-" )
  371.  
  372. if [ $IS_RANGE -eq 1 ]
  373. then
  374. STATUS="range tested"
  375. RANGE_STOP=${PORT##*-} # remove text before last '-'
  376. RANGE_STOP=$(echo $RANGE_STOP | tr -d "-")
  377. RANGE_START=${PORT%-*} # remove text after last '-'
  378. RANGE_START=$(echo $RANGE_START | tr -d "-")
  379. TIMEOUT=""
  380. read -p "Enter timeout in seconds: " TIMEOUT
  381. echo "Testing $sel ports from $RANGE_START to $RANGE_STOP with $TIMEOUT timeout ..."
  382. i=$RANGE_START
  383.  
  384. while [ $i -le $RANGE_STOP ]
  385. do
  386. TestPortOut $i $sel
  387. S=$?
  388. if [ $S -eq 1 ]
  389. then S="$(ChangeColor green text)Port $sel $i Open$(ChangeColor white text)"
  390. else S="$(ChangeColor red text)Port $sel $i Closed$(ChangeColor white text)"
  391. fi
  392. echo "$S"
  393. i=$((i+1))
  394. done
  395.  
  396. read -p "Enter to continue"
  397. else
  398. TestPortOut $PORT $sel
  399. STATUS=$?
  400. if [ $STATUS -eq 1 ]
  401. then STATUS="$(ChangeColor green text)Open$(ChangeColor white text)"
  402. else STATUS="Closed"
  403. fi
  404.  
  405. fi
  406. CONN=$sel
  407. break
  408. done
  409. done
  410. }
  411. ###########################################################################################
  412. ############################ MAIN MENU SELECTION ##########################################
  413. ###########################################################################################
  414. CLS
  415. MENU_ITEMS="Profile Connect Download Clean Ports Install Credits Help Quit"
  416. while true
  417. do
  418. if [ $INFO = "" ]
  419. then INFO=$IMPORTANT
  420. fi
  421.  
  422. CLS
  423. PrintTopMenuInfo
  424. echo "Profile: $(ChangeColor blue text)$SELECTED_PROFILE$(ChangeColor white text)"
  425. echo "Username: $(ChangeColor orange text)$USERNAME$(ChangeColor white text)"
  426. echo "Password: $(ChangeColor orange text)$PASSWORD$(ChangeColor white text)"
  427. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  428. echo "INFO: $(ChangeColor red text)$INFO$(ChangeColor white text)"
  429. echo "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––"
  430. select menu in $MENU_ITEMS; do
  431. case "$menu" in
  432. "Profile") INFO=""; MENU_SelectProfile; break
  433. ;;
  434. "Connect") INFO=""; ConnectProfile; break
  435. ;;
  436. "Download") INFO=""; MENU_DownloadProfiles; break
  437. ;;
  438. "Clean") INFO=""; ClearProfiles; break
  439. ;;
  440. "Ports") INFO=""; MENU_TestPort; break
  441. ;;
  442. "Install") INFO=""; MENU_Install; break
  443. ;;
  444. "Credits") INFO=""; MENU_Credits; break
  445. ;;
  446. "Help") INFO=""; MENU_Help; break
  447. ;;
  448. "Quit") echo "Quiting Free VPN Connect..."; CLS; break 2
  449. ;;
  450. *) INFO="Wrong selection!"; break
  451. ;;
  452. esac
  453. done
  454. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement