Import mails from a non cPanel server

It’s easy for us to import emails over between two cPanel servers, no matter we are migrating 50 or 100 accounts or so, its an easy job to do via WHM or even via backend of cPanel servers. But what if your task to migrate over all emails from a non cPanel server. aahh now you are in trouble!!! 😛

But trust me, you can do that easily with “imapsync”. Following is the command that I did to import mails of email account from a non cpanel.

suppose you want to migrate userx account on server sourceserver.com to userx account on destinationserver.com

====
imapsync –host1 sourceserver.com –user1 userx@domain.net –password1 enterpasshere –host2 destinationserver.com –user2 userx@domain.net –password2 enterpasshere –regexflag “s/\Forwarded//g” –noauthmd5 –syncinternaldates
====

you will see lot of things going on as below in the screen which is a sync process betweeen the two mail servers, wait for a while to complete and then you are done.

============
msg INBOX/208 {34910} copied to INBOX/445
msg INBOX/209 {81261} copied to INBOX/446
msg INBOX/210 {77615} copied to INBOX/447
msg INBOX/211 {10423} copied to INBOX/448
msg INBOX/212 {7092} copied to INBOX/449
msg INBOX/213 {13977} copied to INBOX/450
msg INBOX/214 {57403} copied to INBOX/451
msg INBOX/215 {75258} copied to INBOX/452
msg INBOX/216 {54282} copied to INBOX/453
msg INBOX/217 {77174} copied to INBOX/454
msg INBOX/218 {3298} copied to INBOX/455
msg INBOX/219 {48916} copied to INBOX/456
msg INBOX/220 {19315} copied to INBOX/457
[INBOX.Drafts] -> [INBOX.Drafts]
[INBOX.Junk] -> [INBOX.Junk]
[INBOX.Sent] -> [INBOX.Sent]
[INBOX.Trash] -> [INBOX.Trash]
++++ End looping on each folder
++++ Statistics
Transfer started on : Fri Nov 1 15:47:37 2013
Transfer ended on : Fri Nov 1 15:48:19 2013
Transfer time : 42 sec
Messages transferred : 232
Messages skipped : 0
Messages found duplicate on host1 : 0
Messages found duplicate on host2 : 0
Messages void (noheader) on host1 : 0
Messages void (noheader) on host2 : 0
Messages deleted on host1 : 0
Messages deleted on host2 : 0
Total bytes transferred : 16188117
Total bytes duplicate host1 : 0
Total bytes duplicate host2 : 0
Total bytes skipped : 0
Total bytes error : 0
Message rate : 5.5 messages/s
Average bandwidth rate : 376.4 KiB/s
Reconnections to host1 : 0
Reconnections to host2 : 0
Memory consumption : 115.4 MB
Biggest message : 3019767 bytes
Memory/biggest message ratio : 40.1
Detected 0 errors
============

Before everything you need to ensure imapsync is installed in server. If not just install it using yum.

=====
yum install imapsync
=====

You may require the following perl modules to install in the server.

=====
Mail::IMAPClient 3.34
IO::Socket 1.31
IO::Socket::INET 1.31
IO::Socket::SSL 1.955
Digest::MD5 2.53
Digest::HMAC_MD5 1.01
Term::ReadKey 2.30
Authen::NTLM 1.09
=====

For their installation, just go to cpan prompt and install them one by one.
For eg:

=====
[~]# cpan
cpan> install Mail::IMAPClient
=====

Please note if you are trying to import mails from pop accounts, them imapsync may not work. Such cases you can refer to poptoimap tool. Please read these:

http://www.linux-france.org/prj/pop2imap/pop2imap
http://imapsync.lamiral.info/FAQ

How to extract .jpa archive file? :)

Some clients may approach you with the backup file as .jpa archive(joomlapack) which cannot extract using the usual tools available in server. This can be done by using the third party script Akeeba Extract Wizard.

Download the Akeeba pack from here https://www.akeebabackup.com/download/official/akeeba-kickstart.html

Upload the kickstart zip archive again in public_html or in the same folder where the you have the .jpa archive. Extract the content of the archive. This will put multiple files in the same folder(you see many .ini files of it).

Access the kickstart.php script inside the unzipped kickstart folder via your domain and browser. For example:

http://yourdomain.com/kickstart.php

