Script altera senhas servidores remotamente.

setembro 28, 2012 Deixe um comentário

#!/bin/sh
# =============================================================================================================
#                                              #
# Script para alterar a senha dos servers seven remotamente e automaticamente
#
# Versao: 1.0 BETA
# Modificado: 14/09/2012
# Tecnico Responsavel: Rafael
#
# =============================================================================================================

clear
echo “### SCRIPT ALTERA SENHA DOS SERVIDORES ### ”
echo ”        usuarios admlinux e root ”
echo “”
echo “”

echo  ”    Manualmente em todos os servers:”
echo  ”     -Editar ‘vi /etc/ssh/sshd_config'”
echo  ”     -Alterar ‘PermitRootLogin yes'”
echo  ”     -Inserir ‘AllowUsers root@200.22x.x.xx'”
echo  ”     -Reiniciar ‘ssh /etc/rc.d/rc.sshd restart'”
echo “”
echo “”
sleep 3

echo “Digite 1 – Alterar senha dos servidores Seven”
echo “Digite 2 – Alterar senha dos gateways de clientes”; read digite

####### Alterando a senha de servidores Seven

if [ “$digite” == “1” ]; then

echo “”
echo ” Deseja enviar a chave publica ao servidor (S/N)?”; read decisao

if [ “$decisao” == “S” ]; then

echo “############################################”
echo ” 1 – Enviando chave publica aos servers…”
echo “############################################”
echo “”
echo ” Nao esqueca de manter o arquivo /root/passwd/servers atualizado! ”
echo “”
for servers in `cat /root/passwd/servers`; do
cat /root/.ssh/id_rsa.pub | ssh root@$servers ‘cat – >> /root/.ssh/authorized_keys’ 1>/dev/null 2>/dev/null
done
sleep 3

echo “###############################”
echo ” 2 – Gerando passwd com prefixo…”
echo “###############################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for passwd in `cat /root/passwd/servers` ; do
hashadm=`/root/passwd/randon_pass.pl`
hashroot=`/root/passwd/randon_pass.pl`
echo “$passwd  tjtamb|$hashadm  mgwkym’!’$hashroot” >> /root/passwd/passwd
done
sleep 3

echo “###################################################################”
echo ” 3 – Backup do shadow dos servers em /tmp/shadow-nome_servidor…”
echo “###################################################################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for servers in `cat /root/passwd/servers` ; do
for users in `cat /root/passwd/users`; do
ssh root@$servers ‘cat /etc/shadow’ > /tmp/shadow-$servers 1>/dev/null 2>/dev/null
done
done
sleep 3

echo “#############################################”
echo ” 4 – Alterando a senha de cada servidor…”
echo “#############################################”

# Aliterando a senha do usuario Admlinux
for servers in `cat /root/passwd/passwd  | awk ‘{print$1}’ `; do
echo “Servidor: $servers”
for encontra in `cat /root/passwd/passwd  | grep $servers | awk ‘{print$2}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == admlinux ] ; then
echo “Alterando senha pro user admlinux…”
echo “”

# Caso o servidor seja Redundante
if [ $servers == servidor.com.br ] ; then
ssh root@servidor.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor2.com.br ] ; then
ssh root@servidor2.seven.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor2.seven.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor3.com.br ] ; then
ssh root@servidor3.com.br  “echo ‘$encontra’ | pw user mod admlinux -h 0”
ssh root@servidor3.com.br  “echo ‘$encontra’ | pw user mod admlinux -h 0”

# Caso o servidor seja FreeBSD
elif [ $servers == servidor4.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod admlinux -h 0”
elif [ $servers == servidor5.seven.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod admlinux -h 0”
else

# Caso o servidor seja Linux
ssh root@$servers “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
fi
done
fi
done

#  Alterando a senha do usuario root
echo “Servidor: $servers”
for encontra in `cat /root/passwd/passwd  | grep $servers | awk ‘{print$3}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == root ] ; then
echo “Alterando senha pro user root…”
echo “”

# Caso o servidor seja Redundante
if [ $servers == servidor1.com.br ] ; then
ssh root@servidor1.seven.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor2.seven.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor3.com.br ] ; then
ssh root@servidor4.seven.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor5.seven.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers ==servidor6.com.br ] ; then
ssh root@servidor7.seven.com.br  “echo ‘$encontra’ | pw user mod root -h 0”
ssh root@servidor8.com.br  “echo ‘$encontra’ | pw user mod root -h 0”

# Caso o servidor seja FreeBSD
elif [ $servers == servidor9.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod root -h 0”
elif [ $servers == servidor10.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod root -h 0”
else

# Caso o servidor seja Linux
ssh root@$servers “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
fi
done
fi
done
done

echo””
echo ” Gerando arquivo de passwd…”
cat   /root/passwd/passwd | sed “s/[|,’!’]/ /g” | awk ‘{print$1,$3,$5}’ > /root/passwd/Senhas.txt
echo “Arquivo gerado em /root/passwd/Senhas.txt ”
echo””

echo > /root/passwd/passwd

elif  [ “$decisao” == “N” ]; then

echo “###############################”
echo ” 2 – Gerando passwd com prefixo…”
echo “###############################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for passwd in `cat /root/passwd/servers` ; do
hashadm=`/root/passwd/randon_pass.pl`
hashroot=`/root/passwd/randon_pass.pl`
echo “$passwd  tjtamb|$hashadm  mgwkym’!’$hashroot” >> /root/passwd/passwd
done
sleep 3

echo “###################################################################”
echo ” 3 – Backup do shadow dos servers em /tmp/shadow-nome_servidor…”
echo “###################################################################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for servers in `cat /root/passwd/servers` ; do
for users in `cat /root/passwd/users`; do
ssh root@$servers ‘cat /etc/shadow’ > /tmp/shadow-$servers 1>/dev/null 2>/dev/null
done
done
sleep 3

echo “#############################################”
echo ” 4 – Alterando a senha de cada servidor…”
echo “#############################################”

# Aletrando a senha do usuario Admlinux
for servers in `cat /root/passwd/passwd  | awk ‘{print$1}’ `; do
echo “Servidor: $servers”
for encontra in `cat /root/passwd/passwd  | grep $servers | awk ‘{print$2}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == admlinux ] ; then
echo “Alterando senha pro user admlinux…”
echo “”

# Caso o servidor seja Redundante
if [ $servers == servidor.com.br ] ; then
ssh admlinux@servidor1.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh admlinux@servidor2.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servido3.com.br ] ; then
ssh admlinux@servidor4.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh admlinux@servidor5.com.br “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor7.com.br ] ; then
ssh admlinux@servidor8.com.br  “echo ‘$encontra’ | pw user mod admlinux -h 0”
ssh admlinux@servidor9.com.br  “echo ‘$encontra’ | pw user mod admlinux -h 0”

# Caso o servidor seja FreeBSD
elif [ $servers == servidor10.com.br ] ; then
ssh admlinux@$servers  “echo ‘$encontra’ | pw user mod admlinux -h 0”
elif [ $servers == servidor11.com.br ] ; then
ssh admlinux@$servers  “echo ‘$encontra’ | pw user mod admlinux -h 0”
else

# Caso o servidor seja Linux
ssh root@$servers “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
fi
done
fi
done

# Aletrando a senha do usuario root
echo “Servidor: $servers”
for encontra in `cat /root/passwd/passwd  | grep $servers | awk ‘{print$3}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == root ] ; then
echo “Alterando senha pro user root…”
echo “”

# Caso o servidor seja Redundante
if [ $servers == servidor.com.br ] ; then
ssh root@servidor1.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor2.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor3.com.br ] ; then
ssh root@servidor4.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
ssh root@servidor5.com.br “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
elif [ $servers == servidor7.com.br ] ; then
ssh root@servidor8.com.br  “echo ‘$encontra’ | pw user mod root -h 0”
ssh root@servidor9.com.br  “echo ‘$encontra’ | pw user mod root -h 0”

# Caso o servidor seja FreeBSD
elif [ $servers == servidor10.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod root -h 0”
elif [ $servers == servidor11.com.br ] ; then
ssh root@$servers  “echo ‘$encontra’ | pw user mod root -h 0”
else

# Caso o servidor seja Linux
ssh root@$servers “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
fi
done
fi
done
done

echo””
echo ” Gerando arquivo de passwd…”
cat   /root/passwd/passwd | sed “s/[|,’!’]/ /g” | awk ‘{print$1,$3,$5}’ > /root/passwd/Senhas.txt
echo “Arquivo gerado em /root/passwd/Senhas.txt ”
echo””

echo > /root/passwd/passwd

# Exige condicao correta
elif [ “$decisao” = “” ]; then
echo ” Opcao desconhecida, voce precisa digitar uma palavra ”
else
echo “digite S ou N:”

fi

########## Alterando a senha de Gateways

elif [ “$digite” = “2” ]; then
echo “”
echo ” Deseja enviar a chave publica ao gateway (S/N)?”; read decisao

if [ “$decisao” == “S” ]; then

echo “############################################”
echo ” 1 – Enviando chave publica aos gateways…”
echo “############################################”
echo “”
echo ” Nao esqueca de manter o arquivo /root/passwd/gateways atualizado! ”
echo “”
for gateways in `cat /root/passwd/gateways`; do
cat /root/.ssh/id_rsa.pub | ssh root@$gateways ‘cat – >> /root/.ssh/authorized_keys’ 1>/dev/null 2>/dev/null
done
sleep 3

echo “###############################”
echo ” 2 – Gerando passwd com prefixo…”
echo “###############################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for passwd in `cat /root/passwd/gateways` ; do
hashadm=`/root/passwd/randon_pass.pl`
hashroot=`/root/passwd/randon_pass.pl`
echo “$passwd #Ulk[$hashadm  xm3N]$hashroot” >> /root/passwd/passwd
done
sleep 3

echo “###################################################################”
echo ” 3 – Backup do shadow dos gateways em /tmp/shadow-nome_gateway…”
echo “###################################################################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for gateways in `cat /root/passwd/gateways` ; do
for users in `cat /root/passwd/users`; do
ssh root@$gateways ‘cat /etc/shadow’ > /tmp/shadow-$gateways 1>/dev/null 2>/dev/null
done
done
sleep 3

echo “#############################################”
echo ” 4 – Alterando a senha de cada gateway…”
echo “#############################################”

# Aletrando a senha do usuario Admlinux
for gateways in `cat /root/passwd/passwd  | awk ‘{print$1}’ `; do
echo “Gateway: $gateways”
for encontra in `cat /root/passwd/passwd  | grep $gateways | awk ‘{print$2}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == admlinux ] ; then
echo “Alterando senha pro user admlinux…”
echo “”
ssh root@$gateways “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
done
fi
done

# Aletrando a senha do usuario root
echo “Gateway: $gateways”
for encontra in `cat /root/passwd/passwd  | grep $gateways | awk ‘{print$3}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == root ] ; then
echo “Alterando senha pro user root…”
echo “”
ssh root@$gateways “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
done
fi
done
done

echo””
echo ” Gerando arquivo de passwd…”
cat   /root/passwd/passwd | awk ‘{print$1,$2,$3}’ > /root/passwd/Senhas.txt
echo “Arquivo gerado em /root/passwd/Senhas.txt ”
echo””

echo > /root/passwd/passwd

elif  [ “$decisao” == “N” ]; then

echo “###############################”
echo ” 2 – Gerando passwd com prefixo…”
echo “###############################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for passwd in `cat /root/passwd/gateways` ; do
hashadm=`/root/passwd/randon_pass.pl`
hashroot=`/root/passwd/randon_pass.pl`
echo “$passwd  #Ulk[$hashadm  xm3N]$hashroot” >> /root/passwd/passwd
done
sleep 3

echo “###################################################################”
echo ” 3 – Backup do shadow dos gateways em /tmp/shadow-nome_gateway…”
echo “###################################################################”
echo “”
echo ” Arquivo gerado automaticamente ”
echo “”
for gateways in `cat /root/passwd/gateways` ; do
for users in `cat /root/passwd/users`; do
ssh root@$gateways ‘cat /etc/shadow’ > /tmp/shadow-$gateways 1>/dev/null 2>/dev/null
done
done
sleep 3

echo “#############################################”
echo ” 4 – Alterando a senha de cada gateway…”
echo “#############################################”

# Aletrando a senha do usuario Admlinux
for gateways in `cat /root/passwd/passwd  | awk ‘{print$1}’ `; do
echo “Gateway: $gateways”
for encontra in `cat /root/passwd/passwd  | grep $gateways | awk ‘{print$2}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == admlinux ] ; then
echo “Alterando senha pro user admlinux…”
echo “”
ssh root@$gateways “echo admlinux:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
done
fi
done

# Aletrando a senha do usuario root
echo “Gateway: $gateways”
for encontra in `cat /root/passwd/passwd  | grep $gateways | awk ‘{print$3}’`; do
if [ -n $encontra ] ; then
for users in `cat /root/passwd/users | sed “s/\r//g”`; do
if [ $users == root ] ; then
echo “Alterando senha pro user root…”
echo “”
ssh root@$gateways “echo root:’$encontra’ | chpasswd”  1>/dev/null 2>/dev/null
fi
done
fi
done
done

echo””
echo ” Gerando arquivo de passwd…”
cat   /root/passwd/passwd | awk ‘{print$1,$2,$3}’ > /root/passwd/Senhas.txt
echo “Arquivo gerado em /root/passwd/Senhas.txt ”
echo””

echo > /root/passwd/passwd

# Exige condicao correta
elif [ “$decisao” = “” ]; then
echo ” Opcao desconhecida, voce precisa digitar uma palavra ”
else
echo “digite S ou N:”

fi

# Exige condicao correta
elif [ “$digite” = “” ]; then
echo ” Opcao desconhecida, voce precisa digitar 1 ou 2″
else
echo “digite 1 ou 2:”

fi

Anúncios
Categorias:Uncategorized

Instalando MRTG

agosto 31, 2012 Deixe um comentário

#!/bin/sh

# =============================================================================================================

#

# Script para criacao de Graficos com MRTG

#

# Versao: 1.0

# Modificado: 28/08/2012

#

# Baseado em slackware

=============================================================================================================

#

clear

echo “######################”

echo ”    Instala MRTG”

echo “######################”

sleep 3

 

echo “##################################”

echo “Removendo pacotes conflitantes…”

echo “#################################”

removepkg libpng

removepkg gd

sleep 2

clear

 

echo “##################################”

echo “Instalando zlib…”

echo “##################################”

cd /usr/local/src/

version1=`lynx -dump http://www.zlib.net/ | grep tar.gz | head -3 | tail -1 | awk ‘{print$2}’ | sed “s/[a-z,/,-]//g” | cut -c 3-7`

wget -q http://www.zlib.net/zlib-$version1.tar.gz

gunzip -c zlib-*.tar.gz | tar xf –

rm zlib-*.tar.gz

mv zlib-* zlib

cd zlib

env CFLAGS=”-O6 -march=x86-64″ ; ./configure

make

make install

rehash

ldconfig

cd ..

clear

sleep 2

 

echo “##################################”

echo “Instalando libpng…”

echo “##################################”

cd /usr/local/src/

version2=`lynx -dump ftp://ftp.simplesystems.org/pub/libpng/png/src | grep tar.gz | grep png | tail -2 | head -1 | awk ‘{print$2}’ | sed “s/[a-z,/,-]//g” | cut -c 4-9`

wget -q ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$version2.tar.gz

gunzip -c libpng-$version2.tar.gz | tar xf –

rm libpng-*.tar.gz

mv libpng-* libpng

cd libpng

env CFLAGS=”-O6 -march=x86-64 -fPIC” ./configure –prefix=/usr/local/

make

make install

rehash

ldconfig

cd ..

clear

sleep 2

 

echo “##################################”

echo “Instalando gd…”

echo “##################################”

cd /usr/local/src/

wget -q http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

gunzip -c gd-2.0.33.tar.gz | tar xf –

rm gd-*.tar.gz

mv gd-2.0.33 gd

cd gd

env CFLAGS=”-O6 -march=x86-64″ CPPFLAGS=”-I../zlib -I../libpng” LDFLAGS=”-L../zlib -L../libpng” ./configure –disable-shared –without-freetype –without-jpeg

make

make install

