Friday, June 17, 2011

Transparent Squid Setup Firewall Script

#!/bin/bash

echo 1 > /proc/sys/net/ipv4/ip_forward

# Flush rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -s 10.10.10.0/255.255.255.0 -d 0.0.0.0/0.0.0.0 -j MASQUERADE

Thursday, June 2, 2011

Sample Squid Configuration File

The following is a sample squid 2.7 configuration file (/etc/squid/squid.conf):

acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

acl blocksites url_regex "/etc/squid/squid-block.acl"

acl officehour time M T W H F 9:00-16:59
acl afteroffice time 17:00-24:00
acl beforeoffice time 00:00-6:00
acl banned dst www.pornsite.com

acl SSL_ports port 443 # https
acl SSL_ports port 563 # snews
acl SSL_ports port 873 # rsync
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 631 # cups
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
acl purge method PURGE
acl CONNECT method CONNECT

http_access allow afteroffice blocksites
http_access allow beforeoffice blocksites
http_access deny blocksites

http_access deny banned

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
icp_access allow localnet
icp_access deny all
http_port 3128
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid/access.log squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern (Release|Package(.gz)*)$ 0 20% 2880
refresh_pattern . 0 20% 4320
acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9]
upgrade_http0.9 deny shoutcast
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
extension_methods REPORT MERGE MKACTIVITY CHECKOUT
hosts_file /etc/hosts
coredump_dir /var/spool/squid

Saturday, May 28, 2011

Installing Windows Fonts on Ubuntu Linux

There are three (3) ways to install Windows fonts on Ubuntu Linux. I have tested the following procedure under Ubuntu 10.10 Linux distribution but my guess is it should also work on other Linux distributions as well.

Way No. 1

(1) Access the Linux terminal by accessing the menu, Applications->Accessories->Terminal
(2) On the terminal, you have to be user "root" to install the package. To become "root", issue the command:

$ sudo su

This will prompt you for your password. Type in your password. If you are "root", the prompt should change from $ to #.

(3) To download and install the Windows fonts, type the command:

# apt-get install ttf-mscorefonts-installer

(4) To load the fonts, type the command:

# fc-cache -f -v


I am assuming that your computer is connected to the Internet and therefore by issuing the above-mentioned commands, installation of the fonts becomes trivial. As far as I know, you can also use the "Ubuntu Software Center" (click Applications->Ubuntu Software Center) and look for the MS True Type Fonts package.

If you are curious as to where the fonts are located, Ubuntu Linux copies the fonts to the directory "/usr/share/fonts". This directory is only accessible to the "root" user.


Way No. 2

In way 2, we will be installing fonts by manually copying the Windows fonts files and pasting it in the Ubuntu Linux directory.

(1) Copy the Windows fonts in your computer and place it in a transferable media such as a USB stick or CD.
(2) On the Ubuntu Linux computer, access the default home directory by going to "Places->Home Folder". On the home folder, check the "Show Hidden Files" on the "View" menu.
(3) Create the folder ".fonts". Yes, the folder got a dot before the word fonts. On Linux, folders with beginning dots means hidden folders.
(4) Copy the Windows fonts to the ".fonts" folder.
(5) Load the fonts by issuing the command:

$ fc-cache -f -v

As you can see, you don't need to be a "root" user to do this procedure. The fonts however will only be applied to the current user but not system wide unlike Way 1 procedure.


Way No. 3

In way 3, the procedure involves making the fonts available system-wide.

(1) On the terminal, become "root" by issuing the command:

$ sudo su

(2) Access the file manager in root mode by issuing the command:

# nautilus&

The file manager is called nautilus. The & makes the program independent of the terminal where it is run.

(3) Since you are already on the graphical file manager as "root", copy the Windows fonts to the Ubuntu Linux directory "/usr/share/fonts". I suggest creating a separate folder under this like "msttcorefonts".

(4) Load the fonts by issuing the command in the terminal:

# fc-cache -f -v


Other fonts can also be installed on Linux by following way 2 and 3 procedure above.

By the way, if you are concerned about licensing, the Microsoft Core fonts I have mentioned above can be redistributed freely as depicted in its license terms.

Thursday, August 12, 2010

Formula for the Intercept and Slope

Given a two (2) variable equation of a straight line, the formula for the slope is:

Slope (b) = S xy / S x^2

where:
S = summation
x = X minus the Mean of X
y = Y minus the Mean of Y


The formula for the intercept at its point of origin is:

Intercept (a) = M Y - b (M X)

where:
M = arithmetic mean
M Y = Mean of Y
b = Slope
M X = Mean of X

Monday, June 14, 2010

Getting the Square Root and Cube Root

The OpenOffice Calc spreadsheet formula for square root is:

= sqrt ( A )

Where A = data

This can also be reformulated as:

= A^(1/2)

This reformulation is versatile as it can be extended to handle cube roots as follows:

= A^(1/3)

Harmonic Mean

The Harmonic Mean formula is:

HM = 1.5 / (0.5/A + 0.5/B + 0.5/C )

Where: A, B, and C = sample data
0.5 is the assigned weight for each sample
1.5 is the total assigned weight for all samples

Given only two samples, the formula becomes:

HM = 1 / ( 0.5/A + 0.5/B )

The manual calculation of Harmonic Mean becomes tedious as the number of samples increases.

OpenOffice Calc spreadsheet uses the following formula in calculating for the Harmonic Mean:

= harmean ( range of cells of the sample data )

Geometric Mean Formula

The geometric mean formula is:

GM = ( A * B * C ) ^ (1 / n )

Where: A, B, and C = sample data
n = is the number of samples, in this case 3

If there are only 2 sample data, the formula becomes:

GM = ( A * B ) ^ (1/2)

The calculation of the Geometric Mean becomes tedious as soon as the number of samples increases. Fortunately, modern spreadsheets can easily calculate this measure of central tendency. The OpenOffice formula for the Geometric Mean is:

=geomean( range of cells of the sample data )