Category: Squid Proxy

07/28/04

Permalink 09:47:15 am, by admin Email , 393 words   English (US)
Categories: Service Control Scripts, Squid Proxy

Squid Guard

#!/bin/bash
# squid		This shell script takes care of starting and stopping
#		Squid Internet Object Cache
#
# chkconfig: - 90 25
# description: Squid - Internet Object Cache. Internet object caching is \
# 	a way to store requested Internet objects (i.e., data available \
# 	via the HTTP, FTP, and gopher protocols) on a system closer to the \
#	requesting site than to the source. Web browsers can then use the \
#	local Squid cache as a proxy HTTP server, reducing access time as \
#	well as bandwidth consumption.
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.conf

PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# check if the squid conf file is present
[ -f /usr/local/squid/etc/squid.conf ] || exit 0

# determine the name of the squid binary
[ -f /usr/local/squid/sbin/squid ] && SQUID=squid
[ -z "$SQUID" ] && exit 0

prog="$SQUID"

# determine which one is the cache_swap directory
CACHE_SWAP=`sed -e 's/#.*//g' /usr/local/squid/etc/squid.conf | \
	grep cache_dir |  awk '{ print $3 }'`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/usr/local/squid/var/cache

RETVAL=0

start() {
    for adir in $CACHE_SWAP; do
        if [ ! -d $adir/00 ]; then 
	     echo -n "init_cache_dir $adir... "
	     /usr/local/squid/sbin/squid -z -F 2>/dev/null
	fi
    done
    echo -n $"Starting $SQUID $prog: "
    /usr/local/squid/sbin/squid $SQUID_OPTS 2> /dev/null &
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
    [ $RETVAL -eq 0 ] && echo_success
    [ $RETVAL -ne 0 ] && echo_failure
    echo
    return $RETVAL
}

stop() {
    echo -n  $"Stopping $prog: "
    /usr/local/squid/sbin/squid -k check >/dev/null 2>&1
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
        /usr/local/squid/sbin/squid -k shutdown &
    	rm -f /var/lock/subsys/$SQUID
	timeout=0
 	while : ; do
		[ -f /usr/local/squid/var/logs/squid.pid ] || break
		sleep 2 && echo -n "." 
		timeout=$((timeout+2))
    	done
	echo_success
	echo 
    else
    	echo_failure
	echo
    fi
    return $RETVAL
}    

reload() {
    /usr/local/squid/sbin/squid $SQUID_OPTS -k reconfigure 
}

restart() {
    stop
    start
}    

condrestart() {
    [ -e /var/lock/subsys/squid ] && restart || :
}

rhstatus() { 
    status $SQUID
    /usr/local/squid/sbin/squid -k check
}

probe() {
    return 0
}    

case "$1" in
start)
    start
    ;;

stop)
    stop
    ;;

reload)
    reload
    ;;

restart)
    restart
    ;;

condrestart)
    condrestart
    ;;

status)
    rhstatus
    ;;

probe)
    exit 0
    ;;

*)
    echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
    exit 1
esac

exit $?

07/26/04

Permalink 09:39:42 am, by admin Email , 1393 words   English (US)
Categories: Linux, Squid Proxy

Squid Guard

We'll start by installing Squid:

> cd /root
> wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE3.tar.gz
> tar -xvzf squid-2.5.STABLE3.tar.gz
> cd squid-2.5.STABLE3
> ./configure
> make
> make install
> cd /root
> rm -rf squid-2.5.STABLE3
> mkdir archive
> mv squid-2.5.STABLE3.tar.gz archive

Squid is now installed at /usr/local/squid.

Notice that we use the "wget" command to download the software. Then we unpack and build the software. The build sequence is very typical for Linux packages - configure, make, make install.

We finish up by saving the distribution to /root/archive and removing the build
directory that is no longer needed.

Configuration for squid is pretty simple in the basic case. All configuration is
stored in a single file located at /usr/local/squid/etc/squid.conf.

The squid.conf file can be edited with your favoriate text editor. All though there
are hundreds of configuration options only a few are needed in a basic install. We made the following changes:

a. Find the line that looks like this (approx line 684):

  #cache_dir ufs /usr/local/squid/var/cache 100 16 256

Remove the "#" comment from the begining of the line and set the desired cache size and location:

  cache_dir ufs /usr/local/squid/var/cache 768 16 256

This defines a cache of not more then 768MB of disk storage.

b. Find the line that looks like this (approx line 1760):

  # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

Below this line add the following lines:

  acl our_networks src 172.0.0.0/8
  http_access allow our_networks

  acl my_network src 127.0.0.1
  http_access allow my_network

The first new line defines an access control list (acl) called "our_networks" which 
includes the listed address ranges. The second line tells squid to accept connections
from the "our_networks" acl. The next two lines allow access through the loopback 
address.

c. Find the line (approx line 1973):

  # cache_effective_user nobody

Uncomment this line and change the username to squid. Then add a line to set the group:

  cache_effective_user squid
  cache_effective_group squid

For a basic setup that is all that is required in the way of configuration.

Next well prepare the cache directories and start the proxy server.

Type:

> chown --recursive squid.squid cache
> chown --recursive squid.squid logs
> /usr/local/squid/sbin/squid -z

This command may take several minutes to complete.

Now start the server with:

> /usr/local/squid/sbin/squid 

You can verify that squid is running by checking the log files:

> tail /var/log/messages

Now we can add a service control script to /etc/init.d. A suitable
script can be downloaded from Reliable Penguin:

> wget http://www.reliablepenguin.com/clients/misc/simplesquidguard.rh9.squid.service
> mv simplewquidguard.rh9.squid.service /etc/init.d/squid
> chmod 755 /etc/init.d/squid

And finally squid can be set to start on bootup:

> cd /etc/rc.d/rc5.d
> ln -s ../init.d/squid S25squid
> ln -s ../init.d/squid K25squid

Next we want to install SquidGuard but it requires the BerkeleyDB database 
library package so we'll install it first:

> cd /root
> wget http://www.sleepycat.com/update/snapshot/db-3.3.11.tar.gz
> tar -xvzf db-3.3.11.tar.gz
> cd db-3.3.11
> cd build_unix
> ../dist/configure
> make
> make install
> ldconfig
> cd /root
> rm -rf db-3.3.11
> mv db-3.3.11.tar.gz archive

The build procedure for BerkeleyDB is a little unusual - notice the directory that we 
change into before running configure.

Also notice that we are using a 3.x version of BerkeleyDB. The current release if 4.X
but SquidGuard needs the older version.

Now we can download and install SquidGuard:

> wget http://ftp.teledanmark.no/pub/www/proxy/squidGuard/squidGuard-1.2.0.tar.gz
> tar -xvzf squidGuard-1.2.0.tar.gz
> cd squidGuard-1.2.0
> ./configure --with-db=/usr/local/BerkeleyDB.3.2
> make
> make install
> mkdir /usr/local/squidGuard
> mkdir /usr/local/squidGuard/logs
> cp samples/sample.conf /usr/local/squidGuard

And now squidGuard is installed.

Now lets configure squid to utilize squidGuard. We'll need to edit the squid.conf
file at /usr/local/squid/squid.conf. Look for the line:

  #  TAG: redirect_program

Below this section add this line:

  redirect_program /usr/local/bin/squidGuard

And restart squid:

> service squid restart

Now squid will load and use squidGuard.

Next lets install the blacklists:

> cd /usr/local/squidGuard
> wget http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz
> tar -xvzf blacklists.tar.gz
> chmod --recursive g+w blacklists
> chown --recursive squid.squid blacklists

The next step is to configure squidGuard. We'll start with a very basic setup and
then expand it later using the webmin interface.

Create a new file at /usr/local/squidGuard/squidGuard.conf with the following
contents:

	logdir /usr/local/squidGuard/logs
	dbhome /usr/local/squidGuard/blacklists

	source localnet {
	        ip      172.0.0.0/8
	}

	source localhost {
	        ip      127.0.0.1
	}

	dest ads {
	        domainlist      ads/domains
	        urllist         ads/urls
	        #expressionlist  ads/expressions
	}

	dest audio-video {
	        domainlist      audio-video/domains
	        urllist         audio-video/urls
	        #expressionlist  audio-video/expressions
	}

	dest gambling {
	        domainlist      gambling/domains
	        urllist         gambling/urls
	        #expressionlist  gambling/expressions
	}

	dest mail {
	        domainlist      mail/domains
	        #urllist         mail/urls
	        #expressionlist  mail/expressions
	}

	dest proxy {
	        domainlist      proxy/domains
	        urllist         proxy/urls
	        #expressionlist  proxy/expressions
	}

	dest violence {
	        domainlist      violence/domains
	        urllist         violence/urls
	        expressionlist  violence/expressions
	}

	dest aggressive {
	        domainlist      aggressive/domains
	        urllist         aggressive/urls
	        #expressionlist  aggressive/expressions
	}

	dest drugs {
	        domainlist      drugs/domains
	        urllist         drugs/urls
	        #expressionlist  drugs/expressions
	}
	
	dest hacking {
	        domainlist      hacking/domains
	        urllist         hacking/urls
	        #expressionlist  hacking/expressions
	}
	
	dest porn {
	        domainlist      porn/domains
	        urllist         porn/urls
	        expressionlist  porn/expressions
	}
	
	dest warez {
	        domainlist      warez/domains
	        urllist         warez/urls
	        #expressionlist  warez/expressions
	}
	

	acl {
	        localnet {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	
	        localhost {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	
	        default {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	}

Save the file. 

Next let's set permissions:

> cd /usr/local/squidGuard
> chown --recursive squid.squid *

Restart squid:

> service squid restart

Now squidGuard is running.

Next lets install webmin. Webmin can be downloaded from: 

	http://www.webmin.com

We'll use the RPM to simplify the install.

The install goes like this:

> wget http://unc.dl.sourceforge.net/sourceforge/webadmin/webmin-1.100-1.noarch.rpm
> rpm -U webmin-1.100-1.noarch.rpm

That's about it. Webmin is now installed on the server and can be accessed on 
port 10000. The default user is "root" and the password is the same as the 
root password.

Webmin includes a module for managing Squid by default so there is nothing to
add. We just need to configure the module to know where our install of Squid is located.

Follow these steps:

1. Login to Webmin
2. Click the Servers icon on the top menu bar.
3. Click the Squid Proxy Server icon.
4. Click the Module Config link under the top menu bar.
5. In the "System Configuration" section of the module config form set the following:

a. Full path to squid config file ==> /usr/local/squid/etc/squid.conf
b. Squid executable ==> /usr/local/squid/sbin/squid
c. Full path to PID file ==> /usr/local/squid/var/log/squid.pid
d. Full path to Squid cache directory ==> /usr/local/squid/var/cache
e. Squid cachemgr.cgi executable ==> /usr/local/squid/libexec/cachemgr.cgi
f. Full path to squid log directory ==> /usr/local/squid/var/logs

6. Click the save button at the bottom of the form.

That does it. Now Webmin can be used to manage Squid.

Next lets install a webmin module for managing SquidGuard.

1. Login to Webmin
2. Click the "Webmin" icon in the top menu bar.
3. Click the "Webmin Configuration" icon.
4. Click the "Webmin Modules" icon.
5. Complete the "Install Module" form as follows:

a. Select "From FTP or HTTP URL" and enter the url:

	http://www.niemueller.de/webmin/modules/squidguard/squidguard-0.91.2.wbm.gz

b. Select "Grant access only to users and groups" and enter "root".
c. Press the "Install Module From File" button.


Next to configure the module:

1. Login to Webmin
2. Click the "Servers" icon in the top menu bar.
3. Click the "SquidGuard" icon.
4. Click the "Module Config" link below the top menu bar.
5. Complete the form as follows:

a. Full path to Squidguard configuration file ==> /usr/local/squidGuard/squidGuard.conf
b. Full path to binary for SquidGuard ==> /usr/local/bin/squidGuard
c. Full path to PID file of Squid ==> /usr/local/squid/var/log/squid.pid
d. User the Squid runs as ==> squid
e. Group that Squid runs as ==> squid
f. Use database to extract user information ==> No 
g. Press the Save button.

And that takes care of the squidGuard module for Webmain.


Permalink 08:21:53 am, by admin Email , 638 words   English (US)
Categories: Install Notes, Squid Proxy, Samba File Server

Squid + NTLM

Setup working directory

> mkdir /root/squid
> cd /root/squid

Download squid and samba

> wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE3.tar.gz
> wget http://us2.samba.org/samba/ftp/samba-latest.tar.gz

Unpack squid and samba

> tar -xvzf squid-2.5.STABLE3.tar.gz
> tar -xvzf samba-latest.tar.gz

Build samba

> cd samba-2.2.8a/source
> ./configure --with-winbind --with-winbind-auth-challenge
> make
> make install

Configure samba

> cd /root/samba-2.2.8.a/examples/simple
> cp smb.conf /usr/local/samba/lib/
> emacs /usr/local/samba/lib/smb.conf

Add the following lines to the [global] section of the smb.conf file:

    encrypt passwords = true
    workgroup = RELIABLEPENGUIN
    password server = ADTEST
    security = domain
    winbind uid = 10000-20000
    winbind gid = 10000-20000
    winbind use default domain = yes

Replace RELIABLEPENGUIN and ADTEST with the name of the domain and pdc to
be used for this install. Press Ctrl-X Ctrl-C to save and exit emacs.

Comment out entirely the [homes] and [printers] sections.

Join the server to the windows domain.

> ./smbpasswd -j RELIABLEPENGUIN -r ADTEST -U Administrator

Start the samba services:

> /usr/local/samba/bin/nmbd
> /usr/local/samba/bin/winbindd

Test and verify proper operation:

> /usr/local/samba/bin/wbinfo -t
Secret is good

If wbinfo returns "Secret is bad" then run the above command to join the domain
again.

> /usr/local/samba/bin/wbinfo -a RELIABLEPENGUIN\\Administrator%testing
plaintext password authentication succeeded
challenge/response password authentication succeeded

If you get and error then there is something wrong with the domain membership.

Now build squid:

> cd /root/squid/squid-2.5.STABLE3
> ./configure --enable-auth="ntlm,basic" \
     --enable-basic-auth-helpers="winbind" \
     --enable-ntlm-auth-helpers="winbind" \
     --sysconfdir=/etc/squid \
     --sbindir=/usr/sbin \
     --bindir=/usr/sbin \
     --libexecdir=/usr/lib/squid \
     --datadir=/usr/share/squid \
     --localstatedir=/var/run \
     --mandir=/usr/share/man
> make
> make install

Test the winbind helper:

> /usr/lib/squid/wb_auth -d
/wb_auth[16936](wb_basic_auth.c:168): basic winbindd auth helper build Jun  3 2003, 12:03:17 starting up...
RELIABLEPENGUIN\Administrator testing
/wb_auth[16936](wb_basic_auth.c:129): Got 'RELIABLEPENGUIN\Administrator testing' from squid (length: 37).
/wb_auth[16936](wb_basic_auth.c:55): winbindd result: 1
/wb_auth[16936](wb_basic_auth.c:58): sending 'OK' to squid
OK

Now configure squid to use the helper.
Edit /etc/squid/squid.conf and add the following lines:

  pid_filename /var/run/squid.pid

  ....

  cache_dir ufs /var/cache/squid 5000 16 256

  ....

  cache_access_log /var/log/squid/access.log

  ....

  cache_log /var/log/squid/cache.log

  ....

  cache_store_log /var/log/squid/store.log

  ....

  auth_param ntlm program /usr/lib/squid/wb_ntlmauth
  auth_param ntlm children 5
  auth_param ntlm max_challenge_reuses 0
  auth_param ntlm max_challenge_lifetime 2 minutes

  auth_param basic program /usr/lib/squid/wb_auth
  auth_param basic children 5
  auth_param basic realm Squid proxy-caching web server
  auth_param basic credentialsttl 2 hours

  ....

  acl localnetwork src 10.0.0.0/255.0.0.0
  acl password proxy_auth REQUIRED

  ....

  http_access allow password
  http_access allow localnetwork

Do squid cache setup:

> cd /var/cache
> mkdir squid
> chgrp squid squid
> chmod g+w squid
> squid -z

Do squid logs setup:

> cd /var/log
> mkdir squid
> chgrp squid squid
> chmod g+w squid

Setup squid and samba to start on boot:

The stock startup file distributed by redhat with squid is sufficient
for starting squid. This file is located at /etc/init.d/squid. If the file
does not exists on the target system then copy from another system or extract
from the redhat squid rpm.

A custom startup script is required for samba since we're not acting as a file
server - just nmbd and winbind. A suitable file is located at /etc/init.d/samba.
Copy this file to the target system.

Now symlink the startup scripts into the rc dirctories:

ln -s ../init.d/squid /etc/rc3.d/S25squid
ln -s ../init.d/samba /etc/rc3.d/S24samba
ln -s ../init.d/squid /etc/rc3.d/K25squid
ln -s ../init.d/samba /etc/rc3.d/K24samba

And that does it.

July 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Reliable Penguin offers Linux Server Migrations, Systems Administration & Programming. Visit our main website at:

http://www.reliablepenguin.com

Search

Bookmark and Share

XML Feeds

powered by b2evolution