Sunday, October 27, 2013

not working in PHP 5.3.3

Redeploy my app on WAMP that aare running on PHP version 5.3.3, out of sudden, discover my old code that use is not working. All my pages suddenly display "?>" or ">" characters everywhere in my web page.

Search through the web and finally got the solution:-

Open php.ini, set "short_open_tag" to "On" value as described below

short_open_tag = On
Restart your webserver, everything will be working fine now.

Saturday, October 19, 2013

How to resolve "You don't have administrator rights! freeSSHd will close!" error message while launch freeSSHd?

Setup SSH server using freeSSHd 1.2.6 on my machine running on Window 7. Error message "You don't have administrator rights! freeSSHd will close!" keep prompting when the app is launched.


Below are the steps to resolve this issue
1. Download OllyDbg from http://ollydbg.de/. Launch the app


2. Open "FreeSSHDService.exe" as displayed in the screenshot below.
Note: The file located at the FreeSSHd installation folder


3. Press Ctrl+G and search for address "0041312A"



4. Right click on the selected "0041312A" address, select "Binary" -> "Edit" menu.


5. Change "HEX +00" field value from "74 49" to "90 90". Click on Ok button.


6. Right click on the modified address, select "Copy to executable" -> "Selection" menu.


7. A new exe will be generated. Right click on any boundaries of the window,select "Save File" menu.



8. Overwrite the existing "FreeSSHDService.exe", launch the app, you can find FreeSSHD icon in the system tray..


Tuesday, October 15, 2013

How to migrate MySql data files to other folder/drive?

Let's say you have installed an application that make used of the mysql database and you have completed the installation in a particular folder/drive. Now, you wish to migrate the data storing location to other folder/drive. In order to migrate MySql data files location, below are the details steps :-

Environment
OS: Window 7 Enterprise
MySQL: MySQL version 5.6.12

Assumption
MySQL home directory : [MYSQL_HOME]
MySQL new data files directory : [NEW_DATA_FOLDER]

1. Shutdown MySQL database
2. Copy the "data" folder that normally located at [MYSQL_HOME]\data to new data files directory, [MY_NEW_DATA], for example, "d:\data".
3. Open my.ini that located at [MYSQL_HOME]\my.ini
4. Edit the my.ini by changing the parameter as describe below:
datadir=[NEW_DATA_FOLDER]
5. Restart the MySql database server, that's it!

Thursday, October 3, 2013

How to send email through telnet command to SMTP server?

Assumption
SMTP Server : [SMTP_SERVER]
Client Machine Name : [CLIENT_MACHINE_NAME]
Email From: [EMAIL_FROM]
Email Recipient: [RCPT_TO]

Steps to use telnet command to send email through SMTP server

1. Type in telnet command as described below to connect to the SMTP server.
telnet [SMTP_SERVER] 25
2. Type in the command below to introduce yourself to the SMTP server. For example, "hello localhost"
helo [CLIENT_MACHINE_NAME]
3. Type in the command as described below to set the email address that used to send email.
MAIL FROM:[EMAIL_FROM]
4. Type in the command below to set the recipient gmail id
RCPT TO:[RCPT_TO]
5. Enter the command "DATA" to proceed with composing the email body.
DATA
6. Enter the email body and follow by '.' to trigger email sending
Hello Testing!
.

Tuesday, October 1, 2013

Issue encounter and simple note on PostgreSQL exploration

How to export and import sqldump file into PostgreSQL database?

Note: 2 format types of sqldump that PostgreSql can produce :-
- copy format
- sql format

In case to avoid problems that I encountered by using "copy" format, I advice to use "sql" format.

For my scenario, I use phpPgAdmin to export sqldump. Below are the steps to export sqldump from the source of the database server and import to the target of the database server:
1. Login through phpPgAdmin to access the source database server.
2. Tap on database name in the left menu
3. Tap on "Export" tab in the right hand screen
4. Select "Structure & Data" option with "SQL" format as displayed in the screen below


5. Click on "Export" button, sqldump file in sql extension will be downloaded.
6. Use pgAdminIII tool, create the database in your new target database server.
7. Open the query editor, open the sqldump script and execute the script.
8. Tables structure will be created and all the data will be imported to the target database server.

How to export database schema with command line?

Assume the parameters below represent
Database User ID: [USER_ID]
Database Name: [DATABASE_NAME]
SQL output file: [SQL_FILE]
pg_dump --schema-only -U [USER_ID] [DATABASE_NAME] > [SQL_FILE]
Note: Applicable on Linux

How to export database dump and import into newly created database?

Assume the parameters below represent
Database user id, for example, 'postgres' : [DB_USER_LOGIN]
Database name, for example, 'mydatabase' : [DATABASE_NAME]
Database dump file, for example, 'dump.sql' : [DATABASE_DUMP_FILE]

1. Export database dump from source database using the command as described below (Without copy owner and privileges)
pg_dump --no-owner --no-privileges -U [DB_USER_LOGIN] [DATABASE_NAME] > [DATABASE_DUMP_FILE]
2. Create [DATABASE_NAME] database in your POSTGRES database server

3. Import database dump to the target database using the command as described below
psql -U [DB_USER_LOGIN] [DATABASE_NAME] < [DATABASE_DUMP_FILE]
How to create users and new PostgreSQL database through command line?

Assume the parameters below represent
New user id, for example, 'george' : [NEW_DB_USER_LOGIN]
New user password, for example, '12345678' : [NEW_DB_USER_PASSWORD]
New Database name, for example, 'mydatabase' : [NEW_DATABASE_NAME]

1. In the Linux terminal, type in the command below to add new user
adduser [NEW_DB_USER_LOGIN]
Note: If command not found error message is prompted when 'adduser' is used, type in '/usr/sbin/adduser' to create user.

 2. Use the command below to reset the new user's password
passwd [NEW_DB_USER_LOGIN]
3. Create a new database based on the database template1
psql -d template1 -U postgres
4. Create new user
template1=#CREATE USER [NEW_DB_USER_LOGIN] WITH PASSWORD '[NEW_DB_USER_PASSWORD]';
5. Create new database
template1=#CREATE DATABASE [NEW_DATABASE_NAME];
6. Grant new user access right to the new database
template1=#GRANT ALL PRIVILEGES ON DATABASE [NEW_DATABASE_NAME] to [NEW_DB_USER_LOGIN];
7. Type in '\q' to quit the template1.

How to get your PHPMailer sample code to work properly with your SMTP Server?

Download PHPMailer recently to test on email sending through SMTP server, out of no luck, it just can't send email through the SMTP server  (Microsoft ESMTP MAIL Service, Version: 5.0.2195.738).

Assume the parameters below represent

SMTP Server: [SMTP_SERVER]
Client Server Name: [CLIENT_SERVER_NAME]

Configure all the necessary parameter in SMTP.php class provided by PHPMailer in examples folder, out of no luck, it just can't send email. Turn on the SMTP debug parameters in SMTP.php

// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug  = 2;
The debug messages are displayed as described below:
SMTP -> FROM SERVER:220 [SMTP_SERVER] Microsoft ESMTP MAIL Service, Version: 5.0.2195.7381 ready at Mon, 23 Sep 2013 14:38:12 +0800 
CLIENT -> SMTP: EHLO [[CLIENT_SERVER_NAME]]
SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
SMTP -> ERROR: EHLO not accepted from server: 501 5.5.4 Invalid Address
CLIENT -> SMTP: HELO [[CLIENT_SERVER_NAME]]
SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
SMTP -> ERROR: HELO not accepted from server: 501 5.5.4 Invalid Address
CLIENT -> SMTP: AUTH LOGIN
SMTP -> ERROR: AUTH not accepted from server: 503 5.5.2 Send hello first
CLIENT -> SMTP: quit
SMTP -> FROM SERVER:221 2.0.0 [SMTP_SERVER] Service closing transmission channel
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
Refer to the debug messages, message "Invalid Address" is keep prompting.

Troubleshoot the debug message and discovered that special character '[' and ']' is appended to the [SMTP_SERVER_NAME] value.

Comment out 5 lines of source code at line 720  in "class.smtp.php" as described below and replace with a new 5 lines of source code as described below that removed '[' and ']' characters:
    //if(!$this->SendHello('EHLO', "[" . $host . "]")) {
    //  if(!$this->SendHello('HELO', "[" . $host . "]")) {
    //    return false;
    //  }
    //}
 
    if(!$this->SendHello('EHLO', $host)) {
      if(!$this->SendHello('HELO',$host)) {
        return false;
      }
    }
Try to resend email, it just work like a charm!