ostrolucky/stdinho

Turn any STDIN/STDOUT into HTTP server

Installs: 52

Dependents: 0

Suggesters: 0

Security: 0

Stars: 126

Watchers: 5

Forks: 5

Open Issues: 0

Type:project

0.5.0 2019-11-26 23:27 UTC

README

Latest Version on Packagist Software License Build Status

stdinho is small command-line tool that creates TCP server, accepts any STDOUT as its STDIN and whoever connects to the server will get this data served as HTTP response.

It was written from frustration of having to share remote resources with my under-priviliged colleagues on semi-regular basis. This typically involves downloading file, uploading file, sending the link, waiting until target finishes downloading file, deleting file. In each stage of the process you would normally have to wait.

stdinho animation

Install

Via Composer

composer global require ostrolucky/stdinho

Or grab executable PHAR file from Releases

Usage

As simple as just piping some data in:

echo hello world|stdinho

For all options see

stdinho --help

Features

  • async. Yep, in PHP. No restriction on clients downloading simultaneusly
  • buffers to temp file before client is connected, so no time or data in between is lost
  • cross-platform: Linux/MacOS/Windows
  • detects MIME type and attaches it to HTTP response
  • neat progress bar showing status of buffering and client downloads.

Examples

Video streaming

# Server
$ stdinho 0.0.0.0:1337 < /file/to/a/movie.mp4
# Client
$ firefox http://127.0.0.1:1337

Simple one-way chat

# Server
# Server (broadcaster)
$ { while read a; do echo $a; done }|bin/stdinho 127.0.0.1:1337
# Client
curl 127.0.0.1:1337

Tail application logs in realtime

# Server
$ tail -f project/var/log/*.log|stdinho 0.0.0.0:1337
# Client
$ curl 127.0.0.1:1337 

# Bonus: gzip transfer encoding (server)
$ tail -f project/var/*.log|gzip -c|stdinho 0.0.0.0:1337 --http-headers='["Content-Type: text/plain", "Content-Encoding: gzip", "Transfer-Encoding: gzip"]'

Stream a folder, including compression

# Server
$ zip -qr - project|stdinho 0.0.0.0:1337 -f project.zip
# Client
$ curl 127.0.0.1:1337 -o project.zip # Saves it to project.zip

Dump remote database and stream it to different database on the fly via middle man

# Server
$ ssh admin@example.com "mysqldump -u root -ptoor database|gzip -c"|stdinho 0.0.0.0:1337 -f "$(date).sql.gz" # also saves the backup locally
# Client
$ curl 127.0.0.1:1337|gunzip|mysql -u root -ptoor database # Import it directly to local DB

Use case from GIF in this README

#   There is bad connectivity between A (public server) and B (user connected to network via special VPN), 
#   but good connectivity between A and C (on same local network as A, but not public). 
#   However, B and C are behind NAT in separate networks, so there is no direct connection between them.
#   Here D is introduced, which is public server having good connection to both C and B, but no connection to A. 
#   In final, download stream goes like this: A -> C -> D -> B which bypasses connection problem between A and B and NAT issue at the same time
#   This problem is basically animation shown in introduction of this README.
# C:
$ ssh -NR \*:1337:localhost:1337 D #Reverse tunnel. Note: GatewayPorts cannot be set to "no" in D's sshd_config
$ curl http://A.com/big_file.tar.gz|stdinho 0.0.0.0:1337
# B:
$ curl D:1337 -o big_file.tar.gz

Licensing

GPLv3 license. Please see License File for more information.