cp .libs/* .

rehash

ldconfig

cd ..

clear

sleep 2

 

echo “##################################”

echo “Instalando mrtg…”

echo “##################################”

cd /usr/local/src/

version5=`lynx -dump http://oss.oetiker.ch/mrtg/pub | grep tar.gz | head -4 | tail -1 | awk ‘{print$2}’ | sed “s/[a-z,/,-]//g” | cut -c 5-10`

wget -q http://oss.oetiker.ch/mrtg/pub/mrtg-$version5.tar.gz

tar -zxf mrtg-$version5.tar.gz

rm mrtg-$version5.tar.gz

mv mrtg-$version5 mrtg

cd mrtg

env CFLAGS=”-O6 -march=x86-64″ ; ./configure –prefix=/usr/local/mrtg-2 –with-gd=/usr/local/src/gd –with-z=/usr/local/src/zlib –with-png=/usr/local/src/libpng

make

make install

rehash

ldconfig

cd ..

clear

sleep 2

 

#echo “##################################”

#echo “Instalando snmp…”

#echo “##################################”

#version3=`lynx -dump http://www.net-snmp.org/download.html | grep source | head -n 1 | awk ‘{print$1}’`

#wget -q http://downloads.sourceforge.net/project/net-snmp/net-snmp/$version3/net-snmp-$version3.tar.gz

#tar -zxf net-snmp-*.tar.gz

#rm net-snmp-*.tar.gz

#mv net-snmp-$version3 snmp

#cd snmp/

#env CFLAGS=”-O6 -march=x86-64″ ; ./configure

#make

#make install

#rehash

#ldconfig

 

/bin/cat <<EOF >/usr/local/share/snmp/snmpd.conf

# snmpd.conf

###########################################################################

#       sec.name   source            community

com2sec theworld  127.0.0.1/32   snmpseven

group MyROGroup v1         theworld

group MyROGroup v2c        theworld

#           incl/excl subtree                          mask

view all    included  .1                               80

#                context sec.model sec.level prefix read   write  notif

access MyROGroup “”      any       noauth    exact      all    none   none

######################### Fim snmp.conf ####################################

EOF

 

#/bin/cat <<EOF >/etc/rc.d/rc.snmp

##!/bin/sh

# # Start the SNMP server:

# if [ -f /usr/local/share/snmp/snmpd.conf ]; then

#   echo “Starting SNMP daemon…”

#   /usr/local/sbin/snmpd

# fi

#EOF

#chmod +x /etc/rc.d/rc.snmp

#/etc/rc.d/rc.snmp

/etc/rc.d/rc.snmp restart

sleep 2

 

 

echo “##################################”

echo “Iniciando MRTG…”

echo “##################################”

/usr/local/src/mrtg/bin/cfgmaker –global ‘WorkDir: /usr/local/mrtg-2/bin/webmin.cfg’ –global ‘Options[_]: bits,growright’ –output /usr/local/mrtg-2/bin/webmin.cfg snmpseven@localhost

/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/bin/webmin.cfg

cd ..

/bin/cat <<EOF >/etc/rc.d/rc.mrtg

#!/bin/sh

# Start the MRTG:

echo “Starting MRTG daemon…”

/usr/local/bin/perl -w /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/bin/webmin.cfg

EOF

chmod +x /etc/rc.d/rc.mrtg

sh /etc/rc.d/rc.mrtg

echo /etc/rc.d/rc.mrtg >> /etc/rc.d/rc.local

clear

sleep 2

 

echo “##################################”

echo “Instalando webmin…”

echo “##################################”

version4=`lynx -dump http://www.webmin.com/download.html | grep tar | grep webmin | head -1 | sed “s/[a-z,A-Z/,-]//g” | cut -c 11-15`

wget -q http://downloads.sourceforge.net/project/webadmin/webmin/$version4/webmin-$version4.tar.gz

tar -zxf webmin-$version4.tar.gz

mv webmin-$version4 webmin

cd webmin

sh setup.sh

cd ..

clear

sleep 2

 

echo “##################################”

echo “Baixando modulo webmin MRTG…”

echo “##################################”

wget -q http://www.jla.homepage.t-online.de/pub/webmin/mrtg-0.2p3.wbm

 

echo “#####################”

echo “FIM”

echo “######################”

Categorias:Uncategorized

Configurando o PHP para conectar com banco Microsoft SQL Server

abril 23, 2012 Deixe um comentário

Configurando o PHP para conectar com banco Microsoft SQL Server

Sources necessários que foram compilados ( nesta ordem de compilção ):

1 – openssl-1.0.1a       ( obs: dependência para o cyrus )

2 – cyrus-sasl-2.1.25   ( obs: dependência para o http )

3 – freetype-2.4.8    ( obs: dependência para o php )

4 – unixODBC-2.3.1

5 – freetds-0.91

6 – httpd-2.2.22

7 – php-5.3.10

Os sources FreeTDS e o UnixODBC  são os responsáveis por todo o funcionamento deste esquema,  abaixo algumas explicações:

FreeTDS é uma biblioteca que permite  que diversas linguagens de programção consigam se comunicar com o Microsoft SQL Server

UnixODBC é um projeto open source que implementa a API ODBC,  um ODBC é um drive genérico,   um padrão para acesso a

sistemas que gerenciam bancos de dados. O FreeTDS faz uso do UnixODBC.

1 – Openssl

./config –prefix=/usr shared

make && make install

cd /usr/lib
ln -s libssl.so.* libssl.so.0
ln -s libcrypto.so.* libcrypto.so.0
cd /usr/lib64
mv /usr/lib/libssl.* ./
mv /usr/lib/libcrypto.* ./
ldconfig

2 –  Cyrus-sasl

./configure && make && make install

3 – freetype

./configure && make && make install

4 – unixODBC

./configure –prefix=/usr/local –enable-gui=no

make && make install

5 – freetds

./configure –with-tdsver=8.0 –with-unixodbc=/usr/local

make && make install

6 – Http

./configure –prefix=/usr/local/etc/httpd –enable-rewrite –enable-module=so –enable-ssl –enable-auth-digest –with-mpm=prefork –enable-unique-id

make && make install

7 – PHP

./configure –with-apxs2=/usr/local/etc/httpd/bin/apxs –with-mysql –with-mssql=/usr/local –with-config-file-path=/usr/local/etc/httpd/conf –with-libxml-dir –with-openssl –enable-calendar –with-curl –with-bz2 –with-gd –with-freetype-dir –enable-gd-native-ttf –enable-zip –with-jpeg-dir –enable-mbstring –with-zlib –with-mcrypt –with-unixODBC

make && make install

em /usr/local/etc/httpd/htdocs

index.php, com o conteúdo:

<?php
mssql_connect(“nome-drive-setado-no-freetds.conf”, “user”, “senha”)
or die(“Falha na conexao com o servidor”);
mssql_select_db(“BANCO”)
or die(“Falha na selecao do banco de dados”);
mssql_close();
print “Conexao Estabelecida”;
?>

no mime no httpd.conf

AddType application/x-httpd-php .php .phtml .php3 .phtm .inc

em /usr/local/etc/freetds.conf

# A typical Sybase server
[drive]
host = 200.229.2.125
port = 1433
tds version = 8.0

teste inicial sem usar o php:

tsql -S drive -U user -P ‘senha’ -D BANCO

1> SELECT @@version
2> go
1> quit

Em caso positivo acesse o servidor via web , deverá aparecer a seguinte mensagem no navegador:

“Conexao Estabelecida”

Categorias:Uncategorized

Gerenciando resolv.conf com duas operadoras – IP’s dinâmicos

janeiro 2, 2012 Deixe um comentário

#!/bin/sh
#################################################################
# Gerencia resolv.conf versao 1.0 Rafael
# Duas operadoras fornecem DNS ( velox e net )
# Define DNS no resolv.conf baseado no link down ( failover.sh )
#################################################################

# Limpa arquivo failover que aponta qual link esta down
echo > /var/log/failover.log

sleep 10

# Mostra qual link esta down
i=`cat /var/log/failover.log`

# Caso o link que esteja down seja o da Netvirtua seta DNS Telemar Velox
if [ “$i”=”net Down” ]; then

echo > /etc/resolv.conf
echo “nameserver 200.165.132.148” >> /etc/resolv.conf
echo “nameserver 200.165.132.155” >> /etc/resolv.conf

# Reset Squid necessario para o servico normalizar
/usr/local/squid/sbin/squid -k reconfigure
else

# Caso o link que esteja down seja o Velox seta DNS NetVirtua
echo > /etc/resolv.conf
echo “nameserver 201.17.128.23” >> /etc/resolv.conf
echo “nameserver 201.17.128.14” >> /etc/resolv.conf

# Reset Squid necessario para o servico normalizar
/usr/local/squid/sbin/squid -k reconfigure

fi

Categorias:Uncategorized

IPFW Básico

dezembro 18, 2011 Deixe um comentário

IPFW Básico

 

#!/bin/sh
#Firewall
#Rafael Isac rafael.isac@yahoo.com.br

######Esvaziando firewall
ipfw -f flush

######Valores
ext_if=”tun0″
int_if=”vr0″
lan=”192.168.0.0/24″
ipfw=”/sbin/ipfw -q”

############################## SISTEMA ################################

# Libera localhost e Proibe acesso a loopback
$ipfw add allow ip from any to any via lo0
$ipfw add deny ip from any to 127.0.0.0/8
$ipfw add deny ip from 127.0.0.0/8 to any

############################## SEGURANCA ###############################

# Proibe IP fragments to allow through
$ipfw add deny log all from any to any frag

# Proibe spoofing
$ipfw add deny log ip from any to any in via $ext_if not verrevpath
$ipfw add deny log ip from any to any in via $ext_if not antispoof

# Nega entrando todas as redes nao validas ( spoofing )
$ipfw add deny all from 172.16.0.0/12 to any via $ext_if
$ipfw add deny all from 10.0.0.0/8 to any via $ext_if
$ipfw add deny all from 127.0.0.0/8 to any via $ext_if
$ipfw add deny all from 0.0.0.0/8 to any via $ext_if
$ipfw add deny all from 169.254.0.0/16 to any via $ext_if
$ipfw add deny all from 192.0.2.0/24 to any via $ext_if
$ipfw add deny all from 204.152.64.0/23 to any via $ext_if
$ipfw add deny all from 224.0.0.0/3 to any via $ext_if

########################### PROXY ########################################
########################### PROXY ########################################

# Sites que nao allowam pelo proxy sao desviados aqui
$ipfw add skipto 40000 ip from $lan to 67.15.2.43/32
$ipfw add skipto 40000 ip from $lan to 200.201.128.0/17
$ipfw add skipto 40000 ip from $lan to 200.201.173.68/32
$ipfw add skipto 40000 ip from $lan to 161.148.185.46/32
$ipfw add skipto 40000 ip from $lan to 200.209.70.130/32
$ipfw add skipto 40000 ip from $lan to 207.44.142.6/32
$ipfw add skipto 40000 ip from $lan to 200.150.7.27
$ipfw add skipto 40000 ip from $lan to 201.48.145.0/24
$ipfw add skipto 40000 ip from $lan to 216.205.78.110/32
$ipfw add skipto 40000 ip from $lan to 200.201.173.68/32
$ipfw add skipto 40000 ip from $lan to 200.152.32.144
$ipfw add skipto 40000 ip from $lan to 64.233.163.147
$ipfw add skipto 40000 ip from $lan to 200.198.239.70
$ipfw add skipto 40000 ip from $lan to 72.26.224.77
$ipfw add skipto 40000 ip from $lan to 201.48.145.121
$ipfw add skipto 40000 ip from $lan to 200.152.32.0/20

# Proxy transparent
$ipfw add fwd 127.0.0.1,3128 tcp from any to any 80 via $int_if

############################## NAT ######################################

# Nat
$ipfw add 40000 divert 8668 ip from any to any via $ext_if

############################ FIREWALL DINAMICO ##################################

# Regras statefull
$ipfw add check-state

############################# INTERNET ###################################

# **** > Trafego entrante

# Define trafego Entrando pela interface Externa ( somente resposta de ping e traceroute )
$ipfw add allow icmp from any to me in via $ext_if icmptypes 0,11 keep-state
# Libera TS pro Rodrigo
$ipfw add allow tcp from any to me dst-port 3395 in via $ext_if setup keep-state
# Libera SSH pra mim ( ssh nao aceita setup statefull )
$ipfw add allow tcp from any to me dst-port 2222 in via $ext_if keep-state

# < *** Trafego saindo
# Define trafego Saindo pela interface Externa ( icmp somente ping e traceroute
$ipfw add allow tcp from any to any out via $ext_if setup keep-state
$ipfw add allow udp from any to any out via $ext_if keep-state
$ipfw add allow icmp from any to any out via $ext_if icmptypes 3,8 keep-state

############################# REDE LOCAL ############################################

# Libera tudo interface Interna
$ipfw add allow all from any to any via $int_if keep-state

############################# POLITICA #######################################

# Fecha firewall e loga o que bloquear
$ipfw add deny log all from any to any

Categorias:Uncategorized

Postfix Manager Logs v.3.0

dezembro 1, 2011 Deixe um comentário

#!/bin/sh
#
#
# Trechos de comandos em shell que checa emails enviados ou recebidos nos logs do servidor
#
# Versao: 3.0
# =============================================================================================================

clear
echo -e “33[41;1;37m ************************************************** 33[0m”
echo -e “33[41;1;37m Postfix Manager Logs – Seven Internet v.3.0 33[0m”
echo -e “33[41;1;37m ************************************************** 33[0m”

# Limpa arquivos envolvidos nas buscas a cada nova execucao para pesquisa.
echo > /usr/local/etc/.log-mail
echo > /usr/local/etc/.id-inicio
echo > /usr/local/etc/.id-email
echo > /usr/local/etc/.maillog
echo > /usr/local/etc/.tela

echo “”
# Menu digite a data a ser pesquisado.
echo “Formato das datas:”
echo “Jan”
echo “Feb”
echo “Mor”
echo “Apr”
echo “May”
echo “Jun”
echo “Jul”
echo “Aug”
echo “Sep”
echo “Oct”
echo “Nov”
echo “Dec”
echo “”

echo -e ” 33[1;32m Digite a data de postagem do email que deseja pesquisar nos logs:[Sep01] (Quer dizer 01 de setembro) 33[0m”; read data # variavel que guarda a data

for log in `ls -lah /var/log/ | grep -i ‘maillog.*.bz2’ | awk ‘{print $9, $6$7 }’ | grep $data | awk ‘{print$1}’`; do
echo -e ” 33[1;32m Digite o e-mail que deseja pesquisar nos logs seja remetente ou destinatario: 33[0m”; read email # variavel que guarda o email
result=`bzcat /var/log/$log | grep -i $email`
echo $log $data $result >> /usr/local/etc/.log-mail
`bzcat /var/log/$log | grep -i $email | awk ‘{print$6}’ >> /usr/local/etc/.id-inicio`
done

# Trata os ids dos emails existentes nos logs para checagem abaixo
printf “$(awk ‘!i[$0]++’ /usr/local/etc/.id-inicio) \n” > /usr/local/etc/.id-email
echo “”
echo -e “33[41;1;37m ************************************************************************** 33[0m”
echo -e “33[41;1;37m Aguarde…Abrindo os ids das mensagens e salvando os resultados 33[0m”
echo -e “33[41;1;37m ************************************************************************** 33[0m”

# laco que checa quantidade de mensagens encontradas, os logs correspondentes, o ids das mensagens ja tratados, resultado gerado no arquivo /usr/local/etc/.maillog.
for qtdlog in `cat /usr/local/etc/.log-mail | grep parodius | awk ‘{print$1}’ | wc | awk ‘{print$1}’`; do
for numerolog in `cat /usr/local/etc/.log-mail | grep parodius | awk ‘{print$1}’`; do
for id in `cat /usr/local/etc/.id-email | sed “s/[:]//g” | grep -v module=Quotas`; do
result2=`bzcat /var/log/$numerolog | grep -i $id` #Pesquisa final, abre o conteudo do id encontrado e joga no arquivo .maillog.
echo $result2 >> /usr/local/etc/.maillog
done
done
done
echo “”
# proxima versao pergunta os meses que voce quer checar de logs pra nao pegar tudo e perder tempo.
echo -e “33[41;1;37m ******************************************************************************************************* 33[0m”
echo -e “33[41;1;37m Resultado da pesquisa gerado com sucesso! enviar para o cliente o arquivo /usr/local/etc/.maillog 33[0m”
echo -e “33[41;1;37m ******************************************************************************************************* 33[0m”
echo “”
echo -e ” 33[1;32m Resultado em tela 33[0m”
echo `cat /usr/local/etc/.maillog | awk ‘{print “”$1″\t”$2″\t”$4″\t”$12″\t”$26″\t”$27″\t”$9″\t”$15″\t”$23″\t”$24}’`
echo “”
echo “”
echo “”

Categorias:Uncategorized

Postfix Manager Logs

novembro 28, 2011 Deixe um comentário

Postfix Manager Logs – Script que checa logs do servidor de email a procura de remetentes ou destinatários específicos

#!/bin/sh

# Trechos de comandos em shell que checa emails enviados ou recebidos nos logs do servidor
#
# Versao: 2.0

clear
echo -e “33[41;1;37m ************************************************** 33[0m”
echo -e “33[41;1;37m      Postfix Manager Logs – v.2.0 33[0m”
echo -e “33[41;1;37m ************************************************** 33[0m”

# Limpa arquivos envolvidos nas buscas a cada nova execucao para pesquisa.
echo > /usr/local/etc/.log-mail
echo > /usr/local/etc/.id-inicio
echo > /usr/local/etc/.id-email
echo > /usr/local/etc/.maillog

# Menu digita email a ser pesquisado.
echo -e ” 33[1;32m Digite o e-mail que deseja pesquisar nos logs seja remetente ou destinatario: 33[0m”; read email # variavel que guarda o email

# Contador ira contar quantos arquivos de log existem compactados em /var/log.
cont=0
qtdelog=`ls /var/log/maillog.*.bz2 | wc | awk ‘{print$1}’`
qtdereal=$(($qtdelog-1))

# Laco de repeticao pesquisa email em todos os logs existentes, resultado joga em /usr/local/etc/.log-mail, os ids brutos a serem tratados posteriormente tambem.
while [ $cont -lt $qtdereal ]; do
let cont=cont+1;
result=`bzcat /var/log/maillog.$cont.bz2 | grep -i $email`
echo $cont $result >> /usr/local/etc/.log-mail
`bzcat /var/log/maillog.$cont.bz2 | grep -i $email | awk ‘{print$6}’ >> /usr/local/etc/.id-inicio`
done

# Trata os ids dos emails existentes nos logs para checagem abaixo
printf “$(awk ‘!i[$0]++’ /usr/local/etc/.id-inicio) \n” > /usr/local/etc/.id-email

echo -e “33[41;1;37m ************************************************************************** 33[0m”
echo -e “33[41;1;37m Aguarde…Abrindo os ids das mensagens e salvando os resultados 33[0m”
echo -e “33[41;1;37m ************************************************************************** 33[0m”

# laco que checa quantidade de mensagens encontradas, os logs correspondentes, o ids das mensagens ja tratados, resultado gerado no arquivo /usr/local/etc/.maillog.
for qtdlog in `cat /usr/local/etc/.log-mail | grep parodius | awk ‘{print$1}’ | wc | awk ‘{print$1}’`; do
for numerolog in `cat /usr/local/etc/.log-mail | grep parodius | awk ‘{print$1}’`; do
for id in `cat /usr/local/etc/.id-email | sed “s/[:]//g” | grep -v module=Quotas`; do
result2=`bzcat /var/log/maillog.$numerolog.bz2 | grep -i $id` #Pesquisa final, abre o conteudo do id encontrado e joga no arquivo .maillog.
echo $result2 >> /usr/local/etc/.maillog
done

done

done

echo -e “33[41;1;37m ************************************************************************** 33[0m”
echo -e “33[41;1;37m Resultado da pesquisa gerado com sucesso! Checar /usr/local/etc/.maillog 33[0m”
echo -e “33[41;1;37m ************************************************************************** 33[0m”

Categorias:Uncategorized