Skip to content

Instantly share code, notes, and snippets.

@jeroenjanssens
Last active February 15, 2022 21:44
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeroenjanssens/7896821 to your computer and use it in GitHub Desktop.
Save jeroenjanssens/7896821 to your computer and use it in GitHub Desktop.
Simple chat server in bash, demonstrating websocketd.
#!/bin/bash
# Hacked together by JeroenJanssens.com on 2013-12-10
# Requires: https://github.com/joewalnes/websocketd
# Run: websocketd --devconsole --port 8080 ./chat.sh
echo "Please enter your name:"; read USER
echo "[$(date)] ${USER} joined the chat" >> chat.log
echo "[$(date)] Welcome to the chat ${USER}!"
tail -n 0 -f chat.log --pid=$$ | grep --line-buffered -v "] ${USER}>" &
while read MSG; do echo "[$(date)] ${USER}> ${MSG}" >> chat.log; done
Copy link

ghost commented Dec 10, 2013

this is neat... but I think backticks would present some serious security challenges.

@jeroenjanssens
Copy link
Author

I just checked and backticks are actually escaped properly. But please keep in mind that this is just a toy example. :-)

Copy link

ghost commented Dec 10, 2013

yeah, I just tested it out to see if my comment was even correct and it is not. It's properly escaped. Now I'm trying to figure out how it's properly escaped without performing the typical filter which in this case would be: USER=${USER//[^a-zA-Z0-9_]/} as well as MSG=${MSG//^a-zA-Z0-9_]/}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment