Archive for the ‘Missing Answers’ Category

Disable user authentication for subdirectory when using RewriteRule on Apache server

August 30th, 2010 No comments

If you protect your private beta release from public with AuthType and you are using RewriteRule from mod_rewrite, you will soon find, that combination of <Location> and  Satisfy does not work for you – it does not allow access to the subdirectory as expected.

<VirtualHost *:80>
 DocumentRoot /var/www/example

 <Location />
 AuthType basic
 AuthName "Top Secret Beta!"
 AuthUserFile /etc/httpd/htpasswd.beta
 Require valid-user

 <Location /upload-callback>
 Allow from all
 Satisfy Any

 <Directory /var/www/example>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule !\.(swf|pdf|php|js|ico|txt|gif|jpg|png|css|rar|zip|tar\.gz)$ /index.php [L]

With this setup, the subdirectory will require valid user – because mod_rewrite is applied before <Location> and changes the URL, which no longer matches. You can change this by adding an alias:

Alias /upload-callback /var/www/example/index.php

Now all URLs will go through your nice url generator index.php, but the specified URL will be checked against <Location> and give access based on the Allow directive (in this case to everyone).

Categories: Missing Answers Tags:

Drupal 5 and strange behavior of jQuery

June 28th, 2010 No comments

We have some jQuery code, that we use on all our company sites, however, this code did not work on Drupal sites. jQuery call to position() was returning “static” instead of expected object with top and left properties. We thought we should use newer jQuery (instead of 1.2.6), but this throwed “too much recursion” error in Firebug – which we tried to solve with patch from bug . However, neither upgrade nor that patch really helped. The reason why position() did not work was hidden here: /sites/all/modules/jquery_update/compat.js (I was looking at linked files and this one sounded suspiciously).

And indeed, these helpers caused the problem:

// UPGRADE: The following css helpers should now be used as:
// .css("top") or .css("top","30px")
jQuery.each("top,left,position,float,overflow,color,background".split(","), function(i,n){
  jQuery.fn[ n ] = function(h) {
    return h == undefined ?
      ( this.length ? jQuery.css( this[0], n ) : null ) :
      this.css( n, h );

We have replaced position with xposition and our jQuery works as expected even with version 1.2.6.

Categories: Missing Answers Tags:

ViewVC modified rights of the subversion repository

October 25th, 2009 No comments

From various reasons I ended up with some sophisticated rights settings for my subversion repository, the main idea is to grant access based on group. So I need that the files are created with proper group and with write right on the group.

For the command line ans svn+ssh access I created following files (based on some advice, which I found 4 years ago and did not notice a link):


umask 002
/usr/bin/svn.orig "$@"


umask 002
/usr/bin/svnserve.orig “$@”

As big surprise you will find that the web interface modifies files in the subversion repository – it removes write permission on group. I have solved this by adding following line to viewvc.cgi:

--- viewvc.cgi.orig     2009-10-25 09:55:34.738716284 +0100
+++ viewvc.cgi  2009-10-25 09:51:14.914726062 +0100
@@ -58,4 +58,5 @@

 server = sapi.CgiServer()
 cfg = viewvc.load_config(CONF_PATHNAME, server)
 viewvc.main(server, cfg)
Categories: Missing Answers Tags:

Plesk 9 – disable postfix local mail delivery for webhosting

October 25th, 2009 No comments

The scenario is – you provide only webhosting for certain domain – and you want emails to go wherever MX record points to. So you turn off mail services in the Plesk control panel, but keep receiving mails back with This address no longer accepts mail. when you send emails via your server.

You can check that there is no local delivery for this domain:

postmap -s /var/spool/postfix/plesk/virtual_domains

But the trick is that you have to set emails to this address to be rejected instead of bounced (what seems to be the default). My guess is that the bounce check comes before the local delivery check.

Categories: Missing Answers Tags:

Migrating 1&1 server from one machine to another without interruption

October 23rd, 2009 No comments

Recently I have been migrating my Plesk based machine leased from 1&1 to a newer server and I have not found any tips how to perform the migration properly. So here is my suggestion:

  1. Inform your users that they should not modify any data, turn any possible application into read only mode.
  2. Switch off MTA (qmail or postfix) on old machine – good SMTP servers will try to deliver repeatedly.
  3. Transfer your data using Plesk migration tool
  4. Redirect all common traffic to the new machine (see bellow)
  5. Remove the messages about read only usage on the new machine.
  6. Change DNS settings of your main domain to point to the new machine.
  7. Transfer the domain using 1&1 Control Panel from one package to another – do not be worry about legal steps, the transfer is fully internal and takes just hours to complete.

Iptables rules to forward traffic from one machine to another

I’m pretty sure, this list can be reduced, but this worked well for me and allowed monitoring of the traffic being forwared per port number.


iptables -I FORWARD 1 -p tcp -m tcp -d $NEWIP -j ACCEPT
iptables -I FORWARD 1 -p tcp -m tcp -s $NEWIP -j ACCEPT
iptables -I FORWARD 1 -p udp -m udp -d $NEWIP -j ACCEPT
iptables -I FORWARD 1 -p udp -m udp -s $NEWIP -j ACCEPT

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination $NEWIP:80
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 80 -j MASQUERADE

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j DNAT --to-destination $NEWIP:443
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 443 -j MASQUERADE

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 25 -j DNAT --to-destination $NEWIP:25
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 25 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 465 -j DNAT --to-destination $NEWIP:465
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 465 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 993 -j DNAT --to-destination $NEWIP:993
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 993 -j MASQUERADE

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 53 -j DNAT --to-destination $NEWIP:53
iptables -t nat -A POSTROUTING -p tcp -m tcp -d $NEWIP --dport 53 -j MASQUERADE
iptables -t nat -A PREROUTING -p udp -m udp --dport 53 -j DNAT --to-destination $NEWIP:53
iptables -t nat -A POSTROUTING -p udp -m udp -d $NEWIP --dport 53 -j MASQUERADE
Categories: Missing Answers Tags:

Plesk 9 – installing Bugzilla and CPAN problems

October 21st, 2009 No comments

So we have Bugzilla installed from CVS in some directory and we run ./ – it shows that we need a bunch of modules, but they do not install – all you can see is fail message like — NOT OK.

We need some basic packages to work with CPAN on Plesk 9 machines, you have to install some modules:

yum install gcc make

But make needs to be explicitly set in CPAN (may be for CentOS only):

perl -MCPAN -e shell
cpan> o conf make /usr/bin/make
cpan> o conf commit

This will get rid of the Writing Makefile for — NOT OK problem.

But Bugzilla needs DBI::mysql and this needs extra care because of test. But first of all we install mysql libraries:

yum install mysql-devel

And now the installation itself:

/usr/bin/perl DBD::mysql

but it will leave the package downloaded somewhere like

cd /root/.cpan/build/DBD-mysql-4.013

go there and now prepare test database:

echo 'CREATE DATABASE test;' | mysql -u admin -p`cat /etc/psa/.psa.shadow`

and having this make the package:

perl Makefile.PL  --testuser=admin --testpassword=`cat /etc/psa/.psa.shadow`
make test
make install

Now repeat the ./ and install other missing modules.

Categories: Missing Answers Tags:

Plesk 9 – procmail filtering with postfix through .qmail file

October 19th, 2009 No comments

I have just migrated to Plesk 9.2.2 and there is now postfix instead of qmail, so my procmail rules stopped working. Fortunately Plesk changed the MTA but has left the way they filter email, so if you want to use procmail filtering on Plesk you can just copy your .procmailrc file to /var/qmail/mailnames/$DOMAIN/$MAILBOX and run following:


for PROCMAIL in `find /var/qmail/mailnames/ -maxdepth 3 -name .procmailrc`; do
    chown root: $PROCMAIL
    chmod 644 $PROCMAIL
    DIR=`dirname $PROCMAIL`
    FROM="/usr/bin/deliverquota \./Maildir"
    TO="/usr/bin/procmail -m -o HOME=$DIR $DIR/.procmailrc"
    sed -i $DIR/.qmail -e "s@$FROM@$TO@"

And here just an example of .procmailrc file


# Bayes 99% and spam including 20 points goes away
* ^X-Spam-Status:.*BAYES_99
* ^X-Spam-Level: ...................

# Bayes 99% spam is sure spam
* ^X-Spam-Status:.*BAYES_99
Categories: Missing Answers Tags: