IT

Annoying IE Compatability Mode

I recently had to create a site for an education facility, and they turn on Compatibility mode for all their networked PCs, for legacy support.

This was messing around with some of my JS/CSS functionality, so I needed a work around.

3 options really:

  1. Get the IT manager to remove the global compatibility layer and only apply to the legacy apps. Not going to happen!
  2. Rewrite the code to use IE friendly techniques. Possible but a ball ache.
  3. Force the browser to not use compatibility mode. Sounds best, right?

So, its really very simple, in the head section of the page:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

That worked an absolute treat.

Redirect certain IP address .htaccess

If you ever wanted to prevent certain IP addresses from accessing your site, you can easily acheive this in the .htaccess file.

Simply list the IP addresses and then redirect them to the desired URL:

RewriteEngine on 
RewriteCond %{REMOTE_ADDR} ^xxx\.xxx\.xxx\.xxx$ [OR]
RewriteCond %{REMOTE_ADDR} ^xxx\.xxx\.xxx\.xxx$
RewriteRule ^(.*)$ http://www.redirection-url.com [L]

If you want to add more then do so, but notice there is no [OR] on the last condition.

Now, this could get messy if you have loads, and I am unsure of the performance hit, but its a quick and easy way of redirecting users. A site I work on has 5 servers located worldwide, and I wanted to send LA users attempting to access the UK server back to their designated server

Find a file containing a text string on Linux

There is a very useful command in Linux, called grep. It is a utility for searching plain text files using regular expressions. You can either search files and folders as a parameter, or pipe command outputs to it, such as grep’ing a tail.

For looking for a file:

grep -r "string to find" /folder/to/look/in/

Thats the simple answer.

If you want to pipe the grep to monitor say a tail

tail -f /var/log/maillog | grep "chris@tatedavies.com"

 

Setting up Postfix to use an external mail server

Sometimes sending mail to a dev account is all well and good, but if the mail server you are sending to is not accepting the mail for one reason or another (disallowed dynamic ip addresses, for instance) then you might need to set it up to send through a mail server (relay).

I am using smtp.tatedavies.com as an example here, and the user “frank” with his password being “penguin” (clearly a very high security password)

Fire up terminal and sudo in.

sudo su
postconf -e "relayhost=smtp.tatedavies.com"
postconf -e "smtp_sasl_auth_enable=yes"
postconf -e "smtp_sasl_password_maps=hash:/etc/postfix/smtp_password"
echo "smtp.tatedavies.com frank:penguin" > /etc/postfix/smtp_password
chmod 600 /etc/postfix/smtp_password
postmap /etc/postfix/smtp_password
service postfix restart

Vagrant – Errors trying to start

Using Vagrant as a dev environment is great apart from when it goes arry after an OS crash, or battery fault…

Chriss-MacBook-Pro:ceta chris$ vagrant reload

