This is install and and post-install notes for Netpolice service.

1. Installation Instructions.

cd /usr/ports/www/netpolice/
make install clean

2. Post-installation Instructions.

2.1. Post install options for squid.

At /usr/local/etc/squid/squid.conf you must add or check the following options:

icap_enable on
icap_connect_timeout 100 second
icap_io_timeout 100 second
icap_preview_enable off
icap_send_client_ip on
icap_send_client_username on
icap_client_username_header X-Authenticated-User
icap_client_username_encode on
icap_service service_url_filter_req reqmod_precache bypass=1 icap://127.0.0.1:1344/url_filter
icap_service service_url_filter_resp respmod_precache bypass=1 icap://127.0.0.1:1344/url_filter
adaptation_access service_url_filter_req allow all
adaptation_access service_url_filter_resp allow all 

2.2. Post install options for c-icap.

At /usr/local/etc/c-icap.conf you must add or check the following options:

Service url_filter_module srv_url_filter.so
url_filter.MemcachedServers "127.0.0.1:11211" 
url_filter.Host2CatServer "127.0.0.1:6666" 
url_filter.DBEngine "sqlite3" 
#url_filter.DBHost "localhost" 
#url_filter.DBPort "5432"      
url_filter.DBName "/var/lib/netpolice/filter.db" 
#url_filter.DBUser "username"                
#url_filter.DBPass "password"                
url_filter.RedirectUrl "http://www.google.com" 
#url_filter.ClientIPHeader "X-Client-IP" 
#url_filter.AuthUserHeader "X-Authenticated-User" 
#url_filter.AuthUserPrefix "Local://"             
#url_filter.AuthUserEncoded 0                     
# Default policy settings
# Values are: 0 - accept, 1 - reject, 2 - redirect
#url_filter.DBOpenErrorPolicy    1                
#url_filter.DBQueryErrorPolicy    0               
#url_filter.UnknownRolePolicy    1                
#url_filter.MemcachedConnectErrorPolicy    1      
#url_filter.MemcachedMissPolicy        0          
#url_filter.EmptyCategoryPolicy        0          
#url_filter.CategoryNotFoundPolicy    1           
url_filter.StatLog "/var/log/netpolice/stat.log" 
# Default value - LOG_INFO
#url_filter.SyslogPriority        6
url_filter.SyslogOn     1

Create log files:
touch /var/log/c-icap/access.log
chown _c_icap:netpolice /var/log/c-icap/access.log
touch /var/log/c-icap/server.log
chown _c_icap:netpolice /var/log/c-icap/server.log
touch /var/log/netpolice/stat.log
chown _c_icap:netpolice /var/log/netpolice/stat.log

2.3. Steps for creating database of local policy.

Create schema and test data:
--check that following files exists at /usr/local/libexec/host2cat/:
SQLite3.schema
users
custom_roles
generic_roles

--run script:
mkdir -p /var/lib/netpolice
cd /usr/local/libexec/host2cat/
perl init_filter_db.pl DBI:SQLite:/var/lib/netpolice/filter.db

If you use another sql server then file SQLite.schema rename to %%engine%%.schema (MySQL for example)
and check existence opendbx driver for that engine.

2.4. Post install options for powerdns.

At /usr/local/etc/pdns/pdns.conf  you must add or check the following options: recursor=81.176.72.75:53
Or cp /usr/local/etc/pdns/pdns.conf.sample /usr/local/etc/pdns/pdns.conf
and cp /usr/local/etc/pdns/zones.conf.sample /usr/local/etc/pdns/zones.conf

2.5. Post install options for apache and webadmin.

Add to /usr/local/etc/apache22/httpd.conf line "Listen 9000" in section Listen

cp /usr/local/etc/apache22/virtual/vhost-webadmin.conf.sample /usr/local/etc/apache22/virtual/vhost-webadmin.conf

Edit ethernet ip interface in /etc/local/etc/apache22/virtual/vhost-webadmin.conf

Create user:
cd /var/lib/netpolice/squid/
htpasswd -bc passwd netpolice netpolice

Create database for statistics:
cd /var/lib/netpolice
sqlite3 stat.db

sqlite> CREATE TABLE statistics (
...> id integer NOT NULL PRIMARY KEY,
...> date datetime NOT NULL,
...> user varchar(255),
...> role varchar(255),
...> client_ip varchar(50),
...> url text NOT NULL,
...> action integer NOT NULL,
...> mod smallint unsigned NOT NULL,
...> categories varchar(255)
...> );
sqlite>.quit

Create the following files:
touch /var/lib/netpolice/position
touch /var/lib/netpolice/ZONE.root
chown -R www:www /var/lib/netpolice

2.6. Netpolice.

At /usr/local/etc/netpolice/
cp /usr/local/etc/netpolice/webadmin.conf.sample /usr/local/etc/netpolice/webadmin.conf

3. Cron.

Add this line to your crontab for user www (replace ${version} to current python version):

05	*	*	*	*	/usr/local/bin/python /usr/local/lib/python{$version}/site-packages/webadmin/manage.py export_statistics

4. Steps for enable and run services.

Check or add the folowing records to /etc/rc.conf 

squid_enable="YES"
memcached_enable="YES"
host2cat_enable="YES"
c_icap_enable="YES"
pdns_enable="YES"
apache22_enable="YES"

Run services:
/usr/local/etc/rc.d/memcached start
/usr/local/etc/rc.d/host2cat start
/usr/local/etc/rc.d/c_icap start
/usr/local/etc/rc.d/squid start
/usr/local/etc/rc.d/pdns start
/usr/local/etc/rc.d/apache22 start

