この投稿は新しいものではありませんが、実生活の例を紹介します。 私自身は、BashおよびPHP言語の専門家ではありません。 ほとんどの場合、この指示はさらに簡素化および改善できます。
作業のために、データベースの更新プロセスを自動化し、SquidGuardの禁止ファイルの変更を簡素化する必要がありました。 短い時間で、私の知識のために、この方法でこのタスクを実現しました...
1)禁止データベース(update_squidGuard.sh)を自動的に更新するスクリプトを作成しています。 スクリプトは、現在の禁止シートのバックアップコピーを作成し、シートの新しいデータベースをアップロードし、それを展開し、Squidを更新および再構成します。 彼は週に一度働きます。
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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 '============================'
#!/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ファイルの例:
- < html >
- < 頭 >
- < title >エディター</ title >
- </ 頭 >
- < 本体 >
- < 表 >
- < tbody >
- < tr >
- < td > DOMAINS-BAロックリスト</ td >
- < td > <a href = "lists.php? action = domains-bad">編集</ a > </ td >
- </ tr >
- < tr >
- < td > URLS-BADブロックリスト</ td >
- < td > <a href = "lists.php? action = urls-bad">編集</ a > </ td >
- </ tr >
- </ tbody >
- </ 表 >
- </ body >
- </ html >
*このソースコードは、 ソースコードハイライターで強調表示されました。
4.3)locksheets lists.phpの出力を処理するファイル:
- <? php
- header ( 'Content-Type:text / html; charset = UTF-8' );
- $ var = "domains" ;
- if ( isset ($ _GET [ 'action' ]))
- {
- $ var = $ _GET [ 'action' ];
- }
- ? >
- < font style = "font-size:20px" color = "#000000" face = "Arial" > BL EDITOR: </ フォント >
- <br />
- < form action = "update.php?actions = $ var" method = "get" >
- < 表 >
- < td >
- < th >
- 禁止事項のリスト:
- < textarea name = "$ var" style = "width:300; height:300" >
- <? php
- $ filename = "$ var.diff" ;
- $ fp = fopen ($ filename 、 'r' );
- $ buffer = fread ($ fp 、 filesize ($ filename ));
- $ buffer = str_replace ( "" 、 '' 、$ buffer );
- echo $ buffer ;
- fclose ($ fp );
- ? >
- </ textarea >
- </ th >
- </ td >
- </ 表 >
- <br />
- < 入力 タイプ = "非表示" 名前 = "アクション" 値 = "&# 60 ;?= $ var ? > " >
- < 入力 タイプ =「送信」 名前 =「更新」 値 =「変更の保存」 >
- </ フォーム >
- <br />
- <a href = "#">ホーム<a />
*このソースコードは、 ソースコードハイライターで強調表示されました。
4.4)ロックファイルを変更した後、update.phpを実行し、ファイルに変更を書き込みます。
- <? php
- header ( 'Content-Type:text / html; charset = UTF-8' );
- $ var = "domains" ;
- if ( isset ($ _GET [ 'action' ]))
- {
- $ var1 = $ _GET [ 'action' ];
- }
- // ファイル に 新しい データ を 追加 し ます
- // ドメイン domainの リスト 。 diff
- $ upd1 = $ _GET [ '$ var' ];
- $ upd1 = str_replace ( "\ r" 、 '' 、$ upd1 );
- $ fd = "$ var1.diff" ;
- $ fdomain = fopen ($ fd 、 "w +" );
- fwrite ($ fdomain 、$ upd1 );
- fclose ($ fdomain );
- echo "&# 60 ; b >すべてOK! </ b > ";
- echo " <a href = index. php>ホーム</ a > ";
- ? >
*このソースコードは、 ソースコードハイライターで強調表示されました。
それだけです。結果をテストすることができます。 この経験またはその一部が誰かに役立つことを願っています。 成功。
PS:批判は大歓迎です。