Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Thursday, April 30, 2020

Disable Directory Listing Apache2

Edit the following file:

/etc/apache2/apache2.conf

Remove 'Indexes' from default root directory setting:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Updated apache2.conf file:

<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Restart the apache2 server instance.

Monday, February 15, 2016

LDAP Configuration(On Debian)

LDAP .
            LDAP stands for Lightweight Directory Access Protocol.

Reference. Google is the best reference for any kind of  problem & also for LDAP :)

LDAP Installation.
                        when you are going to install ldap in your are syetm than you must have extra
packages installed for ldap.
For Example.  Apache2 , PHP5

Apache Installation.
apt-get install apache2
For server-side, HTML-embedded scripting languag supports u have to install  libapache2-mod-php5 & also apache2-utils it's a utility programs for webservers.


PHP Installation
apt-get install php5
and php5-common for  Common files for packages built from the php and php5-ldap  it's  LDAP module for php5.

After Installion of apache2 and php5 u have to check them either both r working or not.
Apache testing.
on the webbrowser type http://localhost
It will return u a index.html page but if it's did't it mean there is some problem in ur apache2.

Php testing.
you have to make a php file for cheching php kit it's working or not
Make a php file name test.php
#] vi /var/www/test.php
write some php code or this code is batter for testing
<?php  phpinfo(); ?>

Now type this on webbrowser http://localhost/test.php
phpinfo method will return u a complete informationa about php thats installed in ur system.

LDAP Installation
apt-get install slapd it's a OpenLDAP server (slapd).

After installation there is two most important and editable files
/etc/ldap/slapd.con  (for server configuration)
/etc/ldap/ldap.con  (for client configuration)

when u r going to edit slapd.conf than first make backup for that file.Now you have to change little bit in the configuration file opn it in vi or any other editor.

vi /etc/ldap/slapd.conf
Add suffix it's base of your directory in database
suffix          "dc=imtiaz,dc=emergen,dc=org"


also u have to change and add some attributes.
access to attrs=userPassword
        by dn="cn=admin,dc=imtiaz,dc=emergen,dc=org" write
        by anonymous auth
        by self write
        by * none
The userPassword by default can be changed  by the entry owning it if they are authenticated.
Others should not be able to see it, except the admin entry below.a These access lines apply to database #1 only

or if u feel difficult to edit this file or u don't want to to that than u can configure with the
help of command

dpkg-reconfigure slapd
Add the suffic(i.e. dc=imtiaz,dc=emergen,dc=org) and company name (i.e. Emergen Consulting) and ldap root password. If u select all the option defalut than batter or i u want to set according to ur requirement than u can read and make changes :)

If u wana know about ldap is working or not thats u can check with the builtin command
called
slapdtest
There is a lot of commads they can help u to know about ldap.

Now its time to install phpldapadmin its' web based interface for administering LDAP servers
u can install with the help of
apt-get install phpldapadmin
else  if u have a .gz file also u can extract that.
when u complete ur installation or extrection than there is one configuration file called config.php its available in ../phpldapadmin/config/config.php edit that file.
vi ../phpldapadmin/config/config.php

Before > $ldapservers->SetValue($i,'server','name','My LDAP Server');
After   < $ldapservers->SetValue($i,'server','name','Imtiaz Directory Service');

Before > // $ldapservers->SetValue($i,'server','host','127.0.0.1');
After   < $ldapservers->SetValue($i,'server','host','localhost');

Bwfore > // $ldapservers->SetValue($i,'server','port','389');
After    < $ldapservers->SetValue($i,'server','port','389');




Before > // $ldapservers->SetValue($i,'server','base',array(''));
After   < $ldapservers->SetValue($i,'server','base',array('dc=imtiaz,dc=emergen,dc=org'));

Before > // $ldapservers->SetValue($i,'server','auth_type','cookie');
After < $ldapservers->SetValue($i,'server','auth_type','session');

Before >#  $ldapservers->SetValue($i,'login','dn','cn=Manager,dc=example,dc=com');
After  < $ldapservers->SetValue($i,'login','dn','cn=admin,dc=imtiaz,dc=emergen,dc=org');

Before >  $ldapservers->SetValue($i,'login','pass','secret');
After   < $ldapservers->SetValue($i,'login','pass','emergen');

After change this now it's time to run the phpldapadmin
type this on the web browser
u'll see a phpldapadmin login page on the web browser than login & use who ever u want to use and create what ever u what to create :)

Login DN : cn=admin,dc=imtiaz.dc=emergen,dc=org
 [cn,dc that's u added in phpldapadmin config.php file]
Password  : emergen
[what ever password u was given on phpldapadmin config file.]

Note:- if ur ladp is not aceepting the login dn or password than it's batter to run
dpkg-reconfigure slapd.

When u finished to create  groups & also users than now it's time to check them either they r
completely created and u can use them, u can check that with the help of ssh but befor that u have to installed some more packages and also u have to make changes in some configuration files.

Now install
apt-get install libnss-ldap
apt-get installl libpam-ldap

After installation u have to make changes in file

vi  /etc/nsswitch.conf

passwd:  files ldap
group:   files ldap
shadow:  files ldap

vi /etc/pam.d/common-account

account sufficient      pam_unix.so
account sufficient      pam_ldap.so

vi /etc/pam.d/common-auth

auth    sufficient pam_unix.so nullok_secure
auth    sufficient pam_ldap.so use_first_pass


vi /etc/pam.d/common-password

password sufficient pam_unix.so nullok obscure min=4 max=8 md5
password sufficient pam_ldap.so use_first_pass debug


vi /etc/pam.d/common-session

session required        pam_unix.so
session optional        pam_foreground.so
session sufficient      pam_ldap.so

After editing all these files try to make ssh with ur added user.
if u want to check ur added user's than u can check with

#] getent passwd
It'll show u all the ldap added user's.



if ur successful login than ur ldap is working fine  :)

Zoneminder Installation

l  Install the zoneminder & required packages.

                   apt-get install make
                   apt-get install apache2
                   apt-get install php5

l  For testing  the apache server open the web browser & type.
                   http://localhost

l  After this you must see the apach-default page on the web browser else check you installation again

l  For testing php you have to create a file (test.php) & write some php code in that file and try to execute with the help of web browser.

          Example :
                   vi  /etc/www/ test.php
                        <? phpinfo(); ?>
                        save & exit.
l  For testing php file on the local system type  
l  You'll find the information about php.

l  Install  some more packages that required to run the zoneminder properly.

                   apt-get install php5-mysql
                   apt-get install libapache2-mod-auth-mysql
                   apt-get install mysql-server
                   apt-get install g++
                   apt-get install libdate-manip-perl
                   apt-get install libmysqlclient12-dev
                   apt-get install libjpeg-mmx-dev
                   apt-get install liblwp-protocol-http-socketunix-perl

l  If you are unable to install zoneminder with the help of apt-install than download the zoneminder zip file form the web on any local system and copy that gz file on the target system.

                   scp  /home/ZoneMinder-1.22.2.tar.gz  root@192.168.1.11:/home

l  And than unzip that file.
                   tar -xvzf ZoneMinder-1.22.2.tar.gz

l  And for configure the zm run this command 

./configure --with-webdir=/var/www/zm --with-cgidir=/usr/lib/cgi-bin --with-webuser=www-data –with-webgroup=www-data

          Note : If u find error message like
          configure: error: zm requires openssl/md5.h

l  Than you need some extra package to install libssl-dev than zoneminder is completely configured :)

l  For creating the database in mysql for zoneminder you have to run this command

                   #> mysql mysql < db/zm_create.sql -p

l  when you run this command it'll creat the default zoneminder database. when it's completely created than you have to grant some permission on that database for specific user's.

l  For this open mysql for this type.
                   mysql  -p

l  It's ask for your mysql password. Enter the password and type this command for grant the permission to zmuser.  
     
          Grant select,insert,update,delete on zm.* to
          'zmuser'@localhost identified by 'zmpass';
            (It's a compelete command)           

l  And type exit or quit to close mysql.

l  After this restart the mysqlamin to refresh the database schema for restart type
                        #> mysqladmin reload -p
l  After this type make install to install the zoneminder
                        make install
l  After this you have to make the zm script file for that you have to past this script code in
                        vi /etc/init.d/zm
l  Hare is a script
------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
# description: Control ZoneMinder as a Service
# chkconfig: 2345 99 00
# Source function library.
#. /etc/rc.d/init.d/functions

prog=ZoneMinder
ZM_VERSION="1.22.2"
ZM_PATH_BIN="/usr/local/bin"
ZM_CONFIG="/usr/local/etc/zm.conf"
command="$ZM_PATH_BIN/zmpkg.pl"

loadconf()
{
        if [ -f $ZM_CONFIG ]; then
                . $ZM_CONFIG
        else
                echo "ERROR: $ZM_CONFIG not found."
                return 1
        fi
}

# Check for old config and update if needed
checkcfg()
{
        # Check config
        if [ "$ZM_DB_HOST" = "" -o "$ZM_DB_NAME" = "" -o "$ZM_DB_USER" = "" -o "$ZM_DB_PASS" = "" ]; then
                if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USERA" != "" -a "$ZM_DB_PASSA" != "" ]; then
                        echo -n "Converting $ZM_CONFIG"
                        cp $ZM_CONFIG $ZM_CONFIG.old && \
                        cat $ZM_CONFIG.old | \
                                grep -v ZM_DB_USERB | \
                                grep -v ZM_DB_PASSB | \
                                sed -e 's/ZM_DB_USERA/ZM_DB_USER/' | \
                                sed -e 's/ZM_DB_PASSA/ZM_DB_PASS/' >$ZM_CONFIG && \
                        rm -f $ZM_CONFIG.old
                        RETVAL=$?
                        [ $RETVAL = 0 ] && echo_success
                        [ $RETVAL != 0 ] && echo_failure
                        echo
                fi
                if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USER" != "" -a "$ZM_DB_PASS" != "" ]; then
                        echo -n "Converting $ZM_CONFIG to 1.22.0"
                        cp $ZM_CONFIG $ZM_CONFIG.old
                        rm -f $ZM_CONFIG
                        cat $ZM_CONFIG.old | \
                        sed -e 's/ZM_DB_SERVER/ZM_DB_HOST/' >/tmp/$$
                        . /tmp/$$
                        cp $ZM_CONFIG.rpmnew $ZM_CONFIG && chmod 644 $ZM_CONFIG
                        for n in ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
                                eval "val=\$$n"
                                if [ "$val" != "" ]; then
                                cp $ZM_CONFIG /tmp/$$.rpmnew &&
                                sed 's/^'$n='.*$/'$n=$val'/g' /tmp/$$.rpmnew >$ZM_CONFIG
                                fi
                        done
                        rm /tmp/$$
                        RETVAL=$?
                        [ $RETVAL = 0 ] && echo_success
                        [ $RETVAL != 0 ] && echo_failure
                        echo
                else
                        echo "In $ZM_CONFIG there should not be null values."
                        return 1
                fi
        loadconf
        fi
}

checkdb()
{
        # Check database exisits and version
        GetVer="select Value from Config where Name='ZM_DYN_DB_VERSION'"
        OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
        if [ "$OLD_VERSION" = "" ]; then
                GetVer="select Value from Config where Name='ZM_DYN_CURR_VERSION'"
                OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
                if [ "$OLD_VERSION" = "" ]; then
                        echo -n "You must run zmupdate.pl manualy"
                        return 1
                fi     
        fi
        RETVAL=$?
       
        if [ $RETVAL != 0 ]; then
                tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e 'show tables' $ZM_DB_NAME`
                RETVAL=$?
                if [ $RETVAL = 0 ]; then
                        echo -n "Initialize $prog database: "
                        echo tbls | grep Config >/dev/null 2>&1
                        RETVAL=$?
                        if [ $RETVAL != 0 ]; then
                                mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME < $ZM_PATH_UPDATE/zm_create.sql
                                RETVAL=$?
                                [ $RETVAL = 0 ] && echo_success
                                [ $RETVAL != 0 ] && echo_failure
                                echo
                                return $RETVAL
                        fi
                        ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
                        RETVAL=$?
                        [ $RETVAL = 0 ] && echo_success
                        [ $RETVAL != 0 ] && echo_failure
                        echo
                        return $RETVAL
                else
                        echo "No access to ZoneMinder database. Run $ZM_PATH_BIN/zminit manually."
                        return $RETVAL
                fi
        else
                [ "$ZM_VERSION" = "$OLD_VERSION" ] && return 0
                echo -n "Upgrade $prog database: "
                $ZM_PATH_BIN/zmupdate.pl --version=$OLD_VERSION --noi && ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
                RETVAL=$?
                [ $RETVAL = 0 ] && echo_success
                [ $RETVAL != 0 ] && echo_failure
                echo
                return $RETVAL
        fi
}

start()
{
        loadconf || return $?
        checkcfg || return $?
        checkdb || return $?
        #/usr/local/sbin/motd.sh > /etc/motd
        echo -n "Starting $prog: "
        [ ! -d /var/run/zm ] \
                && mkdir -m 774 /var/run/zm \
                && chown $ZM_WEB_USER:$ZM_WEB_GROUP /var/run/zm
        GetPath="select Value from Config where Name='ZM_PATH_SOCKS'"
        ZM_PATH_SOCK=`echo $GetPath | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
        [ ! -d $ZM_PATH_SOCK ] \
                && mkdir -m 774 $ZM_PATH_SOCK \
                &&chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK
        $command start
        RETVAL=$?
        [ $RETVAL = 0 ] && echo success
        [ $RETVAL != 0 ] && echo failure
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/zm
        return $RETVAL
}

stop()
{
        echo -n $"Stopping $prog: "
        $command stop
        RETVAL=$?
        [ $RETVAL = 0 ] && echo success
        [ $RETVAL != 0 ] && echo failure
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm
}

status()
{
        result=`$command status`
        if [ "$result" = "running" ]; then
                echo "ZoneMinder is running"
                RETVAL=0
        else
                echo "ZoneMinder is stopped"
                RETVAL=1
        fi
}

case "$1" in
        'start')
                start
                ;;
        'stop')
                stop
                ;;
        'restart')
                stop
                start
                ;;
        'condrestart')
                loadconf
                checkcfg
                result=`$ZM_PATH_BIN/zmdc.pl check`
                if [ "$result" = "running" ]; then
                        $ZM_PATH_BIN/zmdc.pl shutdown > /dev/null
                        start
                fi
                ;;
        'status')
                status
                ;;
        *)
                echo "Usage: $0 { start | stop | restart | condrestart | status }"
                RETVAL=1
                ;;
esac
exit $RETVAL
l  After past the script  you have make that file executable with the help of
                   #> chmod +x /etc/init.d/zm
l  After this start the zoneminder.
                   #> /etc/init.d/zm start
l  You have to increase the kernel memory for this open sysctl.conf
                   #>vi /etc/sysctl.conf

l  And this line  kernel.shmmax = 134217728

l  In apache you have to redirect the client request to the zoneminder file for this open
                   vi /etc/apache2/sites-available/default
          Find  RedirectMatch
                   RedirectMatch ^/$ /apache2-default/
          replace
                   RedirectMatch ^/$ /zm/
          Save & Exit

l  You have to set the cookies.
                   Type vi /var/www/zm/zm.php

                        Find setcookie & add this line
                                    setcookie (“cookies”,$cookies);
            If it's already added than there is no need to replace.



l  Restart the apache2
                   /etc/init.d/apache2 restart
l  Restart Zoneminder
                   /etc/init.d/zm restart

l  It's batter to set the static ip address for ur zoneminder machine

                        vi /etc/networking/interfaces

                   iface eth0 inet static
                   address 192.168.1.11
                   netmask 255.255.255.0
                   gateway 192.168.1.1

                        Save & Exit
                        Restart the networking or it's batter to restart ur system :)


                     Setting up ZoneMinder

l  Use a other pc to preform the following steps or use the localhost.

l  For zoneminder configuration you have to change some options for this Click Option and change

                        Network - Check ZM_OPT_REMOTE_CAMERAS
                        Video - Select jpeg for ZM_VIDEO_STREAM_METHOD

l  After this you have to add the new monitor to monitor the different cam. You have to create seprate monitors for every cam.
            Press add monitor

                        General  - Enter monitor name
                        Source Type - Remote / Local / File

l  If you are using IP cam than every cam have it's own IP address you can also set that IP address.

                        Function -  Monitor / Modect / etc
                       
                        IP Source : (Remote Host Name/ IP = 192.168.1.250)
                        Port  #      : (Remote Host Port)
                        Remote Host Path  : /video.cgi  or image.jpg

          Note :- Every ip cam have a different path for it's video / images you             must know about you cam IP,Port No, .cgi file path, .jpg file path.

l  Enter 640/480 for the Capture Width and Height


Now check the monitor im sure it's working :)

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...