August 31, 2010

What’s My IP Address?

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

Your IP address is: 38.107.179.240

August 29, 2010

Fade-in popup window example in Javascript

Filed under: Javascript & AJAX,PHP Hints and Tricks — Paul Vint @ 9:37 am

Source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script type="text/javascript">// <![CDATA[
// Browser safe opacity handling function
function setOpacity( divid, value ) {  
 document.getElementById( divid ).style.opacity = value / 10;
 document.getElementById( divid ).style.filter = 'alpha(opacity=' + value * 10 + ')';
}
function fadeInMyPopup( divid ) {
  for( var i = 0 ; i <= 100 ; i++ )
  setTimeout( 'setOpacity("' + divid + '", ' + (i / 10) + ')' , 8 * i );
}
function fadeOutPopup( divid ) {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity("' + divid + '", ' + (10 - i / 10) + ')' , 8 * i );
 }
 setTimeout('closeMyPopup( divid )', 800 );
}
function closeMyPopup( divid ) {
 document.getElementById( divid ).style.display = "none";
}
function launchMyPopup( divid ) {
 setOpacity( divid, 0 );
 document.getElementById( divid ).style.display = "block";
 fadeInMyPopup( divid );
}
// ]]></script>
<div id="popup1" style="width: 380px; height: 300px; display: none; position: absolute; top: 130px; left: 80px;">
<table border="0" cellspacing="0" cellpadding="0" width="380">
<tbody>
<tr>
<td><img src="/images/menubar_bg.png" alt="" width="356" height="23" /></td>
<td><a href="javascript:fadeOutPopup(&quot;popup1&quot;);"><img src="/images/window-close.png" border="0" alt="" width="24" height="23" /></a></td>
</tr>
<tr>
<td style="padding: 5px 10px; vertical-align: text-top; background: url(/images/popup_body.png) no-repeat scroll left top transparent; width: 380px; height: 277px;" colspan="2">
This is a test of the emergency pop up system.
If this were an actual emergency, you'd have been trampled. :-)</td>
</tr>
</tbody>
</table>
</div>
<input onclick="launchMyPopup('popup1')" type="submit" value=" Launch Popup1! " />

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

1 person likes this post.

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:
 


2 people like 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.

Powered by WordPress