Sindbad~EG File Manager
#!/bin/bash
grep -q nginx /etc/passwd || adduser nginx
test -d /etc/nginx/ssl/ || mkdir /etc/nginx/ssl/
test -e /etc/nginx/ssl/dhparam.pem || cp -va /etc/nginx/openresty/tests/openresty/dhparam.pem /etc/nginx/ssl/dhparam.pem
test -d /var/cpanel/ssl/cpanel/ || mkdir -p /var/cpanel/ssl/cpanel/
test -e /var/cpanel/ssl/cpanel/mycpanel.pem || cp -vaR /etc/nginx/openresty/tests/openresty/cert.pem /var/cpanel/ssl/cpanel/mycpanel.pem
test -d /var/log/oblig/ || mkdir -p /var/log/oblig/
test -e /lib64/libpcre.so.0 || ln -s /usr/lib64/libpcre.so.1 /lib64/libpcre.so.0
ln -s /etc/nginx/openresty /usr/local/openresty/conf
test -L /usr/local/openresty/nginx/conf && rm -vf /usr/local/openresty/nginx/conf
ln -s /etc/nginx/openresty /usr/local/openresty/nginx/conf
test -L /usr/local/openresty/bin/openresty && rm -vf /usr/local/openresty/bin/openresty
ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty
test -e /etc/nginx/openresty/openresty && rm -vf /etc/nginx/openresty/openresty
/usr/local/openresty/bin/opm get thibaultcha/lua-resty-mlcache
/usr/local/openresty/bin/opm get xiangnanscu/lua-resty-cookie
/usr/local/openresty/bin/opm get fffonion/lua-resty-openssl
/usr/local/openresty/bin/opm get ledgetech/lua-resty-http
/usr/local/openresty/bin/opm get openresty/lua-resty-string
cd /root
LATEST_LUA_ROCK=$(curl -s https://luarocks.github.io/luarocks/releases/ |grep -E 'luarocks-[0-9]+.[0-9]+.[0-9]+.tar.gz' | head -n 1 | cut -d'"' -f 2)
wget "https://luarocks.github.io/luarocks/releases/$LATEST_LUA_ROCK"
tar -xvf $LATEST_LUA_ROCK
cd luarocks-*
./configure --prefix=/usr/local/openresty/luajit \
--with-lua=/usr/local/openresty/luajit/ \
--lua-suffix=jit \
--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
make
make install
cd /etc/nginx/openresty/lua
/usr/local/openresty/luajit/bin/luarocks install --tree lua_modules lua-resty-timer
touch /var/log/oblig/web /var/log/openrestyerror.log
REDIS_HOST=$(printenv REDIS_HOST)
HTTPD_HOST=$(printenv HTTPD_HOST)
TEST_SUITE_HOST=$(printenv TEST_SUITE_HOST)
HTTPD_IP=$(dig +short A $HTTPD_HOST | head -n 1)
REDIS_IP=$(dig +short A $REDIS_HOST | head -n 1)
TEST_SUITE_IP=$(dig +short A $TEST_SUITE_HOST | head -n 1)
SELF_IP=$(hostname -i)
# Generate some test data (redis)
echo "Generating some test data"
for N in `seq 1 5` ; do
DOM="domaine-$N.com"
echo $DOM
openssl req -newkey rsa:1024 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out /tmp/$DOM.crt \
-keyout /tmp/$DOM.key \
-extensions san \
-config <(echo '[req]'; echo 'distinguished_name=req';
echo '[san]'; echo "subjectAltName=DNS:$DOM, DNS:www.$DOM,DNS:mail.$DOM,DNS:cpanel.$DOM,DNS:webmail.$DOM") \
-subj "/C=FR/ST=Lima/L=Lima/O=TESTING /OU=IT Department/CN=$DOM" > /dev/null 2>&1
redis-cli -h $REDIS_HOST HSET $DOM originalBackendIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM isSslAvailable 1 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM mainDomain $DOM > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslPort 4430 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM listenToIp $SELF_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassProtocol http > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassPort 8081 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM sslCaBundle "" > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslProtocol https > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslKey </tmp/$DOM.key > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslCrt </tmp/$DOM.crt > /dev/null
cat /tmp/$DOM.key /tmp/$DOM.crt | redis-cli -h $REDIS_HOST -x HSET $DOM rawSslContent > /dev/null
done
# Wilcard sub domain
echo "Wildcard sub domain"
DOM='*.wildcard.com'
openssl req -newkey rsa:1024 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out /tmp/wildcard.crt \
-keyout /tmp/wildcard.key \
-subj "/C=FR/ST=Lima/L=Lima/O=TESTING /OU=IT Department/CN=$DOM" > /dev/null 2>&1
redis-cli -h $REDIS_HOST HSET $DOM originalBackendIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM isSslAvailable 1 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM mainDomain $DOM > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslPort 4430 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM listenToIp $SELF_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassProtocol http > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassPort 8081 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM sslCaBundle "" > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslProtocol https > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslKey </tmp/wildcard.key > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslCrt </tmp/wildcard.crt > /dev/null
cat /tmp/wildcard.key /tmp/wildcard.crt | redis-cli -h $REDIS_HOST -x HSET $DOM rawSslContent > /dev/null
# Domain that redirect to the TEST_SUITE container, so we have PHP to DUMP the $_SERVER and check if some ENV variable
# are passed by Openresty
# Also allow us to test SSL offloading
echo "Dynamic domain"
DOM='dynamic.com'
openssl req -newkey rsa:1024 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out /tmp/wildcard.crt \
-keyout /tmp/wildcard.key \
-subj "/C=FR/ST=Lima/L=Lima/O=TESTING /OU=IT Department/CN=$DOM" > /dev/null 2>&1
redis-cli -h $REDIS_HOST HSET $DOM originalBackendIp $TEST_SUITE_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM isSslAvailable 1 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM mainDomain $DOM > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassIp $TEST_SUITE_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslPort 8000 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM listenToIp $SELF_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassProtocol http > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassPort 8000 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM sslCaBundle "" > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslIp $TEST_SUITE_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslProtocol http > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslKey </tmp/wildcard.key > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslCrt </tmp/wildcard.crt > /dev/null
cat /tmp/wildcard.key /tmp/wildcard.crt | redis-cli -h $REDIS_HOST -x HSET $DOM rawSslContent > /dev/null
# Default Vhost
echo "Default Vhost"
DOM=default
openssl req -newkey rsa:1024 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out /tmp/$DOM.crt \
-keyout /tmp/$DOM.key \
-extensions san \
-config <(echo '[req]'; echo 'distinguished_name=req';
echo '[san]'; echo "subjectAltName=DNS:$DOM, DNS:www.$DOM,DNS:mail.$DOM,DNS:cpanel.$DOM,DNS:webmail.$DOM") \
-subj "/C=FR/ST=Lima/L=Lima/O=TESTING /OU=IT Department/CN=$DOM" > /dev/null 2>&1
redis-cli -h $REDIS_HOST HSET $DOM originalBackendIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM isSslAvailable 1 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM mainDomain $DOM > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslPort 4430 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM listenToIp $SELF_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassProtocol http > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassPort 8081 > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM sslCaBundle "" > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslIp $HTTPD_IP > /dev/null
redis-cli -h $REDIS_HOST HSET $DOM proxyPassSslProtocol https > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslKey </tmp/$DOM.key > /dev/null
redis-cli -h $REDIS_HOST -x HSET $DOM sslCrt </tmp/$DOM.crt > /dev/null
cat /tmp/$DOM.key /tmp/$DOM.crt | redis-cli -h $REDIS_HOST -x HSET $DOM rawSslContent > /dev/null
test -e /etc/nginx/openresty/lua/lib/o2switch_config.lua.bkp || cp -vaR /etc/nginx/openresty/lua/lib/o2switch_config.lua /etc/nginx/openresty/lua/lib/o2switch_config.lua.bkp
test -e /etc/nginx/openresty/lua/lib/o2switch_config.lua && rm -f /etc/nginx/openresty/lua/lib/o2switch_config.lua
cp -va /etc/nginx/openresty/tests/openresty/o2switch_config.lua /etc/nginx/openresty/lua/lib/o2switch_config.lua
sed -i "s/##redisHost##/$REDIS_IP/" /etc/nginx/openresty/lua/lib/o2switch_config.lua
sed -i "s/##redisPort##/6379/" /etc/nginx/openresty/lua/lib/o2switch_config.lua
sed -i "s/##redisPass##/nil/" /etc/nginx/openresty/lua/lib/o2switch_config.lua
/usr/local/openresty/nginx/sbin/nginx -c /etc/nginx/openresty/nginx.conf
echo -e ""
echo -e "Redis KEYS:"
redis-cli -h $REDIS_HOST KEYS '*'
echo -e ""
echo -e "Tail -f logs:"
tail -qfn0 /var/log/oblig/web /var/log/openrestyerror.log
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists