..a dose of zero-day know-hows ..

10/07/2009

How to use 3G Phone/Modem to connect to the Internet on Fedora 11 (Linux)

Its been awhile since I attempted to connect to the internet via 3g using my phone (SGH-i550). The last time I did was several months ago with the help of wvdial. Now that there is a power outage in our area; and I forgot to install wvdial; and I just upgraded to Fedora 11, now is the perfect time to test the new features of the updated NetworkManager into action.

The following are the set of simple steps I have taken to connect to the internet using SGH-i550 via 3g on Fedora 11. I would assume that these steps will also work with other brands/models and most 3g modems around.

  1. Connect 3g phone/modem to the computer

  2. Right-Click on the NetworkManager Applet and select "Edit Connections"



  3. Select "Mobile Broadband" tab





  4. Select the 3g Device from the drop down list and click "Forward"





  5. Select the Country and click "Forward"





  6. Select a Provider and click "Forward"





  7. Select a Plan and click "Forward"





  8. Confirm the details and click "Apply"





  9. Leave the preset defaults and click "Apply"





  10. Close the Connection Settings Dialogue





  11. Right-Click on the NetworkManager Applet again and select the newly created connection





  12. The NetworkManager Applet will change its icon indicating a successful connection has been established





  13. And you are done.

10/03/2009

Web Developer tools for Opera 10 (switching from Firefox)

Just yesterday I decided to completely ditch Firefox and use Opera 10 as my default browser. The chronic issue of memory leaks and excessive CPU usage in Firefox appears to have gotten worse in their latest release and I just couldn't bear with it anymore.

As a recourse I decided to finally switch to Opera 10. I have been using it for awhile and noticed the vast difference in resource usage versus Firefox.

Below is a list of tools and widgets I found useful for web developers using Opera 10.

  • Dragonfly - is Opera's developer tool that is installed by default in Opera 10. It can be accessed via Tools -> Advanced -> Developer Tools. It offers functionalities such as DOM Inspector, CSS/Javascript Error Console, Javascript Console, Network Monitoring and more, it is pretty much like Firefox's Firebug.
  • phpManual - is an Opera Widget which provides the PHP manual. This widget is handy when looking up certain functions without having to search it up on php.net's website, the result just appears inline the widget.
  • CSS Help - provides an expandable CSS 2.1 mini-documentation.
  • Javascript Cheatsheet - as its name implies, provides an easy to browse Javascript Cheatseet.
  • Site Validator - This widget submits the current page to the W3C Markup Validation Service and returns the number of errors found and a link to the actual results. 

There are quite a number of other useful widgets for web developers in Opera's Widget home page. Dragonfly was the one which sold me entirely. I am still looking forward using Firefox again in the near future when the memory leak and high cpu usage issues are addressed.

8/06/2009

Getting "failed to open stream: HTTP request failed! HTTP/1.1 501 Method Not Implemented" When Passing Post Requests to JSON RPC Server

I spent some few hours trying to figure out how to go around the HTTP/1.1 501 error I am getting using the JSON Client Class from JSON-RPC_PHP (http://jsonrpcphp.org).

As it turns out the culprit was the modsecurity module for Apache2. The logs indicate that the JSON Server script is denying the JSON Client access.

[msg "Request content type is not allowed by policy"]


Instead of hacking the JSON-RPC library, what I did was disabled the restrictions inhibiting the JSON client from passing post request to JSON server by commenting out few lines in my /etc/httpd/modsecurity.d/modsecurity_crs_30_http_policy.conf, lines 68-70, specifically the following:


#SecRule REQUEST_METHOD "!^(?:get|head|propfind|options)$" \
#"phase:2,chain,t:none,t:lowercase,deny,log,auditlog,status:501,msg:'Request content type is not allowed by policy',id:'960010',tag:'POLICY/ENCODING_NOT_ALLOWED',severity:'4'"
#SecRule REQUEST_HEADERS:Content-Type "!(?:^(?:application\/x-www-form-urlencoded(?:;(?:\s?charset\s?=\s?[\w\d\-]{1,18})?)??$|multipart/form-data;)|text/xml)" "t:none"


After restarting apache, json server/client works fine. I hope this would spare someone from the hours of hair pulling.

6/22/2009

Migrating Workstations

I am currently migrating my work files, emails, skype logs, apache document root, firefox addons/settings/bookmarks, cached subversion passwords, wine apps to a new workstation. And how handy can the home directory be to move everything in few sweeps..


cd ~
scp -r root@192.168.0.198:/root/Documents .
scp -r root@192.168.0.198:/root/.thunderbird .
scp -r root@192.168.0.198:/root/.Skype .
scp -r root@192.168.0.198:/root/.mozilla .
scp -r root@192.168.0.198:/root/.subversion .
scp -r root@192.168.0.198:/root/.wine .
cd /var/www/
scp -r root@192.168.0.198:/var/www/html .


Now the only manual thing I have to do is do several mysqldumps and transfer it over (well i could hot copy /var/lib/mysql but i do not want to do that at this point as I have many innodb tables).. I think in no time i'll be finished and will be working my way as if im still using the old laptop.

Transferring the hidden files in my home directory using SCP works wonders, and also leaves you thinking how secure you are, as everything can be snap shot and copy your saved passwords/sessions/emails/chatlogs right from your home directory.

6/20/2009

Content Management Systems Unite

Original Article - http://miacms.org/index.php?option=com_content&task=view&id=55&Itemid=1

Written by MiaCMS Team
Jun 14, 2009 at 07:33 AM

We would also like to make a 2nd major announcement at this time and one that has long-term implications to the project itself. Anyone who has followed the MiaCMS, Mambo, and Joomla! projects over the last few years is all too familiar with forks. There are obviously advantages and disadvantages to forking an open source project; Mambo has actually been forked quite a few times over the years with varying degrees of success. Most of these forks have either faded away or simply gone dormant. However, two very successful projects have emerged from the ashes of their parent and even greatly improved upon the codebase they started with; MiaCMS and Joomla!. We do not wish to rehash the reasons for the MiaCMS fork several years ago (for those interested you can find that information here). Today, we are pleased to announce a step in the opposite direction... an open source CMS project merger. The MiaCMS and Aliro projects are joining forces to create a best of breed/next generation CMS.

While we are just announcing this news today, the two teams have already been working together behind the scenes for about 6 months now. Conversations started around creating a compatibility layer for extensions, but soon evolved into plans for a merger since we are tackling the same problems and have very similar end goals. These teams have a history of collaboration. Martin Brampton, founder of Aliro, was a huge contributor and former Core Development Team Leader on the Mambo project several years ago. He wrote much of what became Mambo 4.6, which eventually became the basis for MiaCMS. At Mambo he worked closely with Chad Auld who went on to become Mambo's Project Leader and Core Development Team Leader after Martin's departure, and eventually a co-founder of MiaCMS. Several other current MiaCMS core developers were also on the Mambo team at that time; Neal Thompson and Richard Peter Ong. These folks together with Ozgur Cem Sen, another former Mambo Core Development Team Leader, have decided to reunite. The emerging Aliro platform will serve as the basis for this new era. Much of the work done in MiaCMS since its inception will become part of Aliro, e.g., the YUI implementation, the JavaScript architecture, the WYSIWG editors, a number of extensions, etc. We will be using the name Aliro for the combined project. MiaCMS will remain a standalone project that is fully supported with major bug fixes and security updates for the foreseeable future. The MiaCMS core developers will begin focusing all new development efforts on the Aliro platform after the MiaCMS 4.9 release is out and stable. We will keep you updated as we have news to report. Aliro itself is already a fairly stable product, and we encourage everyone to download the latest beta and take it for a spin. We still have a good bit of work to do before the first official production release, but we are well on our way.

Why was this change needed?
* MiaCMS was created as a fork of the Mambo project, the grandfather of all open source CMS projects. Mambo either serves as the basis for or as an inspiration to most of the CMS systems in use today.
* Mambo is quite old at this point. Releases, developers, and svn activity are all but non-existent, as alluded to in a recent interview with Chad Auld. MiaCMS has given new life to the aging platform, but with the advancements in PHP and related frameworks over the last several years, the system is really in need of a full re-architecture building upon the lessons learned over the last 8 years. While still with the Mambo project we announced such an effort several years ago, before the fork. That effort was to be a Mambo rewrite on top of the CakePHP framework, but it never really got off the ground due to the political infighting that ultimately required the MiaCMS fork.
* So, here we are several years later with a much better system, MiaCMS, but still in need of a much larger architectural shift. While we have advanced the upper layers of the system, Aliro has been focused on the all-important foundation. Building on top of Aliro will allow us to better serve the community and put out a CMS that is even more impressive, efficient, secure, and flexible than the one you currently enjoy.

We hope the community is as excited about this news as we are. We look forward to continued success with you at our side. Thank you!

The MiaCMS team

5/21/2009

Camiro-CMS: 1st Beta Release

5/17/2009

Using PHPMailer and Crontab in Enqueuing/Sending System Generated Emails

This article covers how to use PHPMailer and Crontab to send Emails via an SMTP server without having to directly trigger the actual email sending task via the web process. This implementation gives a performance gain especially to the systems wherein most actions need to trigger email sending (eg. Notification systems in ERP's, CRM's and CMS's).


Scenario
Most of the systems I have dealt with trigger the sending of Emails from the Web server through the web request. An example of this scenario are Notification Emails being sent to the recipients when a certain action is triggered/accomplished.

Although this is a common approach for most systems eg. CMS, CRM etc., I find it inefficient as the execution speed of the script which sends the actual email is dependent to the SMTP server set to be used, in such events, if the SMTP serves lags/fails on responding, the script which invokes fsckopen will wait until the STMP server answers which might cause the script to timeout after some moments of waiting.

Solution:
Instead of attempting to send the email directly along the web process, it is wise to enqueue the email by storing it on a database, and let crontab pick those entries up and send the emails using the php cli by accessing a PHP Email Class such as PHPMailer. The sent emails in the database can then be flagged as 'sent' so the query which picks the emails up can exclude sent emails via "WHERE `sent` != '1' LIMIT ...".

This is a sample implementation (PHPMailer)

A. Setup the Database Table

The first thing that needs to be done is to create a table where the enqueued emails will be stored. This sample table is generic enough for most purposes, but feel free to expand as deem fit.
CREATE TABLE  `outgoing_emails` (
`id` int(9) NOT NULL auto_increment,
`recepient` text,
`subject` text,
`body` text,
`mode` int(1) default '0',
`date_entered` datetime default NULL,
`sent` int(1) default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
In the table above, the basic parts of an Email has columns which correspond to arguments that can be passed to the phpmailer Send() method.

B. Setup the PHPMailer Class
Download PHPMailer (PHPMailer 2.0.4 is used for this example, although other versions may be used), and uncompress it as appropriate.

C. Setup the actual email enqueuing and sending script
This script will be used to access the PHPMailer class, enqueue and send the emails (in short, it will be the all-in-one script which will do all the job). This script will be accessed by cron and execute it via PHP cli.

Note: This is a modified version of the functions used by Mambo CMS to send out emails and is found in all versions up to 4.6.x series. This is a very good implementation anyways and I am lazy to write my own for the sake of demo-ing:



Copy and paste the code above and save as enqueue_emails.php. You may need to modify lines 1-14 to set proper MySQL and SMTP credentials, as well as the path where you extracted the PHPMailer package.

D. Setup the Cron job
Next is set the crontab to run enqueue_emails.php, eg. if you intend to send the email in batches every 2 minutes, you would need to set the cron to the following:

*/2 * * * * php -f /var/www/mail/enqueue_emails.php


E. Reroute the email sending lines in your script to use the 'enqueue_emails()' function
Take it for a spin, An example would be:

require_once( 'enqueue_emails.php' );
enqueue_email('test@example.com', 'email subject', 'email body');

Wait for 2 minutes and let cron pick the email up and send it to the recipient, wait until it arrives in the inbox and And you're done.

For any questions, follow-ups, feel free to leave a comment, I hope this has been helpful.

5/01/2009

Fix: SugarCRM 5.1.2x Inbound Email -> Plain Text attachments getting Discarded

In SugarCRM 5.1.2c and up, you will notice that the Inbound Email functionality fails to pickup plain text attachments, this affects files with csv, txt extenstions and other files with plain text mime type. You should be able reproduce this issue by sending an email to an address that is monitored by SugarCRM, once cron invokes cron.php, the emails will be fetched but the plain text attachments are nowhere in the email.

It took me awhile fixing our company instance only to figure out the culprit was only one line which was added upon my upgrade (from 5.1.2a or 5.1.2b or from 5.1.2b to 5.1.2c I cannot exactly pinpoint)

The fix was simple, simply change line 3385 (approx) of /modules/InboundEmails/InboundEmail.php from

if(strtolower($part->disposition) == 'attachment' || 
((strtolower($part->disposition) == 'inline'))
&& $part->type != 0) {
to
if(strtolower($part->disposition) == 'attachment' || 
((strtolower($part->disposition) == 'inline'))) {
You will notice that with the unchanged code, there is no way for attachments whose $part->type is '0' (plain text) to get parsed and be attached in the email object.

I hope this spares someone form hair pulling I had to go through