vint.ca

September 2, 2010

Change the default “View Source” application in Firefox

Filed under: Uncategorized — Paul Vint @ 9:49 am

I find I’m constantly using the “View Source” option in Firefox while working on sites, but the default viewer isn’t the best.

To configure Firefox so it’ll use a different viewer, do the following:
1. In Firefox, enter “about:config” in the address bar (if you get a warning about dragons, heed it, but continue)
2. type “view” in the Filter field
3. Double-click on “view_source.editor.path” and enter the path to the editor you desire (I used /usr/bin/kate)
4. Double-click “view_source.editor.external” to set it to “True”
5. Restart Firefox

August 31, 2010

What’s My IP Address?

Filed under: Tools — Paul Vint @ 2:54 pm

Your IP address is: 38.107.191.86

August 29, 2010

Fade-in popup window example in Javascript

Filed under: Uncategorized — Paul Vint @ 9:37 am

Source code:



 

You can have multiple popups on one page simply by changing the DIV id and setting the calls to fadeInPopup() and launchMyPopup() accordingly.

August 27, 2010

.htaccess Redirect to a new directory

Filed under: Linux Reference — Paul Vint @ 4:35 pm

I recently found I wanted to move some data on my Apache webserver from one directory to another, and didn’t want to muck around with symbolic links (trying to keep the webspace clean and tidy), but also wanted to ensure that links to these items and searches would still find them.

The answer? .htaccess file and Redirect!

For example, say you moved the /photos directory on your webserver to /media/photos you could do the following to ensure that old links work:

In the .htaccess file in your webserver’s root directory, add the following line:
Redirect permanent /photos/ /media/photos

Shazam! http://yourserver/photos/whatever.jpeg will redirect to http://yourserver/media/photos/whatever.jpeg

1 person likes this post.

August 25, 2010

Online DNS Lookup (MX or A Records)

Filed under: Tools — Paul Vint @ 11:25 am


Lookup A records (IP lookup), MX records (Mail eXchanger), and more for a domain (ie: dig).


Enter Domain:




Results:
 


1 person likes this post.

August 12, 2010

Pronounceable Password Generator

Filed under: Tools — Tags: — Paul Vint @ 11:17 am

Here’s a simple online password generator – I’ll likely add some more features, but it works. You can select the style of password from “_Lf?^x)p” gobbledeegook to “maliLulu” pronounceable (and easier to remember) styles.
These passwords are generated using passook.


Number of passwords:

Level of pronouncability:





 


2 people like this post.

August 9, 2010

Fixing “Warning: file_get_contents()” php error

Filed under: PHP Hints and Tricks — Paul Vint @ 7:31 pm

I recently got the following error on a newly installed webserver:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.

Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:

allow_url_fopen = Off

To:

allow_url_fopen = On

I recently got the following error on a newly installed webserver:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.

Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:

allow_url_fopen = Off

To:

allow_url_fopen = On

Restart Apache, and off you go.

2 people like this post.

August 2, 2010

Backing up MySQL database by database and table

Filed under: MySQL Tips — Paul Vint @ 9:46 am

Backing up mysql databases using mysqldump is pretty quick and painless:
mysqldump -u username -ppassword -h hostname db_name > backup_file.sql
or
mysqldump -u username -ppassword -h hostname --all-databases > backup_file

The only problem is that it becomes quite cumbersome recover a particular table.

I wrote a little script to backup each table in each database to its own file:

#!/bin/bash

