SVN Server changed

Written by: daniel

Date June 22, 2009

Hi folks,

we have recently migrated our svn server to another machine. It is now available at:

svn://svn.devayd.com/cake

username: anon
password: anon

please use your favorite program (like this one) to browse and download our open source stuff.

Unfortunately the web interface will not be available for now.

installing punjab xmpp http client interface on ubuntu-server

Written by: daniel

Date March 23, 2009

Punjab allows to connect to an xmpp server like ejabberd, from a client that supports http requests only (for ex. javascript / ajax). It uses some clever parallel connections to handle input and output streams, so there is very little latency when sending and receiving messages.

First, install needed libraries:

apt-get install python python-twisted

then, download the source code from http://code.stanziq.com/cgit/punjab/punjab/

Once unpacked, edit the configuration file punjab.tac.
I changed the port on which punjab is running to 5821, as the default 5280 is already used by ejabberd web admin interface.

Then, install it and run:
python setup.py install
twistd -y punjab.tac

if it works, you should be able to access http://yourdomain.com:5281 (if you changed the port)

The last thing you need to configure is to setup your apache server, so you can use punjab in your sites.
As by default, you cannot open ajax connections to domains and ports different to the ones that your site uses, so we will have to use mod_proxy and mod_rewrite to enable access to punjab.

edit /etc/apache2/httpd.conf and add the following
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

edit your vhost file and add these lines:
RewriteEngine On
RewriteRule ^/http-bind/ http://yourpunjabserver.com:5281/xmpp-httpbind/ [P]

this means, that everytime you will access yourapplication.com/http-bind/, the request will be transparently proxied to http://yourpunjabserver.com:5281/xmpp-httpbind/

now add the required modules and restart apache:
a2enmod rewrite
a2enmod proxy
a2enmod proxy_http
/etc/init.d/apache2 restart

that’s it! you can now use for example the Strophe xmpp library to create your xmpp applications with javascript.

installing ejabberd on ubuntu-server

Written by: daniel

Date March 20, 2009

Ejabberd is one of the most popular xmpp servers. It is used mostly as a jabber chat server, but the xmpp protocol serves for any purpose when instant messaging, and message queques are needed.
Anytime when you need people (or software components) communicate in realtime over the network, an xmpp server might be what you are looking for.

So, how to install it on an ubuntu-server?

Ejabberd package is in the offical repositories, so the installation is trivial:

apt-get install ejabberd

Once it’s done, you need to edit the /etc/ejabberd/ejabberd.cfg file in order to setup hostnames that your server will manage. Accounts in ejabberd (and in other xmpp servers) are in form of “user@domain_name”, so you need to find the following lines:

%% Hostname
{hosts, ["localhost"]}.

and add all domains that your server will be using, for example:

{hosts, ["localhost", "devayd.com"]}.

then, you need to enable some users that will have admin access to your server. look for “ACCESS CONTROL LIST” in the config file, then uncomment and edit any of sample acl lines. The mine looks like this:

{acl, admin, {user, “admin”, “devayd.com”}}.

this means, that admin@devayd.com will have the admin rights.

ok, we are done with the config. save the file and start the server:

/etc/init.d/ejabberd start

Now, you need to create the admin user. we will use a command line utility that comes with ejabberd.

ejabberdctl register admin devayd.com password

don’t forget to change “devayd.com” with your domain.

now you can access the server web interface on the port 5280 and add more users.

you could also allow users to register with their jabber clients (like pidgin or psi). to do so, look for the following line in the config file:

{access, register, [{deny, all}]}.

and change “deny” with “allow” then restart the server.

back again

Written by: daniel

Date March 9, 2009

it’s been a while since I published my last post, all because of some health problems that I’ve been coping with. Well, I am happy to say, things seem to go better these days and I feel like doing some new exciting projects (and of course blog about it). to be honest, we have been doing more than just work, so stay tune to get some news about our simple “sunday-afternoon’s” and proof of concept projects including:

  • digital signage
  • unit testing in cakephp
  • embedded linux systems
  • openwrt
  • home automation
  • mobile app development
  • xmpp (aca jabber) and web integration
  • webhooks
  • and more…

Custom configuration files in CakePHP

Written by: daniel

Date September 19, 2008

