vpnku.sh 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  1. #!/bin/bash
  2. # VPS Installer
  3. # Script by XAM
  4. #
  5. # Illegal selling and redistribution of this script is strictly prohibited
  6. # Please respect author's Property
  7. # Binigay sainyo ng libre, ipamahagi nyo rin ng libre.
  8. #
  9. #
  10. # Now check if our machine is in root user, if not, this script exits
  11. # If you're on sudo user, run `sudo su -` first before running this script
  12. if [[ $EUID -ne 0 ]];then
  13. ScriptMessage
  14. echo -e "[\e[1;31mError\e[0m] This script must be run as root, exiting..."
  15. exit 1
  16. fi
  17. # Install Webserver
  18. apt -y --purge remove apache2*;
  19. apt -y install nginx
  20. apt -y install php3-fpm php3-cli libssh2-1 php-ssh2 php
  21. sed -i 's/listen = \/run\/php\/php7.3-fpm.sock/listen = 127.0.0.1:9000/g' /etc/php/7.3/fpm/pool.d/www.conf
  22. rm /etc/nginx/sites-enabled/default
  23. rm /etc/nginx/sites-available/default
  24. wget -O /etc/nginx/nginx.conf "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Other/nginx.conf"
  25. wget -O /etc/nginx/conf.d/vps.conf "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Other/vps.conf"
  26. wget -O /etc/nginx/conf.d/monitoring.conf "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Other/monitoring.conf"
  27. mkdir -p /home/vps/public_html
  28. wget -O /home/vps/public_html/index.php "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Panel/index.php"
  29. service php7.3-fpm restart
  30. service nginx restart
  31. # OpenVPN Monitoring
  32. apt-get install -y gcc libgeoip-dev python-virtualenv python-dev geoip-database-extra uwsgi uwsgi-plugin-python
  33. wget -O /srv/openvpn-monitor.tar "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Panel/openvpn-monitor.tar"
  34. cd /srv
  35. tar xf openvpn-monitor.tar
  36. cd openvpn-monitor
  37. virtualenv .
  38. . bin/activate
  39. pip install -r requirements.txt
  40. wget -O /etc/uwsgi/apps-available/openvpn-monitor.ini "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Panel/openvpn-monitor.ini"
  41. ln -s /etc/uwsgi/apps-available/openvpn-monitor.ini /etc/uwsgi/apps-enabled/
  42. # GeoIP For OpenVPN Monitor
  43. mkdir -p /var/lib/GeoIP
  44. wget -O /var/lib/GeoIP/GeoLite2-City.mmdb.gz "https://raw.githubusercontent.com/irwanmohi/AutoScriptDebian10-1/main/Resources/Panel/GeoLite2-City.mmdb.gz"
  45. gzip -d /var/lib/GeoIP/GeoLite2-City.mmdb.gz
  46. MyScriptName='ReGsUb Script'
  47. # OpenSSH Ports
  48. SSH_Port1='22'
  49. SSH_Port2='225'
  50. # OpenSSH Ports
  51. WS_Port1='80'
  52. WS_Port2='8080'
  53. # Your SSH Banner
  54. SSH_Banner='https://pastebin.com/raw/H7iNhF7m'
  55. # Dropbear Ports
  56. Dropbear_Port1='900'
  57. Dropbear_Port2='990'
  58. # Stunnel Ports
  59. Stunnel_Port1='443' # through Dropbear
  60. Stunnel_Port2='144' # through OpenSSH
  61. Stunnel_Port3='142' # through OpenVPN
  62. #ZIPROXY
  63. ZIPROXY='2898'
  64. Proxy_Port1='8000'
  65. Proxy_Port2='8118'
  66. # OpenVPN Ports
  67. OpenVPN_Port1='1720'
  68. OpenVPN_Port2='25222'
  69. OpenVPN_Port3='1194'
  70. OpenVPN_Port4='69' # take note when you change this port, openvpn sun noload config will not work
  71. # Privoxy Ports (must be 1024 or higher)
  72. Privoxy_Port1='6969'
  73. Privoxy_Port2='9696'
  74. # OpenVPN Config Download Port
  75. OvpnDownload_Port='86' # 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
  76. # Server local time
  77. MyVPS_Time='Asia/Kuala_Lumpur'
  78. #############################
  79. #############################
  80. #############################
  81. ## All function used for this script
  82. #############################
  83. ## WARNING: Do not modify or edit anything
  84. ## if you did'nt know what to do.
  85. ## This part is too sensitive.
  86. #############################
  87. #############################
  88. apt-get update
  89. apt-get upgrade -y
  90. apt-get install lolcat -y
  91. gem install lolcat
  92. sudo apt install python -y
  93. clear
  94. [[ ! "$(command -v curl)" ]] && apt install curl -y -qq
  95. [[ ! "$(command -v jq)" ]] && apt install jq -y -qq
  96. ### CounterAPI update URL
  97. COUNTER="$(curl -4sX GET "https://api.countapi.xyz/hit/BonvScripts/DebianVPS-Installer" | jq -r '.value')"
  98. IPADDR="$(curl -4skL http://ipinfo.io/ip)"
  99. GLOBAL_API_KEY="9531fde17724c8f2b297980c00498bc359e80"
  100. CLOUDFLARE_EMAIL="irwan@aidan.my"
  101. DOMAIN_NAME_TLD="vpnku.cf"
  102. DOMAIN_ZONE_ID="b8d4f58651dbc01b934ff7c1b911cbd3"
  103. ### DNS hostname / Payload here
  104. ## Setting variable
  105. ####
  106. ## Creating file dump for DNS Records
  107. TMP_FILE='/tmp/abonv.txt'
  108. curl -sX GET "https://api.cloudflare.com/client/v4/zones/$DOMAIN_ZONE_ID/dns_records?type=A&count=1000&per_page=1000" -H "X-Auth-Key: $GLOBAL_API_KEY" -H "X-Auth-Email: $CLOUDFLARE_EMAIL" -H "Content-Type: application/json" | python -m json.tool > "$TMP_FILE"
  109. ## Getting Existed DNS Record by Locating its IP Address "content" value
  110. CHECK_IP_RECORD="$(cat < "$TMP_FILE" | jq '.result[]' | jq 'del(.meta)' | jq 'del(.created_on,.locked,.modified_on,.proxiable,.proxied,.ttl,.type,.zone_id,.zone_name)' | jq '. | select(.content=='\"$IPADDR\"')' | jq -r '.content' | awk '!a[$0]++')"
  111. cat < "$TMP_FILE" | jq '.result[]' | jq 'del(.meta)' | jq 'del(.created_on,.locked,.modified_on,.proxiable,.proxied,.ttl,.type,.zone_id,.zone_name)' | jq '. | select(.content=='\"$IPADDR\"')' | jq -r '.name' | awk '!a[$0]++' | head -n1 > /tmp/abonv_existed_hostname
  112. cat < "$TMP_FILE" | jq '.result[]' | jq 'del(.meta)' | jq 'del(.created_on,.locked,.modified_on,.proxiable,.proxied,.ttl,.type,.zone_id,.zone_name)' | jq '. | select(.content=='\"$IPADDR\"')' | jq -r '.id' | awk '!a[$0]++' | head -n1 > /tmp/abonv_existed_dns_id
  113. function ExistedRecord(){
  114. MYDNS="$(cat /tmp/abonv_existed_hostname)"
  115. MYDNS_ID="$(cat /tmp/abonv_existed_dns_id)"
  116. }
  117. if [[ "$IPADDR" == "$CHECK_IP_RECORD" ]]; then
  118. ExistedRecord
  119. echo -e " IP Address already registered to database."
  120. echo -e " DNS: $MYDNS"
  121. echo -e " DNS ID: $MYDNS_ID"
  122. echo -e ""
  123. else
  124. PAYLOAD="ws"
  125. echo -e "Your IP Address:\033[0;35m $IPADDR\033[0m"
  126. read -p "Enter desired DNS: " servername
  127. #read -p "Enter desired servername: " servernames
  128. ### Creating a DNS Record
  129. function CreateRecord(){
  130. TMP_FILE2='/tmp/abonv2.txt'
  131. #TMP_FILE3='/tmp/abonv3.txt'
  132. curl -sX POST "https://api.cloudflare.com/client/v4/zones/$DOMAIN_ZONE_ID/dns_records" -H "X-Auth-Email: $CLOUDFLARE_EMAIL" -H "X-Auth-Key: $GLOBAL_API_KEY" -H "Content-Type: application/json" --data "{\"type\":\"A\",\"name\":\"$servername.$PAYLOAD\",\"content\":\"$IPADDR\",\"ttl\":86400,\"proxied\":false}" | python -m json.tool > "$TMP_FILE2"
  133. cat < "$TMP_FILE2" | jq '.result' | jq 'del(.meta)' | jq 'del(.created_on,.locked,.modified_on,.proxiable,.proxied,.ttl,.type,.zone_id,.zone_name)' > /tmp/abonv22.txt
  134. rm -f "$TMP_FILE2"
  135. mv /tmp/abonv22.txt "$TMP_FILE2"
  136. MYDNS="$(cat < "$TMP_FILE2" | jq -r '.name')"
  137. MYDNS_ID="$(cat < "$TMP_FILE2" | jq -r '.id')"
  138. #curl -sX POST "https://api.cloudflare.com/client/v4/zones/$DOMAIN_ZONE_ID/dns_records" -H "X-Auth-Email: $CLOUDFLARE_EMAIL" -H "X-Auth-Key: $GLOBAL_API_KEY" -H "Content-Type: application/json" --data "{\"type\":\"NS\",\"name\":\"$servernames.$PAYLOAD\",\"content\":\"$MYDNS\",\"ttl\":1,\"proxied\":false}" | python -m json.tool > "$TMP_FILE3"
  139. #cat < "$TMP_FILE3" | jq '.result' | jq 'del(.meta)' | jq 'del(.created_on,.locked,.modified_on,.proxiable,.proxied,.ttl,.type,.zone_id,.zone_name)' > /tmp/abonv33.txt
  140. #rm -f "$TMP_FILE3"
  141. #mv /tmp/abonv33.txt "$TMP_FILE3"
  142. #MYNS="$(cat < "$TMP_FILE3" | jq -r '.name')"
  143. #MYNS_ID="$(cat < "$TMP_FILE3" | jq -r '.id')"
  144. #echo "$MYNS" > nameserver.txt
  145. }
  146. CreateRecord
  147. echo -e " Registering your IP Address.."
  148. echo -e " DNS: $MYDNS"
  149. echo -e " DNS ID: $MYDNS_ID"
  150. #echo -e " DNS: $MYNS"
  151. #echo -e " DNS ID: $MYNS_ID"
  152. echo -e ""
  153. fi
  154. rm -rf /tmp/abonv*
  155. echo -e "$DOMAIN_NAME_TLD" > /tmp/abonv_mydns_domain
  156. echo -e "$MYDNS" > /tmp/abonv_mydns
  157. echo -e "$MYDNS_ID" > /tmp/abonv_mydns_id
  158. function Instupdate() {
  159. export DEBIAN_FRONTEND=noninteractive
  160. apt install fail2ban -y
  161. # Removing some firewall tools that may affect other services
  162. # apt-get remove --purge ufw firewalld -y
  163. # Installing some important machine essentials
  164. apt-get install nano wget curl zip unzip tar gzip p7zip-full bc rc openssl cron net-tools dnsutils dos2unix screen bzip2 ccrypt -y
  165. # Now installing all our wanted services
  166. apt-get install dropbear stunnel4 privoxy ca-certificates nginx ruby apt-transport-https lsb-release squid screenfetch -y
  167. # Installing all required packages to install Webmin
  168. 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
  169. apt-get install shared-mime-info jq -y
  170. # Installing a text colorizer
  171. # Trying to remove obsolette packages after installation
  172. apt-get autoremove -y
  173. # Installing OpenVPN by pulling its repository inside sources.list file
  174. #rm -rf /etc/apt/sources.list.d/openvpn*
  175. echo "deb http://build.openvpn.net/debian/openvpn/stable $(lsb_release -sc) main" >/etc/apt/sources.list.d/openvpn.list && apt-key del E158C569 && wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg | apt-key add -
  176. wget -qO security-openvpn-net.asc "https://keys.openpgp.org/vks/v1/by-fingerprint/F554A3687412CFFEBDEFE0A312F5F7B42F2B01E7" && gpg --import security-openvpn-net.asc
  177. apt-get update -y
  178. apt-get install openvpn -y
  179. }
  180. function InstSSH(){
  181. # Removing some duplicated sshd server configs
  182. rm -f /etc/ssh/sshd_config*
  183. # Creating a SSH server config using cat eof tricks
  184. cat <<'MySSHConfig' > /etc/ssh/sshd_config
  185. # My OpenSSH Server config
  186. Port myPORT1
  187. Port myPORT2
  188. AddressFamily inet
  189. ListenAddress 0.0.0.0
  190. HostKey /etc/ssh/ssh_host_rsa_key
  191. HostKey /etc/ssh/ssh_host_ecdsa_key
  192. HostKey /etc/ssh/ssh_host_ed25519_key
  193. PermitRootLogin yes
  194. MaxSessions 1024
  195. PubkeyAuthentication yes
  196. PasswordAuthentication yes
  197. PermitEmptyPasswords no
  198. ChallengeResponseAuthentication no
  199. UsePAM yes
  200. X11Forwarding yes
  201. PrintMotd no
  202. ClientAliveInterval 240
  203. ClientAliveCountMax 2
  204. UseDNS no
  205. Banner /etc/banner
  206. AcceptEnv LANG LC_*
  207. Subsystem sftp /usr/lib/openssh/sftp-server
  208. MySSHConfig
  209. # Now we'll put our ssh ports inside of sshd_config
  210. sed -i "s|myPORT1|$SSH_Port1|g" /etc/ssh/sshd_config
  211. sed -i "s|myPORT2|$SSH_Port2|g" /etc/ssh/sshd_config
  212. # Download our SSH Banner
  213. rm -f /etc/banner
  214. wget -qO /etc/banner "$SSH_Banner"
  215. dos2unix -q /etc/banner
  216. # My workaround code to remove `BAD Password error` from passwd command, it will fix password-related error on their ssh accounts.
  217. sed -i '/password\s*requisite\s*pam_cracklib.s.*/d' /etc/pam.d/common-password
  218. sed -i 's/use_authtok //g' /etc/pam.d/common-password
  219. # 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.
  220. sed -i '/\/bin\/false/d' /etc/shells
  221. sed -i '/\/usr\/sbin\/nologin/d' /etc/shells
  222. echo '/bin/false' >> /etc/shells
  223. echo '/usr/sbin/nologin' >> /etc/shells
  224. # Restarting openssh service
  225. systemctl restart ssh
  226. # Removing some duplicate config file
  227. rm -rf /etc/default/dropbear*
  228. # creating dropbear config using cat eof tricks
  229. cat <<'MyDropbear' > /etc/default/dropbear
  230. # My Dropbear Config
  231. NO_START=0
  232. DROPBEAR_PORT=PORT01
  233. DROPBEAR_EXTRA_ARGS="-p PORT02"
  234. DROPBEAR_BANNER="/etc/banner"
  235. DROPBEAR_RSAKEY="/etc/dropbear/dropbear_rsa_host_key"
  236. DROPBEAR_DSSKEY="/etc/dropbear/dropbear_dss_host_key"
  237. DROPBEAR_ECDSAKEY="/etc/dropbear/dropbear_ecdsa_host_key"
  238. DROPBEAR_RECEIVE_WINDOW=65536
  239. MyDropbear
  240. # Now changing our desired dropbear ports
  241. sed -i "s|PORT01|$Dropbear_Port1|g" /etc/default/dropbear
  242. sed -i "s|PORT02|$Dropbear_Port2|g" /etc/default/dropbear
  243. # Restarting dropbear service
  244. systemctl restart dropbear
  245. }
  246. function InsStunnel(){
  247. StunnelDir=$(ls /etc/default | grep stunnel | head -n1)
  248. # Creating stunnel startup config using cat eof tricks
  249. cat <<'MyStunnelD' > /etc/default/$StunnelDir
  250. # My Stunnel Config
  251. ENABLED=1
  252. FILES="/etc/stunnel/*.conf"
  253. OPTIONS="/etc/banner"
  254. BANNER="/etc/banner"
  255. PPP_RESTART=0
  256. # RLIMITS="-n 4096 -d unlimited"
  257. RLIMITS=""
  258. MyStunnelD
  259. # Removing all stunnel folder contents
  260. rm -rf /etc/stunnel/*
  261. # Creating stunnel certifcate using openssl
  262. openssl req -new -x509 -days 9999 -nodes -subj "/C=MY/ST=SEL/L=Gombak/O=$MyScriptName/OU=$MyScriptName/CN=$MyScriptName" -out /etc/stunnel/stunnel.pem -keyout /etc/stunnel/stunnel.pem &> /dev/null
  263. ## > /dev/null 2>&1
  264. # Creating stunnel server config
  265. cat <<'MyStunnelC' > /etc/stunnel/stunnel.conf
  266. # My Stunnel Config
  267. pid = /var/run/stunnel.pid
  268. cert = /etc/stunnel/stunnel.pem
  269. client = no
  270. socket = l:TCP_NODELAY=1
  271. socket = r:TCP_NODELAY=1
  272. TIMEOUTclose = 0
  273. [stunnel]
  274. connect = 127.0.0.1:WS_Port1
  275. accept = WS_Port2
  276. [dropbear]
  277. accept = Stunnel_Port1
  278. connect = 127.0.0.1:dropbear_port_c
  279. [openssh]
  280. accept = Stunnel_Port2
  281. connect = 127.0.0.1:openssh_port_c
  282. [openvpn]
  283. accept = Stunnel_Port3
  284. connect = 127.0.0.1:MyOvpnPort3
  285. MyStunnelC
  286. # setting stunnel ports
  287. sed -i "s|WS_Port1|$WS_Port1|g" /etc/stunnel/stunnel.conf
  288. sed -i "s|WS_Port2|$WS_Port2|g" /etc/stunnel/stunnel.conf
  289. sed -i "s|MyOvpnPort3|$OpenVPN_Port3|g" /etc/stunnel/stunnel.conf
  290. sed -i "s|Stunnel_Port1|$Stunnel_Port1|g" /etc/stunnel/stunnel.conf
  291. 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
  292. sed -i "s|Stunnel_Port2|$Stunnel_Port2|g" /etc/stunnel/stunnel.conf
  293. 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
  294. sed -i "s|Stunnel_Port3|$Stunnel_Port3|g" /etc/stunnel/stunnel.conf
  295. 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
  296. # Restarting stunnel service
  297. systemctl restart $StunnelDir
  298. }
  299. function InsOpenVPN(){
  300. # Checking if openvpn folder is accidentally deleted or purged
  301. if [[ ! -e /etc/openvpn ]]; then
  302. mkdir -p /etc/openvpn
  303. fi
  304. # Removing all existing openvpn server files
  305. rm -rf /etc/openvpn/*
  306. # Creating server.conf, ca.crt, server.crt and server.key
  307. cat <<'myOpenVPNconf1' > /etc/openvpn/server_tcp.conf
  308. # XAMScript
  309. port MyOvpnPort3
  310. dev tun
  311. proto tcp
  312. ca /etc/openvpn/ca.crt
  313. cert /etc/openvpn/xbarts.crt
  314. key /etc/openvpn/xbarts.key
  315. dh none
  316. persist-tun
  317. persist-key
  318. persist-remote-ip
  319. cipher none
  320. ncp-disable
  321. auth none
  322. comp-lzo
  323. tun-mtu 1500
  324. reneg-sec 0
  325. plugin /etc/openvpn/openvpn-auth-pam.so /etc/pam.d/login
  326. verify-client-cert none
  327. username-as-common-name
  328. max-clients 4000
  329. topology subnet
  330. server 172.16.0.0 255.255.0.0
  331. push "redirect-gateway def1"
  332. keepalive 5 60
  333. status /etc/openvpn/tcp_stats.log
  334. log /etc/openvpn/tcp.log
  335. verb 2
  336. script-security 2
  337. socket-flags TCP_NODELAY
  338. push "socket-flags TCP_NODELAY"
  339. push "dhcp-option DNS 1.0.0.1"
  340. push "dhcp-option DNS 1.1.1.1"
  341. push "dhcp-option DNS 8.8.4.4"
  342. push "dhcp-option DNS 8.8.8.8"
  343. duplicate-cn
  344. myOpenVPNconf1
  345. cat <<'myOpenVPNconf3' > /etc/openvpn/server_tcp2.conf
  346. # XAMScript
  347. port MyOvpnPort1
  348. dev tun
  349. proto tcp
  350. ca /etc/openvpn/ca.crt
  351. cert /etc/openvpn/xbarts.crt
  352. key /etc/openvpn/xbarts.key
  353. dh none
  354. persist-tun
  355. persist-key
  356. persist-remote-ip
  357. cipher none
  358. ncp-disable
  359. auth none
  360. comp-lzo
  361. tun-mtu 1500
  362. reneg-sec 0
  363. plugin /etc/openvpn/openvpn-auth-pam.so /etc/pam.d/login
  364. verify-client-cert none
  365. username-as-common-name
  366. max-clients 4000
  367. topology subnet
  368. server 172.18.0.0 255.255.0.0
  369. push "redirect-gateway def1"
  370. keepalive 5 60
  371. status /etc/openvpn/tcp_stats.log
  372. log /etc/openvpn/tcp.log
  373. verb 2
  374. script-security 2
  375. socket-flags TCP_NODELAY
  376. push "socket-flags TCP_NODELAY"
  377. push "dhcp-option DNS 1.0.0.1"
  378. push "dhcp-option DNS 1.1.1.1"
  379. push "dhcp-option DNS 8.8.4.4"
  380. push "dhcp-option DNS 8.8.8.8"
  381. duplicate-cn
  382. myOpenVPNconf3
  383. cat <<'myOpenVPNconf4' > /etc/openvpn/server_tcp3.conf
  384. # XAMScript
  385. port MyOvpnPort4
  386. dev tun
  387. proto tcp
  388. ca /etc/openvpn/ca.crt
  389. cert /etc/openvpn/xbarts.crt
  390. key /etc/openvpn/xbarts.key
  391. dh none
  392. persist-tun
  393. persist-key
  394. persist-remote-ip
  395. cipher none
  396. ncp-disable
  397. auth none
  398. comp-lzo
  399. tun-mtu 1500
  400. reneg-sec 0
  401. plugin /etc/openvpn/openvpn-auth-pam.so /etc/pam.d/login
  402. verify-client-cert none
  403. username-as-common-name
  404. max-clients 4000
  405. topology subnet
  406. server 172.19.0.0 255.255.0.0
  407. push "redirect-gateway def1"
  408. keepalive 5 60
  409. status /etc/openvpn/tcp_stats.log
  410. log /etc/openvpn/tcp.log
  411. verb 2
  412. script-security 2
  413. socket-flags TCP_NODELAY
  414. push "socket-flags TCP_NODELAY"
  415. push "dhcp-option DNS 1.0.0.1"
  416. push "dhcp-option DNS 1.1.1.1"
  417. push "dhcp-option DNS 8.8.4.4"
  418. push "dhcp-option DNS 8.8.8.8"
  419. duplicate-cn
  420. myOpenVPNconf4
  421. cat <<'myOpenVPNconf2' > /etc/openvpn/server_udp.conf
  422. # XAMScript
  423. port MyOvpnPort2
  424. dev tun
  425. proto udp
  426. ca /etc/openvpn/ca.crt
  427. cert /etc/openvpn/xbarts.crt
  428. key /etc/openvpn/xbarts.key
  429. dh none
  430. persist-tun
  431. persist-key
  432. persist-remote-ip
  433. cipher none
  434. ncp-disable
  435. auth none
  436. comp-lzo
  437. tun-mtu 1500
  438. reneg-sec 0
  439. plugin /etc/openvpn/openvpn-auth-pam.so /etc/pam.d/login
  440. verify-client-cert none
  441. username-as-common-name
  442. max-clients 4000
  443. topology subnet
  444. server 172.17.0.0 255.255.0.0
  445. push "redirect-gateway def1"
  446. keepalive 5 60
  447. status /etc/openvpn/tcp_stats.log
  448. log /etc/openvpn/tcp.log
  449. verb 2
  450. script-security 2
  451. socket-flags TCP_NODELAY
  452. push "socket-flags TCP_NODELAY"
  453. push "dhcp-option DNS 1.0.0.1"
  454. push "dhcp-option DNS 1.1.1.1"
  455. push "dhcp-option DNS 8.8.4.4"
  456. push "dhcp-option DNS 8.8.8.8"
  457. duplicate-cn
  458. myOpenVPNconf2
  459. cat <<'EOF7'> /etc/openvpn/ca.crt
  460. -----BEGIN CERTIFICATE-----
  461. MIIDqTCCAxKgAwIBAgIUBnJqBAnqOixnTtR+X8wEmXk9EDQwDQYJKoZIhvcNAQEL
  462. BQAwgYkxCzAJBgNVBAYTAm15MQwwCgYDVQQIDANzZWwxDzANBgNVBAcMBmdvbWJh
  463. azEOMAwGA1UECgwFYWlkYW4xFTATBgNVBAsMDHd3dy5haWRhbi5teTEVMBMGA1UE
  464. AwwMdnBuLmFpZGFuLm15MR0wGwYJKoZIhvcNAQkBFg5hZG1pbkBhaWRhbi5teTAe
  465. Fw0yMTEwMDcyMTE0NDdaFw00OTAyMjEyMTE0NDdaMIGJMQswCQYDVQQGEwJteTEM
  466. MAoGA1UECAwDc2VsMQ8wDQYDVQQHDAZnb21iYWsxDjAMBgNVBAoMBWFpZGFuMRUw
  467. EwYDVQQLDAx3d3cuYWlkYW4ubXkxFTATBgNVBAMMDHZwbi5haWRhbi5teTEdMBsG
  468. CSqGSIb3DQEJARYOYWRtaW5AYWlkYW4ubXkwgZ8wDQYJKoZIhvcNAQEBBQADgY0A
  469. MIGJAoGBAJmt5wyo8p9tRHSDUNHHUqkt1H2livU3LT7PMzHFGsA3Uv4AchDnzep0
  470. Asl8Zv14kE3WUHCUn9TJKotNZrQcf0JIkdl9mlODMjIDt+Sgw7paal+E5kyztCw/
  471. tP3E9aBq84uJkUHNrx+s4pf4VmcG8jMvFBZ7u6QMz3H1hICRyjXjAgMBAAGjggEK
  472. MIIBBjAdBgNVHQ4EFgQUI9uCexq0CnJyzdDd/3EVIBBARQ0wgckGA1UdIwSBwTCB
  473. voAUI9uCexq0CnJyzdDd/3EVIBBARQ2hgY+kgYwwgYkxCzAJBgNVBAYTAm15MQww
  474. CgYDVQQIDANzZWwxDzANBgNVBAcMBmdvbWJhazEOMAwGA1UECgwFYWlkYW4xFTAT
  475. BgNVBAsMDHd3dy5haWRhbi5teTEVMBMGA1UEAwwMdnBuLmFpZGFuLm15MR0wGwYJ
  476. KoZIhvcNAQkBFg5hZG1pbkBhaWRhbi5teYIUBnJqBAnqOixnTtR+X8wEmXk9EDQw
  477. DAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADgYEADKe3
  478. qVstKktLiPaqapjkl3u9vhouVytAG/hn+udeyeDKVJLP8eni6nw8xVdiDwaKAZZW
  479. 9xTq2EcgQ5qA1UZdttCUSpYvrpsh1kRpCDb1wPM0vEULVs8kcMbV+7rF4vspCjLT
  480. 7VnTDziwIWuZR7z1Ykxt0qlc3Mw3b3m3UVztbRY=
  481. -----END CERTIFICATE-----
  482. EOF7
  483. cat <<'EOF9'> /etc/openvpn/xbarts.crt
  484. Certificate:
  485. Data:
  486. Version: 3 (0x2)
  487. Serial Number:
  488. 0e:19:a0:34:ac:4c:44:ee:4e:e5:af:09:3e:6f:3a:d6
  489. Signature Algorithm: sha256WithRSAEncryption
  490. Issuer:
  491. countryName = my
  492. stateOrProvinceName = sel
  493. localityName = gombak
  494. organizationName = aidan
  495. organizationalUnitName = www.aidan.my
  496. commonName = vpn.aidan.my
  497. emailAddress = admin@aidan.my
  498. Validity
  499. Not Before: Oct 8 12:26:19 2021 GMT
  500. Not After : Jan 11 12:26:19 2024 GMT
  501. Subject:
  502. commonName = vpn.aidan.my
  503. X509v3 extensions:
  504. X509v3 Basic Constraints:
  505. CA:FALSE
  506. X509v3 Subject Key Identifier:
  507. E1:15:1A:9C:87:5A:B0:5F:EB:72:13:28:9F:1F:96:0C:D3:50:6F:1C
  508. X509v3 Authority Key Identifier:
  509. keyid:23:DB:82:7B:1A:B4:0A:72:72:CD:D0:DD:FF:71:15:20:10:40:45:0D
  510. DirName:/C=my/ST=sel/L=gombak/O=aidan/OU=www.aidan.my/CN=vpn.aidan.my/emailAddress=admin@aidan.my
  511. serial:06:72:6A:04:09:EA:3A:2C:67:4E:D4:7E:5F:CC:04:99:79:3D:10:34
  512. X509v3 Extended Key Usage:
  513. TLS Web Server Authentication
  514. X509v3 Key Usage:
  515. Digital Signature, Key Encipherment
  516. X509v3 Subject Alternative Name:
  517. DNS:vpn.aidan.my
  518. -----BEGIN CERTIFICATE-----
  519. MIIDYjCCAkqgAwIBAgIRAMfKRex4P5oCH0gsSFWNJHowDQYJKoZIhvcNAQELBQAw
  520. EzERMA8GA1UEAwwIQ2hhbmdlTWUwHhcNMjExMjA5MTQxMDQyWhcNMzExMjA3MTQx
  521. MDQyWjARMQ8wDQYDVQQDDAZzZXJ2ZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
  522. ggEKAoIBAQCo2sTRSAJoA398DjA9j9w8NLKT03kSlUkGZD3i+VYBSEOPOYxYsY5B
  523. V8J+IgeU22JmWCmcQctWpl7XnXyrCVJT/WO/VyplUioiSUnuPe2lZDaret5OV1pN
  524. 1hQ0tmLF+TTTy+0YreNAtkuinh4Inswp9f5YdhT69DAsidl5odybDllHyMoRH4dZ
  525. KanTuNFOMQa/H5wGKKwaZWRgHtZgxrkOyK4PFWsDV9jlXBxtfD16jjwFnLMM6glD
  526. 2X4mNKZhJdIAopYUA7jVaDHjaHJEuddveWLkEHsmgjpWBEashziSppY53UHHoKkt
  527. C05uASO1tifvETNCF+uNnJg1Y+yk+H4HAgMBAAGjgbIwga8wCQYDVR0TBAIwADAd
  528. BgNVHQ4EFgQUWxG61QzeKIhdHrWOC47mVPS+5CIwTgYDVR0jBEcwRYAUZrqFjj1H
  529. oZBIQJHfJLMA+oQUE0+hF6QVMBMxETAPBgNVBAMMCENoYW5nZU1lghRWoN7FEOBZ
  530. s6O4hB3le1qme///gDATBgNVHSUEDDAKBggrBgEFBQcDATALBgNVHQ8EBAMCBaAw
  531. EQYDVR0RBAowCIIGc2VydmVyMA0GCSqGSIb3DQEBCwUAA4IBAQClLNF/CDaJ6RCQ
  532. yX9R9cnLTxyXCp9+LEcpd8KBW4eyXRzhPhEny2059cwBo/F3BjO+LPEX58o18CEu
  533. pKJqI8a0l9gKf9alEDB6/+bkVcwPbe+10piPBBrjY+zXf92gyTi+CEbTvV1f5lNU
  534. w4py0lSn1Ly2Aa7wZOdGmsG90iUTKhbcBTXNyfehBGVs2OBcCb7IZYHNYuE47yTs
  535. YO+PHgyCUTaFW+03Sh7sFJ9UB6xM9RLN4awbEnuIPwbQjuzpI5vLSrXgSfnYJI4K
  536. ZJ6utnfpTRY7m9rvgdi/aa5i9qM3v145DYrVZ+jURdRveNe8FPY69XXqjpoTBhLJ
  537. pf3ioiv4
  538. -----END CERTIFICATE-----
  539. EOF9
  540. cat <<'EOF10'> /etc/openvpn/xbarts.key
  541. -----BEGIN PRIVATE KEY-----
  542. MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQClfU/iFBQjm6Zu
  543. CZ/Cbu6DZxpPse4yFgnSDpz7Kcy5ReH9IeLkL31wg0LcdbVqp5TaNuQm6dOGCLgv
  544. JJrKYTHZNgPs4wEwJDDCfZTgB6zqyIHGFD1ttQyQ5B/n9L0EyoSo8kN4k/fSgGmf
  545. AIKwNSFR0ld+EOaFUKqAoe28C5n5cOP3wlsrTG71oWGzqnc9M/rw0wACuxO166Jg
  546. +JYcIsuklAHvZmCiFZg11GayyAIs+izy6WpNfUdpqy1BY2rRrOIOk38pplyyr9gR
  547. 46unRbiOqPviBN6GeSzMLB9YT4wpJFXxbhrfW/s6EbQkY9jHu5XKPu9shGcwmFif
  548. ldpSCS5HAgMBAAECggEBAKLueZPQyPM17+out4gqx9G/1PvZ5vaRFCIoGQ5/3Pwc
  549. fZ9HmaenygzYbx+3FGJpk/g0SvS1CnjQZOalV3EhuH5u2/aCmUzYlNkn40eexvRx
  550. bLOkgcZdln2g3Hj3UJJDAdGElEFHDZvGqjbNvd3WsXNpcJLB+PQQs43p37Jgibw3
  551. gBWIS1/kJfVzeTnzk5qgrMogNIW4RAXUzI3tEbhYEVXCi/ZP/iBzalb2eAl/DOC9
  552. iKyZ+rEwPCfWL+JFq5Qe6T0R/USOZAdC1irr6XQ0rNQwWbce/RWAmb45d3QYHbb6
  553. Qjhx0ScuheRdutqaJUkqDHk26V13Z4KjLbKzUQZIg0ECgYEA0l+vajfWtTMnW1CR
  554. Qp+gpxvgQnN+V3tX30KiXOtM2BtGLXFIDdvbQxaMRzd+hW0naVVhu0KIQo07OEOz
  555. 4OH/xNHqVZ47gQgKHkUZub72JXaJAk1F40NdRbLvn5jfMz3I+MtTIXT7f1mBHvM7
  556. xLnBpwhs+JUKAAFTrw+TzOTd2skCgYEAyWGTHsBUEuEt9wj8LEp2fm6M9Iqp3eWS
  557. 6V7TiOqWduK3aCDhyw1BkvVZjWHFiL927y+imik9z0SBAKdUnKPSxLrMkzKH0ZER
  558. v2UmKhZHKMsKERIh8kcaAFYuNZSvxdbWRdMzM5dam5L6P67LvysZutE7gXsorynE
  559. OX8eRUBAOI8CgYEAznUjVM26BBhQrpgSBt1br8R2wSBRRI+C/FOLvj8aKhgSNjSv
  560. bxJuS5fMUXQP0ef+vqwRftJboVyzWpNu6+s/tKwCGsZwRUBblbtg9N6I+NksurqV
  561. NOT+m5FxAyLnIYWoPypjyjjhPOjdBD/XT0ix2Tg2oXq61qh2tR5HgdS2OakCgYEA
  562. s8FANGvS4ANWJzNC/Tn+aT6+3S3FEMfyihNV2NolMruOoQjw43HSvZ35sMS8MSNO
  563. w5QOnXMAtDleuTmjwipNYcOoBiBNsde/MsvT9C9sl1Idiz1XRc8Hu5Mxriwpdfwd
  564. ybgK9Rs+Cq54aE3bmqmbTvGjHyHTH/+1IumAGKqQaKsCgYAMacI1eSUDTNa0I4Us
  565. 29bKpvZrbDn/oDBaLGxBLrLMf450HJvpz0PGvNh0mY2G3a3dd6JRf5ZZ8me1rHXZ
  566. cwB6fMAtJdp6x/2QTDZ2va5avhRB/4lRNyJifl6lhad0XPKhEOByd7wg+VeCBJ6P
  567. xXEZw5bUG9re12VX9nWNBLhJCw==
  568. -----END PRIVATE KEY-----
  569. EOF10
  570. # Getting all dns inside resolv.conf then use as Default DNS for our openvpn server
  571. #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
  572. #echo "push \"dhcp-option DNS $line\"" >> /etc/openvpn/server_tcp.conf
  573. #done
  574. #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
  575. #echo "push \"dhcp-option DNS $line\"" >> /etc/openvpn/server_udp.conf
  576. #done
  577. # setting openvpn server port
  578. sed -i "s|MyOvpnPort1|$OpenVPN_Port1|g" /etc/openvpn/server_tcp2.conf
  579. sed -i "s|MyOvpnPort3|$OpenVPN_Port3|g" /etc/openvpn/server_tcp.conf
  580. sed -i "s|MyOvpnPort4|$OpenVPN_Port4|g" /etc/openvpn/server_tcp3.conf
  581. sed -i "s|MyOvpnPort2|$OpenVPN_Port2|g" /etc/openvpn/server_udp.conf
  582. # Generating openvpn dh.pem file using openssl
  583. #openssl dhparam -out /etc/openvpn/dh.pem 1024
  584. # Getting some OpenVPN plugins for unix authentication
  585. wget -qO /etc/openvpn/b.zip 'https://github.com/imaPSYCHO/Parts/raw/main/openvpn_plugin64'
  586. unzip -qq /etc/openvpn/b.zip -d /etc/openvpn
  587. rm -f /etc/openvpn/b.zip
  588. # Some workaround for OpenVZ machines for "Startup error" openvpn service
  589. if [[ "$(hostnamectl | grep -i Virtualization | awk '{print $2}' | head -n1)" == 'openvz' ]]; then
  590. sed -i 's|LimitNPROC|#LimitNPROC|g' /lib/systemd/system/openvpn*
  591. systemctl daemon-reload
  592. fi
  593. # Allow IPv4 Forwarding
  594. echo 'net.ipv4.ip_forward=1' > /etc/sysctl.d/20-openvpn.conf && sysctl --system &> /dev/null && echo 1 > /proc/sys/net/ipv4/ip_forward
  595. # Iptables Rule for OpenVPN server
  596. #PUBLIC_INET="$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)"
  597. #IPCIDR='10.200.0.0/16'
  598. #iptables -I FORWARD -s $IPCIDR -j ACCEPT
  599. #iptables -t nat -A POSTROUTING -o $PUBLIC_INET -j MASQUERADE
  600. #iptables -t nat -A POSTROUTING -s $IPCIDR -o $PUBLIC_INET -j MASQUERADE
  601. # Installing Firewalld
  602. apt install firewalld -y
  603. systemctl start firewalld
  604. systemctl enable firewalld
  605. firewall-cmd --quiet --set-default-zone=public
  606. firewall-cmd --quiet --zone=public --permanent --add-port=1-65534/tcp
  607. firewall-cmd --quiet --zone=public --permanent --add-port=1-65534/udp
  608. firewall-cmd --quiet --reload
  609. firewall-cmd --quiet --add-masquerade
  610. firewall-cmd --quiet --permanent --add-masquerade
  611. firewall-cmd --quiet --permanent --add-service=ssh
  612. firewall-cmd --quiet --permanent --add-service=openvpn
  613. firewall-cmd --quiet --permanent --add-service=http
  614. firewall-cmd --quiet --permanent --add-service=https
  615. firewall-cmd --quiet --permanent --add-service=privoxy
  616. firewall-cmd --quiet --permanent --add-service=squid
  617. firewall-cmd --quiet --reload
  618. # Enabling IPv4 Forwarding
  619. echo 1 > /proc/sys/net/ipv4/ip_forward
  620. # Starting OpenVPN server
  621. systemctl start openvpn@server_tcp
  622. systemctl start openvpn@server_tcp2
  623. systemctl start openvpn@server_tcp3
  624. systemctl start openvpn@server_udp
  625. systemctl enable openvpn@server_tcp
  626. systemctl enable openvpn@server_tcp2
  627. systemctl enable openvpn@server_tcp3
  628. systemctl enable openvpn@server_udp
  629. systemctl restart openvpn@server_tcp
  630. systemctl restart openvpn@server_tcp2
  631. systemctl restart openvpn@server_tcp3
  632. systemctl restart openvpn@server_udp
  633. # Pulling OpenVPN no internet fixer script
  634. #wget -qO /etc/openvpn/openvpn.bash "https://raw.githubusercontent.com/Bonveio/BonvScripts/master/openvpn.bash"
  635. #0chmod +x /etc/openvpn/openvpn.bash
  636. }
  637. function InsProxy(){
  638. # Removing Duplicate privoxy config
  639. rm -rf /etc/privoxy/config*
  640. # Creating Privoxy server config using cat eof tricks
  641. cat <<'myPrivoxy' > /etc/privoxy/config
  642. # My Privoxy Server Config
  643. user-manual /usr/share/doc/privoxy/user-manual
  644. confdir /etc/privoxy
  645. logdir /var/log/privoxy
  646. filterfile default.filter
  647. logfile logfile
  648. listen-address 0.0.0.0:Privoxy_Port1
  649. listen-address 0.0.0.0:Privoxy_Port2
  650. toggle 1
  651. enable-remote-toggle 0
  652. enable-remote-http-toggle 0
  653. enable-edit-actions 0
  654. enforce-blocks 0
  655. buffer-limit 4096
  656. enable-proxy-authentication-forwarding 1
  657. forwarded-connect-retries 1
  658. accept-intercepted-requests 1
  659. allow-cgi-request-crunching 1
  660. split-large-forms 0
  661. keep-alive-timeout 5
  662. tolerate-pipelining 1
  663. socket-timeout 300
  664. permit-access 0.0.0.0/0 IP-ADDRESS
  665. myPrivoxy
  666. # Setting machine's IP Address inside of our privoxy config(security that only allows this machine to use this proxy server)
  667. sed -i "s|IP-ADDRESS|$IPADDR|g" /etc/privoxy/config
  668. # Setting privoxy ports
  669. sed -i "s|Privoxy_Port1|$Privoxy_Port1|g" /etc/privoxy/config
  670. sed -i "s|Privoxy_Port2|$Privoxy_Port2|g" /etc/privoxy/config
  671. # I'm setting Some Squid workarounds to prevent Privoxy's overflowing file descriptors that causing 50X error when clients trying to connect to your proxy server(thanks for this trick @homer_simpsons)
  672. apt remove --purge squid -y
  673. rm -rf /etc/squid/sq*
  674. apt install squid -y
  675. # Squid Ports (must be 1024 or higher)
  676. cat <<mySquid > /etc/squid/squid.conf
  677. acl VPN dst $(wget -4qO- http://ipinfo.io/ip)/32
  678. http_access allow VPN
  679. http_access deny all
  680. http_port 0.0.0.0:$Proxy_Port1
  681. http_port 0.0.0.0:$Proxy_Port2
  682. coredump_dir /var/spool/squid
  683. dns_nameservers 1.1.1.1 1.0.0.1
  684. refresh_pattern ^ftp: 1440 20% 10080
  685. refresh_pattern ^gopher: 1440 0% 1440
  686. refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
  687. refresh_pattern . 0 20% 4320
  688. visible_hostname localhost
  689. mySquid
  690. sed -i "s|SquidCacheHelper|$Proxy_Port1|g" /etc/squid/squid.conf
  691. sed -i "s|SquidCacheHelper|$Proxy_Port2|g" /etc/squid/squid.conf
  692. sudo apt install ziproxy
  693. cat <<myziproxy > /etc/ziproxy/ziproxy.conf
  694. Port = ZIPROXY
  695. UseContentLength = false
  696. ImageQuality = {30,25,25,20}
  697. myziproxy
  698. sed -i "s|ZIPROXY|$ZIPROXY|g" /etc/ziproxy/ziproxy.conf
  699. # Starting Proxy server
  700. echo -e "Restarting proxy server.."
  701. systemctl restart privoxy
  702. systemctl restart squid
  703. systemctl restart ziproxy
  704. }
  705. function OvpnConfigs(){
  706. # Creating nginx config for our ovpn config downloads webserver
  707. cat <<'myNginxC' > /etc/nginx/conf.d/bonveio-ovpn-config.conf
  708. # My OpenVPN Config Download Directory
  709. server {
  710. listen 0.0.0.0:myNginx;
  711. server_name localhost;
  712. root /var/www/openvpn;
  713. index index.html;
  714. }
  715. myNginxC
  716. # Setting our nginx config port for .ovpn download site
  717. sed -i "s|myNginx|$OvpnDownload_Port|g" /etc/nginx/conf.d/bonveio-ovpn-config.conf
  718. # Removing Default nginx page(port 80)
  719. rm -rf /etc/nginx/sites-*
  720. # Creating our root directory for all of our .ovpn configs
  721. rm -rf /var/www/openvpn
  722. mkdir -p /var/www/openvpn
  723. # Now creating all of our OpenVPN Configs
  724. cat <<EOF152> /var/www/openvpn/GTMConfig.ovpn
  725. # Credits to XAMJYSS
  726. client
  727. dev tun
  728. proto tcp
  729. remote $IPADDR $OpenVPN_Port3
  730. remote-cert-tls server
  731. resolv-retry infinite
  732. nobind
  733. tun-mtu 1500
  734. tun-mtu-extra 32
  735. mssfix 1450
  736. persist-key
  737. persist-tun
  738. auth-user-pass
  739. auth none
  740. auth-nocache
  741. cipher none
  742. keysize 0
  743. comp-lzo
  744. setenv CLIENT_CERT 0
  745. reneg-sec 0
  746. verb 1
  747. http-proxy $(curl -s http://ipinfo.io/ip || wget -q http://ipinfo.io/ip) $Privoxy_Port1
  748. http-proxy-option CUSTOM-HEADER Host redirect.googlevideo.com
  749. http-proxy-option CUSTOM-HEADER X-Forwarded-For redirect.googlevideo.com
  750. <ca>
  751. $(cat /etc/openvpn/ca.crt)
  752. </ca>
  753. EOF152
  754. cat <<EOF16> /var/www/openvpn/XJ-TU-UDP.ovpn
  755. # Credits to XAMJYSS
  756. client
  757. dev tun
  758. proto udp
  759. remote $IPADDR $OpenVPN_Port2
  760. remote-cert-tls server
  761. resolv-retry infinite
  762. nobind
  763. tun-mtu 1500
  764. tun-mtu-extra 32
  765. mssfix 1450
  766. persist-key
  767. persist-tun
  768. auth-user-pass
  769. auth none
  770. auth-nocache
  771. cipher none
  772. keysize 0
  773. comp-lzo
  774. setenv CLIENT_CERT 0
  775. reneg-sec 0
  776. verb 1
  777. <ca>
  778. $(cat /etc/openvpn/ca.crt)
  779. </ca>
  780. EOF16
  781. cat <<EOF160> /var/www/openvpn/XJ-Stories-TCP.ovpn
  782. # Credits to XAMJYSS
  783. client
  784. dev tun
  785. proto tcp
  786. remote $IPADDR $OpenVPN_Port3
  787. remote-cert-tls server
  788. resolv-retry infinite
  789. nobind
  790. tun-mtu 1500
  791. tun-mtu-extra 32
  792. mssfix 1450
  793. persist-key
  794. persist-tun
  795. auth-user-pass
  796. auth none
  797. auth-nocache
  798. cipher none
  799. keysize 0
  800. comp-lzo
  801. setenv CLIENT_CERT 0
  802. reneg-sec 0
  803. verb 1
  804. http-proxy $(curl -s http://ipinfo.io/ip || wget -q http://ipinfo.io/ip) $Privoxy_Port1
  805. http-proxy-option CUSTOM-HEADER CONNECT HTTP/1.0
  806. http-proxy-option CUSTOM-HEADER Host tiktoktreats.onelink.me
  807. http-proxy-option CUSTOM-HEADER X-Online-Host tiktoktreats.onelink.me
  808. http-proxy-option CUSTOM-HEADER X-Forward-Host tiktoktreats.onelink.me
  809. http-proxy-option CUSTOM-HEADER Connection:Keep-Alive
  810. <ca>
  811. $(cat /etc/openvpn/ca.crt)
  812. </ca>
  813. EOF160
  814. cat <<EOF17> /var/www/openvpn/XJ-GAMES.ovpn
  815. # Credits to XAMJYSS
  816. client
  817. dev tun
  818. proto tcp
  819. remote $IPADDR $OpenVPN_Port3
  820. remote-cert-tls server
  821. resolv-retry infinite
  822. nobind
  823. tun-mtu 1500
  824. tun-mtu-extra 32
  825. mssfix 1450
  826. persist-key
  827. persist-tun
  828. auth-user-pass
  829. auth none
  830. auth-nocache
  831. cipher none
  832. keysize 0
  833. comp-lzo
  834. setenv CLIENT_CERT 0
  835. reneg-sec 0
  836. verb 2
  837. http-proxy $(curl -s http://ipinfo.io/ip || wget -q http://ipinfo.io/ip) $Privoxy_Port1
  838. http-proxy-option VERSION 1.1
  839. http-proxy-option CUSTOM-HEADER "Host: c3cdn.ml.youngjoygame.com"
  840. http-proxy-option CUSTOM-HEADER "X-Online-Host: c3cdn.ml.youngjoygame.com"
  841. http-proxy-option CUSTOM-HEADER "X-Forward-Host: c3cdn.ml.youngjoygame.com"
  842. http-proxy-option CUSTOM-HEADER "Connection: Keep-Alive"
  843. <ca>
  844. $(cat /etc/openvpn/ca.crt)
  845. </ca>
  846. EOF17
  847. cat <<EOF179> /var/www/openvpn/default.ovpn
  848. # Credits to XAMJYSS
  849. client
  850. dev tun
  851. proto tcp
  852. remote $IPADDR $OpenVPN_Port3
  853. remote-cert-tls server
  854. resolv-retry infinite
  855. nobind
  856. tun-mtu 1500
  857. tun-mtu-extra 32
  858. mssfix 1450
  859. persist-key
  860. persist-tun
  861. auth-user-pass
  862. auth none
  863. auth-nocache
  864. cipher none
  865. keysize 0
  866. comp-lzo
  867. setenv CLIENT_CERT 0
  868. reneg-sec 0
  869. verb 2
  870. <ca>
  871. $(cat /etc/openvpn/ca.crt)
  872. </ca>
  873. EOF179
  874. # Creating OVPN download site index.html
  875. cat <<'mySiteOvpn' > /var/www/openvpn/index.html
  876. <!DOCTYPE html>
  877. <html lang="en">
  878. <!-- OVPN Download site by XAMJYSS -->
  879. <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 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 Sun <span class="badge light-blue darken-4">Android/iOS/PC/Modem</span><br /><small> For TU/CTC UDP Promos</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/XJ-TU-UDP.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/SMART/TNT <span class="badge light-blue darken-4">Android/iOS/PC/MODEM</span><br /><small> TNT GIGASTORIES</small></p><a class="btn btn-outline-success waves-effect btn-sm" href="http://IP-ADDRESS:NGINXPORT/XJ-Stories-TCP.ovpn" style="float:right;"><i class="fa fa-download"></i> Download</a></li></ul></div></div></div></div></body></html>
  880. mySiteOvpn
  881. # Setting template's correct name,IP address and nginx Port
  882. sed -i "s|MyScriptName|$MyScriptName|g" /var/www/openvpn/index.html
  883. sed -i "s|NGINXPORT|$OvpnDownload_Port|g" /var/www/openvpn/index.html
  884. sed -i "s|IP-ADDRESS|$IPADDR|g" /var/www/openvpn/index.html
  885. # Restarting nginx service
  886. systemctl restart nginx
  887. # Creating all .ovpn config archives
  888. cd /var/www/openvpn
  889. zip -qq -r Configs.zip *.ovpn
  890. cd
  891. }
  892. function ip_address(){
  893. 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 )"
  894. [ -z "${IP}" ] && IP="$( wget -qO- -t1 -T2 ipv4.icanhazip.com )"
  895. [ -z "${IP}" ] && IP="$( wget -qO- -t1 -T2 ipinfo.io/ip )"
  896. [ ! -z "${IP}" ] && echo "${IP}" || echo
  897. }
  898. IPADDR="$(ip_address)"
  899. function ConfStartup(){
  900. # Daily reboot time of our machine
  901. # For cron commands, visit https://crontab.guru
  902. timedatectl set-timezone Asia/Kuala_Lumpur
  903. #write out current crontab
  904. crontab -l > mycron
  905. #echo new cron into cron file
  906. echo -e "0 3 * * * /sbin/reboot >/dev/null 2>&1" >> mycron
  907. #install new cron file
  908. crontab mycron
  909. service cron restart
  910. echo '0 3 * * * /sbin/reboot >/dev/null 2>&1' >> /etc/cron.d/mycron
  911. #removing cron
  912. service cron restart
  913. # Creating directory for startup script
  914. rm -rf /etc/juans
  915. mkdir -p /etc/juans
  916. chmod -R 777 /etc/juans
  917. # Creating startup script using cat eof tricks
  918. cat <<'EOFSH' > /etc/juans/startup.sh
  919. #!/bin/bash
  920. # Setting server local time
  921. ln -fs /usr/share/zoneinfo/MyVPS_Time /etc/localtime
  922. # Prevent DOS-like UI when installing using APT (Disabling APT interactive dialog)
  923. export DEBIAN_FRONTEND=noninteractive
  924. # Allowing ALL TCP ports for our machine (Simple workaround for policy-based VPS)
  925. iptables -A INPUT -s $(wget -4qO- http://ipinfo.io/ip) -p tcp -m multiport --dport 1:65535 -j ACCEPT
  926. # Allowing OpenVPN to Forward traffic
  927. /bin/bash /etc/openvpn/openvpn.bash
  928. # Deleting Expired SSH Accounts
  929. /usr/local/sbin/delete_expired &> /dev/null
  930. EOFSH
  931. chmod +x /etc/juans/startup.sh
  932. # Setting server local time every time this machine reboots
  933. sed -i "s|MyVPS_Time|$MyVPS_Time|g" /etc/juans/startup.sh
  934. #
  935. rm -rf /etc/sysctl.d/99*
  936. # Setting our startup script to run every machine boots
  937. echo "[Unit]
  938. Description=Juans Startup Script
  939. Before=network-online.target
  940. Wants=network-online.target
  941. [Service]
  942. Type=oneshot
  943. ExecStart=/bin/bash /etc/juans/startup.sh
  944. RemainAfterExit=yes
  945. [Install]
  946. WantedBy=multi-user.target" > /etc/systemd/system/juans.service
  947. chmod +x /etc/systemd/system/juans.service
  948. systemctl daemon-reload
  949. systemctl start juans
  950. systemctl enable juans &> /dev/null
  951. # Rebooting cron service
  952. systemctl restart cron
  953. systemctl enable cron
  954. }
  955. function ConfMenu(){
  956. echo -e " Creating Menu scripts.."
  957. cd /usr/local/sbin/
  958. rm -rf {accounts,base-ports,base-ports-wc,base-script,bench-network,clearcache,connections,create,create_random,create_trial,delete_expired,delete_all,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}
  959. wget -q 'https://raw.githubusercontent.com/xamjyss143/VPS/master/menu.zip'
  960. unzip -qq menu.zip
  961. rm -f menu.zip
  962. chmod +x ./*
  963. dos2unix ./* &> /dev/null
  964. sed -i 's|/etc/squid/squid.conf|/etc/privoxy/config|g' ./*
  965. sed -i 's|http_port|listen-address|g' ./*
  966. cd ~
  967. echo 'clear' > /etc/profile.d/juans.sh
  968. echo 'echo '' > /var/log/syslog' >> /etc/profile.d/juans.sh
  969. echo 'screenfetch -p -A Android' >> /etc/profile.d/juans.sh
  970. chmod +x /etc/profile.d/juans.sh
  971. # Turning Off Multi-login Auto Kill
  972. rm -f /etc/cron.d/set_multilogin_autokill_lib
  973. }
  974. function ScriptMessage(){
  975. echo -e ""
  976. echo -e " (。◕‿◕。) $MyScriptName VPS Installer"
  977. echo -e " Script created by Bonveio"
  978. echo -e " Remoded by XAM"
  979. echo -e ""
  980. }
  981. function service() {
  982. cat << PTHON > /usr/sbin/yakult
  983. #!/usr/bin/python
  984. import socket, threading, thread, select, signal, sys, time, getopt
  985. # Listen
  986. LISTENING_ADDR = '0.0.0.0'
  987. if sys.argv[1:]:
  988. LISTENING_PORT = sys.argv[1]
  989. else:
  990. LISTENING_PORT = 80
  991. # Pass
  992. PASS = ''
  993. # CONST
  994. BUFLEN = 4096 * 4
  995. TIMEOUT = 3600
  996. DEFAULT_HOST = '127.0.0.1:900'
  997. RESPONSE = 'HTTP/1.1 101 <font color="purple">xamjyssvpn.com|coronassh.com</font>\r\n\r\nContent-Length: 104857600000\r\n\r\n'
  998. class Server(threading.Thread):
  999. def __init__(self, host, port):
  1000. threading.Thread.__init__(self)
  1001. self.running = False
  1002. self.host = host
  1003. self.port = port
  1004. self.threads = []
  1005. self.threadsLock = threading.Lock()
  1006. self.logLock = threading.Lock()
  1007. def run(self):
  1008. self.soc = socket.socket(socket.AF_INET)
  1009. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1010. self.soc.settimeout(2)
  1011. intport = int(self.port)
  1012. self.soc.bind((self.host, intport))
  1013. self.soc.listen(0)
  1014. self.running = True
  1015. try:
  1016. while self.running:
  1017. try:
  1018. c, addr = self.soc.accept()
  1019. c.setblocking(1)
  1020. except socket.timeout:
  1021. continue
  1022. conn = ConnectionHandler(c, self, addr)
  1023. conn.start()
  1024. self.addConn(conn)
  1025. finally:
  1026. self.running = False
  1027. self.soc.close()
  1028. def printLog(self, log):
  1029. self.logLock.acquire()
  1030. print log
  1031. self.logLock.release()
  1032. def addConn(self, conn):
  1033. try:
  1034. self.threadsLock.acquire()
  1035. if self.running:
  1036. self.threads.append(conn)
  1037. finally:
  1038. self.threadsLock.release()
  1039. def removeConn(self, conn):
  1040. try:
  1041. self.threadsLock.acquire()
  1042. self.threads.remove(conn)
  1043. finally:
  1044. self.threadsLock.release()
  1045. def close(self):
  1046. try:
  1047. self.running = False
  1048. self.threadsLock.acquire()
  1049. threads = list(self.threads)
  1050. for c in threads:
  1051. c.close()
  1052. finally:
  1053. self.threadsLock.release()
  1054. class ConnectionHandler(threading.Thread):
  1055. def __init__(self, socClient, server, addr):
  1056. threading.Thread.__init__(self)
  1057. self.clientClosed = False
  1058. self.targetClosed = True
  1059. self.client = socClient
  1060. self.client_buffer = ''
  1061. self.server = server
  1062. self.log = 'Connection: ' + str(addr)
  1063. def close(self):
  1064. try:
  1065. if not self.clientClosed:
  1066. self.client.shutdown(socket.SHUT_RDWR)
  1067. self.client.close()
  1068. except:
  1069. pass
  1070. finally:
  1071. self.clientClosed = True
  1072. try:
  1073. if not self.targetClosed:
  1074. self.target.shutdown(socket.SHUT_RDWR)
  1075. self.target.close()
  1076. except:
  1077. pass
  1078. finally:
  1079. self.targetClosed = True
  1080. def run(self):
  1081. try:
  1082. self.client_buffer = self.client.recv(BUFLEN)
  1083. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  1084. if hostPort == '':
  1085. hostPort = DEFAULT_HOST
  1086. split = self.findHeader(self.client_buffer, 'X-Split')
  1087. if split != '':
  1088. self.client.recv(BUFLEN)
  1089. if hostPort != '':
  1090. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  1091. if len(PASS) != 0 and passwd == PASS:
  1092. self.method_CONNECT(hostPort)
  1093. elif len(PASS) != 0 and passwd != PASS:
  1094. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  1095. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  1096. self.method_CONNECT(hostPort)
  1097. else:
  1098. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  1099. else:
  1100. print '- No X-Real-Host!'
  1101. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  1102. except Exception as e:
  1103. self.log += ' - error: ' + e.strerror
  1104. self.server.printLog(self.log)
  1105. pass
  1106. finally:
  1107. self.close()
  1108. self.server.removeConn(self)
  1109. def findHeader(self, head, header):
  1110. aux = head.find(header + ': ')
  1111. if aux == -1:
  1112. return ''
  1113. aux = head.find(':', aux)
  1114. head = head[aux+2:]
  1115. aux = head.find('\r\n')
  1116. if aux == -1:
  1117. return ''
  1118. return head[:aux];
  1119. def connect_target(self, host):
  1120. i = host.find(':')
  1121. if i != -1:
  1122. port = int(host[i+1:])
  1123. host = host[:i]
  1124. else:
  1125. if self.method=='CONNECT':
  1126. port = 443
  1127. else:
  1128. port = sys.argv[1]
  1129. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  1130. self.target = socket.socket(soc_family, soc_type, proto)
  1131. self.targetClosed = False
  1132. self.target.connect(address)
  1133. def method_CONNECT(self, path):
  1134. self.log += ' - CONNECT ' + path
  1135. self.connect_target(path)
  1136. self.client.sendall(RESPONSE)
  1137. self.client_buffer = ''
  1138. self.server.printLog(self.log)
  1139. self.doCONNECT()
  1140. def doCONNECT(self):
  1141. socs = [self.client, self.target]
  1142. count = 0
  1143. error = False
  1144. while True:
  1145. count += 1
  1146. (recv, _, err) = select.select(socs, [], socs, 3)
  1147. if err:
  1148. error = True
  1149. if recv:
  1150. for in_ in recv:
  1151. try:
  1152. data = in_.recv(BUFLEN)
  1153. if data:
  1154. if in_ is self.target:
  1155. self.client.send(data)
  1156. else:
  1157. while data:
  1158. byte = self.target.send(data)
  1159. data = data[byte:]
  1160. count = 0
  1161. else:
  1162. break
  1163. except:
  1164. error = True
  1165. break
  1166. if count == TIMEOUT:
  1167. error = True
  1168. if error:
  1169. break
  1170. def print_usage():
  1171. print 'Usage: proxy.py -p <port>'
  1172. print ' proxy.py -b <bindAddr> -p <port>'
  1173. print ' proxy.py -b 0.0.0.0 -p 80'
  1174. def parse_args(argv):
  1175. global LISTENING_ADDR
  1176. global LISTENING_PORT
  1177. try:
  1178. opts, args = getopt.getopt(argv,"hb:p:",["bind=","port="])
  1179. except getopt.GetoptError:
  1180. print_usage()
  1181. sys.exit(2)
  1182. for opt, arg in opts:
  1183. if opt == '-h':
  1184. print_usage()
  1185. sys.exit()
  1186. elif opt in ("-b", "--bind"):
  1187. LISTENING_ADDR = arg
  1188. elif opt in ("-p", "--port"):
  1189. LISTENING_PORT = int(arg)
  1190. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  1191. print "\n:-------PythonProxy-------:\n"
  1192. print "Listening addr: " + LISTENING_ADDR
  1193. print "Listening port: " + str(LISTENING_PORT) + "\n"
  1194. print ":-------------------------:\n"
  1195. server = Server(LISTENING_ADDR, LISTENING_PORT)
  1196. server.start()
  1197. while True:
  1198. try:
  1199. time.sleep(2)
  1200. except KeyboardInterrupt:
  1201. print 'Stopping...'
  1202. server.close()
  1203. break
  1204. ####### parse_args(sys.argv[1:])
  1205. if __name__ == '__main__':
  1206. main()
  1207. PTHON
  1208. }
  1209. function service1() {
  1210. cat << END > /lib/systemd/system/yakult.service
  1211. [Unit]
  1212. Description=Yakult
  1213. Documentation=https://google.com
  1214. After=network.target nss-lookup.target
  1215. [Service]
  1216. Type=simple
  1217. User=root
  1218. NoNewPrivileges=true
  1219. CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  1220. AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  1221. ExecStart=/usr/bin/python -O /usr/sbin/yakult
  1222. ProtectSystem=true
  1223. ProtectHome=true
  1224. RemainAfterExit=yes
  1225. Restart=on-failure
  1226. [Install]
  1227. WantedBy=multi-user.target
  1228. END
  1229. }
  1230. function gatorade() {
  1231. cat << PTHON > /usr/sbin/gatorade
  1232. #!/usr/bin/python
  1233. import socket, threading, thread, select, signal, sys, time, getopt
  1234. # Listen
  1235. LISTENING_ADDR = '0.0.0.0'
  1236. if sys.argv[1:]:
  1237. LISTENING_PORT = sys.argv[1]
  1238. else:
  1239. LISTENING_PORT = 8880
  1240. # Pass
  1241. PASS = ''
  1242. # CONST
  1243. BUFLEN = 4096 * 4
  1244. TIMEOUT = 3600
  1245. DEFAULT_HOST = '127.0.0.1:1194'
  1246. RESPONSE = 'HTTP/1.1 101 <font color="red">xamjyssvpn.com|coronassh.com</font>\r\n\r\nContent-Length: 104857600000\r\n\r\n'
  1247. class Server(threading.Thread):
  1248. def __init__(self, host, port):
  1249. threading.Thread.__init__(self)
  1250. self.running = False
  1251. self.host = host
  1252. self.port = port
  1253. self.threads = []
  1254. self.threadsLock = threading.Lock()
  1255. self.logLock = threading.Lock()
  1256. def run(self):
  1257. self.soc = socket.socket(socket.AF_INET)
  1258. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1259. self.soc.settimeout(2)
  1260. intport = int(self.port)
  1261. self.soc.bind((self.host, intport))
  1262. self.soc.listen(0)
  1263. self.running = True
  1264. try:
  1265. while self.running:
  1266. try:
  1267. c, addr = self.soc.accept()
  1268. c.setblocking(1)
  1269. except socket.timeout:
  1270. continue
  1271. conn = ConnectionHandler(c, self, addr)
  1272. conn.start()
  1273. self.addConn(conn)
  1274. finally:
  1275. self.running = False
  1276. self.soc.close()
  1277. def printLog(self, log):
  1278. self.logLock.acquire()
  1279. print log
  1280. self.logLock.release()
  1281. def addConn(self, conn):
  1282. try:
  1283. self.threadsLock.acquire()
  1284. if self.running:
  1285. self.threads.append(conn)
  1286. finally:
  1287. self.threadsLock.release()
  1288. def removeConn(self, conn):
  1289. try:
  1290. self.threadsLock.acquire()
  1291. self.threads.remove(conn)
  1292. finally:
  1293. self.threadsLock.release()
  1294. def close(self):
  1295. try:
  1296. self.running = False
  1297. self.threadsLock.acquire()
  1298. threads = list(self.threads)
  1299. for c in threads:
  1300. c.close()
  1301. finally:
  1302. self.threadsLock.release()
  1303. class ConnectionHandler(threading.Thread):
  1304. def __init__(self, socClient, server, addr):
  1305. threading.Thread.__init__(self)
  1306. self.clientClosed = False
  1307. self.targetClosed = True
  1308. self.client = socClient
  1309. self.client_buffer = ''
  1310. self.server = server
  1311. self.log = 'Connection: ' + str(addr)
  1312. def close(self):
  1313. try:
  1314. if not self.clientClosed:
  1315. self.client.shutdown(socket.SHUT_RDWR)
  1316. self.client.close()
  1317. except:
  1318. pass
  1319. finally:
  1320. self.clientClosed = True
  1321. try:
  1322. if not self.targetClosed:
  1323. self.target.shutdown(socket.SHUT_RDWR)
  1324. self.target.close()
  1325. except:
  1326. pass
  1327. finally:
  1328. self.targetClosed = True
  1329. def run(self):
  1330. try:
  1331. self.client_buffer = self.client.recv(BUFLEN)
  1332. hostPort = self.findHeader(self.client_buffer, 'X-Real-Host')
  1333. if hostPort == '':
  1334. hostPort = DEFAULT_HOST
  1335. split = self.findHeader(self.client_buffer, 'X-Split')
  1336. if split != '':
  1337. self.client.recv(BUFLEN)
  1338. if hostPort != '':
  1339. passwd = self.findHeader(self.client_buffer, 'X-Pass')
  1340. if len(PASS) != 0 and passwd == PASS:
  1341. self.method_CONNECT(hostPort)
  1342. elif len(PASS) != 0 and passwd != PASS:
  1343. self.client.send('HTTP/1.1 400 WrongPass!\r\n\r\n')
  1344. elif hostPort.startswith('127.0.0.1') or hostPort.startswith('localhost'):
  1345. self.method_CONNECT(hostPort)
  1346. else:
  1347. self.client.send('HTTP/1.1 403 Forbidden!\r\n\r\n')
  1348. else:
  1349. print '- No X-Real-Host!'
  1350. self.client.send('HTTP/1.1 400 NoXRealHost!\r\n\r\n')
  1351. except Exception as e:
  1352. self.log += ' - error: ' + e.strerror
  1353. self.server.printLog(self.log)
  1354. pass
  1355. finally:
  1356. self.close()
  1357. self.server.removeConn(self)
  1358. def findHeader(self, head, header):
  1359. aux = head.find(header + ': ')
  1360. if aux == -1:
  1361. return ''
  1362. aux = head.find(':', aux)
  1363. head = head[aux+2:]
  1364. aux = head.find('\r\n')
  1365. if aux == -1:
  1366. return ''
  1367. return head[:aux];
  1368. def connect_target(self, host):
  1369. i = host.find(':')
  1370. if i != -1:
  1371. port = int(host[i+1:])
  1372. host = host[:i]
  1373. else:
  1374. if self.method=='CONNECT':
  1375. port = 443
  1376. else:
  1377. port = sys.argv[1]
  1378. (soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]
  1379. self.target = socket.socket(soc_family, soc_type, proto)
  1380. self.targetClosed = False
  1381. self.target.connect(address)
  1382. def method_CONNECT(self, path):
  1383. self.log += ' - CONNECT ' + path
  1384. self.connect_target(path)
  1385. self.client.sendall(RESPONSE)
  1386. self.client_buffer = ''
  1387. self.server.printLog(self.log)
  1388. self.doCONNECT()
  1389. def doCONNECT(self):
  1390. socs = [self.client, self.target]
  1391. count = 0
  1392. error = False
  1393. while True:
  1394. count += 1
  1395. (recv, _, err) = select.select(socs, [], socs, 3)
  1396. if err:
  1397. error = True
  1398. if recv:
  1399. for in_ in recv:
  1400. try:
  1401. data = in_.recv(BUFLEN)
  1402. if data:
  1403. if in_ is self.target:
  1404. self.client.send(data)
  1405. else:
  1406. while data:
  1407. byte = self.target.send(data)
  1408. data = data[byte:]
  1409. count = 0
  1410. else:
  1411. break
  1412. except:
  1413. error = True
  1414. break
  1415. if count == TIMEOUT:
  1416. error = True
  1417. if error:
  1418. break
  1419. def print_usage():
  1420. print 'Usage: proxy.py -p <port>'
  1421. print ' proxy.py -b <bindAddr> -p <port>'
  1422. print ' proxy.py -b 0.0.0.0 -p 80'
  1423. def parse_args(argv):
  1424. global LISTENING_ADDR
  1425. global LISTENING_PORT
  1426. try:
  1427. opts, args = getopt.getopt(argv,"hb:p:",["bind=","port="])
  1428. except getopt.GetoptError:
  1429. print_usage()
  1430. sys.exit(2)
  1431. for opt, arg in opts:
  1432. if opt == '-h':
  1433. print_usage()
  1434. sys.exit()
  1435. elif opt in ("-b", "--bind"):
  1436. LISTENING_ADDR = arg
  1437. elif opt in ("-p", "--port"):
  1438. LISTENING_PORT = int(arg)
  1439. def main(host=LISTENING_ADDR, port=LISTENING_PORT):
  1440. print "\n:-------PythonProxy-------:\n"
  1441. print "Listening addr: " + LISTENING_ADDR
  1442. print "Listening port: " + str(LISTENING_PORT) + "\n"
  1443. print ":-------------------------:\n"
  1444. server = Server(LISTENING_ADDR, LISTENING_PORT)
  1445. server.start()
  1446. while True:
  1447. try:
  1448. time.sleep(2)
  1449. except KeyboardInterrupt:
  1450. print 'Stopping...'
  1451. server.close()
  1452. break
  1453. ####### parse_args(sys.argv[1:])
  1454. if __name__ == '__main__':
  1455. main()
  1456. PTHON
  1457. }
  1458. function gatorade1() {
  1459. cat << END > /lib/systemd/system/gatorade.service
  1460. [Unit]
  1461. Description=Gatorade
  1462. Documentation=https://google.com
  1463. After=network.target nss-lookup.target
  1464. [Service]
  1465. Type=simple
  1466. User=root
  1467. NoNewPrivileges=true
  1468. CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  1469. AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  1470. ExecStart=/usr/bin/python -O /usr/sbin/gatorade
  1471. ProtectSystem=true
  1472. ProtectHome=true
  1473. RemainAfterExit=yes
  1474. Restart=on-failure
  1475. [Install]
  1476. WantedBy=multi-user.target
  1477. END
  1478. }
  1479. function BBR() {
  1480. wget -q "https://github.com/yue0706/auto_bbr/raw/main/bbr.sh" && chmod +x bbr.sh && ./bbr.sh
  1481. sed -i '/^\*\ *soft\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
  1482. sed -i '/^\*\ *hard\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
  1483. echo '* soft nofile 65536' >>/etc/security/limits.conf
  1484. echo '* hard nofile 65536' >>/etc/security/limits.conf
  1485. echo '' > /root/.bash_history && history -c && echo '' > /var/log/syslog
  1486. F1='/etc/modules-load.d/modules.conf' && { [[ $(grep -cE '^tcp_bbr$' $F1) -ge 1 ]] && echo "bbr already added" || echo "tcp_bbr" >> "$F1"; } && modprobe tcp_bbr
  1487. F2='net.core.default_qdisc' && F3='net.ipv4.tcp_congestion_control' && sed -i "/^$F2.*/d;/^$F3.*/d" /etc/sysctl{.conf,.d/*.conf} && echo -e "${F2}=fq\n${F3}=bbr" >> /etc/sysctl.d/98-bbr.conf && sysctl --system &>/dev/null
  1488. }
  1489. function ddos () {
  1490. sudo apt install dnsutils
  1491. sudo apt-get install net-tools
  1492. sudo apt-get install tcpdump
  1493. sudo apt-get install dsniff -y
  1494. sudo apt install grepcidr
  1495. wget https://github.com/jgmdev/ddos-deflate/archive/master.zip -O ddos.zip
  1496. unzip ddos.zip
  1497. cd ddos-deflate-master
  1498. ./install.sh
  1499. }
  1500. function setting() {
  1501. service ssh restart
  1502. service sshd restart
  1503. service dropbear restart
  1504. systemctl daemon-reload
  1505. systemctl enable yakult
  1506. systemctl restart yakult
  1507. systemctl daemon-reload
  1508. systemctl enable gatorade
  1509. systemctl restart gatorade
  1510. }
  1511. function slowdns() {
  1512. apt update; apt upgrade -y; rm -rf install; wget https://raw.githubusercontent.com/xamjyss143/slow-dns/main/install; chmod +x install; ./install
  1513. bash /etc/slowdns/slowdns-ssh
  1514. startdns
  1515. }
  1516. function remove() {
  1517. echo ' ' > .bash_history
  1518. history -c
  1519. echo ' ' > /var/log/syslog
  1520. rm -f *
  1521. }
  1522. #############################
  1523. #############################
  1524. ## Installation Process
  1525. #############################
  1526. ## WARNING: Do not modify or edit anything
  1527. ## if you did'nt know what to do.
  1528. ## This part is too sensitive.
  1529. #############################
  1530. #############################
  1531. # (For OpenVPN) Checking it this machine have TUN Module, this is the tunneling interface of OpenVPN server
  1532. if [[ ! -e /dev/net/tun ]]; then
  1533. 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"
  1534. echo -e "[\e[1;31m-\e[0m] Script is now exiting..."
  1535. exit 1
  1536. fi
  1537. # Begin Installation by Updating and Upgrading machine and then Installing all our wanted packages/services to be install.
  1538. ScriptMessage
  1539. sleep 2
  1540. echo -e "\033[0;35mUpdating Libraries....\033[0m"
  1541. Instupdate
  1542. # Configure OpenSSH and Dropbear
  1543. echo -e "\033[0;35mConfiguring ssh...\033[0m"
  1544. InstSSH
  1545. # Configure Stunnel
  1546. echo -e "\033[0;35mConfiguring stunnel...\033[0m"
  1547. InsStunnel
  1548. # Configure Privoxy and Squid
  1549. echo -e "\033[0;35mConfiguring proxy...\033[0m"
  1550. InsProxy
  1551. # Configure OpenVPN
  1552. echo -e "\033[0;35mConfiguring OpenVPN...\033[0m"
  1553. InsOpenVPN
  1554. # Configuring Nginx OVPN config download site
  1555. OvpnConfigs
  1556. # Some assistance and startup scripts
  1557. ConfStartup
  1558. # VPS Menu script v1.0
  1559. ConfMenu
  1560. # Setting server local time
  1561. ln -fs /usr/share/zoneinfo/$MyVPS_Time /etc/localtime
  1562. echo -e "\033[0;35m Installing BBR...\033[0m"
  1563. service
  1564. service1
  1565. gatorade
  1566. gatorade1
  1567. BBR
  1568. ddos
  1569. #slowdns
  1570. setting
  1571. remove
  1572. clear
  1573. cd ~
  1574. # Running sysinfo
  1575. bash /etc/profile.d/juans.sh
  1576. # Showing script's banner message
  1577. ScriptMessage
  1578. # Showing additional information from installating this script
  1579. systemctl enable openvpn
  1580. systemctl restart openvpn
  1581. echo -e " Success Installation"
  1582. echo -e ""
  1583. echo -e " Service Ports: "
  1584. echo -e " OpenSSH: $SSH_Port1, $SSH_Port2"
  1585. echo -e " Stunnel: $Stunnel_Port1, $Stunnel_Port2"
  1586. echo -e " DropbearSSH: $Dropbear_Port1, $Dropbear_Port2"
  1587. echo -e " Privoxy: $Privoxy_Port1, $Privoxy_Port2"
  1588. echo -e " Squid: $Proxy_Port1, $Proxy_Port2"
  1589. echo -e " OpenVPN: $OpenVPN_Port1, $OpenVPN_Port2, $OpenVPN_Port3, $OpenVPN_Port4"
  1590. echo -e " NGiNX: $OvpnDownload_Port"
  1591. echo -e " DNS: $MYDNS"
  1592. #echo -ne "\033[1;33mYOUR KEY:\033[0m " && cat /root/server.pub
  1593. #echo -ne "\033[1;33mYOUR NAMESERVER:\033[0m " && cat nameserver.txt
  1594. echo -e ""
  1595. echo -e " OpenVPN Configs Download site"
  1596. echo -e " http://$IPADDR:$OvpnDownload_Port"
  1597. echo -e ""
  1598. #echo -e "Please RUN this code after installation to finish SLOWDNS installation:"
  1599. #echo -ne "\033[0mcurl -sO https://raw.githubusercontent.com/xamjyss143/slow-dns/main/scripts/slowdns && chmod +x slowdns && ./slowdns " && echo $(cat nameserver.txt /root/server.pub)
  1600. echo -e ""
  1601. #echo -e "RUN this code to show your Nameserver and Chave:"
  1602. #echo -e "cat /etc/slowdns/infons /root/server.pub"
  1603. echo -e ""
  1604. echo -e " [Note] DO NOT RESELL THIS SCRIPT"
  1605. # Clearing all logs from installation
  1606. rm -rf /root/.bash_history && history -c && echo '' > /var/log/syslog