<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Serbest Çağrışım &#187; squidguard</title>
	<atom:link href="http://www.serbestcagrisim.com/archives/tag/squidguard/feed" rel="self" type="application/rss+xml" />
	<link>http://www.serbestcagrisim.com</link>
	<description>Soldan sağa doğru...</description>
	<lastBuildDate>Fri, 02 Jul 2010 10:23:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Daha iyi, daha hızlı, daha güçlü.</title>
		<link>http://www.serbestcagrisim.com/archives/305</link>
		<comments>http://www.serbestcagrisim.com/archives/305#comments</comments>
		<pubDate>Tue, 30 Jun 2009 12:31:46 +0000</pubDate>
		<dc:creator>Omer</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[güçlü]]></category>
		<category><![CDATA[hızlı]]></category>
		<category><![CDATA[iyi]]></category>
		<category><![CDATA[monochrome]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[squidguard]]></category>

		<guid isPermaLink="false">http://www.serbestcagrisim.com/?p=305</guid>
		<description><![CDATA[Bir çok kişi Squid ve SquidGuard&#8217;ı kullanarak Facebook&#8217;a karşı açtığım savaşla ilgili yazımı okumuştur. Önce bir şeyi netleştirelim, Facebook&#8217;a karşı hiç bir garezim yok. Tamam, çok bayılmıyorum kendisine ama asıl sevmediğim şey iş saatlerinde Facebook&#8217;ta dolaşan çalışanlar. İşte bu sistem kullanıcılara takip edildiklerine dair bir mesaj vermek için ideal çözüm. Şimdi savaşı bir adım daha [...]]]></description>
			<content:encoded><![CDATA[<p>Bir çok kişi Squid ve SquidGuard&#8217;ı kullanarak Facebook&#8217;a karşı açtığım savaşla ilgili yazımı okumuştur. Önce bir şeyi netleştirelim, Facebook&#8217;a karşı hiç bir garezim yok. Tamam, çok bayılmıyorum kendisine ama asıl sevmediğim şey iş saatlerinde Facebook&#8217;ta dolaşan çalışanlar. İşte bu sistem kullanıcılara takip edildiklerine dair bir mesaj vermek için ideal çözüm.</p>
<p>Şimdi savaşı bir adım daha öteye götüreceğiz. Bu, firmanızdaki Squid vekil sunucunuz için daha iyi, daha hızlı ve daha güçlü bir çözümdür. Daha önce kullandığımız ImageMagick kütüphanesi iyi bir kütüphaneydi, ama eğer sorunlu kullanıcılarınız varsa ciddi anlamda yavaş kalıyor. Yine resimler üzerinde oynama yapacağız, ama çok daha hızlı bir yöntemle. Okumaya devam edin.</p>
<p><span id="more-305"></span>Önce PHP5 için GD kütüphanesini kuralım;</p>
<pre>sudo apt-get install php5-gd</pre>
<p>Evet, bu sistemin çalışması için hali hazırda çalışan bir web sunucusuna ihtiyacınız var. Şimdi Facebook&#8217;a karşı Squid ve squidGuard&#8217;ı ayarlayalım. Önce aşağıdaki satırları squid.conf dosyanıza ekleyin;</p>
<pre>redirect_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf
redirect_children 5</pre>
<p>Şimdi de squidGuard.conf dosyanızın yaklaşık olarak şöyle gözükmesini sağlayın;</p>
<pre>#
# CONFIG FILE FOR SQUIDGUARD
#

dbhome /home/squidguard/
logdir /var/log/squid/

dest facebook {
 expressionlist  facebook
 redirect        http://192.168.1.1/joker.php?url=%u
 log /var/log/squid/joker.log
}

src herkes {
        ip      192.168.1.0/255.255.255.0
}

acl {
  herkes within workhours {
    pass !facebook all
  } else {
    pass all
  }

  default {
    pass none
  }
}</pre>
<p>Şimdi de URL&#8217;deki resimleri yakalayan regex dosyasını yaratalım. Ben bu dosyayı özellikle /home/squidguard içerisine yerleştirdim, çünkü /home klasörünü düzenli olarak yedekliyorum. Böylece taşınma vs sırasında kaybolma durumu olmuyor.</p>
<pre>.*facebook\.com.*(\.jpg|\.gif|\.png)
.*fbcdn\.net.*(\.jpg|\.gif|\.png)</pre>
<p>Şimdi de fotoğrafları bozan kodumuzu web klasörümüze koyalım. Teorik olarak adı joker.php olmalı, ama eğer farklı bir isim koymak isterseniz squidGuard.conf dosyanızda da gerekli değişiklikleri yaptırdığınızdan emin olun.</p>
<pre name="code" class="php">&lt;?php
/*
joker.php

Burası geçici dosyalarımı tuttuğum klasör.
/tmp klasörünü de kullanabilirsiniz.
*/
$path = "/var/www/joker";
if (!is_dir($path)) {
   mkdir($path,0755);
}

// Squid'den gelen URL'i parçalayalım.
$u = explode(" ",trim($_GET["url"]));
if (count($u) &gt; 0) {
   $url = $u[0];
} else {
   $url = $u;
}

// Geçici dosyanın adı.
$temp = md5(time().microtime().$url);

$ff = fopen($url, "r");
$contents = stream_get_contents($ff);
fclose($ff);

$fz = fopen($path."/".$temp,"w");
fwrite($fz, $contents);
fclose($fz);

$file = $path."/".$temp;

// Bu çizginin altına dokunmaya gerek yok. //
// --------------------------------------- //
// Evet, yukarıdaki çizgiden bahsediyorum. //
switch (substr($url,-4)) {
   case ".jpg":
      $source = imagecreatefromjpeg($file);
      $header = "image/jpeg";
   break;
   case ".png":
      $source = imagecreatefrompng($file);
      $header = "image/png";
   break;
   case ".gif":
      $source = imagecreatefromgif($file);
      $header = "image/gif";
   break;
}

list($width, $height) = getimagesize($file);
$bwimage= imagecreate($width, $height);

for ($c = 0; $c &lt; 256; $c++) {
   $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
}

function yiq($r, $g, $b) {
   $gray = ($r + $g + $b) / 3;
   if ($gray &gt; 0x7F) {
      return 0xFF;
   } else {
      return 0x00;
   }
   return (($r*0.299)+($g*0.587)+($b*0.114));
}

/*
Orijinal rengi pixel pixel okuyalım.
*/
for ($y = 0; $y &lt; $height; $y++) {
   for ($x = 0; $x &lt; $width; $x++) {
      $rgb = imagecolorat($source, $x, $y);
      $r = ($rgb &gt;&gt; 16) &amp; 0xFF;
      $g = ($rgb &gt;&gt; 8) &amp; 0xFF;
      $b = $rgb &amp; 0xFF;

      /*
      Burası yiq kullanarak resmin rgb değerlerini bozduğumuz yer,
      bozup siyah beyaza çeviriyoruz.
      */
      $gs = yiq($r, $g, $b);
      imagesetpixel($bwimage, $x, $y, $palette[$gs]);
   }
}

/*
Bir tane jpg dosyası döndürelim, ama png veya gif de
kullanabilirsiniz.
*/
header("Content-type: ".$header);
imagejpeg($bwimage);
?&gt;</pre>
<p>Squid&#8217;i baştan başlatalım;</p>
<pre>sudo /etc/init.d/squid restart</pre>
<p>Şimdi herşeyin normal bir şekilde çalışıyor olması gerekli, şimdi görelim bakalım sizi gidi Facebook hastaları!</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 631px; width: 1px; height: 1px;">&lt;?<br />
/*<br />
joker.phpThis is where we keep our tmp files.<br />
You can set it to /tmp also.<br />
*/<br />
$path = &#8220;/home/www/html/joker&#8221;;</p>
<p>// Parse the URL line delivered from Squid.<br />
$u = explode(&#8221; &#8220;,trim($_GET["url"]));<br />
if (count($u) &gt; 0) {<br />
$url = $u[0];<br />
} else {<br />
$url = $u;<br />
}</p>
<p>// Temporary file name.<br />
$temp = md5(time().microtime().$url);</p>
<p>$ff = fopen($url, &#8220;r&#8221;);<br />
$contents = stream_get_contents($ff);<br />
fclose($ff);</p>
<p>$fz = fopen($path.&#8221;/&#8221;.$temp,&#8221;w&#8221;);<br />
fwrite($fz, $contents);<br />
fclose($fz);</p>
<p>$file = $path.&#8221;/&#8221;.$temp;</p>
<p>// U shall not touch below this line.<br />
// &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- //<br />
// Yeah, that line above this.<br />
switch (substr($url,-4)) {<br />
case &#8220;.jpg&#8221;:<br />
$source = imagecreatefromjpeg($file);<br />
$header = &#8220;image/jpeg&#8221;;<br />
break;<br />
case &#8220;.png&#8221;:<br />
$source = imagecreatefrompng($file);<br />
$header = &#8220;image/png&#8221;;<br />
break;<br />
case &#8220;.gif&#8221;:<br />
$source = imagecreatefromgif($file);<br />
$header = &#8220;image/gif&#8221;;<br />
break;<br />
}</p>
<p>list($width, $height) = getimagesize($file);<br />
$bwimage= imagecreate($width, $height);</p>
<p>for ($c = 0; $c &lt; 256; $c++) {<br />
$palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);<br />
}</p>
<p>function yiq($r, $g, $b) {<br />
$gray = ($r + $g + $b) / 3;<br />
if ($gray &gt; 0x7F) {<br />
return 0xFF;<br />
} else {<br />
return 0&#215;00;<br />
}</p>
<p>return (($r*0.299)+($g*0.587)+($b*0.114));<br />
}</p>
<p>/*<br />
Reads the original colors pixel by pixel<br />
*/<br />
for ($y = 0; $y &lt; $height; $y++) {<br />
for ($x = 0; $x &lt; $width; $x++) {<br />
$rgb = imagecolorat($source, $x, $y);<br />
$r = ($rgb &gt;&gt; 16) &amp; 0xFF;<br />
$g = ($rgb &gt;&gt; 8) &amp; 0xFF;<br />
$b = $rgb &amp; 0xFF;</p>
<p>/*<br />
This is where we actually use yiq to modify our rbg values,<br />
and then convert them to our grayscale palette<br />
*/<br />
$gs = yiq($r, $g, $b);<br />
imagesetpixel($bwimage, $x, $y, $palette[$gs]);<br />
}<br />
}</p>
<p>/*<br />
Outputs a jpg image, but you can change this to png or gif if that<br />
is what you are working with<br />
*/<br />
header(&#8220;Content-type: &#8220;.$header);<br />
imagejpeg($bwimage);<br />
?&gt;</p></div>
<div id="crp_related"><h3>İlgili Yazılar:</h3><ul><li><a href="http://www.serbestcagrisim.com/archives/299" rel="bookmark" class="crp_title">Better, faster, stronger.</a></li><li><a href="http://www.serbestcagrisim.com/archives/54" rel="bookmark" class="crp_title">Facebook fun with Squid</a></li><li><a href="http://www.serbestcagrisim.com/archives/49" rel="bookmark" class="crp_title">squid ile facebook eğlencesi II &#8211; daha hızlı çözümler</a></li><li><a href="http://www.serbestcagrisim.com/archives/24" rel="bookmark" class="crp_title">squid ile facebook eğlencesi</a></li><li><a href="http://www.serbestcagrisim.com/archives/345" rel="bookmark" class="crp_title">Yanlış Facebook uygulaması!</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.serbestcagrisim.com/archives/305/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Better, faster, stronger.</title>
		<link>http://www.serbestcagrisim.com/archives/299</link>
		<comments>http://www.serbestcagrisim.com/archives/299#comments</comments>
		<pubDate>Tue, 30 Jun 2009 12:13:13 +0000</pubDate>
		<dc:creator>Omer</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[squidguard]]></category>

		<guid isPermaLink="false">http://www.serbestcagrisim.com/?p=299</guid>
		<description><![CDATA[OK, most of you have read my work on Squid and SquidGuard against Facebook. Let&#8217;s make something clear, I have nothing against Facebook. Ok, I don&#8217;t like it much, but what I really don&#8217;t like is people who surf at it in working hours. So this script makes clear that they are being followed. Now, [...]]]></description>
			<content:encoded><![CDATA[<p>OK, most of you have read my work on Squid and SquidGuard against Facebook. Let&#8217;s make something clear, I have nothing against Facebook. Ok, I don&#8217;t like it much, but what I really don&#8217;t like is people who surf at it in working hours. So this script makes clear that they are being followed.</p>
<p>Now, its time to move one step further. Better, faster and a stronger solution for your corporate squid server. ImageMagick library is a nice library, but it remains slow if you have reckless users. We will keep on manipulating images, yes, but in a much faster way. Just keep on reading.</p>
<p><span id="more-299"></span>First lets install GD library for PHP5;</p>
<pre>sudo apt-get install php5-gd</pre>
<p>Yes, you should have a running web server available for this to work. Now lets setup our Squid and squidGuard against facebook. First add these lines to the end of your squid.conf file;</p>
<pre>redirect_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf
redirect_children 5</pre>
<p>Now make sure your squidGuard.conf file looks something like this;</p>
<pre>#
# CONFIG FILE FOR SQUIDGUARD
#

dbhome /home/squidguard/
logdir /var/log/squid/

src everyone {
        ip      192.168.1.0/255.255.255.0
}

dest facebook {
 expressionlist  facebook
 redirect        http://192.168.1.1/joker.php?url=%u
 log /var/log/squid/joker.log
}

acl {
  everyone within workhours {
    pass !facebook all
  } else {
    pass all
  }

  default {
    pass none
  }
}</pre>
<p>Now let&#8217;s create the file that catches the URL regex. I placed it in /home/squidguard this time, since I backup my whole /home directory everyday. It does not get lost between setups.</p>
<pre>.*facebook\.com.*(\.jpg|\.gif|\.png)
.*fbcdn\.net.*(\.jpg|\.gif|\.png)</pre>
<p>Let&#8217;s create our image manipulation script in our web root. You should name it to joker.php or whatever you want, just keep it in sync with your squidGuard.conf file.</p>
<pre name="code" class="php">&lt;?php
/*
joker.php

This is where we keep our tmp files.
You can set it to /tmp also.
*/
$path = "/var/www/joker";
if (!is_dir($path)) {
   mkdir($path,0755);
}

// Parse the URL line delivered from Squid.
$u = explode(" ",trim($_GET["url"]));
if (count($u) &gt; 0) {
   $url = $u[0];
} else {
   $url = $u;
}

// Temporary file name.
$temp = md5(time().microtime().$url);

$ff = fopen($url, "r");
$contents = stream_get_contents($ff);
fclose($ff);

$fz = fopen($path."/".$temp,"w");
fwrite($fz, $contents);
fclose($fz);

$file = $path."/".$temp;

// U shall not touch below this line.
// ------------------------------- //
// Yeah, that line above this. //
switch (substr($url,-4)) {
   case ".jpg":
      $source = imagecreatefromjpeg($file);
      $header = "image/jpeg";
   break;
   case ".png":
      $source = imagecreatefrompng($file);
      $header = "image/png";
   break;
   case ".gif":
      $source = imagecreatefromgif($file);
      $header = "image/gif";
   break;
}

list($width, $height) = getimagesize($file);
$bwimage= imagecreate($width, $height);

for ($c = 0; $c &lt; 256; $c++) {
   $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
}

function yiq($r, $g, $b) {
   $gray = ($r + $g + $b) / 3;
   if ($gray &gt; 0x7F) {
      return 0xFF;
   } else {
      return 0x00;
   }
   return (($r*0.299)+($g*0.587)+($b*0.114));
}

/*
Reads the original colors pixel by pixel
*/
for ($y = 0; $y &lt; $height; $y++) {
   for ($x = 0; $x &lt; $width; $x++) {
      $rgb = imagecolorat($source, $x, $y);
      $r = ($rgb &gt;&gt; 16) &amp; 0xFF;
      $g = ($rgb &gt;&gt; 8) &amp; 0xFF;
      $b = $rgb &amp; 0xFF;

      /*
      This is where we actually use yiq to modify our rbg values,
      and then convert them to our grayscale palette
      */
      $gs = yiq($r, $g, $b);
      imagesetpixel($bwimage, $x, $y, $palette[$gs]);
   }
}

/*
Outputs a jpg image, but you can change this to png or gif if that
is what you are working with
*/
header("Content-type: ".$header);
imagejpeg($bwimage);
?&gt;</pre>
<p>Let&#8217;s restart our Squid;</p>
<pre>sudo /etc/init.d/squid restart</pre>
<p>Everything should be working fine right now, good luck now you facebook lovers!</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 631px; width: 1px; height: 1px;">&lt;?<br />
/*<br />
joker.php</p>
<p>This is where we keep our tmp files.<br />
You can set it to /tmp also.<br />
*/<br />
$path = &#8220;/home/www/html/joker&#8221;;</p>
<p>// Parse the URL line delivered from Squid.<br />
$u = explode(&#8221; &#8220;,trim($_GET["url"]));<br />
if (count($u) &gt; 0) {<br />
$url = $u[0];<br />
} else {<br />
$url = $u;<br />
}</p>
<p>// Temporary file name.<br />
$temp = md5(time().microtime().$url);</p>
<p>$ff = fopen($url, &#8220;r&#8221;);<br />
$contents = stream_get_contents($ff);<br />
fclose($ff);</p>
<p>$fz = fopen($path.&#8221;/&#8221;.$temp,&#8221;w&#8221;);<br />
fwrite($fz, $contents);<br />
fclose($fz);</p>
<p>$file = $path.&#8221;/&#8221;.$temp;</p>
<p>// U shall not touch below this line.<br />
// &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- //<br />
// Yeah, that line above this.<br />
switch (substr($url,-4)) {<br />
case &#8220;.jpg&#8221;:<br />
$source = imagecreatefromjpeg($file);<br />
$header = &#8220;image/jpeg&#8221;;<br />
break;<br />
case &#8220;.png&#8221;:<br />
$source = imagecreatefrompng($file);<br />
$header = &#8220;image/png&#8221;;<br />
break;<br />
case &#8220;.gif&#8221;:<br />
$source = imagecreatefromgif($file);<br />
$header = &#8220;image/gif&#8221;;<br />
break;<br />
}</p>
<p>list($width, $height) = getimagesize($file);<br />
$bwimage= imagecreate($width, $height);</p>
<p>for ($c = 0; $c &lt; 256; $c++) {<br />
$palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);<br />
}</p>
<p>function yiq($r, $g, $b) {<br />
$gray = ($r + $g + $b) / 3;<br />
if ($gray &gt; 0x7F) {<br />
return 0xFF;<br />
} else {<br />
return 0&#215;00;<br />
}</p>
<p>return (($r*0.299)+($g*0.587)+($b*0.114));<br />
}</p>
<p>/*<br />
Reads the original colors pixel by pixel<br />
*/<br />
for ($y = 0; $y &lt; $height; $y++) {<br />
for ($x = 0; $x &lt; $width; $x++) {<br />
$rgb = imagecolorat($source, $x, $y);<br />
$r = ($rgb &gt;&gt; 16) &amp; 0xFF;<br />
$g = ($rgb &gt;&gt; 8) &amp; 0xFF;<br />
$b = $rgb &amp; 0xFF;</p>
<p>/*<br />
This is where we actually use yiq to modify our rbg values,<br />
and then convert them to our grayscale palette<br />
*/<br />
$gs = yiq($r, $g, $b);<br />
imagesetpixel($bwimage, $x, $y, $palette[$gs]);<br />
}<br />
}</p>
<p>/*<br />
Outputs a jpg image, but you can change this to png or gif if that<br />
is what you are working with<br />
*/<br />
header(&#8220;Content-type: &#8220;.$header);<br />
imagejpeg($bwimage);<br />
?&gt;</p></div>
<div id="crp_related"><h3>İlgili Yazılar:</h3><ul><li><a href="http://www.serbestcagrisim.com/archives/305" rel="bookmark" class="crp_title">Daha iyi, daha hızlı, daha güçlü.</a></li><li><a href="http://www.serbestcagrisim.com/archives/54" rel="bookmark" class="crp_title">Facebook fun with Squid</a></li><li><a href="http://www.serbestcagrisim.com/archives/49" rel="bookmark" class="crp_title">squid ile facebook eğlencesi II &#8211; daha hızlı çözümler</a></li><li><a href="http://www.serbestcagrisim.com/archives/24" rel="bookmark" class="crp_title">squid ile facebook eğlencesi</a></li><li><a href="http://www.serbestcagrisim.com/archives/345" rel="bookmark" class="crp_title">Yanlış Facebook uygulaması!</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.serbestcagrisim.com/archives/299/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
