CentOS7

プロキシサーバーでコンテンツフィルタリング(squidGuard)

Squidと連携して使用するフィルタリングソフトであるsquidGuardを利用して子供がスマホでアダルトサイト等の不適切なサイトへアクセスできないようにする。ここでは、アクセス元IPアドレス※により、ブラックリストに登録されたサイトへアクセスできないようにする。

※あらかじめDHCP設定で固定IPアドレスを割り当てておくこと

squidGuardインストール

[root@localhost ~]# yum -y install squidGuard ← squidGuardインストール

squidGuard設定

Google翻訳コマンドインストール ※後述の「ブラックリスト作成」で使用

[root@localhost ~]# git clone https://github.com/soimort/translate-shell ← translate-shellダウンロード
[root@localhost ~]# cd translate-shell/ ← ダウンロード先ディレクトリへ移動
[root@localhost translate-shell]# make && make install ← translate-shellインストール
[root@localhost translate-shell]# cd ← ホームディレクトリへ戻る
[root@localhost ~]# rm -rf translate-shell/ ← translate-shellディレクトリ削除

ブラックリスト作成

Shalla's Blacklistsで提供されるブラックリストを使用する。

[root@localhost ~]# rm -f /var/squidGuard/blacklists.tar.gz ← squidGuardと一緒にインストールされるサンプルブラックリスト削除 ※Shalla's Blacklistsのブラックリストを使用するので不要なため
[root@localhost ~]# vi /etc/cron.daily/squidGuard-blacklists-udate ← ブラックリスト日次更新スクリプト作成
#!/bin/sh

cd /var/squidGuard/

# ブラックリストダウンロード
wget http://www.shallalist.de/Downloads/shallalist.tar.gz > /dev/null 2>&1
[ $? -ne 0 ] && echo "$(basename ${0}) aborted!" | mail -s "$(basename ${0}) aborted!" root && exit

# ブラックリスト展開
tar zxvf shallalist.tar.gz > /dev/null 2>&1
[ $? -ne 0 ] && echo "$(basename ${0}) aborted!" | mail -s "$(basename ${0}) aborted!" root && exit
rm -f shallalist.tar.gz

# squidGuard設定ファイル(ブラックリスト定義)作成
rm -f /etc/squid/squidGuard-blacklist.conf
cat BL/global_usage | while read line
do
echo ${line} | grep "^NAME:" > /dev/null 2>&1
if [ $? -eq 0 ]; then
NAME=`echo ${line} | awk '{print $2}'`
fi
echo ${line} | grep "^DESC EN:" > /dev/null 2>&1
if [ $? -eq 0 ]; then
DESC=`echo ${line} | sed -e 's/DESC EN: \(.*\)/\1/p' -e d | /usr/local/bin/trans -b --no-auto :ja`
fi
echo ${line} | grep "^NAME EN:" > /dev/null 2>&1
if [ $? -eq 0 ]; then
NAME_FULL=`echo ${line} | sed -e 's/NAME EN: \(.*\)/\1/p' -e d`
echo "# ${NAME_FULL}" >> /etc/squid/squidGuard-blacklist.conf
echo "# ${DESC}" >> /etc/squid/squidGuard-blacklist.conf
echo "dest ${NAME} {" >> /etc/squid/squidGuard-blacklist.conf
echo " domainlist BL/${NAME}/domains" >> /etc/squid/squidGuard-blacklist.conf
echo " urllist BL/${NAME}/urls" >> /etc/squid/squidGuard-blacklist.conf
echo " redirect http://hoge.com/cgi-bin/squidGuard-simple.cgi?clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&targetgroup=%t&url=%u" >> /etc/squid/squidGuard-blacklist.conf
echo " log anonymous block.log" >> /etc/squid/squidGuard-blacklist.conf
echo "}" >> /etc/squid/squidGuard-blacklist.conf
echo >> /etc/squid/squidGuard-blacklist.conf
fi
done

