Last active
May 5, 2018 14:40
-
-
Save benaryorg/427fb7c0b387aad76be3c7c3ba78ad02 to your computer and use it in GitHub Desktop.
voip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# you can then forward the port pretty well using ssh -NR | |
# port to listen on | |
port=1337 | |
### | |
# | |
# print error to stderr and return negative error code for chaining | |
# | |
function error() | |
{ | |
cat >& 2 <<<${@} | |
return 1 | |
} | |
### | |
# | |
# main function | |
# | |
function main() | |
{ | |
openssl rand -base64 24 \ | |
| read -r passphrase \ | |
|| error "cannot generate passphrase" \ | |
|| return 1 | |
cat <<<"password: ${passphrase}" | |
zmodload -ab zsh/net/tcp ztcp \ | |
|| error "cannot load zsh/net/tcp" \ | |
|| return 1 | |
{ | |
ztcp -l ${port} \ | |
|| error "cannot listen" \ | |
|| return 1 | |
listenfd=${REPLY} | |
while | |
ztcp -a ${listenfd} \ | |
|| error "cannot accept connection" | |
do | |
currentfd=${REPLY} | |
{ | |
ffmpeg -f alsa -i hw:0,0 -acodec libvorbis -f oga - 2>/dev/null \ | |
| PASSPHRASE=${passphrase} openssl enc -e -chacha20 -pass env:PASSPHRASE \ | |
| pv -Ppetra -CN input -B 8m \ | |
| cat >& ${currentfd} \ | |
& | |
cat <& ${currentfd} \ | |
| pv -Ppetra -CN output -B 8m \ | |
| PASSPHRASE=${passphrase} openssl enc -d -chacha20 -pass env:PASSPHRASE \ | |
| ffplay -nodisp 2>/dev/null \ | |
& | |
wait | |
} \ | |
always \ | |
{ | |
ztcp -c ${currentfd} \ | |
|| error "cannot close currentfd" \ | |
|| return 1 | |
} | |
done | |
} \ | |
always \ | |
{ | |
ztcp -c ${listenfd} \ | |
|| error "cannot close listenfd" \ | |
|| return 1 | |
} | |
} | |
main ${@} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment