DebianVPS-Installer 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. #!/bin/bash
  2. # Debian 9 and 10 VPS Installer
  3. # Original Script by Bonveio Abitona
  4. # Modified By KuroShion
  5. #
  6. # Variables (Can be changed depends on your preferred values)
  7. # Script name
  8. MyScriptName='AidanVPN'
  9. # OpenSSH Ports
  10. SSH_Port1='22'
  11. SSH_Port2='299'
  12. # Your SSH Banner
  13. SSH_Banner='https://pastebin.com/raw/bqjYZ0xA'
  14. # Dropbear Ports
  15. Dropbear_Port1='143'
  16. Dropbear_Port2='2770'
  17. # Stunnel Ports
  18. Stunnel_Port1='442' # through Dropbear
  19. Stunnel_Port2='441' # through OpenSSH
  20. Stunnel_Port3='445' # through Openvpn
  21. # OpenVPN Ports
  22. OpenVPN_TCP_Port='502' # take note when you change this port, openvpn sun noload config will not work
  23. OpenVPN_UDP_Port='1194'
  24. # Privoxy Ports
  25. Privoxy_Port1='8000'
  26. Privoxy_Port2='3100'
  27. # Squid Ports
  28. Squid_Port1='3233'
  29. Squid_Port2='7003'
  30. Squid_Port3='9005'
  31. # OpenVPN Config Download Port
  32. OvpnDownload_Port='85' # Before changing this value, please read this document. It contains all unsafe ports for Google Chrome Browser, please read from line #23 to line #89: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/master/net/base/port_util.cc
  33. # Server local time
  34. MyVPS_Time='Asia/KualaLumpur'
  35. ## All function used for this script
  36. #############################
  37. ## WARNING: Do not modify or edit anything
  38. ## if you didn't know what to do.
  39. ## This part is too sensitive.
  40. function InstUpdates(){
  41. export DEBIAN_FRONTEND=noninteractive
  42. apt-get update
  43. apt-get upgrade -y
  44. # Removing some firewall tools that may affect other services
  45. apt-get remove --purge ufw firewalld -y
  46. # Installing some important machine essentials
  47. apt-get install nano wget curl zip unzip tar gzip p7zip-full bc rc openssl cron net-tools dnsutils dos2unix screen bzip2 ccrypt -y
  48. # Now installing all our wanted services
  49. apt-get install dropbear stunnel4 privoxy ca-certificates nginx ruby apt-transport-https lsb-release squid screenfetch -y
  50. # Installing all required packages to install Webmin
  51. apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python dbus libxml-parser-perl -y
  52. apt-get install shared-mime-info jq -y
  53. # Installing a text colorizer
  54. gem install lolcat
  55. # install fail2ban
  56. apt-get -y install fail2ban
  57. # Trying to remove obsolette packages after installation
  58. apt-get autoremove -y
  59. # Installing OpenVPN by pulling its repository inside sources.list file
  60. rm -rf /etc/apt/sources.list.d/openvpn*
  61. echo "deb http://build.openvpn.net/debian/openvpn/stable $(lsb_release -sc) main" > /etc/apt/sources.list.d/openvpn.list
  62. wget -qO - http://build.openvpn.net/debian/openvpn/stable/pubkey.gpg|apt-key add -
  63. apt-get update
  64. apt-get install openvpn easy-rsa -y
  65. }
  66. function InstWebmin(){
  67. # Download the webmin .deb package
  68. # You may change its webmin version depends on the link you've loaded in this variable(.deb file only, do not load .zip or .tar.gz file):
  69. WebminFile='http://prdownloads.sourceforge.net/webadmin/webmin_1.910_all.deb'
  70. wget -qO webmin.deb "$WebminFile"
  71. # Installing .deb package for webmin
  72. dpkg --install webmin.deb
  73. rm -rf webmin.deb
  74. # Configuring webmin server config to use only http instead of https
  75. sed -i 's|ssl=1|ssl=0|g' /etc/webmin/miniserv.conf
  76. # Then restart to take effect
  77. systemctl restart webmin
  78. }
  79. function InstSSH(){
  80. # Removing some duplicated sshd server configs
  81. rm -f /etc/ssh/sshd_config*
  82. # Creating a SSH server config using cat eof tricks
  83. cat <<'MySSHConfig' > /etc/ssh/sshd_config
  84. # My OpenSSH Server config
  85. Port myPORT1
  86. AddressFamily inet
  87. ListenAddress 0.0.0.0
  88. HostKey /etc/ssh/ssh_host_rsa_key
  89. HostKey /etc/ssh/ssh_host_ecdsa_key
  90. HostKey /etc/ssh/ssh_host_ed25519_key
  91. PermitRootLogin yes
  92. MaxSessions 1024
  93. PubkeyAuthentication yes
  94. PasswordAuthentication yes
  95. PermitEmptyPasswords no
  96. ChallengeResponseAuthentication no
  97. UsePAM yes
  98. X11Forwarding yes
  99. PrintMotd no
  100. ClientAliveInterval 240
  101. ClientAliveCountMax 2
  102. UseDNS no
  103. Banner /etc/banner
  104. AcceptEnv LANG LC_*
  105. Subsystem sftp /usr/lib/openssh/sftp-server
  106. MySSHConfig
  107. # Now we'll put our ssh ports inside of sshd_config
  108. sed -i "s|myPORT1|$SSH_Port1|g" /etc/ssh/sshd_config
  109. # Download our SSH Banner
  110. rm -f /etc/banner
  111. wget -qO /etc/banner "$SSH_Banner"
  112. dos2unix -q /etc/banner
  113. # My workaround code to remove `BAD Password error` from passwd command, it will fix password-related error on their ssh accounts.
  114. sed -i '/password\s*requisite\s*pam_cracklib.s.*/d' /etc/pam.d/common-password
  115. sed -i 's/use_authtok //g' /etc/pam.d/common-password
  116. # Some command to identify null shells when you tunnel through SSH or using Stunnel, it will fix user/pass authentication error on HTTP Injector, KPN Tunnel, eProxy, SVI, HTTP Proxy Injector etc ssh/ssl tunneling apps.
  117. sed -i '/\/bin\/false/d' /etc/shells
  118. sed -i '/\/usr\/sbin\/nologin/d' /etc/shells
  119. echo '/bin/false' >> /etc/shells
  120. echo '/usr/sbin/nologin' >> /etc/shells
  121. # Restarting openssh service
  122. systemctl restart ssh
  123. # Removing some duplicate config file
  124. rm -rf /etc/default/dropbear*
  125. # creating dropbear config using cat eof tricks
  126. cat <<'MyDropbear' > /etc/default/dropbear
  127. # My Dropbear Config
  128. NO_START=0
  129. DROPBEAR_PORT=PORT01
  130. DROPBEAR_EXTRA_ARGS=""
  131. DROPBEAR_BANNER="/etc/banner"
  132. DROPBEAR_RSAKEY="/etc/dropbear/dropbear_rsa_host_key"
  133. DROPBEAR_DSSKEY="/etc/dropbear/dropbear_dss_host_key"
  134. DROPBEAR_ECDSAKEY="/etc/dropbear/dropbear_ecdsa_host_key"
  135. DROPBEAR_RECEIVE_WINDOW=65536
  136. MyDropbear
  137. # Now changing our desired dropbear ports
  138. sed -i "s|PORT01|$Dropbear_Port1|g" /etc/default/dropbear
  139. # Restarting dropbear service
  140. systemctl restart dropbear
  141. }
  142. function InsStunnel(){
  143. StunnelDir=$(ls /etc/default | grep stunnel | head -n1)
  144. # Creating stunnel startup config using cat eof tricks
  145. cat <<'MyStunnelD' > /etc/default/$StunnelDir
  146. # My Stunnel Config
  147. ENABLED=1
  148. FILES="/etc/stunnel/*.conf"
  149. OPTIONS=""
  150. BANNER="/etc/banner"
  151. PPP_RESTART=0
  152. # RLIMITS="-n 4096 -d unlimited"
  153. RLIMITS=""
  154. MyStunnelD
  155. # Removing all stunnel folder contents
  156. rm -rf /etc/stunnel/*
  157. # Creating stunnel certifcate using openssl
  158. openssl req -new -x509 -days 9999 -nodes -subj "/C=MY/ST=Selangor/L=Gombak/O=$MyScriptName/OU=$MyScriptName/CN=$MyScriptName" -out /etc/stunnel/stunnel.pem -keyout /etc/stunnel/stunnel.pem &> /dev/null
  159. ## > /dev/null 2>&1
  160. # Creating stunnel server config
  161. cat <<'MyStunnelC' > /etc/stunnel/stunnel.conf
  162. # My Stunnel Config
  163. pid = /var/run/stunnel.pid
  164. cert = /etc/stunnel/stunnel.pem
  165. client = no
  166. socket = l:TCP_NODELAY=1
  167. socket = r:TCP_NODELAY=1
  168. TIMEOUTclose = 0
  169. [dropbear]
  170. accept = Stunnel_Port1
  171. connect = 127.0.0.1:dropbear_port_c
  172. [openssh]
  173. accept = Stunnel_Port2
  174. connect = 127.0.0.1:openssh_port_c
  175. [openvpn]
  176. accept = Stunnel_Port3
  177. connect = 127.0.0.1:OpenVPN_TCP_Port
  178. MyStunnelC
  179. # setting stunnel ports
  180. sed -i "s|Stunnel_Port1|$Stunnel_Port1|g" /etc/stunnel/stunnel.conf
  181. sed -i "s|dropbear_port_c|$(netstat -tlnp | grep -i dropbear | awk '{print $4}' | cut -d: -f2 | xargs | awk '{print $2}' | head -n1)|g" /etc/stunnel/stunnel.conf
  182. sed -i "s|Stunnel_Port2|$Stunnel_Port2|g" /etc/stunnel/stunnel.conf
  183. sed -i "s|openssh_port_c|$(netstat -tlnp | grep -i ssh | awk '{print $4}' | cut -d: -f2 | xargs | awk '{print $2}' | head -n1)|g" /etc/stunnel/stunnel.conf
  184. # Restarting stunnel service
  185. systemctl restart $StunnelDir
  186. }
  187. function InsOpenVPN(){
  188. # Checking if openvpn folder is accidentally deleted or purged
  189. if [[ ! -e /etc/openvpn ]]; then
  190. mkdir -p /etc/openvpn
  191. fi
  192. # Removing all existing openvpn server files
  193. rm -rf /etc/openvpn/*
  194. # Creating server.conf, ca.crt, server.crt and server.key
  195. cp -r /usr/share/easy-rsa/ /etc/openvpn
  196. mkdir /etc/openvpn/easy-rsa/keys
  197. sed -i 's|export KEY_COUNTRY="US"|export KEY_COUNTRY="MY"|' /etc/openvpn/easy-rsa/vars
  198. sed -i 's|export KEY_PROVINCE="CA"|export KEY_PROVINCE="Selangor"|' /etc/openvpn/easy-rsa/vars
  199. sed -i 's|export KEY_CITY="SanFrancisco"|export KEY_CITY="Gombak"|' /etc/openvpn/easy-rsa/vars
  200. sed -i 's|export KEY_ORG="Fort-Funston"|export KEY_ORG="AidanVPN"|' /etc/openvpn/easy-rsa/vars
  201. sed -i 's|export KEY_EMAIL="me@myhost.mydomain"|export KEY_EMAIL="irwanmohi@gmail.com"|' /etc/openvpn/easy-rsa/vars
  202. sed -i 's|export KEY_OU="MyOrganizationalUnit"|export KEY_OU="AidanVPN"|' /etc/openvpn/easy-rsa/vars
  203. sed -i 's|export KEY_NAME="EasyRSA"|export KEY_NAME="AidanVPN"|' /etc/openvpn/easy-rsa/vars
  204. sed -i 's|export KEY_OU=changeme|export KEY_OU=AidanVPN|' /etc/openvpn/easy-rsa/vars
  205. # Create Diffie-Helman Pem
  206. openssl dhparam -out /etc/openvpn/dh.pem 1024
  207. # Create PKI
  208. cd /etc/openvpn/easy-rsa
  209. cp openssl-1.0.0.cnf openssl.cnf
  210. . ./vars
  211. ./clean-all
  212. export EASY_RSA="${EASY_RSA:-.}"
  213. "$EASY_RSA/pkitool" --initca $*
  214. # Create key server
  215. export EASY_RSA="${EASY_RSA:-.}"
  216. "$EASY_RSA/pkitool" --server server
  217. # Setting KEY CN
  218. export EASY_RSA="${EASY_RSA:-.}"
  219. "$EASY_RSA/pkitool" client
  220. # cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key,ca.crt} /etc/openvpn
  221. cd
  222. cp /etc/openvpn/easy-rsa/keys/server.crt /etc/openvpn/server.crt
  223. cp /etc/openvpn/easy-rsa/keys/server.key /etc/openvpn/server.key
  224. cp /etc/openvpn/easy-rsa/keys/ca.crt /etc/openvpn/ca.crt
  225. chmod +x /etc/openvpn/ca.crt
  226. cat <<'myOpenVPNconf' > /etc/openvpn/server_tcp.conf
  227. # My OpenVPN
  228. port MyOvpnPort
  229. dev tun
  230. proto tcp
  231. ca /etc/openvpn/ca.crt
  232. cert /etc/openvpn/server.crt
  233. key /etc/openvpn/server.key
  234. dh /etc/openvpn/dh.pem
  235. cipher AES-128-CBC
  236. ncp-disable
  237. auth none
  238. comp-lzo
  239. plugin /etc/openvpn/openvpn-auth-pam.so login
  240. verify-client-cert none
  241. username-as-common-name
  242. max-clients 4000
  243. server 10.200.0.0 255.255.0.0
  244. tun-mtu 1500
  245. mssfix 1460
  246. reneg-sec 0
  247. sndbuf 393216
  248. rcvbuf 393216
  249. push "sndbuf 393216"
  250. push "rcvbuf 393216"
  251. push "route-method exe"
  252. push "route-delay 2"
  253. client-to-client
  254. keepalive 10 120
  255. persist-tun
  256. persist-key
  257. persist-remote-ip
  258. status /etc/openvpn/tcp_stats.log
  259. log /etc/openvpn/tcp.log
  260. verb 3
  261. script-security 2
  262. socket-flags TCP_NODELAY
  263. push "socket-flags TCP_NODELAY"
  264. myOpenVPNconf
  265. cat <<'myOpenVPNconf2' > /etc/openvpn/server_udp.conf
  266. # My OpenVPN
  267. port MyOvpnPort
  268. dev tun
  269. proto udp
  270. ca /etc/openvpn/ca.crt
  271. cert /etc/openvpn/server.crt
  272. key /etc/openvpn/server.key
  273. dh /etc/openvpn/dh.pem
  274. cipher AES-128-CBC
  275. ncp-disable
  276. auth none
  277. comp-lzo
  278. plugin /etc/openvpn/openvpn-auth-pam.so login
  279. verify-client-cert none
  280. username-as-common-name
  281. max-clients 4000
  282. server 10.201.0.0 255.255.0.0
  283. tun-mtu 1500
  284. mssfix 1460
  285. reneg-sec 0
  286. sndbuf 393216
  287. rcvbuf 393216
  288. push "sndbuf 393216"
  289. push "rcvbuf 393216"
  290. push "route-method exe"
  291. push "route-delay 2"
  292. client-to-client
  293. keepalive 10 120
  294. persist-tun
  295. persist-key
  296. persist-remote-ip
  297. status /etc/openvpn/udp_stats.log
  298. log /etc/openvpn/udp.log
  299. verb 3
  300. script-security 2
  301. socket-flags TCP_NODELAY
  302. push "socket-flags TCP_NODELAY"
  303. myOpenVPNconf2
  304. # Getting all dns inside resolv.conf then use as Default DNS for our openvpn server
  305. grep -v '#' /etc/resolv.conf | grep 'nameserver' | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | while read -r line; do
  306. echo "push \"dhcp-option DNS $line\"" >> /etc/openvpn/server.conf
  307. done
  308. # Creating a New update message in server.conf
  309. # cat <<'NUovpn' > /etc/openvpn/server.conf
  310. # New Update are now released, OpenVPN Server
  311. # are now running both TCP and UDP Protocol. (Both are only running on IPv4)
  312. # But our native server.conf are now removed and divided
  313. # Into two different configs base on their Protocols:
  314. # * OpenVPN TCP (located at /etc/openvpn/server_tcp.conf
  315. # * OpenVPN UDP (located at /etc/openvpn/server_udp.conf
  316. #
  317. # Also other logging files like
  318. # status logs and server logs
  319. # are moved into new different file names:
  320. # * OpenVPN TCP Server logs (/etc/openvpn/tcp.log)
  321. # * OpenVPN UDP Server logs (/etc/openvpn/udp.log)
  322. # * OpenVPN TCP Status logs (/etc/openvpn/tcp_stats.log)
  323. # * OpenVPN UDP Status logs (/etc/openvpn/udp_stats.log)
  324. #
  325. # Server ports are configured base on env vars
  326. # executed/raised from this script (OpenVPN_TCP_Port/OpenVPN_UDP_Port)
  327. #
  328. # Enjoy the new update
  329. # NUovpn
  330. # setting openvpn server port
  331. sed -i "s|MyOvpnPort|$OpenVPN_TCP_Port|g" /etc/openvpn/server_tcp.conf
  332. sed -i "s|MyOvpnPort|$OpenVPN_UDP_Port|g" /etc/openvpn/server_udp.conf
  333. # Getting some OpenVPN plugins for unix authentication
  334. wget -qO /etc/openvpn/b.zip 'https://raw.githubusercontent.com/jm051484/jm051484script/master/openvpn_plugin64'
  335. unzip -qq /etc/openvpn/b.zip -d /etc/openvpn
  336. rm -f /etc/openvpn/b.zip
  337. # Some workaround for OpenVZ machines for "Startup error" openvpn service
  338. if [[ "$(hostnamectl | grep -i Virtualization | awk '{print $2}' | head -n1)" == 'openvz' ]]; then
  339. sed -i 's|LimitNPROC|#LimitNPROC|g' /lib/systemd/system/openvpn*
  340. systemctl daemon-reload
  341. fi
  342. # Allow IPv4 Forwarding
  343. sed -i '/net.ipv4.ip_forward.*/d' /etc/sysctl.conf
  344. echo 'net.ipv4.ip_forward=1' > /etc/sysctl.d/20-openvpn.conf
  345. sysctl --system &> /dev/null
  346. # Iptables Rule for OpenVPN server
  347. cat <<'EOFipt' > /etc/openvpn/openvpn.bash
  348. #!/bin/bash
  349. PUBLIC_INET="$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)"
  350. IPCIDR='10.200.0.0/16'
  351. IPCIDR2='10.201.0.0/16'
  352. iptables -I FORWARD -s $IPCIDR -j ACCEPT
  353. iptables -I FORWARD -s $IPCIDR2 -j ACCEPT
  354. iptables -t nat -A POSTROUTING -o $PUBLIC_INET -j MASQUERADE
  355. iptables -t nat -A POSTROUTING -s $IPCIDR -o $PUBLIC_INET -j MASQUERADE
  356. iptables -t nat -A POSTROUTING -s $IPCIDR2 -o $PUBLIC_INET -j MASQUERADE
  357. EOFipt
  358. chmod +x /etc/openvpn/openvpn.bash
  359. bash /etc/openvpn/openvpn.bash
  360. # Enabling IPv4 Forwarding
  361. echo 1 > /proc/sys/net/ipv4/ip_forward
  362. # Starting OpenVPN server
  363. systemctl start openvpn@server_tcp
  364. systemctl enable openvpn@server_tcp
  365. systemctl start openvpn@server_udp
  366. systemctl enable openvpn@server_udp
  367. # Pulling OpenVPN no internet fixer script
  368. wget -qO /etc/openvpn/openvpn.bash "https://raw.githubusercontent.com/jm051484/jm051484script/master/openvpn.bash"
  369. chmod +x /etc/openvpn/openvpn.bash
  370. }
  371. function InsProxy(){
  372. # Removing Duplicate privoxy config
  373. rm -rf /etc/privoxy/config*
  374. # Creating Privoxy server config using cat eof tricks
  375. cat <<'myPrivoxy' > /etc/privoxy/config
  376. # My Privoxy Server Config
  377. user-manual /usr/share/doc/privoxy/user-manual
  378. confdir /etc/privoxy
  379. logdir /var/log/privoxy
  380. filterfile default.filter
  381. logfile logfile
  382. listen-address 0.0.0.0:Privoxy_Port1
  383. toggle 1
  384. enable-remote-toggle 0
  385. enable-remote-http-toggle 0
  386. enable-edit-actions 0
  387. enforce-blocks 0
  388. buffer-limit 4096
  389. enable-proxy-authentication-forwarding 1
  390. forwarded-connect-retries 1
  391. accept-intercepted-requests 1
  392. allow-cgi-request-crunching 1
  393. split-large-forms 0
  394. keep-alive-timeout 5
  395. tolerate-pipelining 1
  396. socket-timeout 300
  397. permit-access 0.0.0.0/0 IP-ADDRESS
  398. myPrivoxy
  399. # Setting machine's IP Address inside of our privoxy config(security that only allows this machine to use this proxy server)
  400. sed -i "s|IP-ADDRESS|$IPADDR|g" /etc/privoxy/config
  401. # Setting privoxy ports
  402. sed -i "s|Privoxy_Port1|$Privoxy_Port1|g" /etc/privoxy/config
  403. # Removing Duplicate Squid config
  404. rm -rf /etc/squid/squid.conf*
  405. # Creating Squid server config using cat eof tricks
  406. cat <<'mySquid' > /etc/squid/squid.conf
  407. # My Squid Proxy Server Config
  408. acl VPN dst IP-ADDRESS/32
  409. http_access allow VPN
  410. http_access deny all
  411. http_port Squid_Port1
  412. http_port Squid_Port2
  413. http_port Squid_Port3
  414. coredump_dir /var/spool/squid
  415. refresh_pattern ^ftp: 1440 20% 10080
  416. refresh_pattern ^gopher: 1440 0% 1440
  417. refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
  418. refresh_pattern . 0 20% 4320
  419. visible_hostname A.Dev
  420. mySquid
  421. # Setting machine's IP Address inside of our squid config(security that only allows this machine to use this proxy server)
  422. sed -i "s|IP-ADDRESS|$IPADDR|g" /etc/squid/squid.conf
  423. # Setting squid ports
  424. sed -i "s|Squid_Port1|$Squid_Port1|g" /etc/squid/squid.conf
  425. sed -i "s|Squid_Port2|$Squid_Port2|g" /etc/squid/squid.conf
  426. sed -i "s|Squid_Port3|$Squid_Port3|g" /etc/squid/squid.conf
  427. sed -i "s|MyScriptName|$MyScriptName|g" /etc/squid/squid.conf
  428. # Starting Proxy server
  429. echo -e "Restarting proxy server.."
  430. systemctl restart privoxy
  431. systemctl restart squid
  432. }
  433. function OvpnConfigs(){
  434. # Creating nginx config for our ovpn config downloads webserver
  435. cat <<'myNginxC' > /etc/nginx/conf.d/jm051484-ovpn-config.conf
  436. # My OpenVPN Config Download Directory
  437. server {
  438. listen 0.0.0.0:myNginx;
  439. server_name localhost;
  440. root /var/www/openvpn;
  441. index index.html;
  442. }
  443. myNginxC
  444. # Setting our nginx config port for .ovpn download site
  445. sed -i "s|myNginx|$OvpnDownload_Port|g" /etc/nginx/conf.d/jm051484-ovpn-config.conf
  446. # Removing Default nginx page(port 80)
  447. rm -rf /etc/nginx/sites-*
  448. # Creating our root directory for all of our .ovpn configs
  449. rm -rf /var/www/openvpn
  450. mkdir -p /var/www/openvpn
  451. # Now creating all of our OpenVPN Configs
  452. cat <<EOF15> /var/www/openvpn/GTMConfig.ovpn
  453. client
  454. dev tun
  455. proto tcp
  456. remote $IPADDR $OpenVPN_TCP_Port
  457. remote-cert-tls server
  458. resolv-retry infinite
  459. connect-retry infinite
  460. nobind
  461. tun-mtu 1500
  462. mssfix 1460
  463. persist-key
  464. persist-tun
  465. auth-user-pass
  466. auth none
  467. auth-nocache
  468. cipher none
  469. keysize 0
  470. comp-lzo
  471. setenv CLIENT_CERT 0
  472. reneg-sec 0
  473. verb 3
  474. #http-proxy $IPADDR $Squid_Port1
  475. http-proxy $IPADDR $Privoxy_Port1
  476. http-proxy-option VERSION 1.1
  477. http-proxy-option CUSTOM-HEADER Host www.googleapis.com
  478. http-proxy-option CUSTOM-HEADER X-Forwarded-For www.googleapis.com
  479. <ca>
  480. $(cat /etc/openvpn/ca.crt)
  481. </ca>
  482. EOF15
  483. cat <<EOF16> /var/www/openvpn/SunConfig.ovpn
  484. client
  485. dev tun
  486. proto tcp
  487. remote $IPADDR $OpenVPN_TCP_Port
  488. remote-cert-tls server
  489. connect-retry infinite
  490. resolv-retry infinite
  491. nobind
  492. tun-mtu 1500
  493. mssfix 1460
  494. persist-key
  495. persist-tun
  496. auth-user-pass
  497. auth none
  498. auth-nocache
  499. cipher none
  500. keysize 0
  501. comp-lzo
  502. setenv CLIENT_CERT 0
  503. reneg-sec 0
  504. verb 3
  505. #http-proxy $IPADDR $Squid_Port1
  506. http-proxy $IPADDR $Privoxy_Port1
  507. http-proxy-option CUSTOM-HEADER Host www.viber.com.edgekey.net
  508. http-proxy-option CUSTOM-HEADER X-Online-Host www.viber.com.edgekey.net
  509. http-proxy-option CUSTOM-HEADER X-Forwarded-For www.viber.com.edgekey.net
  510. <ca>
  511. $(cat /etc/openvpn/ca.crt)
  512. </ca>
  513. EOF16
  514. cat <<EOF162> /var/www/openvpn/SunUDPConfig.ovpn
  515. client
  516. dev tun
  517. proto udp
  518. remote $IPADDR $OpenVPN_UDP_Port
  519. remote-cert-tls server
  520. resolv-retry infinite
  521. float
  522. fast-io
  523. nobind
  524. tun-mtu 1500
  525. mssfix 1460
  526. persist-key
  527. persist-remote-ip
  528. persist-tun
  529. auth-user-pass
  530. auth none
  531. auth-nocache
  532. cipher none
  533. keysize 0
  534. comp-lzo
  535. setenv CLIENT_CERT 0
  536. reneg-sec 0
  537. verb 3
  538. <ca>
  539. $(cat /etc/openvpn/ca.crt)
  540. </ca>
  541. EOF162
  542. cat <<EOF17> /var/www/openvpn/SunNoloadConfig.ovpn
  543. client
  544. dev tun
  545. proto tcp-client
  546. remote $IPADDR $OpenVPN_TCP_Port
  547. remote-cert-tls server
  548. bind
  549. float
  550. tun-mtu 1500
  551. tun-mtu-extra 32
  552. mssfix 1450
  553. mute-replay-warnings
  554. connect-retry-max 9999
  555. redirect-gateway def1
  556. connect-retry 0 1
  557. resolv-retry infinite
  558. setenv CLIENT_CERT 0
  559. persist-tun
  560. persist-key
  561. auth-user-pass
  562. auth none
  563. auth-nocache
  564. auth-retry interact
  565. cipher none
  566. keysize 0
  567. comp-lzo
  568. reneg-sec 0
  569. verb 0
  570. nice -20
  571. log /dev/null
  572. <ca>
  573. $(cat /etc/openvpn/ca.crt)
  574. </ca>
  575. EOF17
  576. # Creating OVPN download site index.html
  577. cat <<'mySiteOvpn' > /var/www/openvpn/index.html
  578. <!DOCTYPE html>
  579. <html lang="en">
  580. <!-- Simple OVPN Download site by jm051484 -->
  581. <head><meta charset="utf-8" /><title>MyScriptName OVPN Config Download</title><meta name="description" content="MyScriptName Server" /><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" /><meta name="theme-color" content="#000000" /><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"><link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"><link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.3/css/mdb.min.css" rel="stylesheet"></head><body><div class="container justify-content-center" style="margin-top:9em;margin-bottom:5em;"><div class="col-md"><div class="view"><img src="https://openvpn.net/wp-content/uploads/openvpn.jpg" class="card-img-top"><div class="mask rgba-white-slight"></div></div><div class="card"><div class="card-body"><h5 class="card-title">Config List</h5><br /><ul class="list-group"><li class="list-group-item justify-content-between align-items-center" style="margin-bottom:1em;"><p>For Globe/TM <span class="badge light-blue darken-4">Android/iOS</span><br /><small> For EZ/GS Promo with WNP,SNS,FB and IG freebies</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/GTMConfig.ovpn" style="float:right;"><i class="fa fa-download"></i> Download</a></li><li class="list-group-item justify-content-between align-items-center" style="margin-bottom:1em;"><p>For Globe/TM <span class="badge light-blue darken-4">PC/Modem</span><br /><small> For EZ/GS Promo with WNP,SNS,FB and IG freebies</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/GTM-PC-Config.ovpn" style="float:right;"><i class="fa fa-download"></i> Download</a></li><li class="list-group-item justify-content-between align-items-center" style="margin-bottom:1em;"><p>For Sun <span class="badge light-blue darken-4">Android/iOS/PC/Modem</span><br /><small> For TU Promos</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/SunConfig.ovpn" style="float:right;"><i class="fa fa-download"></i> Download</a></li><li class="list-group-item justify-content-between align-items-center" style="margin-bottom:1em;"><p>For Sun <span class="badge light-blue darken-4">Modem</span><br /><small> Without Promo/Noload</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/SunNoloadConfig.ovpn" style="float:right;"><i class="fa fa-download"></i> Download</a></li></ul></div></div></div></div></body></html>
  582. mySiteOvpn
  583. # Setting template's correct name,IP address and nginx Port
  584. sed -i "s|MyScriptName|$MyScriptName|g" /var/www/openvpn/index.html
  585. sed -i "s|NGINXPORT|$OvpnDownload_Port|g" /var/www/openvpn/index.html
  586. sed -i "s|IP-ADDRESS|$IPADDR|g" /var/www/openvpn/index.html
  587. # Restarting nginx service
  588. systemctl restart nginx
  589. # Creating all .ovpn config archives
  590. cd /var/www/openvpn
  591. zip -qq -r Configs.zip *.ovpn
  592. cd
  593. }
  594. function ip_address(){
  595. local IP="$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )"
  596. [ -z "${IP}" ] && IP="$( wget -qO- -t1 -T2 ipv4.icanhazip.com )"
  597. [ -z "${IP}" ] && IP="$( wget -qO- -t1 -T2 ipinfo.io/ip )"
  598. [ ! -z "${IP}" ] && echo "${IP}" || echo
  599. }
  600. IPADDR="$(ip_address)"
  601. function ConfStartup(){
  602. # Daily reboot time of our machine
  603. # For cron commands, visit https://crontab.guru
  604. echo -e "0 4\t* * *\troot\treboot" > /etc/cron.d/b_reboot_job
  605. # Creating directory for startup script
  606. rm -rf /etc/jm051484
  607. mkdir -p /etc/jm051484
  608. chmod -R 755 /etc/jm051484
  609. # Creating startup script using cat eof tricks
  610. cat <<'EOFSH' > /etc/jm051484/startup.sh
  611. #!/bin/bash
  612. # Setting server local time
  613. ln -fs /usr/share/zoneinfo/MyVPS_Time /etc/localtime
  614. # Prevent DOS-like UI when installing using APT (Disabling APT interactive dialog)
  615. export DEBIAN_FRONTEND=noninteractive
  616. # Allowing ALL TCP ports for our machine (Simple workaround for policy-based VPS)
  617. iptables -A INPUT -s $(wget -4qO- http://ipinfo.io/ip) -p tcp -m multiport --dport 1:65535 -j ACCEPT
  618. # Allowing OpenVPN to Forward traffic
  619. /bin/bash /etc/openvpn/openvpn.bash
  620. # Deleting Expired SSH Accounts
  621. /usr/local/sbin/delete_expired &> /dev/null
  622. EOFSH
  623. chmod +x /etc/jm051484/startup.sh
  624. # Setting server local time every time this machine reboots
  625. sed -i "s|MyVPS_Time|$MyVPS_Time|g" /etc/jm051484/startup.sh
  626. #
  627. rm -rf /etc/sysctl.d/99*
  628. # Setting our startup script to run every machine boots
  629. echo "[Unit]
  630. Description=jm051484 Startup Script
  631. Before=network-online.target
  632. Wants=network-online.target
  633. [Service]
  634. Type=oneshot
  635. ExecStart=/bin/bash /etc/jm051484/startup.sh
  636. RemainAfterExit=yes
  637. [Install]
  638. WantedBy=multi-user.target" > /etc/systemd/system/jm051484.service
  639. chmod +x /etc/systemd/system/jm051484.service
  640. systemctl daemon-reload
  641. systemctl start jm051484
  642. systemctl enable jm051484 &> /dev/null
  643. # install ddos deflate
  644. cd
  645. apt-get -y install dnsutils dsniff
  646. wget https://raw.githubusercontent.com/jm051484/Deb83in1Autoscript/master/ddos-deflate-master.zip
  647. unzip ddos-deflate-master.zip
  648. cd ddos-deflate-master
  649. ./install.sh
  650. rm -rf /root/ddos-deflate-master.zip
  651. # Rebooting cron service
  652. systemctl restart cron
  653. systemctl enable cron
  654. }
  655. function ConfMenu(){
  656. echo -e " Creating Menu scripts.."
  657. cd /usr/local/sbin/
  658. rm -rf {accounts,base-ports,base-ports-wc,base-script,bench-network,clearcache,connections,create,create_random,create_trial,delete_expired,diagnose,edit_dropbear,edit_openssh,edit_openvpn,edit_ports,edit_squid3,edit_stunnel4,locked_list,menu,options,ram,reboot_sys,reboot_sys_auto,restart_services,server,set_multilogin_autokill,set_multilogin_autokill_lib,show_ports,speedtest,user_delete,user_details,user_details_lib,user_extend,user_list,user_lock,user_unlock}
  659. wget -q 'https://raw.githubusercontent.com/jm051484/jm051484script/master/menu.zip'
  660. unzip -qq menu.zip
  661. rm -f menu.zip
  662. chmod +x ./*
  663. dos2unix ./* &> /dev/null
  664. sed -i 's|/etc/squid/squid.conf|/etc/privoxy/config|g' ./*
  665. sed -i 's|http_port|listen-address|g' ./*
  666. cd ~
  667. echo 'clear' > /etc/profile.d/jm051484.sh
  668. echo 'echo '' > /var/log/syslog' >> /etc/profile.d/jm051484.sh
  669. echo 'screenfetch -p -A Android' >> /etc/profile.d/jm051484.sh
  670. chmod +x /etc/profile.d/jm051484.sh
  671. }
  672. function ScriptMessage(){
  673. echo -e " (。◕‿◕。) $MyScriptName Debian VPS Installer"
  674. echo -e " Open release version"
  675. echo -e ""
  676. echo -e " Original Script created by Bonveio"
  677. echo -e " Modified by A.Dev"
  678. echo -e ""
  679. }
  680. #############################
  681. #############################
  682. ## Installation Process
  683. #############################
  684. ## WARNING: Do not modify or edit anything
  685. ## if you didn't know what to do.
  686. ## This part is too sensitive.
  687. #############################
  688. #############################
  689. # First thing to do is check if this machine is Debian
  690. source /etc/os-release
  691. if [[ "$ID" != 'debian' ]]; then
  692. ScriptMessage
  693. echo -e "[\e[1;31mError\e[0m] This script is for Debian only, exting..."
  694. exit 1
  695. fi
  696. # Now check if our machine is in root user, if not, this script exits
  697. # If you're on sudo user, run `sudo su -` first before running this script
  698. if [[ $EUID -ne 0 ]];then
  699. ScriptMessage
  700. echo -e "[\e[1;31mError\e[0m] This script must be run as root, exiting..."
  701. exit 1
  702. fi
  703. # (For OpenVPN) Checking it this machine have TUN Module, this is the tunneling interface of OpenVPN server
  704. if [[ ! -e /dev/net/tun ]]; then
  705. echo -e "[\e[1;31m×\e[0m] You cant use this script without TUN Module installed/embedded in your machine, file a support ticket to your machine admin about this matter"
  706. echo -e "[\e[1;31m-\e[0m] Script is now exiting..."
  707. exit 1
  708. fi
  709. # Begin Installation by Updating and Upgrading machine and then Installing all our wanted packages/services to be install.
  710. ScriptMessage
  711. sleep 2
  712. InstUpdates
  713. # Configure OpenSSH and Dropbear
  714. echo -e "Configuring ssh..."
  715. InstSSH
  716. # Configure Stunnel
  717. echo -e "Configuring stunnel..."
  718. InsStunnel
  719. # Configure Webmin
  720. echo -e "Configuring webmin..."
  721. InstWebmin
  722. # Configure Privoxy and Squid
  723. echo -e "Configuring proxy..."
  724. InsProxy
  725. # Configure OpenVPN
  726. echo -e "Configuring OpenVPN..."
  727. InsOpenVPN
  728. # Configuring Nginx OVPN config download site
  729. OvpnConfigs
  730. # Some assistance and startup scripts
  731. ConfStartup
  732. ## DNS maker plugin for SUN users(for vps script usage only)
  733. wget -qO dnsmaker "https://raw.githubusercontent.com/jm051484/jm051484script/master/DNSMaster/debian"
  734. chmod +x dnsmaker
  735. ./dnsmaker
  736. rm -rf dnsmaker
  737. sed -i "s|http-proxy $IPADDR|http-proxy $(cat /tmp/abonv_mydns)|g" /var/www/openvpn/SunConfig.ovpn
  738. sed -i "s|remote $IPADDR|remote $(cat /tmp/abonv_mydns)|g" /var/www/openvpn/SunUDPConfig.ovpn
  739. curl -4sSL "$(cat /tmp/abonv_mydns_domain)" &> /dev/null
  740. mv /tmp/abonv_mydns /etc/jm051484/my_domain_name
  741. mv /tmp/abonv_mydns_id /etc/jm051484/my_domain_id
  742. rm -rf /tmp/abonv*
  743. # VPS Menu script v1.0
  744. ConfMenu
  745. # Setting server local time
  746. ln -fs /usr/share/zoneinfo/$MyVPS_Time /etc/localtime
  747. clear
  748. cd ~
  749. # Running sysinfo
  750. bash /etc/profile.d/jm051484.sh
  751. # Showing script's banner message
  752. ScriptMessage
  753. # Showing additional information from installating this script
  754. echo -e ""
  755. echo -e " Success Installation"
  756. echo -e ""
  757. echo -e " Service Ports: "
  758. echo -e " OpenSSH: $SSH_Port1"
  759. echo -e " Stunnel: $Stunnel_Port1, $Stunnel_Port2"
  760. echo -e " DropbearSSH: $Dropbear_Port1, $Dropbear_Port2"
  761. echo -e " Privoxy: $Privoxy_Port1"
  762. echo -e " Squid: $Squid_Port1"
  763. echo -e " OpenVPN TCP: $OpenVPN_TCP_Port"
  764. echo -e " OpenVPN UDP: $OpenVPN_UDP_Port"
  765. echo -e " NGiNX: $OvpnDownload_Port"
  766. echo -e " Webmin: 10000"
  767. echo -e ""
  768. echo -e ""
  769. echo -e " OpenVPN Configs Download site"
  770. echo -e " http://$IPADDR:$OvpnDownload_Port"
  771. echo -e ""
  772. echo -e " All OpenVPN Configs Archive"
  773. echo -e " http://$IPADDR:$OvpnDownload_Port/Configs.zip"
  774. echo -e ""
  775. echo -e " [For SUN Users]:"
  776. echo -e " Your DNS: $(cat /etc/jm051484/my_domain_name)"
  777. echo -e " Your DNS ID: $(cat /etc/jm051484/my_domain_id)"
  778. echo -e " * Keep your DNS ID in private, do not share your ID to anyone"
  779. echo -e ""
  780. echo -e ""
  781. echo -e " [Note] DO NOT RESELL THIS SCRIPT"
  782. # Clearing all logs from installation
  783. rm -rf /root/.bash_history && history -c && echo '' > /var/log/syslog
  784. rm -f DebianVPS-Installer*
  785. exit 1