Pensamos

Búsqueda por archivo: 2006

Hello world!

4tm.biz
Jose Luis Canciani

Update: we are not using wordpress anymore. We prefer a custom developed blog software that is easy to extend :)

This is obviously the first post of the blog.

Thanks to the people that created Wordpress!!!

I hope you get some good information on this site.

Regards,

Jose Canciani

4tm.biz

About

4tm.biz
Jose Luis Canciani

This is the Weblog of 4Team members. You can find more about 4Team on http://www.4tm.com.ar/

Gmail Spam Analyzer

4tm.biz , php , spam , gmail
Jose Luis Canciani

gmailspamanalitics.jpgToo many email address redirect to your gmail account? Watching your Spam folder getting bigger (and boring) everytime? It was for me.

So I decided to write some scripts (thanks to libgmailer) and now I can spend my time reading a newspaper or going out ;)

During the last years I've collected a lot of email addresses: one for each company I've worked for, one for msn, one for gmail, one for yahoo, and the list goes on. I finally decided to foward all my email address to a Gmail box. There's something about the conversation view that no other client has yet...Of course this move had the side effect of multiplying the spam emails I receive in the gmail box. The spam system does a good job, but I think some reports can be useful.

Several years ago I came up with the idea of using a domain name I have to create email address for each webpage I sign up and I don't trust much. So every email I create is something like thesiteurl@mydomain.com. I have all the domain emails redirected to my account. When I see some email address is sending too much spam I simply block the address and that's all.

Anyway it is still a pain in the a** to go through my spam folder every day to control this stuff. So I decided that a script should be doing it for me.

Basically the script connects to gmail, reads the spam folder, and saves certain data from the email to a database table which I later can review from a webpage with some cool effects. On the right you can see a screenshot of the reports. I've add some graphics to make it a little more interesting ;)

The script is written in php. It uses libgmailer (from the gmail-lite project). It reads the folder content for unread messages and when if found a conversation it read each email and saves the recepient, the sender and the subject for later analysis. Using adodb it inserts in a database table the data.

Let's see a bit of the collect.php code.

This scripts should be run from a cron job periodically (every hour should be fine). First, we have to create the table in the database where we are going to save the data the script will collect:

 

CREATE TABLE spam_occurance (
  message_id VARCHAR(30) NOT NULL ,
  ts INT(11) NOT NULL ,
  recv_email VARCHAR(60) NOT NULL ,
  subj VARCHAR(200) NOT NULL ,
  from_email VARCHAR(60) NOT NULL ,
  PRIMARY KEY (message_id),
  INDEX (recv_email,ts),
  INDEX (ts,recv_email)
);

 

Then we modify the config.inc.php and specify a database connection URI to access that table.

Now let's review some insteresting parts of the collect code:

Connect to gmail, apparently the library saves login cookies in a session var, so that it won't have to re-authenticate every time it runs... Anyway, I don't think that this works when running from the command line...

 

 $gm = new GMailer();
 $gm->setLoginInfo($myemail, $pwd, $tz);

 

Next, we get the spam box conversations and cycle in the unread conversations to get the real emails:

 

