.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | ## Installation :
21 |
22 | * `apt update`
23 | * `apt install git -y`
24 | * `git clone https://github.com/htr-tech/host.git`
25 | * `cd host`
26 |
27 | #### > Run : `bash host.sh`
28 |
29 | ## Single Command :
30 | ```
31 | apt update ; apt install git -y ; git clone https://github.com/htr-tech/host.git ; cd host ; bash host.sh
32 | ```
33 |
34 |
35 |
36 |
37 | ### <<< If you copy , Then Give me The Credits >>>
38 |
39 | ## Features :
40 | #### [+] 4 Port Forwarding Options !
41 | #### [+] Easy for Beginners !
42 |
43 | ## Tunelling Options :
44 | #### > Localhost (127.0.0.1)
45 | #### > Ngrok (https://ngrok.com)
46 | #### > Cloudflared (https://github.com/cloudflare/cloudflared)
47 | #### > LocalXpose (https://localxpose.io/)
48 |
49 | ## Find Me on :
50 | [](https://github.com/htr-tech)
51 | [](https://www.instagram.com/tahmid.rayat)
52 | [](https://m.me/tahmid.rayat.official)
53 |
--------------------------------------------------------------------------------
/host.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ## Host : Expose your Localhost :) Temporary File hosting
4 | ## Author : TAHMID RAYAT
5 | ## Version : 2.3
6 | ## Github : https://github.com/htr-tech
7 |
8 | ## If you Copy Then Give the credits :)
9 |
10 | ## GNU GENERAL PUBLIC LICENSE
11 | ## Version 3, 29 June 2007
12 | ##
13 | ## Copyright (C) 2007 Free Software Foundation, Inc.
14 | ## Everyone is permitted to copy and distribute verbatim copies
15 | ## of this license document, but changing it is not allowed.
16 | ##
17 | ## Preamble
18 | ##
19 | ## The GNU General Public License is a free, copyleft license for
20 | ## software and other kinds of works.
21 | ##
22 | ## The licenses for most software and other practical works are designed
23 | ## to take away your freedom to share and change the works. By contrast,
24 | ## the GNU General Public License is intended to guarantee your freedom to
25 | ## share and change all versions of a program--to make sure it remains free
26 | ## software for all its users. We, the Free Software Foundation, use the
27 | ## GNU General Public License for most of our software; it applies also to
28 | ## any other work released this way by its authors. You can apply it to
29 | ## your programs, too.
30 | ##
31 | ## When we speak of free software, we are referring to freedom, not
32 | ## price. Our General Public Licenses are designed to make sure that you
33 | ## have the freedom to distribute copies of free software (and charge for
34 | ## them if you wish), that you receive source code or can get it if you
35 | ## want it, that you can change the software or use pieces of it in new
36 | ## free programs, and that you know you can do these things.
37 | ##
38 | ## To protect your rights, we need to prevent others from denying you
39 | ## these rights or asking you to surrender the rights. Therefore, you have
40 | ## certain responsibilities if you distribute copies of the software, or if
41 | ## you modify it: responsibilities to respect the freedom of others.
42 | ##
43 | ## For example, if you distribute copies of such a program, whether
44 | ## gratis or for a fee, you must pass on to the recipients the same
45 | ## freedoms that you received. You must make sure that they, too, receive
46 | ## or can get the source code. And you must show them these terms so they
47 | ## know their rights.
48 | ##
49 | ## Developers that use the GNU GPL protect your rights with two steps:
50 | ## (1) assert copyright on the software, and (2) offer you this License
51 | ## giving you legal permission to copy, distribute and/or modify it.
52 | ##
53 | ## For the developers' and authors' protection, the GPL clearly explains
54 | ## that there is no warranty for this free software. For both users' and
55 | ## authors' sake, the GPL requires that modified versions be marked as
56 | ## changed, so that their problems will not be attributed erroneously to
57 | ## authors of previous versions.
58 | ##
59 | ## Some devices are designed to deny users access to install or run
60 | ## modified versions of the software inside them, although the manufacturer
61 | ## can do so. This is fundamentally incompatible with the aim of
62 | ## protecting users' freedom to change the software. The systematic
63 | ## pattern of such abuse occurs in the area of products for individuals to
64 | ## use, which is precisely where it is most unacceptable. Therefore, we
65 | ## have designed this version of the GPL to prohibit the practice for those
66 | ## products. If such problems arise substantially in other domains, we
67 | ## stand ready to extend this provision to those domains in future versions
68 | ## of the GPL, as needed to protect the freedom of users.
69 | ##
70 | ## Finally, every program is threatened constantly by software patents.
71 | ## States should not allow patents to restrict development and use of
72 | ## software on general-purpose computers, but in those that do, we wish to
73 | ## avoid the special danger that patents applied to a free program could
74 | ## make it effectively proprietary. To prevent this, the GPL assures that
75 | ## patents cannot be used to render the program non-free.
76 | ##
77 | ## The precise terms and conditions for copying, distribution and
78 | ## modification follow.
79 | ##
80 | ## Copyright (C) 2022 HTR-TECH (https://github.com/htr-tech)
81 | ##
82 |
83 | # Deafult Port
84 | def_port='8080'
85 |
86 | # Color Codes
87 | CR=$'\e[1;31m' CG=$'\e[1;32m' CY=$'\e[1;33m' CB=$'\e[1;34m' CC=$'\e[1;36m' CW=$'\e[1;37m' RS=$'\e[1;0m'
88 |
89 | architecture=`uname -m`
90 |
91 | # Terminate Program
92 | terminated() {
93 | printf "\n\n${RS} ${CR}[${CW}!${CR}]${CY} Program Interrupted ${CR}[${CW}!${CR}]${RS}\n"
94 | exit 1
95 | }
96 |
97 | trap terminated SIGTERM
98 | trap terminated SIGINT
99 |
100 | kill_pid() {
101 | check_PID="php ngrok cloudflared loclx"
102 | for process in ${check_PID}; do
103 | if [[ $(pidof ${process}) ]]; then
104 | killall ${process} > /dev/null 2>&1
105 | fi
106 | done
107 | }
108 |
109 | # Host Banner
110 | logo(){
111 |
112 | clear
113 | echo "${CY} _ _ _
114 | ${CY} | | | | ${CC}V${CB}-${CG}2.3${CY} | |
115 | ${CG} | |__| | ___ ___| |_
116 | ${CG} | __ |/ _ \/ __| __|
117 | ${CY} | | | | (_) \__ \ |_
118 | ${CY} |_| |_|\___/|___/\__|
119 | ${RS}
120 | ${CR} [${CW}~${CR}]${CY} Created By HTR-TECH ${CG}(${CC}Tahmid Rayat${CG})${RS}"
121 |
122 | }
123 |
124 | path(){
125 | logo
126 | printf "\n${RS} ${CR}[${CW}1${CR}]${CY} Use Current Path [host/htdocs]"
127 | printf "\n${RS} ${CR}[${CW}2${CR}]${CY} Setup a Path"
128 | printf "\n${RS}"
129 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Select A Hosting option: ${CC}"
130 | read red_path
131 |
132 | if [[ $red_path == 1 || $red_path == 01 ]]; then
133 | path=$'./htdocs'
134 | elif [[ $red_path == 2 || $red_path == 02 ]]; then
135 | printf "\n${RS} ${CC}Enter File Path [Example : /home/tahmid/htdocs]"
136 | printf "\n${RS}"
137 | printf "\n${RS} ${CR}>>${CG} ${CC}"
138 | read path
139 | else
140 | printf "\n${RS} ${CR}[${CW}!${CR}]${CY} Invalid option ${CR}[${CW}!${CR}]${RS}\n"
141 | sleep 2 ; logo ; path
142 | fi
143 |
144 | [[ ! -d "$path" ]] && mkdir -p "$path"
145 | menu
146 | }
147 |
148 | package(){
149 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Setting up Environment..${RS}"
150 | if [[ -d "/data/data/com.termux/files/home" ]]; then
151 | if [[ ! $(command -v proot) ]]; then
152 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Installing ${CY}Proot${RS}\n"
153 | pkg install proot resolv-conf -y
154 | fi
155 | fi
156 |
157 | if [[ $(command -v php) && $(command -v curl) && $(command -v unzip) ]]; then
158 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Environment Setup Completed !${RS}"
159 | else
160 | repr=(curl php unzip)
161 | for i in "${repr[@]}"; do
162 | type -p "$i" &>/dev/null ||
163 | {
164 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Installing ${CY}${i}${RS}\n"
165 |
166 | if [[ $(command -v pkg) ]]; then
167 | pkg install "$i" -y
168 | elif [[ $(command -v apt) ]]; then
169 | sudo apt install "$i" -y
170 | elif [[ $(command -v apt-get) ]]; then
171 | sudo apt-get install "$i" -y
172 | elif [[ $(command -v dnf) ]]; then
173 | sudo dnf -y install "$i"
174 | else
175 | printf "\n${RS} ${CR}[${CW}!${CR}]${CY} Unfamiliar Distro ${CR}[${CW}!${CR}]${RS}\n"
176 | exit 1
177 | fi
178 | }
179 | done
180 | fi
181 | }
182 |
183 | ## Download Binaries
184 | download() {
185 | url="$1"
186 | output="$2"
187 | file=`basename $url`
188 | if [[ -e "$file" || -e "$output" ]]; then
189 | rm -rf "$file" "$output"
190 | fi
191 | curl --silent --insecure --fail --retry-connrefused \
192 | --retry 3 --retry-delay 2 --location --output "${file}" "${url}"
193 |
194 | if [[ -e "$file" ]]; then
195 | if [[ ${file#*.} == "zip" ]]; then
196 | unzip -qq $file > /dev/null 2>&1
197 | elif [[ ${file#*.} == "tgz" ]]; then
198 | tar -zxf $file > /dev/null 2>&1
199 | else
200 | mv -f $file $output > /dev/null 2>&1
201 | fi
202 | chmod +x $output > /dev/null 2>&1
203 | rm -rf "$file"
204 | else
205 | echo -e "\n${RS} ${CR}[${CW}!${CR}]${CY} Error occured while downloading ${CR}${output}."
206 | exit 1
207 | fi
208 | }
209 |
210 | ## Install ngrok
211 | install_ngrok() {
212 | if [[ -e "./ngrok" ]]; then
213 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Ngrok already installed.${RS}"
214 | else
215 | printf "\n${RS} ${CR}[${CW}-${CR}]${CC} Installing ngrok...${RS}"
216 | if [[ ("$architecture" == *'arm'*) || ("$architecture" == *'Android'*) ]]; then
217 | download 'https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-arm.tgz' 'ngrok'
218 | elif [[ "$architecture" == *'aarch64'* ]]; then
219 | download 'https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-arm64.tgz' 'ngrok'
220 | elif [[ "$architecture" == *'x86_64'* ]]; then
221 | download 'https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz' 'ngrok'
222 | else
223 | download 'https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-386.tgz' 'ngrok'
224 | fi
225 | fi
226 | }
227 |
228 | ## Install Cloudflared
229 | install_cloudflared() {
230 | if [[ -e "./cloudflared" ]]; then
231 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Cloudflared already installed.${RS}"
232 | else
233 | printf "\n${RS} ${CR}[${CW}-${CR}]${CC} Installing Cloudflared...${RS}"
234 | if [[ ("$architecture" == *'arm'*) || ("$architecture" == *'Android'*) ]]; then
235 | download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm' 'cloudflared'
236 | elif [[ "$architecture" == *'aarch64'* ]]; then
237 | download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64' 'cloudflared'
238 | elif [[ "$architecture" == *'x86_64'* ]]; then
239 | download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64' 'cloudflared'
240 | else
241 | download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-386' 'cloudflared'
242 | fi
243 | fi
244 | }
245 |
246 | ## Install LocalXpose
247 | install_localxpose() {
248 | if [[ -e "./loclx" ]]; then
249 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Localxpose already installed.${RS}"
250 | else
251 | printf "\n${RS} ${CR}[${CW}-${CR}]${CC} Installing Localxpose...${RS}"
252 | if [[ ("$architecture" == *'arm'*) || ("$architecture" == *'Android'*) ]]; then
253 | download 'https://api.localxpose.io/api/v2/downloads/loclx-linux-arm.zip' 'loclx'
254 | elif [[ "$architecture" == *'aarch64'* ]]; then
255 | download 'https://api.localxpose.io/api/v2/downloads/loclx-linux-arm64.zip' 'loclx'
256 | elif [[ "$architecture" == *'x86_64'* ]]; then
257 | download 'https://api.localxpose.io/api/v2/downloads/loclx-linux-amd64.zip' 'loclx'
258 | else
259 | download 'https://api.localxpose.io/api/v2/downloads/loclx-linux-386.zip' 'loclx'
260 | fi
261 | fi
262 | }
263 |
264 | ## LocalXpose Authentication
265 | localxpose_auth() {
266 | ./loclx -help > /dev/null 2>&1 &
267 | { logo; sleep 1; }
268 | [ -d ".localxpose" ] && auth_f=".localxpose/.access" || auth_f="$HOME/.localxpose/.access"
269 | [ -d "/data/data/com.termux/files/home" ] && status=$(termux-chroot ./loclx account status) || status=$(./loclx account status)
270 |
271 | if [[ $status == *"Error"* ]]; then
272 | echo -e "\n${CR} [${CW}!${CR}]${CG} Create an account on ${CY}localxpose.io${CG} & copy the token\n"
273 | sleep 3
274 | read -p "${CR} [${CW}?${CR}]${CY} Input Loclx Token :${CY} " loclx_token
275 | if [[ ${#loclx_token} -lt 10 ]]; then
276 | echo -e "\n${CR} [${CQ}!${CR}]${CR} You have to input Localxpose Token."
277 | sleep 2; menu;
278 | else
279 | echo -n "$loclx_token" > $auth_f 2> /dev/null
280 | fi
281 | fi
282 | }
283 |
284 | ## Ngrok Authentication
285 | ngrok_auth() {
286 | if ! [[ -e ".ngrok.yml" && $(awk -F'authtoken: ' '{print $2}' "./.ngrok.yml" | xargs) != "" ]]; then
287 | { logo; sleep 1; }
288 | echo -e "\n${CR} [${CW}!${CR}]${CG} Create an account on ${CY}ngrok.com${CG} & copy the token\n"
289 | sleep 3
290 | read -p "${CR} [${CW}?${CR}]${CY} Input Ngrok.com Token :${CY} " ngrok_token
291 | if [[ ${#ngrok_token} -lt 10 ]]; then
292 | echo -e "\n${CR} [${CQ}!${CR}]${CR} You have to input valid ngrok Token."
293 | sleep 2; menu;
294 | else
295 | ./ngrok --config ".ngrok.yml" authtoken $ngrok_token > /dev/null 2>&1 &
296 | fi
297 | fi
298 | }
299 |
300 | ## Host on Localhost. Just "php -S" lol
301 | localhost() {
302 | printf "\n${RS} ${CR}[${CW}-${CR}]${CY} Input Port [default:${def_port}]: ${CC}"
303 | read port
304 | port="${port:-${def_port}}"
305 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Starting PHP Server on Port ${CY}${port}${RS}\n"
306 | cd "$path" && php -S 127.0.0.1:"$port" > /dev/null 2>&1 &
307 | sleep 2
308 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Successfully Hosted at : ${CY}http://127.0.0.1:$port ${RS}"
309 | printf "\n\n ${CR}[${CW}-${CR}]${CC} Press Ctrl + C to exit.${RS}\n"
310 | while [ true ]; do
311 | sleep 0.75
312 | done
313 | }
314 |
315 | ## Start ngrok
316 | ngrok() {
317 | ngrok_auth
318 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Starting PHP Server on Port ${CY}${def_port}${RS}\n"
319 | cd "$path" && php -S 127.0.0.1:"$def_port" > /dev/null 2>&1 &
320 | sleep 1
321 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Launching Ngrok on Port ${CY}${def_port}${RS}"
322 |
323 | if [[ `command -v termux-chroot` ]]; then
324 | sleep 2 && termux-chroot ./ngrok --config ".ngrok.yml" http 127.0.0.1:"$def_port" --log=stdout > /dev/null 2>&1 &
325 | else
326 | sleep 2 && ./ngrok --config ".ngrok.yml" http 127.0.0.1:"$def_port" --log=stdout > /dev/null 2>&1 &
327 | fi
328 |
329 | sleep 8
330 | ngrk=$(curl -s -N http://127.0.0.1:4040/api/tunnels | grep -Eo '(https)://[^/"]+(.ngrok.io)')
331 | printf "\n\n${RS} ${CR}[${CW}-${CR}]${CG} Successfully Hosted at : ${CY}${ngrk}${RS}"
332 | printf "\n\n ${CR}[${CW}-${CR}]${CC} Press Ctrl + C to exit.${RS}\n"
333 | while [ true ]; do
334 | sleep 0.75
335 | done
336 | }
337 |
338 | ## Start Cloudflared
339 | cloudflared() {
340 | rm .cld.log > /dev/null 2>&1 &
341 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Starting PHP Server on Port ${CY}${def_port}${RS}\n"
342 | cd "$path" && php -S 127.0.0.1:"$def_port" > /dev/null 2>&1 &
343 | sleep 1
344 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Launching Cloudflared on Port ${CY}${def_port}${RS}"
345 |
346 | if [[ `command -v termux-chroot` ]]; then
347 | sleep 2 && termux-chroot ./cloudflared tunnel -url 127.0.0.1:"$def_port" --logfile ".cld.log" > /dev/null 2>&1 &
348 | else
349 | sleep 2 && ./cloudflared tunnel -url 127.0.0.1:"$def_port" --logfile ".cld.log" > /dev/null 2>&1 &
350 | fi
351 |
352 | sleep 8
353 | cldflr=$(grep -o 'https://[-0-9a-z]*\.trycloudflare.com' ".cld.log")
354 | printf "\n\n${RS} ${CR}[${CW}-${CR}]${CG} Successfully Hosted at : ${CY}${cldflr}${RS}"
355 | printf "\n\n ${CR}[${CW}-${CR}]${CC} Press Ctrl + C to exit.${RS}\n"
356 | while [ true ]; do
357 | sleep 0.75
358 | done
359 | }
360 |
361 | ## Start LocalXpose
362 | localxpose() {
363 | rm .loclx.log > /dev/null 2>&1 &
364 | localxpose_auth
365 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Starting PHP Server on Port ${CY}${def_port}${RS}\n"
366 | cd "$path" && php -S 127.0.0.1:"$def_port" > /dev/null 2>&1 &
367 | sleep 1
368 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Launching LocalXpose on Port ${CY}${def_port}${RS}"
369 |
370 | if [[ `command -v termux-chroot` ]]; then
371 | sleep 2 && termux-chroot ./loclx tunnel --raw-mode http --https-redirect -t 127.0.0.1:"$def_port" > ".loclx.log" 2>&1 &
372 | else
373 | sleep 2 && ./loclx tunnel --raw-mode http --https-redirect -t 127.0.0.1:"$def_port" > ".loclx.log" 2>&1 &
374 | fi
375 |
376 | sleep 8
377 | loclx_url=$(grep -o '[0-9a-zA-Z.]*\.loclx.io' ".loclx.log")
378 | printf "\n\n${RS} ${CR}[${CW}-${CR}]${CG} Successfully Hosted at : ${CY}http://${loclx_url}${RS}"
379 | printf "\n\n ${CR}[${CW}-${CR}]${CC} Press Ctrl + C to exit.${RS}\n"
380 | while [ true ]; do
381 | sleep 0.75
382 | done
383 | }
384 |
385 | menu() {
386 | logo
387 | echo -e "\n${CR} [${CW}01${CR}]${CG} Localhost ${CR}[${CC}Manual Forwarding${CR}]"
388 | echo -e "${CR} [${CW}02${CR}]${CG} Ngrok.io"
389 | echo -e "${CR} [${CW}03${CR}]${CG} Cloudflared"
390 | echo -e "${CR} [${CW}04${CR}]${CG} LocalXpose"
391 | printf "\n${RS} ${CR}[${CW}-${CR}]${CG} Select an Option: ${CB}"
392 | read REPLY
393 |
394 | case $REPLY in
395 | 1 | 01)
396 | localhost;;
397 | 2 | 02)
398 | ngrok;;
399 | 3 | 03)
400 | cloudflared;;
401 | 4 | 04)
402 | localxpose;;
403 | *)
404 | printf "\n${RS} ${CR}[${CW}!${CR}]${CY} Invalid option ${CR}[${CW}!${CR}]${RS}\n"
405 | sleep 2; path;;
406 | esac
407 | }
408 |
409 | kill_pid
410 | package
411 | install_ngrok
412 | install_cloudflared
413 | install_localxpose
414 | path
415 |
--------------------------------------------------------------------------------