Source

ossec-wui / setup.sh

ddpbsd ae0e165 



























































































#!/bin/sh
# Setup script for OSSEC UI
# Author: Daniel B. Cid <dcid@ossec.net>


# Finding my location
LOCAL=`dirname $0`;
cd $LOCAL
PWD=`pwd`
ERRORS=0;

# Looking for echo -n
ECHO="echo -n"
hs=`echo -n "a"`
if [ ! "X$hs" = "Xa" ]; then
    ls "/usr/ucb/echo" > /dev/null 2>&1
    if [ $? = 0 ]; then
        ECHO="/usr/ucb/echo -n"
    else
        ECHO=echo
    fi
fi        

# Looking for htpasswd
HTPWDCMD="htpasswd"
ls "`which $HTPWDCMD`" > /dev/null 2>&1
if [ ! $? = 0 ]; then
    HTPWDCMD="htpasswd2"
    ls "`which $HTPWDCMD`" > /dev/null 2>&1
    if [ ! $? = 0 ]; then
        HTPWDCMD=""
    fi    
fi    


# Default options
HT_DIR_ACCESS="deny from all"
HT_FLZ_ACCESS="AuthUserFile $PWD/.htpasswd"
HT_DEFAULT="htaccess_def.txt"


echo "Setting up ossec ui..."
echo ""


ls $HT_DEFAULT > /dev/null 2>&1
if [ ! $? = 0 ]; then
    echo "** ERROR: Could not find '$HT_DEFAULT'. Unable to continue."    
    ERRORS=1;
fi    


# 1- Create .htaccess blocking access to private directories.
PRIV_DIRS="site lib tmp"
mkdir tmp >/dev/null 2>&1
chmod 777 tmp
for i in $PRIV_DIRS; do
    echo $HT_DIR_ACCESS > ./$i/.htaccess;
done

# 2- Create. htaccess blocking access to .sh and config files.    
echo $HT_FLZ_ACCESS > ./.htaccess;
echo "" >> ./.htaccess;
cat $HT_DEFAULT >> ./.htaccess;


# 3- Create password
while [ 1 ]; do
    if [ "X$MY_USER" = "X" ]; then
        $ECHO "Username: "
        read MY_USER;
    else
        break;
    fi        
done

if [ "X$HTPWDCMD" = "X" ]; then
    echo "** ERROR: Could not find htpasswd. No password set."    
    ERRORS=1;
else
    $HTPWDCMD -c $PWD/.htpasswd $MY_USER
    if [ ! $? = 0 ]; then
        ERRORS=1;
    fi    
fi    

if [ $ERRORS = 0 ]; then
    echo ""
    echo "Setup completed successfuly."
else
    echo ""
    echo "Setup failed to complete."
fi        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.