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

12/06/2008

splitting large sql files using split

The split command have a couple of essential switches, one may either split per line,per bytes or line per bytes. Lets see which is best applicable for SQL dumps.

Splitting per line:
Splitting a very large SQL file generated from mysqldump will not be optimal and effective to be splitted using the per line switch, simply because data from one table will take up one line only regardless how large it is making the split almost useless.

Splitting per byte:
Splitting an SQL file per byte can be effective at times, but there is no guarantee that the the input file will be splitted in the proper string positions. SQL errors is likely to happen in situations where the splitted sql files contain incomplete query at the end because it is terminated in between a line.

Splitting line per byte:
This is the best way to split a huge sql file. It splits the SQL file in bytes specified but takes into account the line so it does not split the SQL file in between. Ex:


split -C 40312832 data.sql 


In the example above, data.sql is splitted into several files (xaa, xab xac... xaz..) and tries to fit as much line to the specified bytes. Although the output splitted files will not have the exact size as the byte specified, split will try to fill as much but making sure that no line is truncated between, thus assuring that the query will be valid upon execution.

Availability:
split command is part of the GNU coreutils and is available in almost all linux distributions and *nix based operating systems. In some OS's like Solaris 9 Sparc, you may need to upgrade the coreutils package that is prebundled with the system to have access to split binary that supports the -C switch.

11/20/2008

php fsockopen problems when connecting to ssl and tls mail servers

Few weeks ago I was stumped by some error that took me sometime to resolve concerning PHP Mailer - having it fetch emails from Gmail. After grepping through logs, I discovered few fsockopen errors stating wrong function parameter issues. The logs states:


Warning: fsockopen() expects parameter 2 to be long

I have gone and checked if the PHP Mailer version I use supports connecting via SSL, and it appeared it didn't, in effect I upgraded PHP Mailer to version 2.03. Everything worked fine in my local development server, but behold, yet another error only occurring in our live server, it was:


Warning: fsockopen() [function.fsockopen]:
unable to connect to ssl://smtp.gmail.com:465
(Unable to find the socket transport "ssl" -
did you forget to enable it when you configured PHP?)

The error message was obvious enough for me to realize that I did not compile the php on our server with ssl support. The final resolution was I re-compiled PHP with the following params:


'./configure'
'--with-apxs2=/usr/local/apache2/bin/apxs'
'--with-mysql=/usr/local/mysql/'
'--enable-mbstring'
'--with-gd'
'--with-jpeg-dir=/usr/local/lib'
'--with-png-dir=/usr/local/lib'
'--with-zlib' '--with-curl'
'--with-gettext'
'--with-ncurses'
'--with-imap=/usr/local/imap/imap-2006c1/'
'--with-imap-ssl=/usr/local/ssl/'
'--with-openssl'
'--enable-sockets'

The '--with-openssl' part was just what I needed. After recompiling and restarting httpd, everything worked fine.

7/21/2008

MiaCMS on PacktPub OpenSource CMS Awards 2008

Hey guys! help MiaCMS make it into the OpenSource CMS Award. Please take time visiting the following links

http://www.packtpub.com/article/nominate-overall-open-source-cms-winner
http://www.packtpub.com/article/nominate-most-promising-open-source-cms

and entering the following info

Nominated Content Management System: MiaCMS
Website: http://miacms.org

Thank you very much.

7/07/2008

How to use SmartBro Prepaid Kit on Linux (ZTE MF622 HSDPA USB MODEM)

Due to the typhoon that hit our area (Kalibo, Aklan), I was pushed offline, internetless for a week. As a recourse I was forced to purchase the SmartBro Prepaid Kit (ZTE MF622 HSDPA Modem).

Here's how I was able to use the SmartBro Prepaid Kit (ZTE MF622 HSDPA Modem) on my Linux dev machine (fedora 8) and should be applicable to other popular desktop linux distros.

I created two files as follows:

/etc/udev/rules.d/25-zte-mf622.rules containing:
ACTION!="add", GOTO="End"
SUBSYSTEM=="usb", SYSFS{idProduct}=="2000",
SYSFS{idVendor}=="19d2", GOTO="ZeroCD"
SUBSYSTEM=="usb", SYSFS{idProduct}=="0001",
SYSFS{idVendor}=="19d2", GOTO="Modem"
LABEL="ZeroCD"
RUN+="/sbin/rmmod usb_storage"
LABEL="Modem"
RUN+="/sbin/modprobe usbserial vendor=0x19d2 product=0x0001",
MODE="660", GROUP="dialout"
LABEL="End"
/etc/smartbro.conf containing:
[Dialer Defaults]
Init2 = ATZ
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init5 = AT+CGDCONT=1,"IP","smartbro"
Stupid Mode = 1
Modem Type = Analog Modem
ISDN = 0
Phone = *99#
Modem = /dev/ttyUSB0
Username = user
Password = pass
Dial Command = ATDT
Baud = 460800
To connect to the internet via the usb modem, simply invoke the following command on the terminal:
wvdial --config=/etc/smartbro.conf

To Disconnect, kill the process ID of the PPPD command called by wvdial or simply remove the USB HSDPA Modem.

5/25/2008

..just got back from Manila..

I just got back from Manila, staying at the airport for 15 hours to wait for my flight gave me a nasty headache. Yesterday I gave a talk about websecurity for tri{php}letreat@USAutoPartsPhilippines seminar. I was slated as the last speaker, luckily the USAutoPartsPhilippines training room has an unlimitted supply of coffee enabling participants to stay alive until my topic is over.

At the event, I was able to meet co-presentors Reynold Lariza and Reuben Ravago; PHPUGPH Officers Clodelio Delfino, Bryan Blas, JR Yap and Cherrie Anne Domingo. I had a fun time with them although JR Yap was not able to tour me around Q.C., I sure hope the next time I visit Manila, i would not chance upon his car broke :D.

I will be posting materials for the web security talk i did for this the event soon.. I have a whole heap of backlogs to catch up with. Ah.. sundays.. :D