full of … these

Redirect http to https behind varnish for php services

Posted: July 21st, 2011 | Author: | Filed under: howto | Tags: , , | 1 Comment »

It may happen to want to redirect a site from http to https behind a varnish cache system.

Is known the fact that varnish has a lack of redirect procedures, mostly from http to https.

A redirect on varnish from http to https looks like this:

if (req.http.host ~ "^(www\.)?site\.com$" && req.url ~ "\/checkout\/cart") {
       error 750 "https://www.site.com/checkout/cart";
sub vcl_error {
 #redirect to https
 if (obj.status == 750) {
 set obj.http.Location = obj.response;
 set obj.status = 302;
 return(deliver);
 }
 }

That will not work!

Varnish is not aware if the request was made from http (request directly sent to varnish) or https (request sent to pound).

So, I have found another page suggesting that the redirect can be added to php like this:

if (($_SERVER['REQUEST_URI'] == '/admin' || $_SERVER['REQUEST_URI'] ==  '/checkout/cart/') && !$_SERVER['HTTP_X_FORWARDED_PROTO']){
  header("Location: https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}elseif (($_SERVER['REQUEST_URI'] != '/admin' && $_SERVER['REQUEST_URI'] != '/checkout/cart/') && $_SERVER['HTTP_X_FORWARDED_PROTO']) {
  header("Location: http://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}

This code fixes https redirection.
Any comments are welcome. I am new to varnish.


Rotate backups over FTP

Posted: June 14th, 2011 | Author: | Filed under: howto | Tags: , | No Comments »

I was looking for a method to rotate old files from external backup account.

It looks like is not that easy but a small fuse module can mount the ftp account locally. This allows you to use scripts and tools from local server to search, delele, upload, download files like they were local.

To carry out this I have installed curlftpfs:
apt-get install curlftpfs

Mount the external ftp account:
curlftpfs -o allow_other username:p4ss@backupserver.external /media/ftpmount/

Notice the -o allow_other, without this no other user than the user used to mount the account will be able to use it.

Now you can use: rsync, find, cp, vim or du to make whatever you need with the files.


trac: already updated: Error binding parameter 3 – probably unsupported type

Posted: October 20th, 2010 | Author: | Filed under: howto, linux | Tags: , , , , | No Comments »

I’m sick today, but, here is a short one.

If the user cannot log in into trac after a self password reset and you receive this message:

user.name already updated: Error binding parameter 3 - probably unsupported type.

all you need is to delete the cached users session in the sqlite database.

First make a backup:  cp trac.db trac.db-backup
Now you have to find the sessions stored in the database:
sqlite2 trac.db
select * from session_attribute;

Find the user with the problems and delete his data:
DELETE FROM session_attribute WHERE sid = "user.name";

Now test.
Please do backup the database first.


Windows XP, suddenly “USB device not recognized” message

Posted: September 21st, 2010 | Author: | Filed under: howto, idiots | Tags: , , , , , | No Comments »

USB stopped working, suddenly! F#uck! Nothing on USB is working, but it did! WTF can you do?

On MS support the KB articles are not offering a straight to the point solution for this.

So, I have searched the internet and after a few searches I have found this article (Google PR 3 page):

http://www.online-tech-tips.com/computer-tips/usb-device-not-recognized/

The answer is:

UNPLUG YOUR COMPUTER FROM THE POWER SUPPLY!!! and wait a few minutes to have all residual power consumed.

So, I did it.

And, it worked.

I had a 3 m USB cable extension for a USB WIFI adapter and, after removing it, is all good. It works!!!

Later edit:

This is a bit extreme, it still works if you shutdown the computer, unplug the power cord, push the buttons of the computer a few times, plug-in USB devices and wait for a minute or so.

One cause of this may be the grounding of the appliances, high density of wireless devices, unshielded USB cable, or, a combination of these.


Office Word 2003/2007 mouse hourglassing (blinking)

Posted: June 29th, 2010 | Author: | Filed under: howto, idiots | Tags: , , , , | No Comments »

My buddy with the gmail account problems in Outlook 2007 said today that the Word’s behavior is odd and the mouse cursor is switching fast between edit vertical line (text select) and the hour glass.

Investigating and applying different solutions including complete reinstall, rename Normal.dot or delete Data and Options sections from registry, uninstalling using revo uninstaller didn’t fixed the problem.

So, I went back to forums and after half an hour of reading I have found that the default printer may cause this problem.

Setting (the) other printer as default one or uninstalling it fixed the problem.

Now I have to find other/better drivers because each time when he will need to print something from Word he will need to select another printer.

Of course OpenOffice has no problems at all :)