(should load the correct path where your kickstart.php resides. If it is in a subfolder, load as http://yourdomain.com/subfolder/kickstart.php)

On the kickstart.php loaded on browser, you can browse the .jpa archive file exists in the same folder and go click Extract. You will see the extracted files and folders in the same folder where your kickstart package downloaded 🙂

PHP 5.4 : Strict standards : Non-static methods called statically

I got the following error while loading up a domain running on php 5.4

=======================
Strict Standards: Non-static method JLoader::import() should not be called statically in /home/user/public_html/libraries/joomla/import.php on line 29
Strict Standards: Non-static method JLoader::register() should not be called statically in /home/user/public_html/libraries/joomla/loader.php on line 71
Strict Standards: Non-static method JLoader::import() should not be called statically in /home/user/public_html/libraries/joomla/import.php on line 32
=======================

and I did the below steps to clear them

=======================
In php.ini,
changed error_reporting = E_ALL | E_STRICT to error_reporting = E_ALL & ~E_NOTICE

changed display_errors = On to display_errors = Off
=======================

If the above still doesn’t help you, do the following too.

In the domains index.php file set it like inside the php division.

========
ini_set(‘display_errors’,0);
========

This should fix it 🙂

Legacy filter_module syntax causing 500 error in apache 2.4

Hey, sometimes you may come up with the following error in error log which is actually causing by legacy filter_module syntax on the htaccess file.


======================
[Sun Oct 06 18:20:24.119633 2013] [core:alert] [pid 47884] [client 5.x.x.x:54039] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
[Sun Oct 06 18:20:31.705923 2013] [core:alert] [pid 48315] [client 157.x.x.x:46020] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
[Sun Oct 06 18:20:31.707094 2013] [core:alert] [pid 48315] [client 157.x.x.x:46020] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
======================

Probably the apache version is 2.4 in your server and it wont take the legacy filter_module syntax. You should need to make some changes in it. For example my users filter_module rules were as follows in his .htaccess file.


FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/x-icon
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no

I changed it to


FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/html'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/css'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/plain'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/x-component'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/javascript'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/json'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xhtml+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/rss+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/atom+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/vnd.ms-fontobject'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/svg+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/x-icon'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/x-font-ttf'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'font/opentype'"
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no

The error has gone then 🙂

Snoopy logger

Snoopy logger is a powerful utility which makes the admin work more easy by providing a log of commands executed via shell. It logs each and every users shell command executions to “/var/log/secure”. We can later check the log and recognize the user and the command it executed from the uid.

I am pasting a portion of snoopy log below:

=======================================
Sep 10 05:38:20 serverXXX snoopy[206015]: [uid:0 sid:187552 tty:/dev/pts/2 cwd:/root filename:/usr/bin/tail]: tail -f /var/log/secure
Sep 10 05:38:21 serverXXX snoopy[206016]: [uid:99 sid:185700 tty: cwd:/home/user123/public_html/my-notepad.biz/forum/archive filename:/opt/suphp/sbin/suphp]: /opt/suphp/sbin/suphp
Sep 10 05:38:21 serverXXX snoopy[206016]: [uid:1002 sid:185700 tty: cwd:/home/user123/public_html/my-notepad.biz/forum/archive filename:/usr/bin/php]: /usr/bin/php /home/markwesl/public_html/my-notepad.biz/forum/archive/index.php
Sep 10 05:38:21 serverXXX snoopy[206017]: [uid:99 sid:185700 tty: cwd:/home/user456/public_html/current filename:/opt/suphp/sbin/suphp]: /opt/suphp/sbin/suphp
Sep 10 05:38:22 serverXXX snoopy[206024]: [uid:1006 sid:185700 tty: cwd:/home/user999/public_html/drwhofigures.co.uk/forum filename:/usr/bin/php]: /usr/bin/php /home/senseb/public_html/domain.com/forum/cron.php
=======================================

You can find the user using uid using the following command or from the /etc/passwd file.

=======================================
root@serverxxx [~]# getent passwd 99
nobody:x:99:99:Nobody:/:/sbin/nologin
root@serverxxx [~]# getent passwd 1002
user123:x:1002:997::/home/user123:/usr/local/cpanel/bin/noshellsnoopy-1.8.0.tar.gz
root@serverxxx [~]# getent passwd 1006
user999:x:1006:1001::/home/user999:/usr/local/cpanel/bin/noshell
=======================================


Snoopy Installation Steps
=========================
* cd /usr/src
* wget ftp://ftp.uwsg.indiana.edu/pub/FreeBSD/ports/distfiles/snoopy-1.8.0.tar.gz
* tar xvf snoopy-1.8.0.tar.gz
* cd snoopy-1.8.0
# Check configuration options:
./configure –help

# Then continue with normal build procedure:
./configure [OPTIONS]
make
make install

# Then you can actually enable snoopy:
make enable
=========================

Snoopy “/usr/local/lib/snoopy.so” is placed in /etc/ld.so.preload. To remove snoopy later, simply edit /etc/ld.so.preload and remove the
reference to snoopy.so and delete /usr/local/lib/snoopy.so. For more information, you can read the “README” file in the source directory.