Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@ghost

This comment has been minimized.

Copy link

commented Dec 10, 2013

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

@jeroenjanssens

This comment has been minimized.

Copy link
Owner Author

commented Dec 10, 2013

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

@ghost

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.