$gm->fetchBox(GM_STANDARD, "spam", 0);
      $snapshot = $gm->getSnapshot(GM_STANDARD);
      if ($snapshot) {
           debug('Total # of conversations in Spam folder = ' . $snapshot->box_total.$nl.$nl);
         foreach ($snapshot->box as $conv) {
             // we will only inspect unread messages for better performance
             if ($conv['is_read']==1) {
                        debug('Conversation "'.strip_tags($conv['subj']).'" (id: '.$conv['id'].')'.$nl);
                 
                 // get the messages in the conversation
                 $q = "search=spam&view=cv&th=".$conv['id'];
                $gm->fetch($q);
                    $snapshot2 = $gm->getSnapshot(GM_STANDARD | GM_LABEL| GM_QUERY| GM_CONVERSATION);
      ....

 

So now we have the real emails in the conversation in the $snapshot2 object. We only have to collect that email info, verify that it wasn't already analyzed/inserted (could happen when a new mail enters an already read conversation) and finally insert the data in the table:

foreach ($snapshot2->conv as $msg) {
    debug(' From: '.$msg['sender_email'].' ID: '.$msg['id'].' was send to ');
    foreach ($msg['recv_email'] as $recv_email){
        $email = '';
        eregi($regex, $recv_email, $email);
        debug($email[0].' ');
        $sql = 'select 1 from spam_occurance where message_id = ?';
        $rs = $db->execute($sql,array($msg['id']));
        if ($rs->EOF) {
            $sql =  'insert into spam_occurance '.
                    '(message_id,ts,recv_email,subj,from_email) '.
                    ' values (?,?,?,?,?)';
            $db->execute($sql, array( $msg['id'],time(),$email[0],
                                    strip_tags($conv['subj']),$msg['sender_email']));
            debug('INSERTED');
        } else {
            debug('SKIPPED');
        }
    }                
    debug($nl);
}

 

Data is now in the database and ready to be seen by the report script.

The reports.php script is a little bit more complicated (with the ajax stuff) so just go ahead and download it to see it. Anyway the powerfull part was the use of libgmailer. It's a very good library that I could imagine using in a lot of ways!

You can get the source code here: 4TM Open Source Tools

Making YouTube XHTML 1.0 Valid

html , multimedia
Jose Luis Canciani

I'm working on a new design for one of my clients (Feria Argentina). This project is a new website re-design, the last one was created by 4Team on 2002.

This time we are working with a strict XHTML 1.0 validation policy.

When trying to insert some YouTube videos I find out that the code YouTube gave me it was not a valid XHTML 1.0 one. I tried surfing the web for a quick answer and I found out this was, as I expected, a common problem for a lot of programmers and bloggers. I even find plugins for making this work with third party tools (check this out: http://forum.textpattern.com/viewtopic.php?pid=126350).

Apparently the "embed" tag has some problems with the validation. But we can totally disregard the embed tag using only the object tag with the type attribute correctly set. Here's how:

Before:

 

    <object width="300" height="300"
               type="application/x-shockwave-flash"
               data="http://www.youtube.com/v/CazD1uYmVSI">
          <param name="movie" value="http://www.youtube.com/v/CazD1uYmVSI" />
    </object>

 

After (Valid xhtml 1.0):

 

    <object width="300" height="300"
               type="application/x-shockwave-flash"
               data="http://www.youtube.com/v/CazD1uYmVSI">
          <param name="movie" value="http://www.youtube.com/v/CazD1uYmVSI" />
    </object> 

 

This works with IE and Firefox as of today :)

Please let me know if you see something wrong here.

Jose.

YouTube and Google Video on the Nokia 770

html , multimedia , mobile , nokia , video , maemo linux
Jose Luis Canciani

Recently a friend of mine bought a Nokia Internet Table 770. It's a great little device with an ARM processor and a version of linux called maemo. It comes with the Opera browser but unfortunately it has Flash version 6 only.

The streaming features of sites like YouTube needs flash version 8 or even 9. So how can he watch the videos easily in the device? Well, actually is pretty easy (after some search, I hope this can make you save some time).

First you have to install MPlayer for 770. Check out Maemo applications. MPlayer can play FLV files.

Now you need to be able to easily download the flv file from the page. Use the Opera browser of the device and go to this site: http://1024k.de/bookmarklets/video-bookmarklets.html. That's a great collection of Javascript codes that will help you download the videos. Just bookmark them clicking and holding over each link. Use the "Flash Video files (.flv)" as this will download directly from the website you will be looking at (ie YouTube or Google Video).

That's it. Now go to Youtube, choose a video and when the page finish loading just click the bookmarked link and you will be asked to save a .flv file.

You can also open the file directly with MPlayer if you associate .flv with it.

Follow this instructions: http://www.internettablettalk.com/forums/showpost.php?p=19205&postcount=84.

Nice watching!

Jose.

Anonymous browsing from the office

tools , network , ssh
Jose Luis Canciani

I have some webpages I usually access from my office computer that I don't want to show in the company's access logs (don't think bad, usually it's just pages that are blocked becouse of the url words which are banned from the company's proxy).

This is a quick howto to bypass the proxy.

This article assumes you are able to do outgoing connections to a home server using an ssh port. If you don't, you can still manage to do it through your company's proxy if you setup your ssh daemon to listen to the 443 port. Usually the 443 port of the corporate's proxys are allowed to make permanent connections. Give it a try, it worked for me in my previous job (Putty program let's you use proxy servers).

I'm using Gentoo at home, so I just installed tinyproxy (emerge tinyproxy) and then edit /etc/tinyproxy/tinyproxy.conf and set the daemon to listen only to the internal interface. That will save us some time configuring access rules in the proxy.

 

 
Port 8888
Listen 127.0.0.1
Bind 127.0.0.1

 

Now start the server (/etc/init.d/tinyproxy start).

So now we have Tinyproxy listening to port 8888 on the loopback interface. All we have to do know is connect from your office pc with ssh and do a port fowarding of your local 8888 port to your home's box 8888 port on the local interface. It should look something like this (with openssh):

 

 
ssh -L 8888:localhost:8888 user@homebox

 

With Putty you set port fowarding in Connection -> SSH -> Tunnels: Source port: 8888, Destination: localhost:8888 and press Add. Once connected you should have you office pc's 8888 port fowarding to Tinyproxy. Now you just have to configure your browser to use a proxy server at localhost:8888. Firefox has several extensions for changing the proxy server from a tool bar bottom (for example xyzproxy).

That's it, you are know browsing anonymously (well, at least in your company, since you will be showing your home IP address to the sites you visit).

You can repeat this procedure using an anonymous proxy on the internet if you want full anonymity (is that a word??).

Happy browsing!

Jose.

Bluetooth net between Nokia770 and Windows

mobile , nokia , maemo linux , network
Jose Luis Canciani

Since there is no wireless connection at the office and because Bluetooth is less power consuming than wifi, my friend (who has the Nokia 770) and I start searching the web for a Bluetooth network connection. This tutorial(-wannabe) is based in these two articles:

http://maemo.org/maemowiki/HOWTO-BluetoothNetworking

http://www.internettablettalk.com/.....okia_770_over_Bluetooth

First thing to do is pair the device with the PC, if you haven't already. You can do it by creating a new bluetooth connection in the Nokia 770. You will be asked to send a pair key which you should then type in your windows PC. If you have the choice click the checkbox to automatically connect to it next time. There's no need to create the connection once it's paired, just cancel it after the pairing has been successful.

If you have Nokia's latest OS (2006) you will have to run (as root) the following to load the bnep module (needed to set the interface later):

 

insmod /mnt/initfs/lib/modules/current/bnep.ko

 

We are assuming you have the Windows bluetooth driver correctly installed, and you have setup a bluetooth network interface with the following settings:

 

Ethernet adapter Bluetooth Network:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.0.1
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :

 

You can also set a gateway if you want to route all traffic to another interface (with bridge networking, which we will not cover it here). Ok, now let's try to connect to the network. In the Nokia 770 run:

 

hcitool scan 
pand --connect 00:10:20:30:40:50

 

The hcitool scan will give you a bluetooth ID and name of all devices in range. Search for your computer and replace 00:10:20:30:40:50 for you computer's id.

Once you run the connect command your windows bluetooth driver should show a popup warning you about an incoming connection. Click on it and be sure to check the "Always allow" before clicking the allow bottom.

Now you are connected! If you run ifconfig you whould see the bnep0 interface. We have to configure it. Try this:

 

 

ifconfig bnep0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255

 

Running ifconfig again you should see it configured now. If you will use bridged connections on windows then you have to add a default gateway with the route command and setup your resolve.conf file. For this tutorial I recommend installing a proxy server like CCProxy (http://www.youngzsoft.net).

You should now be able to ping each addresses and receive a response (be sure to disable firewalls if you have some).

Last thing to do is to install a dummy connection in the Nokia 770 because when you try to open a browser window it will ask you to connect first. Here is how:

 

 

gconftool -s -t string /system/osso/connectivity/IAP/DEFAULT/type DUMMY

 

That's almost it, you just have to edit the DEFAULT connection you just created and setup the proxy servers. Use the IP of your windows bluetooth interface (192.68.0.1 for this example) and the ports where your proxy server is listening (808 for CCProxy by default).

I hope this quick steps can help you! For more information click on the links I've mention at the beginning of this post.

Jose.



Últimos comentarios
  • Posteado por: Ezequiel Sanson

    "Muy buena la pagina... habra que entrar mas seguido!..." »leer y comentar
  • Posteado por: Carla Ferfolja

    "Testing Carli..." »leer y comentar
  • Posteado por: Jose Luis Canciani

    "Gracias por el aviso!..." »leer y comentar
  • Posteado por: ikobopyjomedek

    "ikobopyjomedek... Mimsy F..." »leer y comentar
  • Posteado por: eqetitijefajon

    "eqetitijefajon... Beat..." »leer y comentar

2010 Copyright © 4TM - todos los derechos reservados

www.4tm.biz