if [ ${#} -eq 0 ]; then

# squidGuard設定ファイル生成
cat /etc/squid/squidGuard-common.conf \
/etc/squid/squidGuard-src.conf \
/etc/squid/squidGuard-blacklist.conf \
/etc/squid/squidGuard-acl.conf > /etc/squid/squidGuard.conf

# ブラックリストDB化
squidGuard -C all
chown -R squid.squid /var/squidGuard/
chown -R squid.squid /var/log/squidGuard/

# Squid再読み込み
squid -k reconfigure
fi
[root@localhost ~]# chmod +x /etc/cron.daily/squidGuard-blacklists-udate ← ブラックリスト日次更新スクリプトに実行権限付加
[root@localhost ~]# /etc/cron.daily/squidGuard-blacklists-udate 1 ← ブラックリスト日次更新スクリプト実行(squidGuard設定ファイル(ブラックリスト定義)作成)

squidGuard設定

[root@localhost ~]# vi /etc/squid/squidGuard-common.conf ← squidGuard設定ファイル(基本)作成
dbhome /var/squidGuard
logdir /var/log/squidGuard
[root@localhost ~]# vi /etc/squid/squidGuard-src.conf ← squidGuard設定ファイル(IPアドレス定義)作成
# IPアドレス定義(管理者)
src admin {
ip 192.168.1.11
}

# IPアドレス定義(ママ)
src mama {
ip 192.168.1.12
}

# IPアドレス定義(子供)
src kids {
ip 192.168.1.13
ip 192.168.1.14
}
[root@localhost ~]# vi /etc/squid/squidGuard-acl.conf ← squidGuard設定ファイル(アクセス制御定義)作成
# アクセス制御定義
acl {

# アクセス制御定義(管理者)
admin {
# 無制限
pass any
}

# アクセス制御定義(ママ)
mama {
# 無制限
pass any
}

# アクセス制御定義(その他)
default {
# ブラックリストの下記カテゴリ以外アクセス許可
# ※各カテゴリの意味はsquidGuard設定ファイル(ブラックリスト定義)参照
pass !aggressive !costtraps !dating !drugs !gamble !hacking !porn !religion !sex/lingerie !sex/education !spyware !violence !warez !weapons all
}
}
[root@localhost ~]# cat /etc/squid/squidGuard-common.conf \
/etc/squid/squidGuard-src.conf \
/etc/squid/squidGuard-blacklist.conf \
/etc/squid/squidGuard-acl.conf > /etc/squid/squidGuard.conf ← squidGuard設定ファイル生成
[root@localhost ~]# squidGuard -d -C all ← ブラックリストDB化



2017-06-19 16:01:40 [782] squidGuard 1.4 started (1497855664.965)
2017-06-19 16:01:40 [782] db update done
2017-06-19 16:01:40 [782] squidGuard stopped (1497855700.105)
[root@localhost ~]# chown -R squid.squid /var/squidGuard/ ← DBディレクトリ所有者変更
[root@localhost ~]# chown -R squid.squid /var/log/squidGuard/ ← ログディレクトリ所有者変更
[root@localhost ~]# vi /etc/squid/squid.conf ← Squid設定ファイル編集
以下を追加
# squidGuard連携設定
url_rewrite_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf
[root@localhost ~]# vi /var/www/cgi-bin/squidGuard-simple.cgi ← squidGuard-simple.cgi編集
# Email Adresse des Proxy Administrators:
# Edit to your requirements. Make sure to keep the @ escaped.
my $PROXYEMAIL = "root\@hoge.com"; ← 管理者メールアドレス変更

print " <A HREF=\"http://www.squidguard.org/\"><IMG SRC=\"http://www.squidguard.org/Logos/squidGuard.gif\"\n"; ← squidGuardロゴURL変更

print " <A HREF=\"http://www.squidguard.org/\"><IMG SRC=\"http://www.squidguard.org/Logos/squidGuard.gif\"\n"; ← squidGuardロゴURL変更

print " <A HREF=\"http://www.squidguard.org/\"><IMG SRC=\"http://www.squidguard.org/Logos/squidGuard.gif\"\n"; ← squidGuardロゴURL変更
[root@localhost ~]# systemctl reload squid ← Squid設定再読込み

Apache設定

アクセスブロック時に実行されるCGIスクリプトへ内部からのみアクセスできるよう制限する。

[root@localhost ~]# vi /etc/httpd/conf.d/squidGuard.conf ← Apache用squidGuard設定ファイル作成
<Files "squidGuard-simple.cgi">
<IfModule mod_authz_core.c>
# Apache 2.4
Require ip 127.0.0.1
Require ip 10.0.0.0/8
Require ip 172.16.0.0/12
Require ip 192.168.0.0/16
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order allow,deny
Allow from 127.0.0.1
Allow from 10.0.0.0/8
Allow from 172.16.0.0/12
Allow from 192.168.0.0/16
</IfModule>
</Files>
[root@localhost ~]# systemctl reload httpd ← Apache用squidGuard設定反映
[root@localhost ~]# rm -f /var/www/cgi-bin/squidGuard-simple-de.cgi ← 使用しないCGIスクリプト削除
[root@localhost ~]# rm -f /var/www/cgi-bin/squidGuard.cgi ← 使用しないCGIスクリプト削除

squidGuard確認


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-08-29 (水) 15:48:14