- easy to use
<?bash echo "hello world" ?>
- write fast wabapps in pure #!bash script
- QUERY_STRING and POST_STRING variables can used as normal bash variables (e.g example?var1=foo&var2=bar&var3=nase becomes to echo "${var1} ${var2} ${var3})
- Funktion for decoding URL-encoding: var_dec=$(urldecode $var1)
- Bash for Web Applications
- Because there's nothing you can't fix with a #!Bash Script.
apt-get update; apt-get install -y apache2
tee /etc/apache2/sites-enabled/000-default.conf >/dev/null <<EOF
<VirtualHost *:80>
ServerName example.org
ServerAdmin webmaster@example.org
DocumentRoot /var/www/html/
ScriptAlias "/index.html" "/usr/lib/cgi-bin/index.cgi"
ScriptAlias "/index" "/usr/lib/cgi-bin/index.cgi"
RedirectMatch 404 .*\.htsh
<Directory /var/www/html/>
AllowOverride none
Options -Indexes
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
Include conf-available/serve-cgi-bin.conf
</VirtualHost>
EOF
a2enmod cgid
service apache2 restart
cd /var/www/html # your html folder
wget https://raw.githubusercontent.com/tinoschroeter/bash_on_steroids/master/build.sh
wget https://raw.githubusercontent.com/tinoschroeter/bash_on_steroids/master/index.htsh # example file
chmod +x build.sh
./build.sh
$ index.cgi can be found in /usr/lib/cgi-bin
All bash codes are to be enclosed within <?bash ... ?> or in short, <? ... ?>
tags.
<!doctype html>
<html>
<body>
<ul>
<?bash for i in Buzz Rex Bo Hamm Slink Potato; do echo "
<li>$i</li>
" done ?>
</ul>
</body>
</html>
The Template Enginge will create this cgi script out of it
#!/bin/bash
echo "X-Bash-On-Steroids: Because there's nothing you can't fix with a #!Bash Script."
echo Content-type: text/html
echo ""
## make POST and GET stings
## as bash variables available
if [ ! -z $CONTENT_LENGTH ] && [ "$CONTENT_LENGTH" -gt 0 ] && [ $CONTENT_TYPE != "multipart/form-data" ]; then
read -n $CONTENT_LENGTH POST_STRING <&0
eval $(echo "${POST_STRING//;}"|grep '='|tr '&' ';')
fi
eval $(echo "${QUERY_STRING//;}"|grep '='|tr '&' ';')
## decode URL-encoding
urldecode() { : "${*//+/ }"; echo -e "${_//%/\x}"; }
echo "<!DOCTYPE html>"
echo "<html>"
echo " <body>"
echo " <ul>"
for i in Buzz Rex Bo Hamm Slink Potato; do
echo "<li>$i</li>"
done
echo "</ul>"
echo "</body>"
echo "</html>"
transform this %23%21%2Fbin%2Fbash to that #!/bin/bash
example:
var_dec=$(urldecode $var)
https://en.wikipedia.org/wiki/Percent-encoding
./build.sh
index.htsh --->> /usr/lib/cgi-bin/index.cgi
git clone https://github.com/tinoschroeter/bash_on_steroids.git
cd bash_on_steroids
vagrant up
open http://localhost:8090/