The wiki is currently undergoing some major improvements. If you need some information and you don't know where to look, please come to #ecnet

PfSenseVideoCache

From ECNet Wiki

How to install VideoCache on pfSense 1.2.x

This guide is based on VideoCache's guide here: http://cachevideos.com/install-videocache-pfsense
Comments here: http://cachevideos.com/forum/post/how-cachevideos-pfsense

  1. Install pfSense 1.2 per this guide http://doc.pfsense.org/index.php/HOWTO_Install_pfSense (current stable version as of writing this guide is 1.2.2).

  2. Log into http://192.168.1.1/. Select System > Packages and install Squid (I used 2.6.21_08. This may work with Squid3 but I have not tested this). I will continue to use 192.168.1.1 throughout this guide but you can enter your actually LAN IP if it is otherwise.

  3. Select System > General Setup. Enable SSH. Also, set the webGUI protocol to http and blank out the webGUI port (defaulting it to 80). Reboot and make sure Squid is not only running but still working (blacklist a site and then try to visit it). I seem to be having an issue where Squid sometimes goes corrupt and need a reinstall after a reboot.

  4. SSH to 192.168.1.1 logging is as "root" and using the same password as the admin user of the webGUI.

  5. pfSense is based on FreeBSD 7.0 and not 7.1 so we must change an environment variable so pkg_add will pull packages from the proper URL. Type "setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7-stable/Latest/". By default it will try to pull from "ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7-release/Latest/" which no longer exists and will give you an error. Update: This is not needed for pfSence 1.2.3.

  6. Install Python and additional libraries. Ignore any errors generated by the installers in the next few steps.
# pkg_add -r python
# pkg_add -r py25-bsddb
# pkg_add -r py25-gdbm
# pkg_add -r py25-sqlite3
# pkg_add -r py25-tkinter


  1. Install URLGrabber from http://linux.duke.edu/projects/urlgrabber/download/ (3.1.0 is the current version as of this writing.)
# fetch http://linux.duke.edu/projects/urlgrabber/download/urlgrabber-x.x.x.tar.gz
# tar -xzf urlgrabber-x.x.x.tar.gz
# cd urlgrabber-x.x.x
# python setup.py bdist_rpm
# python setup.py install


  1. Install Iniparse (http://code.google.com/p/iniparse/downloads/list get the tar.gz not the deb or rpm. 0.3.1 is the current version as of this writing.)
# fetch http://iniparse.googlecode.com/files/iniparse-x.x.x.tar.gz
# tar -xzf iniparse-x.x.x.tar.gz
# cd iniparse-x.x.x
# python setup.py bdist_rpm
# python setup.py install


  1. Install VideoCache (http://cachevideos.com/download Get the tar.gz. Current version is 1.9.1 as of this writing.)
# fetch http://cachevideos.com/sites/default/files/pub/videocache/videocache-x.x.x.tar.gz
# tar -xvzf videocache-x.x.tar.gz
# cd videocache-x.x.x
# python setup.py install


  1. Configure VideoCache

Using vi or ee, edit /etc/videocache.conf. Set proxy to 192.168.1.1. (Note: Set this to the LAN IP even if you are using transparent mode). Set cache_host to http://192.168.1.1:3128/ (do not use 127.0.0.1). Set max_parallel_downloads to 3.

  1. Configure Squid

Add the following lines to /usr/local/pkg/squid.inc and /usr/local/etc/squid/squid.conf. Add the lines after the acls.

# --BEGIN-- videocache config for squid
url_rewrite_program /usr/local/bin/python /usr/share/videocache/videocache.py
url_rewrite_children 2
acl videocache_allow_url url_regex -i \.youtube\.com\/get_video\?
acl videocache_allow_url url_regex -i \.googlevideo\.com\/videoplayback \.googlevideo\.com\/videoplay \.googlevideo\.com\/get_video\?
acl videocache_allow_url url_regex -i \.google\.com\/videoplayback \.google\.com\/videoplay \.google\.com\/get_video\?
acl videocache_allow_url url_regex -i \.google\.[a-z][a-z]\/videoplayback \.google\.[a-z][a-z]\/videoplay \.google\.[a-z][a-z]\/get_video\?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/videoplayback\?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/videoplay\?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/get_video\?
acl videocache_allow_url url_regex -i proxy[a-z0-9\-][a-z0-9][a-z0-9][a-z0-9]?\.dailymotion\.com\/
acl videocache_allow_url url_regex -i vid\.akm\.dailymotion\.com\/
acl videocache_allow_url url_regex -i [a-z0-9][0-9a-z][0-9a-z]?[0-9a-z]?[0-9a-z]?\.xtube\.com\/(.*)flv
acl videocache_allow_url url_regex -i bitcast\.vimeo\.com\/vimeo\/videos\/
acl videocache_allow_url url_regex -i va\.wrzuta\.pl\/wa[0-9][0-9][0-9][0-9]?
acl videocache_allow_url url_regex -i \.files\.youporn\.com\/(.*)\/flv\/
acl videocache_allow_url url_regex -i \.msn\.com\.edgesuite\.net\/(.*)\.flv
acl videocache_allow_url url_regex -i media[a-z0-9]?[a-z0-9]?[a-z0-9]?\.tube8\.com\/ mobile[a-z0-9]?[a-z0-9]?[a-z0-9]?\.tube8\.com\/
acl videocache_allow_url url_regex -i \.mais\.uol\.com\.br\/(.*)\.flv
acl videocache_allow_url url_regex -i \.video[a-z0-9]?[a-z0-9]?\.blip\.tv\/(.*)\.(flv|avi|mov|mp3|m4v|mp4|wmv|rm|ram)
acl videocache_allow_url url_regex -i video\.break\.com\/(.*)\.(flv|mp4)
acl videocache_allow_dom dstdomain .mccont.com dl.redtube.com .cdn.dailymotion.com
acl videocache_deny_url url_regex -i http:\/\/[a-z][a-z]\.youtube\.com http:\/\/www\.youtube\.com
url_rewrite_access deny videocache_deny_url
url_rewrite_access allow videocache_allow_url
url_rewrite_access allow videocache_allow_dom
redirector_bypass on
# --END-- videocache config for squid


  1. Link the videocache directly to lighthttpd's webGUI directory.
ln -s /var/spool/videocache /usr/local/www/videocache


  1. Change ownership permissions.
chown -R proxy:proxy /var/spool/videocache
chown -R proxy:proxy /usr/local/www/videocache
chown -R proxy:proxy /var/log/videocache


  1. In my install /var/log/videocache/videocache.log is filling up to over 200MB in 5 minutes so I linked it to /dev/null so all logging attempts get sent straight to the bit bucket.

ln -s /dev/null /var/log/videocache/videocache.log
  1. Reload Squid (hit save on any tab on Services > Proxy Server without making any changes).
Personal tools