File "documentacao-2.0.sh"

Full path: /www/wwwroot/fabriciovc.eti.br/downloads/ORGANIZAR/documentacao/documentacao-2.0.sh
File size: 27.79 KiB (28458 bytes)
MIME-type: text/x-shellscript
Charset: utf-8

Download   Open   Back

#!/bin/sh

###############################################################################
# Copyright (C) 2009 - Fabricio Vaccari Constanski                            #
# http://www.fabriciovc.eti.br | fabriciovc@fabriciovc.eti.br                 #
#                                                                             #
# Este trabalho está licenciado sob uma Licença Creative Commons              #
# Atribuição-Compartilhamento pela mesma Licença 2.5 Brasil. Para ver a copia #
# desta licença, acesse: http://creativecommons.org/licenses/by-sa/2.5/br/    #
# ou envie uma carta para Creative Commons, 171 Second Street, Suite 300,     #
# San Francisco, California 94105, USA.                                       #
#                                                                             #
# Modificações em 14 de julho de 2009 por Evaldo Junior (InFog)               #
# http://infog.casoft.info     | junior@casoft.info                           #
# Modificações em 22 de julho de 2009 por Fabricio Vaccari Constanski         #
# http://www.fabriciovc.eti.br | fabriciovc@fabriciovc.eti.br                 #
#                                                                             #
###############################################################################
#
# Versão 1.0
# - Versão original
#
# Versão 1.1
# - Adicionada verificação de usuário root
# - Retirados os "which" e guardando os caminhos em variáveis
#   - Esta alteração foi feita apenas nos "whiches" utilizados mais de uma vez
# - Alterada a forma de instalação dos 3 pacotes via aptitude
# - Adicionadas algumas tarefas ao TODO

# Versão 2.0
# - Adicionado alguns parametros de comandos para melhoras saidas
# - Adicionado algumas expressoes regulares para filtro de saida de arquivos de conf
# - Agora é permitida a escolha do nome do arquivo de saída
# - Adicionada saída em formato HTML
# - Adicionadas algumas tarefas ao TODO

# == FUNCOES ==================================================================
USUARIO=`whoami`
if [ "$USUARIO" != "root" ]; then
  echo
  echo "=============================================================================="
  echo " ESTE PROGRAMA PRECISA SER EXECUTADO COM PERMISSOES DE SUPERUSUARIO!"
  echo " Abortando..."
  echo "=============================================================================="
  echo
  exit 1
fi

_HEAD () {
`which clear`
echo "=============================================================================="
echo "                           SISTEMA DE DOCUMENTACAO"
echo "=============================================================================="

}

_FILE_NAME () {
_HEAD
if [ -z $DOC ]; then
  echo
  echo -n "Forneca o nome do arquivo (sem espacos) ou [enter] para nome padrao: "
  read NAME
fi

if [ -z "$NAME" ]; then
  echo
  echo "Nome não informado. Utilizando o nome padrao `uname -n`"
  DOC="`uname -n`"
else
  DOC="$NAME"
fi

echo "DOCUMENTACAO DO SERVIDOR $DOC" > $DOC
echo "Fabricio VC" >> $DOC
echo "Ultima atualização em: %%date(%d/%m/%Y)" >> $DOC
echo >> $DOC
echo "%! Style   : fancy.css" >> $DOC
echo "%! Encoding: utf-8" >> $DOC
#echo "%! Encoding: iso8859-1" >> $DOC
echo "%! Cmdline : -t html --toc --enum--title" >> $DOC
echo "%!postproc(html): '<BODY.*?>' '<body bgcolor="#ffffee" text="#303030">'" >> $DOC
#echo >> $DOC
#echo "Hi! This is my test document." >> $DOC
#echo "Its content will end here." >> $DOC

echo >> $DOC

}
_FILE_NAME

_CHECKOK () {
if [ $? -eq 0 ]; then
  sleep 1
  echo -e "\\033[1;32m OK \\033[0;39m"
else
  sleep 1
  echo -e "\\033[1;31m FALHOU \\033[0;39m"
fi
}

echo
echo "Aguarde..., instalando alguns pacotes necessários ... "
`which aptitude` install -y nmap+ pciutils+ tree+ txt2tags+ > /dev/null
#`which aptitude` install -y nmap+ pciutils+ tree+ txt2tags+ 

echo
echo "Documentação sendo gerada. Aguarde..."

# Variáveis com os caminhos dos programas usados:
CAT=`which cat`
DPKG=`which dpkg`
GREP=`which grep`
EGREP=`which egrep`
LS=`which ls`
NMAP=`which nmap`
TREE=`which tree`
UNAME=`which uname`
UNIQ=`which uniq`

# == FUNCOES QUE GERAM A DOCUMENTACAO =========================================
_SYSTEM_INFO () {
echo "--------------------" >> $DOC
echo "= INFORMACOES DO SISTEMA =" >> $DOC

echo "== Nome da Maquina ==" >> $DOC
echo '```' >> $DOC
$UNAME -n >> $DOC
echo '```' >> $DOC

echo "== Versão do Kernel ==" >> $DOC
echo '```' >> $DOC
$UNAME -sr >> $DOC
echo '```' >> $DOC

if [ -f /etc/debian_version ]; then
  echo "== Versao da Distro ==" >> $DOC
  echo '```' >> $DOC
  echo "Debian GNU/Linux `$CAT /etc/debian_version`" >> $DOC
  echo '```' >> $DOC
fi

if [ -f /etc/lsb-release ]; then
  echo "== Informações Específicas da Distro ==" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/lsb-release >> $DOC
  echo '```' >> $DOC
fi

echo "== Locale Configurado ==" >> $DOC
echo '```' >> $DOC
`which locale` >> $DOC
echo '```' >> $DOC

echo "== Runlevel do Sistema ==" >> $DOC
echo '```' >> $DOC
`which runlevel` >> $DOC
echo '```' >> $DOC

echo "== Uptime do Sistema e Load Average ==" >> $DOC
echo '```' >> $DOC
`which uptime` >> $DOC
echo '```' >> $DOC

echo "== Servicos Configurados ==" >> $DOC
echo '```' >> $DOC
$LS /etc/rc2.d/S* >> $DOC
echo '```' >> $DOC

echo "== Reboots da Máquina ==" >> $DOC
echo '```' >> $DOC
`which last` | $GREP boot >> $DOC
echo '```' >> $DOC

echo "== Hosts e IPs ==" >> $DOC
echo "=== /etc/hosts ===" >> $DOC
echo '```' >> $DOC
$CAT /etc/hosts >> $DOC
echo '```' >> $DOC

echo "== Portas Abertas ==" >> $DOC
echo '```' >> $DOC
$NMAP 127.0.0.1 >> $DOC
echo '```' >> $DOC

echo "== Alguns Diretorios Importantes ==" >> $DOC
echo "=== /etc ==="  >> $DOC
echo '```' >> $DOC
$TREE -d -L 1 /etc >> $DOC
echo '```' >> $DOC

echo "=== /home ==="  >> $DOC
echo '```' >> $DOC
$TREE -d -L 2 /home >> $DOC
echo '```' >> $DOC

echo "=== /srv ==="  >> $DOC
echo '```' >> $DOC
$TREE -d -L 2 /srv >> $DOC
echo '```' >> $DOC

echo "== Usuarios e Grupos ==" >> $DOC
echo "=== /etc/passwd ===" >> $DOC
echo '```' >> $DOC
$CAT /etc/passwd >> $DOC
echo '```' >> $DOC

echo "=== /etc/group ===" >> $DOC
echo '```' >> $DOC
$CAT /etc/group >> $DOC
echo '```' >> $DOC

echo "== Modulos ==" >> $DOC
if [ -f /etc/modprobe.d/aliases ]; then
  echo "=== /etc/modprobe.d/aliases ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/modprobe.d/aliases | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
fi

echo "=== Modulos carregados ===" >> $DOC
echo '```' >> $DOC
`which lsmod` >> $DOC
echo '```' >> $DOC
}

_HARDWARE () {
echo "--------------------" >> $DOC
echo "= INFORMACOES DE HARDWARE =" >> $DOC

echo "== Informações do Processador ==" >> $DOC
echo "=== /proc/cpuinfo ===" >> $DOC
echo '```' >> $DOC
$CAT /proc/cpuinfo >> $DOC
echo '```' >> $DOC

echo "== Informações de Memória ==" >> $DOC
echo "=== /proc/meminfo ===" >> $DOC
echo '```' >> $DOC
$CAT /proc/meminfo >> $DOC
echo '```' >> $DOC

echo "=== Informações de Memória no Estado Atual ===" >> $DOC
echo '```' >> $DOC
`which free` -m >> $DOC
echo '```' >> $DOC

echo "== Informações dos Discos Rigidos ==" >> $DOC
echo "=== Particionamentos dos discos locais ===" >> $DOC
echo '```' >> $DOC
`which fdisk` -l >> $DOC
echo '```' >> $DOC

echo "=== Partições Montadas e Sistema de Arquivos ===" >> $DOC
echo '```' >> $DOC
`which df` -hT >> $DOC
echo '```' >> $DOC

echo "=== Pontos de Montagens das Partições ===" >> $DOC
echo '```' >> $DOC
$CAT /etc/fstab | $EGREP -v '^#' | $UNIQ -u >> $DOC
echo '```' >> $DOC

if [ -f /proc/mdstat ]; then
  echo "=== Informações de RAID disponíveis ===" >> $DOC
  echo '```' >> $DOC
  $CAT /proc/mdstat >> $DOC
  echo '```' >> $DOC
fi

echo "== Dispositivos PCI Instalados ==" >> $DOC
echo '```' >> $DOC
`which lspci` >> $DOC
echo '```' >> $DOC

echo "== Dispositivos USB Instalados ==" >> $DOC
echo '```' >> $DOC
`which lsusb` >> $DOC
echo '```' >> $DOC
}

_BOOT () {
echo "--------------------" >> $DOC
echo "= INFORMAÇÕES DE BOOT =" >> $DOC

echo "== Lista de arquivos do /boot ==" >> $DOC
echo '```' >> $DOC
$LS /boot/* >> $DOC
echo '```' >> $DOC

echo "== Arquivo de configuração do GRUB ==" >> $DOC
echo "=== /boot/grub/menu.lst ===" >> $DOC
echo '```' >> $DOC
$CAT /boot/grub/menu.lst | $EGREP -v '^#' | $UNIQ -u >> $DOC
echo '```' >> $DOC
}

_REDE () {
echo "--------------------" >> $DOC
echo "= INFORMAÇÕES DA REDE =" >> $DOC

echo "== Arquivo de configuração de Rede ==" >> $DOC
echo "=== /etc/network/interfaces ===" >> $DOC
echo '```' >> $DOC
$CAT /etc/network/interfaces | $EGREP -v '^#' | $UNIQ -u >> $DOC
echo '```' >> $DOC

echo "== Endereços IPS ==" >> $DOC
echo '```' >> $DOC
`which ifconfig` >> $DOC
echo '```' >> $DOC

echo "== Informações de Roteamento ==" >> $DOC
echo '```' >> $DOC
`which route` -n >> $DOC
echo '```' >> $DOC
}

_NFS () {
echo "--------------------" >> $DOC
echo "= NFS =" >> $DOC
if [ -f /etc/exports ]; then
  echo "= NFS =" >> $DOC

  echo "== Diretorios Exportados via NFS ==" >> $DOC
  echo '```' >> $DOC
  `which showmount` -e 127.0.0.1 >> $DOC
  echo '```' >> $DOC

  echo "=== /etc/exports ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/exports | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SAMBA () {
echo "--------------------" >> $DOC
echo "= SAMBA =" >> $DOC

if [ -f /etc/samba/smb.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP samba >> $DOC
  $DPKG -l | $GREP smb >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Samba ==" >> $DOC
  echo "=== /etc/samba/smb.conf ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/samba/smb.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_LDAP () {
echo "--------------------" >> $DOC
echo "= LDAP =" >> $DOC

if [ -f /etc/ldap/slapd.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP ldap >> $DOC
  $DPKG -l | $GREP slap >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Ldap ==" >> $DOC
  for FILE in `$LS /etc/ldap/*.conf`
  do
    echo === $FILE === >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  if [ -f /etc/libnss-ldap.conf ]; then
    echo "=== /etc/libnss-ldap.conf ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/libnss-ldap.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/pam_ldap.conf ]; then
    echo "=== /etc/pam_ldap.conf ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/pam_ldap.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  echo "=== /etc/nsswitch.conf ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/nsswitch.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  if [ -f /var/www/phpldapadmin/config/config.php ]; then
    echo "=== /var/www/phpldapadmin/config/config.php ===" >> $DOC
    echo '```' >> $DOC
    $CAT /var/www/phpldapadmin/config/config.php | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo >> $DOC
  echo "**Serviço não configurado**" >> $DOC
fi
}

_PAM () {
echo "--------------------" >> $DOC
echo "= INFORMAÇÕES DA PAM =" >> $DOC

echo "== Arquivos de Configuração da PAM ==" >> $DOC
for FILE in `$LS /etc/pam.d/common-*`
do
  echo === $FILE === >> $DOC
  echo '```' >> $DOC
  $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
done
}

_APACHE () {
echo "--------------------" >> $DOC
echo "= APACHE E PHP =" >> $DOC

if [ -f /etc/apache2/apache2.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP apache >> $DOC
  $DPKG -l | $GREP php >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Apache ==" >> $DOC
  if [ -f /etc/apache2/apache2.conf ]; then
    for FILE in `$LS /etc/apache2/*.conf`
    do
      echo === $FILE === >> $DOC
      echo '```' >> $DOC
      $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
      echo '```' >> $DOC
    done
  fi

  if [ -d /etc/apache2/sites-enabled/ ]; then
    for FILE in `$LS /etc/apache2/sites-enabled/*`
    do
      echo === $FILE === >> $DOC
      echo '```' >> $DOC
      $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
      echo '```' >> $DOC
    done
  fi

  echo "== Estrutura de diretórios de sites (/var/www/) ==" >> $DOC
  echo '```' >> $DOC
  $TREE -d -L 2 /var/www/ >> $DOC
  echo '```' >> $DOC

  if [ -f /etc/php5/apache2/php.ini ]; then
    echo "== Arquivos de Configuração do PHP ==" >> $DOC
    echo "=== /etc/php5/apache2/php.ini ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/php5/apache2/php.ini | $EGREP -v '^#' | $EGREP -v '^;' | $UNIQ -u >> $DOC
    echo '```' >> $DOC

    if [ -f /etc/php5/cli/php.ini ]; then
      echo "=== /etc/php5/cli/php.ini ===" >> $DOC
      echo '```' >> $DOC
      $CAT /etc/php5/cli/php.ini | $EGREP -v '^#' | $EGREP -v '^;' | $UNIQ -u >> $DOC
      echo '```' >> $DOC
    fi
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_BIND () {
echo "--------------------" >> $DOC
echo "= BIND =" >> $DOC

if [ -d /srv/bind/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP bind >> $DOC
  $DPKG -l | $GREP dns >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Bind ==" >> $DOC
  for FILE in `$LS /srv/bind/etc/bind/*`
  do
    echo === $FILE === >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $EGREP -v '^;' | $EGREP -v '^/' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  for FILE in `$LS /srv/bind/var/cache/bind/*`
  do
    echo === $FILE === >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  echo "== Estrutura de Diretórios do Bind ==" >> $DOC
  echo '```' >> $DOC
  $TREE /srv/bind/ >> $DOC
  echo '```' >> $DOC

elif [ -d /etc/bind/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP bind >> $DOC
  $DPKG -l | $GREP dns >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Bind ==" >> $DOC
  for FILE in `$LS /etc/bind/*`
  do
    echo === $FILE === >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $EGREP -v '^;' | $EGREP -v '^/' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SYSLOG () {
echo "--------------------" >> $DOC
echo "= SYSLOG =" >> $DOC

if [ -f /etc/syslog.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP logd >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Syslog ==" >> $DOC
  echo "=== /etc/syslog.conf ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/syslog.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  if [ -f /etc/default/syslogd ]; then
    echo "=== /etc/default/syslogd ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/default/syslogd | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
elif [ -f /etc/rsyslog.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP logd >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Rsyslog ==" >> $DOC
  echo "=== /etc/rsyslog.conf ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/rsyslog.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  if [ -f /etc/default/rsyslogd ]; then
    echo "=== /etc/default/rsyslogd ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/default/rsyslogd | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SSH () {
echo "--------------------" >> $DOC
echo "= SSH =" >> $DOC

if [ -f /etc/ssh/sshd_config ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP ssh >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do SSH ==" >> $DOC
  echo "=== /etc/ssh/sshd_config ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/ssh/sshd_config | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SNMP () {
echo "--------------------" >> $DOC
echo "= SNMP =" >> $DOC

if [ -f /etc/snmp/snmpd.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP snmp | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do SNMP ==" >> $DOC
  echo "=== /etc/snmp/snmpd.conf ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/snmp/snmpd.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  if [ -f /etc/default/snmpd ]; then
    echo "=== /etc/default/snmpd ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/default/snmpd | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_VSFTPD () {
echo "--------------------" >> $DOC
echo "= VSFTPD =" >> $DOC

if [ -f /etc/vsftpd.conf ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP vsftp >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do VSFTP ==" >> $DOC
  for FILE in `$LS /etc/vsftpd.*`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_IPTABLES () {
echo "--------------------" >> $DOC
echo "= IPTABLES =" >> $DOC

echo "== Pacotes Instalados ==" >> $DOC
echo '```' >> $DOC
$DPKG -l | $GREP iptables >> $DOC
$DPKG -l | $GREP iproute >> $DOC
echo '```' >> $DOC

if [ -f /etc/init.d/rc.firewall ]; then
  echo "== Arquivos de Configuração de Firewall ==" >> $DOC
  echo "=== /etc/init.d/rc.firewall ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/init.d/rc.firewall >> $DOC
  echo '```' >> $DOC
else
  echo "**Nenhum script de firewall configurado**" >> $DOC
fi
}

_CRONTAB () {
echo "--------------------" >> $DOC
echo "= CRONTAB =" >> $DOC

if [ -d /var/spool/cron/crontabs/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP cron | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Crontab ==" >> $DOC
  if [ -f /var/spool/cron/crontabs/root ]; then
    for FILE in `$LS /var/spool/cron/crontabs/*`
    do
      echo "=== $FILE ===" >> $DOC
      echo '```' >> $DOC
      $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
      echo '```' >> $DOC
    done
  fi
else
  echo >> $DOC
  echo "**Serviço não configurado**" >> $DOC
fi
}

_MYSQL () {
echo "--------------------" >> $DOC
echo "= MYSQL =" >> $DOC

if [ -d /etc/mysql/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP mysql >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do MySQL ==" >> $DOC
  for FILE in `$LS /etc/mysql/*.cnf`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  echo "== Estrutura de diretórios do mysql ==" >> $DOC
  echo '```' >> $DOC
  $TREE -d /var/lib/mysql >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_CLAMAV () {
echo "--------------------" >> $DOC
echo "= CLAMAV =" >> $DOC

if [ -d /etc/clamav/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP clam >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Clamav ==" >> $DOC
  for FILE in `$LS /etc/clamav/*.conf`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_AMAVIS () {
echo "--------------------" >> $DOC
echo "= AMAVIS =" >> $DOC

if [ -d /etc/amavis/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP amavis >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Amavis ==" >> $DOC
  for FILE in `$LS /etc/amavis/conf.d/*`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SPAMASSASSIN () {
echo "--------------------" >> $DOC
echo >> $DOC
echo "= SPAMASSASSIN =" >> $DOC

if [ -d /etc/spamassassin/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP spam >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Spamassassin ==" >> $DOC
  for FILE in `$LS /etc/spamassassin/*.cf`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  echo "=== /etc/default/spamassassin ===" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/default/spamassassin | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_CACTI () {
echo "--------------------" >> $DOC
echo "= CACTI =" >> $DOC

if [ -d /etc/cacti/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP cacti >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Spamassassin ==" >> $DOC
  for FILE in `$LS /etc/cacti/*`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_NAGIOS () {
echo "--------------------" >> $DOC
echo "= NAGIOS =" >> $DOC

if [ -d /etc/nagios3/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP nagios >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Nagios ==" >> $DOC
  for FILE in `$LS /etc/nagios3/*.cfg`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  for FILE in `$LS /etc/nagios3/*.conf`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  for FILE in `$LS /etc/nagios3/conf.d/*.cfg`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  echo "== /etc/nagios3/htpasswd.users ==" >> $DOC
  echo '```' >> $DOC
  $CAT /etc/nagios3/htpasswd.users | $EGREP -v '^#' | $UNIQ -u >> $DOC
  echo '```' >> $DOC
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_POSTFIX () {
echo "--------------------" >> $DOC
echo "= POSTFIX =" >> $DOC

if [ -d /etc/postfix/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP postfix >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Postfix ==" >> $DOC
  for FILE in `$LS /etc/postfix/*.cf`
  do
    echo "=== $FILE ===" >> $DOC
    echo '```' >> $DOC
    $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  done

  if [ -d /etc/postfix/sasl/smtpd.conf ]; then
    for FILE in `$LS /etc/postfix/sasl/*`
    do
      echo "=== $FILE ===" >> $DOC
      echo '```' >> $DOC
      $CAT $FILE | $EGREP -v '^#' | $UNIQ -u >> $DOC
      echo '```' >> $DOC
    done
  fi

  if [ -f /etc/postfix/aliases ]; then
    echo "=== /etc/postfix/aliases ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/postfix/aliases | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/aliases ]; then
    echo "=== /etc/aliases ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/aliases | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/default/saslauthd ]; then
    echo "=== /etc/default/saslauthd ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/default/saslauthd | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /var/www/postfixadmin/config.inc.php ]; then
    echo "=== /var/www/postfixadmin/config.inc.php ===" >> $DOC
    echo '```' >> $DOC
    $CAT /var/www/postfixadmin/config.inc.php | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/pam.d/smtp ]; then
    echo "=== /etc/pam.d/smtp ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/pam.d/smtp | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_COURIER () {
echo "--------------------" >> $DOC
echo "= COURIER =" >> $DOC

if [ -d /etc/courier/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP courier >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Courier ==" >> $DOC

  if [ -f /etc/courier/authdaemonrc ]; then
    echo "=== /etc/courier/authdaemonrc ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/courier/authdaemonrc | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/courier/authmysqlrc ]; then
    echo "=== /etc/courier/authmysqlrc ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/courier/authmysqlrc | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/courier/imapd ]; then
    echo "=== /etc/courier/imapd ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/courier/imapd | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/courier/pop3d ]; then
    echo "=== /etc/courier/pop3d ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/courier/pop3d | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/pam.d/pop3 ]; then
    echo "=== /etc/pam.d/pop3 ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/pam.d/pop3 | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/pam.d/pop ]; then
    echo "=== /etc/pam.d/pop ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/pam.d/pop | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  if [ -f /etc/pam.d/imap ]; then
    echo "=== /etc/pam.d/imap ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/pam.d/imap | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

_SQUID () {
echo "--------------------" >> $DOC
echo "= SQUID =" >> $DOC

if [ -d /etc/squid/ ]; then
  echo "== Pacotes Instalados ==" >> $DOC
  echo '```' >> $DOC
  $DPKG -l | $GREP squid >> $DOC
  echo '```' >> $DOC

  echo "== Arquivos de Configuração do Squid ==" >> $DOC
  if [ -f /etc/squid/squid.conf ]; then
    echo "=== /etc/squid/squid.conf ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/squid/squid.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi

  echo "== Estrutura de Diretórios do Squid ==" >> $DOC
  echo '```' >> $DOC
  $TREE -d -L 2 /etc/squid/ >> $DOC
  echo '```' >> $DOC

  if [ -f /etc/squid/sarg.conf ]; then
    echo "== Arquivos de Configuração do Sarg ==" >> $DOC
    echo >> $DOC
    echo "=== /etc/squid/squid.conf ===" >> $DOC
    echo '```' >> $DOC
    $CAT /etc/squid/squid.conf | $EGREP -v '^#' | $UNIQ -u >> $DOC
    echo '```' >> $DOC
  fi
else
  echo "**Serviço não configurado**" >> $DOC
fi
}

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

# == EXECUTAR FUNCOES =========================================================
_SYSTEM_INFO
_HARDWARE
_BOOT
_REDE
_NFS
_SAMBA
_LDAP
_PAM
_APACHE
_BIND
_SYSLOG
_SSH
_SNMP
_VSFTPD
_IPTABLES
_CRONTAB
_MYSQL
_CLAMAV
_AMAVIS
_SPAMASSASSIN
_CACTI
_NAGIOS
_POSTFIX
_COURIER
_SQUID
# =============================================================================

echo "--------------------" >> $DOC
echo '```' >> $DOC
echo "Copyright (C) 2009 - Fabricio Vaccari Constanski" >> $DOC
echo "http://www.fabriciovc.eti.br | fabriciovc@fabriciovc.eti.br" >> $DOC
echo >> $DOC
echo "Este trabalho está licenciado sob uma Licença Creative Commons
Atribuição-Compartilhamento pela mesma Licença 2.5 Brasil. Para ver a copia
desta licença, acesse: http://creativecommons.org/licenses/by-sa/2.5/br/
ou envie uma carta para Creative Commons, 171 Second Street, Suite 300,
San Francisco, California 94105, USA." >> $DOC
echo '```' >> $DOC
echo "--------------------" >> $DOC

`which txt2tags` -t html $DOC > /dev/null
`which rm` -f $DOC

echo
echo "Concluído. Pressione [enter] para finalizar."
read

_HEAD
echo
echo "Documentacao gerada com sucesso."
echo "Ela pode ser visualizada em $DOC.html!"
echo


# ==== TODO ====
# ## Fabrício
# - Adicionar locale fixo no script para acertar acentuacao
#
# ## Evaldo
# - Melhorar o output
# ==============

PHP File Manager