if [ $# -lt 2 ]
then
        echo "Usage: backup_all_tables username password [host]"
        exit
fi

mysql_bin="/usr/bin/mysql"
mysqldump_bin="/usr/bin/mysqldump"
backup_path="/opt/backups/www/"

if [ $# -eq 3 ]
then
        host=$3
else
        host="localhost"
fi

user=$1
pass=$2

for db in `echo "show databases" | $mysql_bin -u $user -p$pass -h $host | grep -v Database | grep -v information_schema`
do
        for table in `echo "show tables" | $mysql_bin -u $user -p$pass -h $host $db | grep -v "Tables_in"`
        do
                echo "Backing up $host.$db.$table to $backup_path${host}_$db.$table.sql"
                $mysqldump_bin -u $user -p$pass -h $host $db $table > ${backup_path}${host}_$db.$table.sql
        done
done

save the script as “backup_all_tables.sh”, edit the $backup_path variable to suit, do a chmod +x backup_all_tables to make it executable, and run it using:
./backup_all tables username password hostname
If the database is on your local machine you can omit the hostname.

This will backup the files in the format “host_db.table.sql”, ie: “localhost_mysql.user.sql”

1 person likes this post.

August 1, 2010

Huge sendmail queue – clearing it out

Filed under: Linux Reference — Paul Vint @ 4:02 pm

There are numerous reasons that the mail queue can get over full, ranging from general network problems, to having a user repeatedly sending an email with a large attachment to an incorrectly type address.

The first thing you likely want to do is get some information on what’s in the queue:
To find out how many messages are in the queue:
mailq | tail -1
This will give you the total number of emails in the queue, ie:
Total requests: 6592
You might also want to know how old or new they are, so:
ls -lt | tail -10
and
ls -ltr | tail -10
will show you the oldest 10 and the newest 10 respectively.
To have sendmail retry the emails, simply run (as root):
sendmail -q -v
If you are in a situation where it has filled up the disk and need to fix it FAST, move the directory to another partition and then have sendmail process it from there (stopping sendmail with “/etc/init.d/sendmail stop” is recommended:
mkdir /root/tmpq
mv /var/spool/mqueue/* /root/tmpq
sendmail -q -v -oQ/root/tmpq

(if you get an error like “Argument list too long” instead run “mv /var/spool/mqueue /root/tmp” with sendmail stopped, then restart it)

1 person likes this post.

July 31, 2010

The importance of email quotas

Filed under: Linux Reference — Paul Vint @ 1:20 pm

Running an email server can result in some strange problems at times – a common one being the /var/spool/mqueue filling up (which I really need to write an article on….), and one which can be hard to pin down: A POP3 user with a mailbox that is too big.

I recently ran into a scenario where a user’s mailbox (which REALLY should have had a quota, but didn’t) had grown quite large (~1GB). When the user went to check their mail, the following would happen:

  1. Mail client (Thunderbird, in this case), connects to the mail server and sends username and password
  2. When the user is authenticated (right after the client sends the “PASS xxxxx” command), the pop3d process makes a copy of the user’s mailbox in the temporary directory (/tmp in my case)
  3. There was insufficient space for the copy of the user’s mailbox in the temporary directory, and when if ills up the server aborts the operation sending an error like “-ERR cannot open mailbox /home/userdir/.mail/mbox: No space left on device”
  4. The pop3d process clears out the temporary file (something like /tmp/pop3oj5oyy) freeing up the space
  5. Email client (hopefully) shows the end user a meaningful error

The real problem with this process is the momentary filling up of the temporary directory which can cause a problem for virtually any other process (in my case it was frequently showing up as database errors on websites, amongst other odd problems)

In this case, I found I had a user’s mailbox file that was about 1.2GB:
ls -sh /home/userdir/.mail/mbox
1.2G mbox

To check how many messages there are in it run:
grep -c "^From\ " mbox
15881

15000+ messages!

Now to the fixing it part:

First move to another location so that nothing is added to it while working with it (preferably after shutting down your MTA, ie: /etc/init.d/sendmail stop – depending on your situation, this may not be practical) and switch to the directory where it is:
mv /home/userdir/.mail/mbox ~/mbox.tmp && cd ~
In my case, I figure if I break it into 10 chunks (about 1500 messages each) it should work fine:

cat mbox.tmp | formail -1500 -s > mbox.1

This gave me a file about 115MB.
If you shut down your MTA, just copy/move that file to the location where the original mailbox file was, fire up the MTA, and download the mail. If you did not shut down the MTA, you should append this new file to the mailbox that may be there now (if there was any new mail received). Note: This may be slightly dangerous, so making a backup copy of the mailbox file that is in place is highly recommended):

cat mbox.1 >> /home/userdir/.mail/mbox
Then, as above, download the mail.

Second chunk:
cat mbox.tmp | formail +1500 -1500 -s >mbox.2
Move the mbox.2 file as per above, and download.

Rinse and repeat, if necessary:
cat mbox.tmp | formail +3000 -1500 -s >mbox.2
Increasing the “+xxx value by the amount per download as required until it’s done.

Oh, and back to the title of this article: If we had a quota in place on this account, none of this would ever had happened!

Older Posts »

Powered by WordPress