<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.webos-internals.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AndrewColes</id>
	<title>WebOS Internals - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.webos-internals.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AndrewColes"/>
	<link rel="alternate" type="text/html" href="http://wiki.webos-internals.org/wiki/Special:Contributions/AndrewColes"/>
	<updated>2026-04-24T12:39:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>http://wiki.webos-internals.org/index.php?title=SetupSquidTransparentProxy&amp;diff=7860</id>
		<title>SetupSquidTransparentProxy</title>
		<link rel="alternate" type="text/html" href="http://wiki.webos-internals.org/index.php?title=SetupSquidTransparentProxy&amp;diff=7860"/>
		<updated>2009-12-30T00:24:28Z</updated>

		<summary type="html">&lt;p&gt;AndrewColes: Added details on how to do ad-blocking on the pre using the squid proxy&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Squid Transparent Proxy on Palm Pre =&lt;br /&gt;
&lt;br /&gt;
Ok, someone asked for it, so I figured it out, how to do it for fun and profit:&lt;br /&gt;
&lt;br /&gt;
== Installing Squid ==&lt;br /&gt;
&lt;br /&gt;
First, you need to have root access to your device. How to get root, is described elsewhere in this wiki. It would be a good idea to know a little about linux and networking too. '''Be warned: this can make your networking unfunctional!'''&lt;br /&gt;
&lt;br /&gt;
Make your root disk writable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
cd / &amp;amp;&amp;amp; mount -v -o remount,rw /&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Login to the pre console and type this command to install the squid optware package&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@palm-webos-device: # ipkg-opt install squid&lt;br /&gt;
Installing squid (2.6.21-2) to root...&lt;br /&gt;
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/squid_2.6.21-2_arm.ipk&lt;br /&gt;
Configuring squid&lt;br /&gt;
create default cache and logs dir&lt;br /&gt;
chown: unknown user/group nobody:nobody&lt;br /&gt;
chown: unknown user/group nobody:nobody&lt;br /&gt;
FATAL: Could not determine fully qualified hostname.Please set 'visible_hostname'&lt;br /&gt;
&lt;br /&gt;
Squid Cache (Version 2.6.STABLE21): Terminated abnormally.&lt;br /&gt;
CPU Usage: 0.020 seconds = 0.010 user + 0.010 sys&lt;br /&gt;
Maximum Resident Size: 0 KB&lt;br /&gt;
Page faults with physical i/o: 0&lt;br /&gt;
Segmentation fault&lt;br /&gt;
&lt;br /&gt;
You should review the configuration file /opt/etc/squid/squid.conf,&lt;br /&gt;
make any necessary change, and complete the install by running -&lt;br /&gt;
/opt/etc/init.d/S80squid start&lt;br /&gt;
&lt;br /&gt;
Successfully terminated.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ignore the errors for the moment, we'll get to it soon.&lt;br /&gt;
&lt;br /&gt;
== Create a basic proxy config ==&lt;br /&gt;
&lt;br /&gt;
Change to the directory '''/opt/etc/squid''' and move the file '''squid.conf''' which is already there to somewhere else. Now create a new squid.conf, which should have the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
visible_hostname localhost&lt;br /&gt;
http_port 3128 transparent                 &lt;br /&gt;
hierarchy_stoplist cgi-bin ?               &lt;br /&gt;
access_log /var/cache/squid/squid.log squid          &lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \?                   &lt;br /&gt;
cache deny QUERY                                     &lt;br /&gt;
refresh_pattern ^ftp:           1440    20%     10080&lt;br /&gt;
refresh_pattern ^gopher:        1440    0%      1440&lt;br /&gt;
refresh_pattern .               0       20%     4320&lt;br /&gt;
acl apache rep_header Server ^Apache                &lt;br /&gt;
broken_vary_encoding allow apache    &lt;br /&gt;
coredump_dir /var/cache/squid        &lt;br /&gt;
cache_dir ufs /var/cache/squid 20 5 5&lt;br /&gt;
access_log /var/cache/squid/squid.log&lt;br /&gt;
cache_log /var/cache/squid/cache.log&lt;br /&gt;
cache_store_log /dev/null&lt;br /&gt;
&lt;br /&gt;
acl all src 0.0.0.0/0.0.0.0&lt;br /&gt;
acl manager proto cache_object&lt;br /&gt;
acl localhost src 127.0.0.1/255.255.255.255&lt;br /&gt;
acl to_localhost dst 127.0.0.0/8&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80          # http&lt;br /&gt;
acl Safe_ports port 21          # ftp&lt;br /&gt;
acl Safe_ports port 443         # https&lt;br /&gt;
acl Safe_ports port 70          # gopher&lt;br /&gt;
acl Safe_ports port 210         # wais&lt;br /&gt;
acl Safe_ports port 1025-65535  # unregistered ports&lt;br /&gt;
acl Safe_ports port 280         # http-mgmt&lt;br /&gt;
acl Safe_ports port 488         # gss-http&lt;br /&gt;
acl Safe_ports port 591         # filemaker&lt;br /&gt;
acl Safe_ports port 777         # multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
http_access allow manager localhost&lt;br /&gt;
http_access deny manager&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
acl enemy dstdomain www.apple.com&lt;br /&gt;
http_access deny enemy&lt;br /&gt;
&lt;br /&gt;
http_access allow all&lt;br /&gt;
icp_access allow all&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basically this is a config for a transparent proxy, thus a browser will be redirected to it without knowing that it is actually connected to a proxy. We must configure it this way because the WebOS browser cannot be configured to use a proxy.&lt;br /&gt;
&lt;br /&gt;
Note that we have added a single ACL here, which denies access to some random site *g*. Any other requests will be allowed. SSL (HTTPS) will not be passed through the proxy because this requires the browser to connect to it using a proxy request.&lt;br /&gt;
&lt;br /&gt;
== Prepare the directories for squid ==&lt;br /&gt;
&lt;br /&gt;
Squid needs a directory where to store it's files, as content it caches and logfiles. You may consider to disable caching and logging. But caching may be a good idea if your traffic is limited, so you'll save some. Logging is always usefull for debugging. If you want to turn it off, use '''/dev/null''' as target for the logfiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
mkdir /var/cache/squid&lt;br /&gt;
chown nobody /var/cache/squid&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next you need let squid to prepare the directory structure using the -z option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@palm-webos-device: # squid -z -f squid.conf&lt;br /&gt;
2009/11/26 23:19:29| Creating Swap Directories&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should not see any errors here!&lt;br /&gt;
&lt;br /&gt;
== Starting squid ==&lt;br /&gt;
&lt;br /&gt;
The installer already added it to the startup daemons, now we will start it manually:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
/opt/etc/init.d/S80squid start&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Look in '''/var/cache/squid/cache.log''' for any errors. Use ps to see if it really runs. You may consider to install '''lynx''' and test the proxy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
ipkg-opt install lynx&lt;br /&gt;
export http_proxy=http://localhost:3128&lt;br /&gt;
lynx www.google.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you see a google textmode site, it works.&lt;br /&gt;
&lt;br /&gt;
== Redirect Web Traffic to the Proxy ==&lt;br /&gt;
&lt;br /&gt;
Now comes the ugly part. I'll not explain it in detail: we install some iptable Rules. We tell iptables to forward any traffic destined to tcp port 80 to localhost port 3128 (this is where squid listens for incoming connections). To avoid that the requests of the proxy itself are forwarded to localhost (which would create a loop), we add a rule telling iptables to not forward web traffic if it were generated by user nobody (the user squid runs as):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --gid-owner 65534 -j ACCEPT&lt;br /&gt;
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:3128&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should not get any response from iptables. Let's see if the rules were added correctly:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
root@palm-webos-device: # iptables -nL -t nat&lt;br /&gt;
Chain PREROUTING (policy ACCEPT)&lt;br /&gt;
target     prot opt source               destination         &lt;br /&gt;
&lt;br /&gt;
Chain POSTROUTING (policy ACCEPT)&lt;br /&gt;
target     prot opt source               destination         &lt;br /&gt;
&lt;br /&gt;
Chain OUTPUT (policy ACCEPT)&lt;br /&gt;
target     prot opt source               destination         &lt;br /&gt;
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 owner GID match65534 &lt;br /&gt;
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 to:127.0.0.1:3128&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may add the iptables commands to the squid startup script (/opt/etc/init.d/S80squid). &lt;br /&gt;
&lt;br /&gt;
== See it working ==&lt;br /&gt;
&lt;br /&gt;
So, let's see how it works. Fire up the browser and enter the url of your favourite enemy vendor (the one we configured above):&lt;br /&gt;
&lt;br /&gt;
[[Image:Squid-access-denied-palm-pre.png]]&lt;br /&gt;
&lt;br /&gt;
== Blocking Adverts ==&lt;br /&gt;
&lt;br /&gt;
Now squid is set up, we can use it for ad blocking.  There are two steps to this:&lt;br /&gt;
&lt;br /&gt;
=== Obtain a block list ===&lt;br /&gt;
&lt;br /&gt;
An excellent ad block list is maintained at [http://pgl.yoyo.org/as/].  We need to download it in a suitable format for squid, which can be done by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
wget -q -O - 'http://pgl.yoyo.org/as/serverlist.php?hostformat=squid-dstdom-regex;showintro=0'  | grep -v &amp;quot;&amp;gt;&amp;quot; | grep &amp;quot;.&amp;quot; &amp;gt; /opt/etc/squid/blocklist&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Technical details: the wget command downloads the URL given in single quotes, then we strip the HTML mark-up and blank lines using grep. The filename at the end is where the black list will be stored.)&lt;br /&gt;
&lt;br /&gt;
=== Configure squid to use the block list ===&lt;br /&gt;
&lt;br /&gt;
Now we need to tell squid to block the list of URLs in the file we've just created.  Open the ''/opt/etc/squid/squid.conf'' file we created above, and scroll down to where it reads:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
acl enemy dstdomain www.apple.com&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace this line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
acl enemy dstdom_regex &amp;quot;/opt/etc/squid/blocklist&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, restart squid:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
/opt/etc/init.d/S80squid restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To test it's working, open a browser and try to visit ''ads.msn.com'' (one of the blocked URLs).  The error given should be similar to the screenshot given above.&lt;br /&gt;
&lt;br /&gt;
If in the future you need to update the ad blocking list, run the commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
cd / &amp;amp;&amp;amp; mount -v -o remount,rw /&lt;br /&gt;
wget -q -O - 'http://pgl.yoyo.org/as/serverlist.php?hostformat=squid-dstdom-regex;showintro=0'  | grep -v &amp;quot;&amp;gt;&amp;quot; | grep &amp;quot;.&amp;quot; &amp;gt; /opt/etc/squid/blocklist&lt;br /&gt;
/opt/etc/init.d/S80squid restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For further details of filtering URLs using squid, please refer to the [http://www.squid-cache.org/Doc/ excelent documentation of the squid cache project].&lt;/div&gt;</summary>
		<author><name>AndrewColes</name></author>
	</entry>
</feed>