<?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"
	>

<channel>
	<title>Ruy Rocha</title>
	<atom:link href="http://ruyrocha.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ruyrocha.com</link>
	<description>Ruby, Ruby on Rails, Linux, OpenBSD, Ubuntu, CentOS, Red Hat, Psychobilly/Rockabilly, LA{Z}Adm, LDAP, LS{F}D, Squid, Cerveja, Eisenbahn</description>
	<pubDate>Tue, 11 Nov 2008 12:17:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>GreenSQL&#8230; WHAT!?</title>
		<link>http://ruyrocha.com/2008/11/11/greensql-what/</link>
		<comments>http://ruyrocha.com/2008/11/11/greensql-what/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 12:17:41 +0000</pubDate>
		<dc:creator>Ruy Rocha</dc:creator>
		
		<category><![CDATA[Database]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://ruyrocha.com/?p=85</guid>
		<description><![CDATA[GreenSQL is an Open Source database firewall used to protect databases from SQL injection attacks. GreenSQL works as a proxy and has built in support for MySQL. The logic is based on evaluation of SQL commands using a risk scoring matrix as well as blocking known db administrative commands (DROP, CREATE, etc). GreenSQL is distributed [...]]]></description>
			<content:encoded><![CDATA[<p>GreenSQL is an Open Source database firewall used to protect databases from SQL injection attacks. GreenSQL works as a proxy and has built in support for MySQL. The logic is based on evaluation of SQL commands using a risk scoring matrix as well as blocking known db administrative commands (DROP, CREATE, etc). GreenSQL is distributed under the GPL license.</p>
<p><a title="GreenSQL" href="http://www.greensql.net/" target="_blank">Project page</a></p>
Similar Posts:<ul><li>None Found</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ruyrocha.com/2008/11/11/greensql-what/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SAMBA3: VFS, kernel interface to file systems</title>
		<link>http://ruyrocha.com/2008/11/07/samba3-vfs-kernel-interface-to-file-systems/</link>
		<comments>http://ruyrocha.com/2008/11/07/samba3-vfs-kernel-interface-to-file-systems/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 08:34:46 +0000</pubDate>
		<dc:creator>Ruy Rocha</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[OpenBSD]]></category>

		<category><![CDATA[samba]]></category>

		<category><![CDATA[samba 3]]></category>

		<category><![CDATA[vfs]]></category>

		<category><![CDATA[vfs modules]]></category>

		<category><![CDATA[vfs objects]]></category>

		<guid isPermaLink="false">http://ruyrocha.com/?p=29</guid>
		<description><![CDATA[Extraindo diretamente do man:
"DESCRIPTION
     The virtual file system, VFS, is the kernel interface to file systems.
     The interface specifies the calls for the kernel to access file systems.
     It also specifies the core functionality that a file system must provide
    [...]]]></description>
			<content:encoded><![CDATA[<p>Extraindo diretamente do man:</p>
<pre>"<strong>DESCRIPTION</strong>
     The virtual file system, VFS, is the kernel interface to file systems.
     The interface specifies the calls for the kernel to access file systems.
     It also specifies the core functionality that a file system must provide
     to the kernel.

     The focus of vfs activity is the vnode and is discussed in vnode(9).</pre>
<p>Então, tem quase 1 ano que estou com este draft da vida para ser publicado&#8230; Vou escrever enquanto faço um servicinho nada limpo agora <img src='http://ruyrocha.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><span id="more-29"></span></p>
<p>Os objetos VFS (e não VSF) dão uma puta ajuda no Samba. Não tem muito o que falar, TUDO está nas man pages. Vou dar dois exemplos que uso bastante: audit &amp; recycle. No smb.conf feliz, faça:</p>
<pre class="prettyprint"><code class="prettyprint">[global]
;  vfs modules
   vfs objects = audit, recycle
   audit:facility = LOCAL1
   audit:priority = NOTICE
   recycle:facility = LOCAL1
   recycle:priority = NOTICE
   recycle:directory_mode = 0770
   recycle:keeptree = yes
   recycle:versions = yes

; shares
[Agentes]
   comment = Agentes de Credito
   path = /data/agentes
   read only = no
   create mask = 0775
   directory mask = 0775
   user = @agentes
</code></pre>
<p>Feito isto, vamos conectar ao compartilhamento:</p>
<pre class="prettyprint"><code class="prettyprint">spoofing@frw:~$ smbclient //10.1.1.2/Agentes -U qualquer
Password:
Domain=[SERVIDOR] OS=[Unix] Server=[Samba 3.0.28]
smb: \> ls
  .                                   D        0  Fri Nov  7 04:49:11 2008
  ..                                  D        0  Fri Nov  7 04:49:47 2008

                45351 blocks of size 4194304. 43083 blocks available
smb: \> put this-is-just-a-modern-rock-song
putting file this-is-just-a-modern-rock-song as \this-is-just-a-modern-rock-song (0.0 kb/s) (average 0.0 kb/s)
smb: \>
</code></pre>
<p>No queridasso messages:</p>
<pre class="prettyprint"><code class="prettyprint">Nov  7 06:02:09 frw smbd_audit[32758]: connect to service Agentes by user qualquer
Nov  7 06:02:12 frw smbd_audit[32758]: opendir ./
Nov  7 06:02:19 frw smbd_audit[32758]: opendir .
Nov  7 06:02:19 frw smbd_audit[32758]: open this-is-just-a-modern-rock-song (fd 26) for writing
Nov  7 06:02:19 frw smbd_audit[32758]: fchmod_acl this-is-just-a-modern-rock-song mode 0x1f4 failed: Function not implemented
Nov  7 06:02:19 frw smbd_audit[32758]: close fd 26
</code></pre>
<p>É isso que o &#8220;audit&#8221; faz. Agora, vamos para o recycle. Vamos deletar o arquivo feliz que colocamos, ainda via smbclient:</p>
<pre class="prettyprint"><code>smb: \> del this-is-just-a-modern-rock-song
smb: \>
</code></pre>
<p>E novamente no messages:</p>
<pre class="prettyprint"><code>
Nov  7 06:09:13 frw smbd_audit[32758]: opendir ./
Nov  7 06:09:14 frw smbd_audit[32758]: opendir ./
Nov  7 06:09:14 frw smbd_audit[32758]: chmod_acl .recycle mode 0x1c0 failed: Function not implemented
Nov  7 06:09:14 frw smbd_audit[32758]: unlink ./this-is-just-a-modern-rock-song
</code></pre>
<p>Certo, arquivo deletado e somos felizes. Indo até o compartilhamento (caminho real, no file system), teremos o seguinte:</p>
<pre class="prettyprint"><code>
root@frw:/data/agentes# ls -la
total 12
drwxrwxr-x  3 root       agentes  512 Nov  7 06:19 .
drwxr-xr-x  7 root       wheel    512 Nov  7 04:49 ..
drwxrwx---  2 qualquer  agentes  512 Nov  7 06:19 .recycle
root@frw:/data/agentes# cd .recycle/
root@frw:/data/agentes/.recycle# ls -la
total 8
drwxrwx---  2 qualquer  agentes  512 Nov  7 06:19 .
drwxrwxr-x  3 root       agentes  512 Nov  7 06:19 ..
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:18 this-is-just-a-modern-rock-song
root@frw:/data/agentes/.recycle#
</code></pre>
<p>Lá está o nosso arquivo, até aí tudo bem. E se eu enviar o arquivo novamente, e deletá-lo!? Veja:</p>
<pre class="prettyprint"><code>smb: \> put this-is-just-a-modern-rock-song
putting file this-is-just-a-modern-rock-song as \this-is-just-a-modern-rock-song (0.0 kb/s) (average 0.0 kb/s)
smb: \> del this-is-just-a-modern-rock-song
smb: \> 

...

root@frw:/data/agentes/.recycle# ls -la
total 8
drwxrwx---  2 qualquer  agentes  512 Nov  7 06:22 .
drwxrwxr-x  3 root       agentes  512 Nov  7 06:22 ..
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:22 Copy #1 of this-is-just-a-modern-rock-song
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:18 this-is-just-a-modern-rock-song
root@frw:/data/agentes/.recycle#
</code></pre>
<p>Certo também. E se existir algum sub-diretório, etc, como o recycle se comporta!?</p>
<pre class="prettyprint"><code>smb: \> mkdir diretorio
smb: \> cd diretorio/
smb: \diretorio\> put this-is-just-a-modern-rock-song
putting file this-is-just-a-modern-rock-song as \diretorio\this-is-just-a-modern-rock-song (0.0 kb/s) (average NaN kb/s)
smb: \diretorio\> 

...

Nov  7 06:28:16 frw smbd_audit[27327]: opendir ./
Nov  7 06:28:21 frw smbd_audit[27327]: opendir .
Nov  7 06:28:21 frw smbd_audit[27327]: chmod_acl diretorio mode 0x1fd failed: Function not implemented
Nov  7 06:28:21 frw smbd_audit[27327]: mkdir diretorio
Nov  7 06:28:23 frw smbd_audit[27327]: opendir ./
Nov  7 06:28:37 frw smbd_audit[27327]: opendir diretorio
Nov  7 06:28:37 frw smbd_audit[27327]: open diretorio/this-is-just-a-modern-rock-song (fd 26) for writing
Nov  7 06:28:37 frw smbd_audit[27327]: fchmod_acl diretorio/this-is-just-a-modern-rock-song mode 0x1f4 failed: Function not implemented
Nov  7 06:28:37 frw smbd_audit[27327]: close fd 26

...

smb: \diretorio\> del this-is-just-a-modern-rock-song
smb: \diretorio\> 

...

root@frw:/data/agentes# ls -la .recycle/
total 12
drwxrwx---  3 qualquer  agentes  512 Nov  7 06:30 .
drwxrwxr-x  4 root       agentes  512 Nov  7 06:28 ..
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:22 Copy #1 of this-is-just-a-modern-rock-song
drwxrwx---  2 qualquer  agentes  512 Nov  7 06:30 diretorio
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:18 this-is-just-a-modern-rock-song
root@frw:/data/agentes# ls -la .recycle/diretorio/
total 8
drwxrwx---  2 qualquer  agentes  512 Nov  7 06:30 .
drwxrwx---  3 qualquer  agentes  512 Nov  7 06:30 ..
-rwxrw-r--  1 qualquer  agentes    0 Nov  7 06:28 this-is-just-a-modern-rock-song
root@frw:/data/agentes#
</code></pre>
<p>Legal, né!? Então, dá pra fazer bastante coisa legal com esses módulos. Com algum conhecimento de programação, dá pra fazer alguns hacks mais legais ainda. E não esqueça do <strong>apropos vfs</strong>.</p>
Similar Posts:<ul><li>None Found</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ruyrocha.com/2008/11/07/samba3-vfs-kernel-interface-to-file-systems/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Érre o quê!? Monitoramento ativo via MSN Messenger</title>
		<link>http://ruyrocha.com/2008/11/07/erre-o-que-monitoramento-ativo-via-msn-messenger/</link>
		<comments>http://ruyrocha.com/2008/11/07/erre-o-que-monitoramento-ativo-via-msn-messenger/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 06:15:53 +0000</pubDate>
		<dc:creator>Ruy Rocha</dc:creator>
		
		<category><![CDATA[CentOS]]></category>

		<category><![CDATA[Database]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[OpenBSD]]></category>

		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[active response]]></category>

		<category><![CDATA[alerts]]></category>

		<category><![CDATA[msn]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://ruyrocha.com/?p=70</guid>
		<description><![CDATA[Eu estava ouvindo Tool - Hooker with a penis quando me ocorreram algumas idéias. Geralmente, alertas de monitoramento ou de chamados (helpdesk) chegam por e-mail, ou você tem ir em uma página web, atualizar para ver se tem algo novo, etc. Neste meio tempo, é bem simples dar atenção a alguma conversa no MSN, e [...]]]></description>
			<content:encoded><![CDATA[<p>Eu estava ouvindo <a title="Tool - Hooker with a penis" href="http://www.youtube.com/watch?v=YUYf3b8_wj4" target="_blank">Tool - Hooker with a penis</a> quando me ocorreram algumas idéias. Geralmente, alertas de monitoramento ou de chamados (helpdesk) chegam por e-mail, ou você tem ir em uma página web, atualizar para ver se tem algo novo, etc. Neste meio tempo, é bem simples dar atenção a alguma conversa no MSN, e principalmente se a janela for de alguma <a title="Delicinhas - segundo o Google" href="http://www.sedentario.org/wp-content/uploads/2008/08/s2site.jpg" target="_blank">delicinha</a>, e foi justamente pensando neste tipo de situaçao que surgiu ele (ou seria ela!?): <strong>rööker.rb</strong>, um bot para MSN, que possibilita monitoramento ativo dos serviços.</p>
<p>O que o rööker.rb faz:</p>
<p>- existe uma base com todos os clientes, contendo o quê (serviços) roda em quem (empresa);</p>
<p>- existe uma checagem constante dos serviços. Se algum deles cai, no mesmo momento é gerado um <strong>alarme</strong>, e através deste alarme é possível saber o quê parou em quem;</p>
<p>- no mesmo momento, uma mensagem no MSN é recebida, e esta mensagem traz informações sobre qual serviço parou e em qual empresa. Agora entra a intervenção, ficando a critério &#8220;deixar de lado&#8221; (pois o chamado não foi aberto pela empresa ainda), ou fazer o serviço voltar;</p>
<p>Na janela do chat é possível digitar comandos, por exemplo:</p>
<pre class="prettyprint"><code class="prettyprint">#c0344 httpd restart
</code></pre>
<p>Esta mensagem que envio diz o seguinte: deve ser reiniciado o <strong>Apache</strong> no cliente <strong>c0344</strong>. Então o &#8220;rööker&#8221; conecta via SSH no cliente e faz todo o serviço, simples assim.</p>
<p>Tem mais coisa a ser feita: alarmes via <strong>gTalk</strong> e <strong>twitter</strong>. Quando tudo estiver redondinho eu posto o fonte aqui. Estou testando tudo em Linux (CentOS 5.2) e OpenBSD (4.4).</p>
Similar Posts:<ul><li>None Found</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ruyrocha.com/2008/11/07/erre-o-que-monitoramento-ativo-via-msn-messenger/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrate Ruby and Asterisk (call detail record) using ActiveRecord</title>
		<link>http://ruyrocha.com/2008/11/07/integrate-ruby-and-asterisk-call-detail-record-using-activerecord/</link>
		<comments>http://ruyrocha.com/2008/11/07/integrate-ruby-and-asterisk-call-detail-record-using-activerecord/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 06:05:18 +0000</pubDate>
		<dc:creator>Ruy Rocha</dc:creator>
		
		<category><![CDATA[Database]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[VoIP]]></category>

		<category><![CDATA[asterisk]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://ruyrocha.com/?p=44</guid>
		<description><![CDATA[First of all, I would like to let you know I&#8217;m working with Asterisk PBX again (not enough, but that&#8217;s ok).
As far we know, Asterisk can store entire call logs in a database - MySQL at this point. So, let we have some fun with Ruby and Asterisk and Mysql too, and all we want [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, I would like to let you know I&#8217;m working with Asterisk PBX again (not enough, but that&#8217;s ok).</p>
<p>As far we know, Asterisk can store entire call logs in a database - MySQL at this point. So, let we have some fun with Ruby and Asterisk and Mysql too, and all we want is: retrieve all calls&#8217; time, in seconds, just to know how much time we spent on phone.</p>
<p><span id="more-44"></span></p>
<h3>Let&#8217;s rock</h3>
<p>I will not cover any installation (asterisk, mysql, ruby, rails, etc).</p>
<p>I have a <a title="Trixbox" href="http://www.trixbox.org" target="_blank">Trixbox</a> running and it stores cdr in MySQL (I think it&#8217;s part of FreePBX). Let&#8217;s rock:</p>
<pre class="prettyprint"><code class="prettyprint">mysql>  SELECT SUM(duration)
    ->  FROM cdr
    ->  WHERE (
    ->  (dcontext="from-internal" AND dstchannel like "SIP/voip-gw1%")
    ->  AND (calldate BETWEEN '2008-07-01%' AND  '2008-07-30%')
    ->  AND (disposition="ANSWERED")
    ->  )
    ->  GROUP BY dcontext;
+---------------+
| SUM(duration) |
+---------------+
|         90845 |
+---------------+
1 row in set (0.00 sec)
</code></pre>
<p>Explaining: we just care about answered calls made in period (between 2008-07-01 and 2008-07-30) via VOIP-GW1 (a trunk which give us N free minutes to talk per month).</p>
<h3>Rubyfying</h3>
<h4>database.yml</h4>
<p>We&#8217;ll use ActiveRecord as I said. First, we need to setup our database connection, so write a database.yml (like rails&#8217; proj/config/database.yml):</p>
<pre class="prettyprint"><code class="prettyprint">  adapter: mysql
  database: asterisk
  username: asterisk
  password: asterisk
  host: 127.0.0.1
  port: 3306
</code></pre>
<h4>Running it</h4>
<pre class="prettyprint"><code class="prettyprint">#!/usr/bin/env ruby

require 'yaml'
require 'rubygems'
require 'active_record'

database = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(database)

class CallReport < ActiveRecord::Base
    set_table_name 'cdr'
    set_primary_key 'uniqueid'

    def self.used_minutes(startdate,finaldate)
      @context = 'from-internal'
      @dstchannel = 'SIP/voip-gw1%'
      @firstdate = "#{startdate}%"
      @lastdate = "#{finaldate}%"
      @disposition = 'ANSWERED'

      @minutes = CallReport.find(:all,
                                  :select => '*, SUM(duration) as total',
                                  :group => 'dcontext',
                                  :conditions => [
                                  'dcontext = ? AND dstchannel like ? AND calldate BETWEEN ? and ? AND DISPOSITION = ?',
                                   @context,@dstchannel,@firstdate,@lastdate,@disposition])
      @minutes.each do |minute|
        return minute.total
      end

    end

end

total_time = CallReport.used_minutes('2008-07-01','2008-07-10')
p total_time
</code></pre>
<h4>Result</h4>
<pre class="prettyprint"><code class="prettyprint">rocha@vorheez:~/devel/ruby/prepaid$ ruby main.rb
"23649"
rocha@vorheez:~/devel/ruby/prepaid$
</code></pre>
Similar Posts:<ul><li>None Found</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ruyrocha.com/2008/11/07/integrate-ruby-and-asterisk-call-detail-record-using-activerecord/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