[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory

VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterface, interface IHostNetworkInterface
VBoxManage: error: Context: "int handleCreate(HandlerArg*, int, int*)" at line 68 of file VBoxManageHostonly.cpp

The only way I have found to fix this is to restart the VirtualBox service:

> sudo /Library/StartupItems/VirtualBox/VirtualBox restart

And then re-up it

> vagrant up

 

Saving username and password OpenVPN config

I use the openvpn command line to connect to a certain VPN site, and I get annoyed at having to find the password everytime

So, in the .ovpn file, there is a setting:

auth-user-pass

So, I create a file (lets call it new-file.txt) in the same folder as the config, and it only contains 2 lines, first line username, second password

Change the auth-user-pass line to be

auth-user-pass new-file.txt

And now it connects without prompting me for password. Super.

Obviously this is a slight security issue, but this is on a pretty secure VM on a secure machine. So its quite safe. Just think about it if you are implementing the same workaround.

Log in to SSH with no password

So you want to have your password remembered by a remote SSH connection?

Easy, following these steps

On your local machine, create a new SSH key:

ssh-keygen

It will ask you for a file location and a keyphrase, but I always just hit enter three times.

This will create a file in the default folder (or whichever folder you chose in the first step)

/home/user/.ssh/id_rsa.pub

The contents of this file want to go into a file on the remote server: If the file doesn’t exist, you’ll have to create it.

/root/.ssh/authorized_keys, or
/home/user/.ssh/authorized_keys

That’s it. There are some cases where you have to change the permissions of the authorized_keys file but I’ve not had to do that. I think the suggested chmods are 640 and 700, but don’t hold me to that

From now on, you won’t be prompted for your password when SSH’ing in from the local machine. In order to revoke access, delete the right line from the authorized_keys file.

Enabling SVN log message editing

Subversion, by default will stop you from editing a log message after its been committed. This is because SVN has a powerful feature called ‘hooks’ that enable the repo administrator to control the message logs when their developers are committing.

Fortunately, if you have access to the repo, you can switch off the hook that stops this.

The process is to copy the ‘template’ hook as a proper hook and de-activate it.

SSH into the server and go to the SVN repo folder (as sudo)

sudo su
cd /home/svn/codebase
cp hooks/pre-revprop-change.tmpl hooks/pre-revprop-change

Then, edit the hooks/pre-revprop-change file. All you need to do is stick this at the top of the file:

exit 0

The above command will return a success message to the SVN repo and every change will be allowed.

And every log message change will be accepted. Now, be warned that this will allow people to piss about and change their messages ‘after the fact’ and you won’t have any control over it. But if you work in a small trustworthy team like me, then its not such a biggie.

Just FYI, the command for changing an SVN log message is :

svn propset -r <revision> --revprop svn:log "<enter your new log message here>"

Note: You do not need to specify the SVN URL if you perform this command from within your SVN working copy.

If your message is a simple edit or you want to write loads, you can leave off the message and it will open a text editor with the existing message in, and when you save and quit, it will update the message with what ever is in the file. Like so:

svn propedit -r <revision> --revprop svn:log

Mounting HTML folder in Centos VirtualBox

I have a particular Linux set up I need to test something on, but I use a Mac, so I use VirtualBox with a Linux VM for the testing.

So, to do this normally, you either install an IDE on the VM and code on there. Installing Java, Netbeans, Subversion, Git, etc, etc, etc, or, you just checkout the code on the VM and make code changes on the Mac…

Neither of these options are really that great, so a friend recommended I mount the code folder from the Mac on the Linux VM. Great idea. So I install a new copy of CentOS and keep it minimal, no window managers, nothing like that. Just Apache, and the database connectors I require.

Now, I would not class myself as a Linux expert in any shape or form. I can set up a server and manage it, ut if you delve too deeply, I start to struggle. I used the VirtualBox automatic mounting for my code folder (using Guest Additions) – this just would not work. I tried checking out the code into a local folder and that worked fine. Must be a problem with the share/permissions or something.

After wasting an hour or so checking permissions and groups, I gave up and tried the internet. Came across a really helpful post, which I sort of followed. I had to alter it for CentOS as it was Ubuntu orientated.

You have to install Guest Additions first!

Add a virtual box shared folder

Create a Transient folder in the shared folders section and take note of the name, I used ‘sites’ – do not select any of the checkboxes when creating the share. This is what causes the problem as VirtualBox creates the share with permissions that Apache cannot use.

mkdir /var/www/sites
mount -t vboxsf -o rw,uid=0,gid=0 sites /var/www/sites

I used the UID and GID of 0 as I was only installing this VM as root. There were no other users installed, but you do need to change the UID and GID of the Apache process (www-data?)

Test that and make sure it works, if it does, lets make it permanent:

nano /etc/fstab
sites /var/www/sites vboxsf defaults 0 0

Hey presto, the folder is mounted on boot and you should be able to serve the docs from there.

Obviously you need to update the vhosts to point at the shared folder. But you know how to do that, right?