SQUIDプロキシオートメーション

この投稿は新しいものではありませんが、実生活の例を紹介します。 私自身は、BashおよびPHP言語の専門家ではありません。 ほとんどの場合、この指示はさらに簡素化および改善できます。
作業のために、データベースの更新プロセスを自動化し、SquidGuardの禁止ファイルの変更を簡素化する必要がありました。 短い時間で、私の知識のために、この方法でこのタスクを実現しました...

1)禁止データベース(update_squidGuard.sh)を自動的に更新するスクリプトを作成しています。 スクリプトは、現在の禁止シートのバックアップコピーを作成し、シートの新しいデータベースをアップロードし、それを展開し、Squidを更新および再構成します。 彼は週に一度働きます。
  1. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  2. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  3. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  4. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  5. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  6. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  7. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  8. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  9. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  10. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  11. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  12. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  13. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  14. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  15. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  16. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  17. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  18. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  19. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  20. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'
  21. #!/bin/sh echo '__________ __________' tar zcf old_blacklists.tgz /etc/squid/blacklists/ echo '============================' echo '!' echo '============================' echo '__________ __________' /usr/bin/wget -q --cache=off 'http://www.shallalist.de/Downloads/shallalist.tar.gz' –O /etc/squid/updatedb/shallalist.tar.gz tar zxf /etc/squid/updatedb/shallalist.tar.gz -C /etc/squid/updatedb/ cp -R -f /etc/squid/updatedb/BL/* /etc/squid/blacklists/ rm -R /etc/squid/updatedb/BL/ echo '============================' echo '!' echo '============================' echo '__________ SQUID__________' /etc/squid/updatedb/rebuid_base.sh squid -k reconfigure echo '============================' echo ' !' echo '============================'


2)SquidGuardのデータベースを20分ごとに更新するファイル(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)クラウンでスクリプトを実行します。
tux# crontab –u squid –e
0,20,40 * * * * /etc/squid/updatedb/rebuid_base.sh
00 21 * * 7 /etc/squid/updatedb/update_squidGuard.sh


4)当然、Squidのリモート制御と監視には多くの複雑なシステムがあります。 歴史的に、SAMSは私たちから統計を収集しますが、今日まで知られていない理由により、そのロックリストを使用したい人はいません。 小さなファイルエディタを30分で書きました。 禁止されているファイルは20分ごとに処理されるため、禁止のリストを簡単に変更できます。
最初に、/ var / www / html /内のロックグループごとにファイルシンボリックリンク(* .diff)を作成します。
グループシートの例:bad、good、pron。
domains-bad.diff
domains-good.diff
domains-pron.diff

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



これは確かに退屈で感謝に値する仕事ではありませんが、一度やったことはもう考えられません。
4.1)htaccessファイルによるサイトのこのセクションへの最も簡単なアクセス保護:
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)index.htmlファイルの例:
  1. < html >
  2. < >
  3. < title >エディター</ title >
  4. </ >
  5. < 本体 >
  6. < >
  7. < tbody >
  8. < tr >
  9. < td > DOMAINS-BAロックリスト</ td >
  10. < td > <a href = "lists.php? action = domains-bad">編集</ a > </ td >
  11. </ tr >
  12. < tr >
  13. < td > URLS-BADブロックリスト</ td >
  14. < td > <a href = "lists.php? action = urls-bad">編集</ a > </ td >
  15. </ tr >
  16. </ tbody >
  17. </ >
  18. </ body >
  19. </ html >
*このソースコードは、 ソースコードハイライターで強調表示されました。

4.3)locksheets lists.phpの出力を処理するファイル:
  1. <? php
  2. header'Content-Type:text / html; charset = UTF-8' );
  3. $ var = "domains" ;
  4. ifisset ($ _GET [ 'action' ]))
  5. {
  6. $ var = $ _GET [ 'action' ];
  7. }
  8. >
  9. < font style = "font-size:20px" color = "#000000" face = "Arial" > BL EDITOR: </ フォント >
  10. <br />
  11. < form action = "update.php?actions = $ var" method = "get" >
  12. < >
  13. < td >
  14. < th >
  15. 禁止事項のリスト:
  16. < textarea name = "$ var" style = "width:300; height:300" >
  17. <? php
  18. $ filename = "$ var.diff" ;
  19. $ fp = fopen ($ filename'r' );
  20. $ buffer = fread ($ fpfilesize ($ filename ));
  21. $ buffer = str_replace""'' 、$ buffer );
  22. echo $ buffer ;
  23. fclose ($ fp );
  24. >
  25. </ textarea >
  26. </ th >
  27. </ td >
  28. </ >
  29. <br />
  30. < 入力 タイプ = "非表示" 名前 = "アクション" = "&# 60 ;?= $ var> " >
  31. < 入力 タイプ =「送信」 名前 =「更新」 =「変更の保存」 >
  32. </ フォーム >
  33. <br />
  34. <a href = "#">ホーム<a />
*このソースコードは、 ソースコードハイライターで強調表示されました。

4.4)ロックファイルを変更した後、update.phpを実行し、ファイルに変更を書き込みます。
  1. <? php
  2. header'Content-Type:text / html; charset = UTF-8' );
  3. $ var = "domains" ;
  4. ifisset ($ _GET [ 'action' ]))
  5. {
  6. $ var1 = $ _GET [ 'action' ];
  7. }
  8. // ファイル 新しい データ 追加 ます
  9. // ドメイン domainの リストdiff
  10. $ upd1 = $ _GET [ '$ var' ];
  11. $ upd1 = str_replace"\ r"'' 、$ upd1 );
  12. $ fd = "$ var1.diff" ;
  13. $ fdomain = fopen ($ fd"w +" );
  14. fwrite ($ fdomain 、$ upd1 );
  15. fclose ($ fdomain );
  16. echo "&# 60 ; b >すべてOK! </ b > ";
  17. echo " <a href = index. php>ホーム</ a > ";
  18. >
*このソースコードは、 ソースコードハイライターで強調表示されました。

それだけです。結果をテストすることができます。 この経験またはその一部が誰かに役立つことを願っています。 成功。
PS:批判は大歓迎です。

Source: https://habr.com/ru/post/J74653/


All Articles