#!/bin/bash # Script um die cache_peer funktion von Squid manuell von der Website aus upzudaten. # V1.0 # 13.10.2010 # Stoeckholzer, Haas while [ "1" == "1" ]; do write=1 zero=0 # ueberpruefen ob file vpnid_man vorhanden if [ -e /var/vpn/vpnid_man ]; then echo 1 zero=1 fi # ueberpruefen ob file vpnid_next vorhanden if [ -e /var/vpn/vpnid_next ]; then echo 2 zero=2 fi if [ "$zero" == "1" ]; then # Manuelle ID als hex einlesen einlesen hex=$(cat /var/vpn/vpnid_man) id=$(printf "%d\n" 0x$hex) echo $id > /var/vpn/vpnid rm /var/vpn/vpnid_man echo $hex # Login-Daten aus Datenbank holen credentials=$(/home/christoph/squid_dynamic/squidy $hex) fi if [ "$zero" == "2" ]; then schleife="1" rm /var/vpn/vpnid_next while [ $schleife == "1" ] ; do # Zaehlvariable einlesen id_alt=$(cat /var/vpn/vpnid) # alte id HEX wandeln zum BLacklisten hex_alt=$(echo "obase=16; $id_alt" |bc) # Abfrage ob Strinlaenge von hex kleiner als 2 if [ ${#hex_alt} -lt 2 ]; then hex_alt=0$hex_alt fi # alte id BLacklisten if [ $write == 1 ]; then echo $hex_alt >> /var/vpn/blacklist fi # id inkrementieren let id=$id_alt+1 # 255 Overflow verhindern if [ $id -gt 254 ] then id=0 fi # Variable id fuer naechsten Durchlauf speichern echo $id > /var/vpn/vpnid # id HEX wandeln hex=$(echo "obase=16; $id" |bc) # Abfrage ob Strinlaenge von hex kleiner als 2 if [ ${#hex} -lt 2 ]; then hex=0$hex fi # hole id_hex aus BLacklist? black=$(cat /var/vpn/blacklist|grep $hex) # Abfrage ob id_hex in BLacklist if [ ${#black} -lt 2 ]; then # Login-Daten aus Datenbank holen credentials=$(/home/christoph/squid_dynamic/squidy $hex) # Abfrage ob Datensatz leer : if [ ${#credentials} -gt 10 ]; then schleife="0" fi else write=0 fi done fi # Abfrage ob Datensatz leer (zur Sicherheit): if [ ${#credentials} -gt 10 ] && [ $zero != "0" ]; then # stop squid sudo killall -9 unlinkd sudo killall -9 squid sudo rm /etc/squid3/squid.conf ###################################################################################### # Config- Datei schreiben. sudo echo -e -n " # Squid config by h44z # TAG: http_port # Usage: port # hostname:port # 1.2.3.4:port http_port 10.8.0.1:3128 transparent http_port 10.8.0.1:8080 #https_port 10.8.0.1:8181 key=/etc/apache2/ssl/apache.pem visible_hostname vpnrack # TAG: icp_port icp_port 0 # TAG: no_cache acl QUERY urlpath_regex cgi-bin \\? no_cache deny QUERY # TAG: cache_mem (bytes) cache_mem 32 MB # TAG: cache_dir cache_dir ufs /var/cache/squid 100 16 256 # TAG: cache_access_log cache_access_log /var/log/squid/access.log # TAG: cache_log cache_log /var/log/squid/cache.log # TAG: cache_store_log cache_store_log /var/log/squid/store.log # TAG: emulate_httpd_log on|off emulate_httpd_log on # TAG: pid_filename pid_filename /var/run/squid.pid # TAG: cache_mgr cache_mgr christoph.haas2@students.htlinn.ac.at http_access allow all acl https port 443 http_access allow https # TAG: http_reply_access # Allow replies to client requests. This is complementary to http_access. #http_reply_access allow all cache_peer 192.168.195.101 parent 8080 7 no-query default no-digest login=$credentials never_direct allow all " > /etc/squid3/squid.conf ###################################################################################### echo "Written: $credentials" #start squid squid -D -YC -f /etc/squid3/squid.conf fi sleep 2 done