Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created May 8, 2017 17:23
Show Gist options
  • Select an option

  • Save jeffotoni/eaf6e8b3174ed72f22c2e4f4299ffbbf to your computer and use it in GitHub Desktop.

Select an option

Save jeffotoni/eaf6e8b3174ed72f22c2e4f4299ffbbf to your computer and use it in GitHub Desktop.
#!/bin/bash
clear
tput setaf 7 ; tput setab 1 ; tput bold ; printf '%35s%s%-20s\n' "VPS Management 4.2 © @Nilbertocs" ; tput sgr0
tput setaf 6 ; tput bold ; echo "" ; echo "Este script irá:" ; echo ""
echo "● Instalar e configurar o proxy squid nas portas 80, 3128, 8080 e 8799"
echo "● Configurar o OpenSSH para rodar nas portas 22 e 443"
echo "● Instalar e Configurar o OpenVPN"
echo "● Instalar um conjunto de scripts como comandos do sistema para o gerenciamento" ; tput sgr0
echo ""
tput setaf 3 ; tput bold ; read -n 1 -s -p "Aperte qualquer tecla para continuar..." ; echo "" ; echo "" ; tput sgr0
IP=$(wget -qO- ipv4.icanhazip.com)
tput setaf 3 ; tput bold ; read -p "Confirme o IP deste servidor: " -e -i $IP ipdovps tput sgr0
if [ -z "$ipdovps" ]
then
tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "" ; echo " Você não digitou o IP deste servidor. Tente novamente. " ; echo "" ; echo "" ; tput sgr0
exit 1
fi
clear
if [ -f "/root/usuarios.db" ]
then
tput setaf 6 ; tput bold ; echo ""
echo "Uma base de dados de usuários SSH foi encontrada!"
tput setaf 6 ; tput bold ; echo ""
echo "[1] Manter Base de Dados Atual"
echo "[2] Criar uma Nova Base de Dados"
echo "" ; tput sgr0
read -p "Opção?: " -e -i 1 optiondb
else
awk -F : '$3 >= 500 { print $1 " 1" }' /etc/passwd | grep -v '^nobody' > /root/usuarios.db
fi
clear
if [ -f "/root/openclientes.db" ]
then
tput setaf 6 ; tput bold ; echo ""
echo "Uma base de dados de usuários OpenVPN foi encontrada!"
tput setaf 6 ; tput bold ; echo ""
echo "[1] Manter Base de Dados Atual"
echo "[2] Criar uma Nova Base de Dados"
echo "" ; tput sgr0
read -p "Opção?: " -e -i 1 optiondb
else
awk -F : '$3 >= 500 { print $1 " 1" }' /etc/passwd | grep -v '^nobody' > /root/openclientes.db
fi
echo ""
tput setaf 3 ; tput bold ; read -p "Ativar a compressão SSH (pode aumentar o consumo de RAM)? [s/n]) " -e -i n sshcompression tput sgr0
echo ""
clear
tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Aguarde a configuração automática" ; echo "" ; tput sgr0
sleep 3
tput setaf 6
apt-get update -y
apt-get upgrade -y
rm /bin/criarusuario /bin/expcleaner /bin/sshlimiter /bin/addhost /bin/listar /bin/sshmonitor /bin/ajuda > /dev/null
rm /root/ExpCleaner.sh /root/CriarUsuario.sh /root/sshlimiter.sh > /dev/null
apt-get install squid3 bc screen nano unzip git dos2unix wget htop nload python-pip -y
pip install speedtest-cli
killall apache2
apt-get purge apache2 -y
if [ -f "/usr/sbin/ufw" ] ; then
ufw allow 443/tcp ; ufw allow 80/tcp ; ufw allow 3128/tcp ; ufw allow 8799/tcp ; ufw allow 8080/tcp
fi
if [ -d "/etc/squid3/" ]
then
wget http://nnet.comlu.com/vpsmanagement/squid1.text -O /tmp/sqd1
echo "acl url3 dstdomain -i $ipdovps" > /tmp/sqd2
wget http://nnet.comlu.com/vpsmanagement/squid2.text -O /tmp/sqd3
cat /tmp/sqd1 /tmp/sqd2 /tmp/sqd3 > /etc/squid3/squid.conf
wget http://nnet.comlu.com/vpsmanagement/payload.text -O /etc/squid3/payload.txt
echo " " >> /etc/squid3/payload.txt
grep -v "^Port 443" /etc/ssh/sshd_config > /tmp/ssh && mv /tmp/ssh /etc/ssh/sshd_config
echo "Port 443" >> /etc/ssh/sshd_config
echo "Banner /etc/banner" >> /etc/ssh/shhd_config
grep -v "^PasswordAuthentication yes" /etc/ssh/sshd_config > /tmp/passlogin && mv /tmp/passlogin /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
rm /bin/addhost
wget http://nnet.comlu.com/vpsmanagement/addhost.sh -O /bin/addhost
chmod +x /bin/addhost
rm /bin/alterarsenha
wget http://nnet.comlu.com/vpsmanagement/alterarsenha.sh -O /bin/alterarsenha
chmod +x /bin/alterarsenha
rm /bin/banner
wget http://nnet.comlu.com/vpsmanagement/banner.sh -O /bin/banner
chmod +x /bin/banner
dos2unix /bin/banner
rm /bin/criarusuario
wget http://nnet.comlu.com/vpsmanagement/criarusuario.sh -O /bin/criarusuario
chmod +x /bin/criarusuario
rm /bin/ delhost
wget http://nnet.comlu.com/vpsmanagement/delhost.sh -O /bin/delhost
chmod +x /bin/delhost
rm /bin/expcleaner
wget http://nnet.comlu.com/vpsmanagement/expcleaner.sh -O /bin/expcleaner
chmod +x /bin/expcleaner
rm /bin/mudardata
wget http://nnet.comlu.com/vpsmanagement/mudardata.sh -O /bin/mudardata
chmod +x /bin/mudardata
rm /bin/remover
wget http://nnet.comlu.com/vpsmanagement/remover.sh -O /bin/remover
chmod +x /bin/remover
rm /bin/sshlimiter
wget http://nnet.comlu.com/vpsmanagement/sshlimiter.sh -O /bin/sshlimiter
chmod +x /bin/sshlimiter
rm /bin/alterarlimite
wget http://nnet.comlu.com/vpsmanagement/alterarlimite.sh -O /bin/alterarlimite
chmod +x /bin/alterarlimite
rm /bin/sshmonitor
wget http://nnet.comlu.com/vpsmanagement/sshmonitor.sh -O /bin/sshmonitor
chmod +x /bin/sshmonitor
rm /bin/udp_unlock
wget http://nnet.comlu.com/vpsmanagement/beta/udp_unlock.sh -O /bin/udp_unlock
chmod +x /bin/udp_unlock
dos2unix /bin/udp_unlock
rm /bin/hostmenu
wget http://nnet.comlu.com/vpsmanagement/hostmenu.sh -O /bin/hostmenu
chmod +x /bin/hostmenu
rm /bin/usersmodmenu
wget http://nnet.comlu.com/vpsmanagement/usersmodmenu.sh -O /bin/usersmodmenu
chmod +x /bin/usersmodmenu
#OpenVPN Install Area
rm /bin/openvpnsetup
rm /bin/openvivo.sh
rm ovinstall
rm -rf /etc/ssh/sshd_config
wget http://nnet.comlu.com/vpsmanager/ovpn2/sshd_config -O /etc/ssh/sshd_config
wget http://nnet.comlu.com/vpsmanager/ovpn2/squidconf
chmod +x squidconf
./squidconf
wget http://nnet.comlu.com/vpsmanager/ovpn2/menu -O /bin/menu
chmod +x /bin/menu
#Comandos de Controle
wget http://nnet.comlu.com/vpsmanager/ovpn2/payloads -O /etc/payloads
wget http://nnet.comlu.com/vpsmanager/ovpn2/alterarsenha -O /bin/alterarsenha
chmod +x /bin/alterarsenha
wget http://nnet.comlu.com/vpsmanager/ovpn2/criarusuario -O /bin/criarusuario
chmod +x /bin/criarusuario
wget http://nnet.comlu.com/vpsmanager/ovpn2/mudardata -O /bin/mudardata
chmod +x /bin/mudardata
wget http://nnet.comlu.com/vpsmanager/ovpn2/remover -O /bin/remover
chmod +x /bin/remover
wget http://nnet.comlu.com/vpsmanager/ovpn2/ajuda -O /bin/ajuda
chmod +x /bin/ajuda
wget http://nnet.comlu.com/vpsmanager/ovpn2/statusvpn -O /bin/statusvpn
chmod +x /bin/statusvpn
ssh-keygen -A
cat /dev/null > ~/.bash_history && history -c
#Fim da Configuração do OpenVPN
if [ ! -f "/etc/init.d/squid3" ]
then
service squid3 reload > /dev/null
else
/etc/init.d/squid3 reload > /dev/null
fi
if [ ! -f "/etc/init.d/ssh" ]
then
service ssh reload > /dev/null
else
/etc/init.d/ssh reload > /dev/null
fi
fi
if [ -d "/etc/squid/" ]
then
wget http://nnet.comlu.com/vpsmanagement/squid1.text -O /tmp/sqd1
echo "acl url3 dstdomain -i $ipdovps" > /tmp/sqd2
wget http://nnet.comlu.com/vpsmanagement/squid.text -O /tmp/sqd3
cat /tmp/sqd1 /tmp/sqd2 /tmp/sqd3 > /etc/squid/squid.conf
wget http://nnet.comlu.com/vpsmanagement/payload.text -O /etc/squid/payload.txt
echo " " >> /etc/squid/payload.txt
grep -v "^Port 443" /etc/ssh/sshd_config > /tmp/ssh && mv /tmp/ssh /etc/ssh/sshd_config
echo "Port 443" >> /etc/ssh/sshd_config
grep -v "^PasswordAuthentication yes" /etc/ssh/sshd_config > /tmp/passlogin && mv /tmp/passlogin /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
wget http://nnet.comlu.com/vpsmanagement/addhost.sh -O /bin/addhost
chmod +x /bin/addhost
wget http://nnet.comlu.com/vpsmanagement/alterarsenha.sh -O /bin/alterarsenha
chmod +x /bin/alterarsenha
wget http://nnet.comlu.com/vpsmanagement/banner.sh -O /bin/banner
chmod +x /bin/banner
dos2unix /bin/banner
wget http://nnet.comlu.com/vpsmanagement/criarusuario.sh -O /bin/criarusuario
chmod +x /bin/criarusuario
wget http://nnet.comlu.com/vpsmanagement/delhost.sh -O /bin/delhost
chmod +x /bin/delhost
wget http://nnet.comlu.com/vpsmanagement/expcleaner.sh -O /bin/expcleaner
chmod +x /bin/expcleaner
wget http://nnet.comlu.com/vpsmanagement/mudardata.sh -O /bin/mudardata
chmod +x /bin/mudardata
wget http://nnet.comlu.com/vpsmanagement/remover.sh -O /bin/remover
chmod +x /bin/remover
wget http://nnet.comlu.com/vpsmanagement/sshlimiter.sh -O /bin/sshlimiter
chmod +x /bin/sshlimiter
wget http://nnet.comlu.com/vpsmanagement/alterarlimite.sh -O /bin/alterarlimite
chmod +x /bin/alterarlimite
wget http://nnet.comlu.com/vpsmanagement/sshmonitor.sh -O /bin/sshmonitor
chmod +x /bin/sshmonitor
wget http://nnet.comlu.com/vpsmanagement/beta/udp_unlock.sh -O /bin/udp_unlock
chmod +x /bin/udp_unlock
dos2unix /bin/udp_unlock
wget http://nnet.comlu.com/vpsmanagement/menu.sh -O /bin/menuSSH
chmod +x /bin/menuSSH
wget http://nnet.comlu.com/vpsmanager/ovpn2/ovinstall
bash ovinstall
if [ ! -f "/etc/init.d/squid" ]
then
service squid reload > /dev/null
else
/etc/init.d/squid reload > /dev/null
fi
if [ ! -f "/etc/init.d/ssh" ]
then
service ssh reload > /dev/null
else
/etc/init.d/ssh reload > /dev/null
fi
fi
rm -rvf vpsmanagement.sh
clear
echo ""
tput setaf 2 ; tput setab 1 ; tput bold ; echo " Script configurado " ; tput sgr0
tput setaf 7 ; tput setab 1 ; tput bold ; echo "Proxy Squid Instalado e rodando nas portas: 80, 3128, 8080 e 8799" ; tput sgr0
tput setaf 7 ; tput setab 1 ; tput bold ; echo "OpenSSH rodando nas portas 22 e 443 " ; tput sgr0
tput setaf 7 ; tput setab 1 ; tput bold ; echo "OpenVPN configurado " ; tput sgr0
tput setaf 7 ; tput setab 1 ; tput bold ; echo "Canal do telegram, para saber de atualizações @NilbertoNNet " ; tput sgr0
tput setaf 7 ; tput setab 1 ; tput bold ; echo "Para iniciar use o comando: menu " ; tput sgr0
echo ""
if [[ "$optiondb" = '2' ]]; then
awk -F : '$3 >= 500 { print $1 " 1" }' /etc/passwd | grep -v '^nobody' > /root/usuarios.db
fi
if [[ "$sshcompression" = 's' ]]; then
grep -v "^Compression yes" /etc/ssh/sshd_config > /tmp/sshcp && mv /tmp/sshcp /etc/ssh/sshd_config
echo "Compression yes" >> /etc/ssh/sshd_config
fi
if [[ "$sshcompression" = 'n' ]]; then
grep -v "^Compression yes" /etc/ssh/sshd_config > /tmp/sshcp && mv /tmp/sshcp /etc/ssh/sshd_config
fi
rm openvivo.sh
rm openvpnssh_setup.sh
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment