martedì, Marzo 19, 2024

Capire e usare il Proxy con Squid e Sarg

Qualche tempo fa ho realizzato un proxy server utilizzando Ubuntu.

SQUID

Ho installato Squid utilizzando il comando:

sudo apt-get install squid squid-common

E poi l’ho configurato, ma ATTENZIONE: prima di modificare qualsiasi configurazione bisogna copiare il file originale e proteggerlo da scrittura con i seguenti comandi:

sudo cp /etc/squid/squid.conf   /etc/squid/squid.conf.original
sudo chmod  a-w  /etc/squid/squid.conf.original

fatto ciò sono passato alla configurazione:

sudo nano /etc/squid/squid.conf

Basta modificare due parametri ed il proxy sarà funzionante:

aggiungere alla fine della sezione ACL

acl nomedelnetwork src 192.168.0.1/24 -->permette l’accesso agli utenti della rete 

                                                                                                                                                                             

Aggiungere all’inizio della sezione http_access la seguente riga:

http_access allow nomedelnetwork

Salvare il file digitando CTRL+X  e poi  Y e riavviare il servizio:

sudo /etc/init.d/squid restart 

Se non dovesse funzionare il comando digitare semplicemente:

service squid restart

Utilizzando Squid per lunghi periodi la cache si riempie in maniera spropositata ed ecco dei comandi che ci aiutano a svuotarla e liberare un bel po’ di spazio dal disco:

su root
service squid stop
cd /var/spool/squid
rm  -rf *
service squid start

SARG (Squid Analysis Report Generator)

Sarg ci permette di generare report sugli accessi ai siti internet da parte degli utenti “sotto proxy”.

Per installarlo:

sudo apt-get install sarg

Per utilizzare Sarg è necessaria la presenza del file access.log nella directory /var/log/squid/. Il file di default (su altre distro) non esiste quindi lo si genera aggiungendo al file /etc/squid/squid.conf la stringa:

access_log /var/log/squid/access.log

Non è necessario configurare il file di sarg per renderlo funzionante, ma se volete dare un’occhiata:
usr/local/etc/sarg/sarg.conf.

Sarg crea report automaticamente in var/www/squid-reports

Se si vogliono creare dei report al giornalieri:

sudo sarg-reports daily

Anche i dati di sarg come la cache di squid, con l’andare del tempo, tendono ad aumentare, quindi bisogna resettare i log.

su root
cd /var/log/squid/access.log

Cancellare il file access.log e ricrearlo.

Questa procedura ci permette di avere della pulizia sia a livello di spazio, ma soprattutto per quanto concerne la generazione dei report istantanei (sudo sarg).

Sarg esiste anche per Ubuntu 10.10 Maverick.

Package sarg

Name: sarg
Description: squid analysis report generator Sarg is a Squid Analysis Report Generator that allow you to view "where" your users are going to on the Internet. Sarg generate reports in html, with many fields, like: users, IP Addresses, bytes, sites and times.
Latest version: 2.2.7.1-2
Ubuntu release: maverick (10.10)
Level: base
Repository: universe

All versions of sarg in Maverick

No other version of this package in available in the Maverick release.

See all versions of sarg in all Ubuntu releases and repositories.

Directory di Sarg:

Source: http://sourceforge.net/projects/sarg/

Installation

------------

1. run ./configure

Useful configure options:

--prefix - The root directory of the installation

default: /usr/local

--bindir - where sarg binary will be saved

default: /usr/local/bin

--sysconfdir - where the configuration directory is

default: /usr/local/etc

--mandir - where the sarg man page will be saved

default: /usr/local/share/man

--enable-sargphp - where to install sarg-php (--disable-sargphp don't install sarg-php)

default: /var/www/html

--enable-fontdir - where to find the fonts for the reports (--diable-fontdir don't install the fonts)

default: /usr/local/share/sarg/fonts

--enable-imagedir - where sarg take the images to include in the reports

default: /usr/local/share/sarg/images

--enable-extraprotection - compile sarg with extra GCC options for increased security

default: use standard compilation warnings and no protection

For a complete list of all the options, run ./configure --help.

3. make

4. make install

5. Go to /usr/local/sarg (or file entered with --sysconfdir on configure)

and change sarg.conf as you need.

6. Notes about sarg:

Date/Time report:

Every minute that a request is logged your time is incremented by the smaller

of 1 minute or the total time for the requests.

Usage: sarg -h

Alessio Alessandro

Articoli correlati

Il caso “Medusa Ransomware”

I ransomware stanno diventando sempre più una minaccia di rilevanza importante, quasi da non far dormire sonni tranquilli ad aziende sia pubbliche che private,...

Digital Transformation


 

Noleggia una Tesla per il tuo evento ICT!

Categorie