Хаклаб/Squid: Разлика помеѓу преработките

Од Сподели wiki
Прејди на прегледникот Прејди на пребарувањето
с (4 ревизии: initial)
 
(нема разлика)

Последна преработка од 18:41, 29 јануари 2011

Squid во хаклабот

squid верзија

debilan:~# dpkg -l | grep squid3
ii  squid3                            3.0.STABLE8-3+lenny3     A full featured Web Proxy cache (HTTP proxy)
ii  squid3-common                     3.0.STABLE8-3+lenny3     A full featured Web Proxy cache (HTTP proxy)ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0Usc9/xQM5ZFHtFk3zvHgh529Rb2YngMYjbjnXbUIdsFViHXRaciho58x+6De34Gyqj5ZKckygZPMeI1P68RjiJiBRalIyO19gbqej41JsKXHwmsdwNIQosFd4yR4cY2elpFwm06eKT6H2S69s6FDfZevjmdJPQnTUVc52WDEIVUBKrkoPGWUhtfahK7yc/MT4yj7s9DAGQyRIIFnMD+FB5zrkMDgD2Z7hIr0p0wedscA5ChOw8OID4OZqwgF7byQtp2cZzSYbWBqkCb8nDk2HAwJppz31lu0KuLT2crgt3JpnyRYQxVv3oAekneGftGdjXUgEJDZTkeK39VVbg4ww== aleks@ZarakiKenpachi

squid.conf

debilan:~# grep -v "^#" /etc/squid3/squid.conf | sed -e '/^$/d'
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl hacklab_ipv4	src 192.168.88.0/24
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow hacklab_ipv4
http_access deny all
icp_access deny all
htcp_access deny all
http_port 3128 transparent
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid3/access.log squid
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern (cgi-bin|\?)	0	0%	0
refresh_pattern .		0	20%	4320
icp_port 3130
coredump_dir /var/spool/squid3


iptables conf

/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

calamaris squid log analyzer

Достапно на http://ipv6.softver.org.mk/squidstats/. За заштита на приватноста сквидот не логира во Хаклаб. (access_log /dev/null squid)

debilan:~# dpkg -l | grep calamaris
ii  calamaris                         2.99.4.0-8               log analyzer for Squid or Oops proxy log fil

Плус печот од http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=501396#28

Се генерира во logrotate.d/squid4, за да го фати access log пред да се изротира:

debilan:~# cat /etc/logrotate.d/squid3 
#
#	Logrotate fragment for squid3.
#
/var/log/squid3/*.log {
	daily
	compress
	delaycompress
	rotate 2
	missingok
	nocreate
	sharedscripts
	prerotate
		cat /var/log/squid3/access.log | calamaris --config-file /etc/calamaris/calamaris.conf -a --output-format html,graph --output-path /home/html/squidstats --generate-index --image-type png --cache-output-file /home/html/squidstats/kesh.dat --cache-input-file /home/html/squidstats/kesh.dat
	endscript
	postrotate
		test ! -e /var/run/squid3.pid || /usr/sbin/squid3 -k rotate
	endscript
}


redirektor

За луѓето кои првпат доаѓаат во Хаклаб да добијат информации за ресурсите во Хаклабот има редиректор скрипта која кога ќе види некоја ајпи адреса првпат ја опслужува со специјална страница.

###### squid3.conf
url_rewrite_program /home/ftp/squid/redirektor.py
acl yuck dstdomain .lugola.net # da raboti dobredojde t.e wiki.lugola.net
url_rewrite_access deny yuck


##### redirektor.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
    Redirector (url_rewrite_program) скрипта за squid. 

    Секоја нова ИП адреса првите 30 секунди неможе да сурфа и целиот http сообраќај ѝ го редиректира на
    специјална страница „Вовед во Hacklab.sk“.

    Нова ИП адреса е секоја адреса после 8 часа.

    Идејата од:
    http://gofedora.com/how-to-write-custom-redirector-rewritor-plugin-squid-python/

    TODO:
        - Да работи во тредови. Сега цел сообраќај низ едно цевче проаѓа.
"""

import sys
import time

ip_db = dict()
TIMEOUT=8*60*60 
IP_WHITELIST = ['192.168.88.110','192.168.88'] # не ги ремети овие ИП адреси

while True:

    #0 http://www.facebook.com/ 192.168.88.110/- - GET myip=66.220.145.13 myport=80
    line = sys.stdin.readline().strip()
    argumenti = line.split(' ')
    id = argumenti[0]
    ip = argumenti[2].split('/')[0]

    if ip in IP_WHITELIST:
        sys.stdout.write(line + '\n')
        sys.stdout.flush()
        continue

    now = time.time()
    first_visit = ip_db.setdefault(ip, now)

    if 30 < now - first_visit < TIMEOUT:
        sys.stdout.write(line + '\n')
        sys.stdout.flush()
    else:
        newline = '%s %s\n' % (id,'http://127.0.0.1/ftp/squid/dobredojde.html')
        sys.stdout.write(newline)
        sys.stdout.flush()

        if now - first_visit > TIMEOUT:
            ip_db[ip] = now