In order to speed up our development process and following the DRY rule we always try to split our code in reusable modules. Then when creating a new project we just get them one by one and add to the current code. Its pretty easy and efficient (now we can spend this time on adding new cool features) but there is one problem when this custom modules need some extra functions or configuration.

Let’s take a look for example at our contact module, that creates a simple contact form. In order to work properly, it needs to have these variables configured when cake starts:

Configure::write(’Admin.name’, ‘John Smith’);
Configure::write(’Admin.email’, ‘admin@example.com’);

This way, we can use this data across our application and they can be changed easily if necessary.

OK, as we know this can be added easily to the bootstrap.php file, but there is always a pain to remember to do it when installing a module. And if you have a dozen of modules this becomes a big hassle to go and manually add stuff for each of them.

Our solution is to create a custom directory in app/config, let’s say its my_config, and then command cake to load at bootstrap all files it finds there. Now our modules can provide their own configuration files which are included automatically.

The function that loads these files is placed in /app/config/bootstrap.php and it’s pretty simple:

<?php

//include all php files from app/config/my_config
foreach(glob(APP.”config/my_config/*.php”) as $configFile) {
include($configFile);
}

?>

Quick copy of data from one db to another on linux

Written by: daniel

Date September 18, 2008

mysqldump -u user1 -p -h host1 sourcedatabase | mysql -u user2 -p -h host2 -D destinationdatabase

El pueblo habla

Written by: daniel

Date September 17, 2008

No estoy seguro hasta que punto esto puede ser un reflejo de la omnipresente crisis económica, pero últimamamente ha aumentado mucho el numero de manifestaciones que pasan cerca de mi casa.

Supongo que ante una situación difícil la gente tiende a quejarse más y exigir que las autoridades tomen medidas…

Copy messages from a Thunderbird mbox file to a MySQL table using php

Written by: Maciej Grajcarek

Date July 1, 2008

If for some reason you would like to copy your messages from Thunderbird to a MySQL database, here you can find a simple PHP script which will do it for you! All you have to do is to set some variables in the php class and create a proper database table. Let’s start with the class.

var $file_name = 'some_mbox_file';
var $file_path = '/path/to/file/';

var $db_user = 'user';
var $db_password = 'pass';
var $db_host = 'localhost';
var $db_name = 'mbox';

$file_name is the name of the thunderbird mbox file and $file_path points to the folder it is located (deafult path in Windows looks sth like this: C:\\Documents and Settings\\%user%\\Application Data\\Thunderbird\\Profiles).
You should also define the database connection variables.

Next thing is to create a database table:


CREATE TABLE  `messages` (
`id` int(10) unsigned NOT NULL auto_increment,
`from` varchar(255) collate latin1_general_ci NOT NULL,
`to` varchar(255) collate latin1_general_ci NOT NULL,
`subject` varchar(255) collate latin1_general_ci NOT NULL,
`date` varchar(255) collate latin1_general_ci NOT NULL,
`message` text collate latin1_general_ci NOT NULL,
`received_ip` varchar(15) collate latin1_general_ci NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

As you can see, this script will read: from, to, subject, date, received_ip and message fields for each of messages. It will not copy attachments!

It supports also processing of big files. We have used it to parse files bigger than 3GB.

server crash

Written by: daniel

Date July 1, 2008

Hemos perdido temporalmente los datos del blog pero finalmente se ha podido restaurar todo :) Por suerte hemos tenido un backup. Así que ya estamos de vuelta.

CakePHP 1.2 Filter Component

Written by: Maciej Grajcarek

Date June 11, 2008

Tworzenie formularzy i metod służących do filtrowania danych jest bardzo częstym zadaniem w codziennej pracy programisty. Zwykle, aby osiągnąć pożądany efekt, korzystałem z kombinacji metod modelu i kontrolera . Zwykle oznacza to również pisanie wielu linii kodu i strata czasu na mało interesujące zadanie. Zacząłem więc szukać rozwiązania, które zdejmie ze mnie choć troszkę pracy. Najbardziej interesujący okazał się dla mnie kod zaprezentowany przez Pana Nik’a Chankov’a na jego blogu, który to kod stał się fundamentem do moich dalszych prac.

Read the rest of this entry »