** TL;DR ** I made a text server Container with everything in it using Docker for Textbelt.
So back in December I decided to attempt to use the following technologies to setup Textbelt:
- Google Cloud compute
- Node.js
- Textbelt
I did all the setup and created the environment, and I got it to get myself a free text sending message, limited to I think 100 free text messages per day. I got this thing to work, and then wrote a simple text scripting app to send my friend a text every 30 seconds, which was kind of fun.
But the problem with this is that, it’s not portable! So this time, I want to
- Document the steps I would take to setup this process
- Make a Docker container so that I could easily run it on Google Cloud Compute, Amazon, Azure, wherever!
Now at this step, I got the latest debian container, and logged in but I was logged in as root. There is something wrong about logging in as root, so I did some Googling to get around it. So the easiest way seemed like making your own Dockerfile….
so Here it is. Replace username with your username:
#courtesy of https://stackoverflow.com/questions/47876144/can-you-start-a-process-inside-a-docker-container-as-root-while-having-the-defa
FROM debian:latest
ENV user_name user
RUN apt-get update
RUN apt-get install -y sudo
RUN useradd --create-home -s /bin/bash ${user_name}
RUN echo "${user_name} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${user_name}
WORKDIR /home/${user_name}
USER ${user_name}
CMD /bin/bash
#this line is from treehouse
RUN sudo apt-get -y install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
RUN sudo apt-get -y install redis-server
RUN sudo apt-get -y install libsasl2-2
RUN sudo apt-get -y install gnutls-bin
RUN sudo apt-get -y install mutt
RUN sudo apt-get -y install git-all
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
RUN sudo apt-get -y install nodejs
RUN sudo apt-get -y install nano
RUN sudo mkdir -p /.mutt/cache
RUN git clone https://github.com/typpo/textbelt
RUN npm --prefix ./textbelt install ./textbelt
RUN touch ~/.muttrc
RUN echo '"account-hook imap://gmail/ "' >> ~/.muttrc
RUN echo 'set from = "[email protected]"'>> ~/.muttrc
RUN echo 'set realname = "yourusername"' >> ~/.muttrc
RUN echo 'set imap_user = "[email protected]"' >> ~/.muttrc
RUN echo 'set imap_pass = "yourpassword"' >> ~/.muttrc
RUN echo 'set folder = "imaps://imap.gmail.com:993"' >> ~/.muttrc
RUN echo 'set spoolfile = "+INBOX"' >> ~/.muttrc
RUN echo 'set postponed ="+[Gmail]/Drafts"' >> ~/.muttrc
RUN echo 'set header_cache =~/.mutt/cache/headers' >> ~/.muttrc
RUN echo 'set message_cachedir =~/.mutt/cache/bodies' >> ~/.muttrc
RUN echo 'set certificate_file =~/.mutt/certificates' >> ~/.muttrc
RUN echo 'set smtp_url = "smtp://[email protected]@smtp.gmail.com:587/"' >> ~/.muttrc
RUN echo 'set smtp_pass = "yourpassword"' >> ~/.muttrc
RUN echo 'set move = no' >> ~/.muttrc
RUN echo 'set imap_keepalive = 900"' >> ~/.muttrc
Afterwards, I logged into it:
docker run -it -p 127.0.0.1:80:9090/tcp byshiny/textbelt:version1 bash
#this means that bind port 8080 of the container to 127.0.0.1 of the
#host machine.
#refer to: https://docs.docker.com/engine/reference/commandline/run/#add-bind-mounts-or-volumes-using-the---mount-flag
Clone the git repository:
git clone https://github.com/typpo/textbelt
cd textbelt
npm install
Start the redis server in the background
redis-server --daemonize yes
Create the torlist to avoid textbelt errors
touch server/torlist
Setup a mutt configuration stuff(already did this in the Dockerfile)
#create cache file? Not sure if this was needed
sudo mkdir -p /.mutt/cache
nano ~/.muttrc
account-hook imap://gmail/ “set
set from = "[email protected]"
set realname = "yourusername"
set imap_user = "[email protected]"
set imap_pass = "yourpassword"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = "smtp://[email protected]@smtp.gmail.com:587/"
set smtp_pass = "yourpassword"
set move = no
set imap_keepalive = 900
So at this point, you should encrypt this password. I haven’t gotten around to it yet, but you should…
Go into the directory and run the server in the background
cd textbelt
nodejs server/app.js &
Now this is the most exciting part. You can run the command to send yourself a text message! Something like this:
#this is in the actual container
curl -X POST http://127.0.0.1:9090/text --data-urlencode number='18001337 carrier=att' --data-urlencode 'message=Hello world'
txting phone your-number : Hello world
#if you want to publish from outside the Containers
curl -X POST http://127.0.0.1:80/text --data-urlencode number='18001337 carrier=att' --data-urlencode 'message=Hello world'
txting phone your-number: Hello world
And finally we get this:
And lastly, save the version of the image for your future use:
docker commit c3f279d17e0a byshiny/textbelt:version1