SQUID Proxy Automation

    This post does not claim to be new, I give an example from real life. I myself am not an expert on Bash & PHP languages. Most likely, this instruction can be further simplified and improved.
    For work, it was necessary to automate the database update process and simplify the modification of the ban files for SquidGuard. In a short time and because of my knowledge, I implemented this task in this way ...

    1) We write a script for automatically updating the prohibition databases (update_squidGuard.sh). The script creates a backup copy of the current prohibition sheet, uploads a new database of sheets, unpacks it, updates and reconfigures Squid. He will work once a week.
    1. #!/bin/sh
    2. echo '__________Создаем резервную копию листа запретов__________'
    3. tar zcf old_blacklists.tgz /etc/squid/blacklists/
    4. echo '============================'
    5. echo 'Успешно!'
    6. echo '============================'
    7. echo '__________Скачиваем свежую базу и перемещаем её поверх старой__________'
    8. /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O
    9. /etc/squid/updatedb/shallalist.tar.gz
    10. tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/
    11. cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/
    12. rm -R /etc/squid/updatedb/BL/
    13. echo '============================'
    14. echo 'Успешно!'
    15. echo '============================'
    16. echo '__________Обновляем базы и реконфигурируем SQUID__________'
    17. /etc/squid/updatedb/rebuid_base.sh
    18. squid -k reconfigure
    19. echo '============================'
    20. echo 'Всё успешно сделано!'
    21. echo '============================'


    2) Create a file that will update the database for SquidGuard every 20 minutes (rebuild_base.sh)
    #!/bin/sh
    chown -R squid:squid /etc/squid/blacklists
    /usr/local/bin/squidGuard -u /etc/squid/blacklists/*/*.diff
    chown -R apache:apache /etc/squid/blacklists/*/*.diff
    /usr/sbin/squid -k reconfigure


    3) Run the scripts on the crown:
    tux# crontab –u squid –e
    0,20,40 * * * * /etc/squid/updatedb/rebuid_base.sh
    00 21 * * 7 /etc/squid/updatedb/update_squidGuard.sh


    4) Naturally, there are many complex systems for remote control and monitoring of Squid. Historically, SAMS collects statistics from us, but nobody wants to use its lock lists, for reasons not known to this day. I wrote my little file editor in 30 minutes. Since files with prohibitions are processed by us every 20 minutes, I can easily change the list of prohibitions.
    First, create file symlinks (* .diff) for each of the lock groups in / var / www / html /:
    Example for group sheets: bad, good, pron.
    domains-bad.diff
    domains-good.diff
    domains-pron.diff

    urls-bad.diff
    urls-good.diff
    urls-pron.diff



    This is certainly a tedious and not grateful task, but having done it once, you can no longer think about it.
    4.1) The easiest access protection to this section of the site through the htaccess file:
    Order deny,allow
    Deny from all
    Allow from 192.168.0.1
    Allow from 192.168.0.2
    Allow from 192.168.0.3



    4.2) Example index.html file:
    1. Редактор
    2.  
    3.   
    4.    
    5.    
    6.   
    7.   
    8.    
    9.    
    10.   
    11.  
    12. Список блокировок DOMAINS-BA редактировать
      Список блокировок URLS-BAD редактировать
    * This source code was highlighted with Source Code Highlighter.

    4.3) File dealing with the output of locksheet lists.php:
    1. header('Content-Type: text/html; charset=UTF-8');
    2. $var = "domains";
    3. if (isset($_GET['action']))
    4. {
    5.   $var = $_GET['action'];
    6. }
    7. ?>
    8. BL EDITOR:

    9. Список запретов:



    10. На главную
    * This source code was highlighted with Source Code Highlighter.

    4.4) After changing the lock files, run update.php, which writes the changes to the file.
    1. header('Content-Type: text/html; charset=UTF-8');
    2. $var = "domains";
    3. if (isset($_GET['action']))
    4. {
    5.   $var1 = $_GET['action'];
    6. }
    7. // Добавляем новые данные в файл
    8. // списка доменов domains.diff
    9. $upd1 = $_GET['$var'];
    10. $upd1 = str_replace("\r",' ',$upd1);
    11. $fd = "$var1.diff";
    12. $fdomain = fopen($fd,"w+");
    13. fwrite($fdomain, $upd1);
    14. fclose($fdomain);
    15. echo "<b>all ok!
      ";
    16. echo "Home";
    17. ?>
    * This source code was highlighted with Source Code Highlighter.

    That's all, you can try to test the result. I hope this experience or parts of it will be useful to someone. Successes.
    PS: Criticism is welcome.


    Also popular now: