John Hesch

Echoing my thoughts and interests

Archive for the ‘Web Development’ Category

07-17-07

XAJAX addReplace is Broke

Posted by John

I'm building an online cash register and decided to use XAJAX as my PHP/Ajax toolkit. It was very easy to learn and begin using. In fact, I am amazed at how easy XAJAX is to use. The problem, it is still in the infancy stage and today I found that not all responses work as expected.

I needed to replace an element like this

JavaScript:
  1. $objResponse->addReplace("title", "innerHTML", "<h2>Enter Order Information</h2>", "<h2>Transaction Summary</h2>");

The expected result would be the HTML tag and text,

HTML:
  1. <h2>Enter Order Information</h2>

would be replaced with

HTML:
  1. <h2>Transaction Summary</h2>

I just couldn't get it to work. It appears that the problem is with Firefox. I didn't try IE but from what others have said, addReplace works in IE.

I finally had to come up with a workaround because I needed this to work in both IE and FF.

JavaScript:
  1. $objResponse->addClear("title", "innerHTML");
  2. $objResponse->addAssign("title","innerHTML", "<h2>Transaction Summary</h2>");

Simple, eh?

07-6-07

CSS Redundancy Checker

Posted by John

CSS Redundancy Checker

A simple script that, given a CSS stylesheet and either a .txt file listing URLs of HTML files, or a directory of HTML files, will iterate over them all and list the CSS statements in the stylesheet which are never called in the HTML.

Basically, it helps you keep your CSS files relevant and compact. And it's reasonably accurate.

Unfortunately for me it requires Rubygems and Hpricot, plus a reasonably up-to-date version of Ruby.

All major browsers change the color of links users have visited. With some JavaScript, a web site can view the colors of the links in a users browser history and determine if they have visited a site. A web site can't pull a list of sites the user has visited from their browser, but they can test a predefined list of URL's to see if they have visited any of them.

Spyjax makes it super easy for web sites to spy on their visitors. With Ajax, thousands of links can be tested against a visitors browser history to determine which web sites have been visited.

Luckily, if you're a Firefox user, there is SafeHistory. A Firefox add-on that restricts the marking of visited links on the basis of the originating document, defending against web privacy attacks that remote sites can use to determine your browser history at other sites.

I recently stumbled upon a free CSS editor available for Windows, Mac and Linux.

To help you work with CSS, we've created a free tool called Simple CSS, which runs on Macs, Windows and Linux. Simple CSS allows you to easily create Cascading Style Sheets from scratch, and/or modify existing ones, using a familiar point-and-click interface.

Simple CSS

Whitelist For Exim Sender Verify Callout

Recently a user called and said that he was not receiving emails from a particular person. The email was being sent, but not received by the user. After verifying that the email was not getting caught up in a spam filter, I looked through the Exim logs located at /var/log/exim_mainlog. I found the email was being rejected with the error

could not complete sender verify callout

Exim by default, will check the senders email address and send a callback to the sending server to check and see if the users email address actually exists. In this case the senders email server was not verifying the email address actually exists and so the email was being rejected.

I didn't want to turn off callouts to verify the existence of email senders so I did some digging and found that Exim allows the callout feature to check with a whitelist to see if a callout instruction should be ignored. The instructions were locked within the cPanel forums which require registration and so my Google check didn't find these instructions.

I'm posting them here in hopes that others can find them easily. The original forum post is located here.

Create a file that will be the actual whitelist. In this example it is /etc/whitelist_senders - the addresses need to be listed one entry per line, either the email address or use the wildcard to do an entire domain. To create the file:

CODE:
  1. touch /etc/whitelist_senders

In WHM, in the top most edit box add (if there is anything else in the text box add this bellow it):

CODE:
  1. addresslist whitelist_senders = wildlsearch;/etc/whitelist_senders

Still in WHM. scroll down to where there are three text boxes together. This is the begin ACL section. In the middle box scroll down until you find:

CODE:
  1. #sender verifications are required for all messages that are not sent to lists
  2. require verify = sender/callout
  3. accept domains = +local_domains
  4. endpass

and change it to:

CODE:
  1. #sender verifications are required for all messages that are not sent to lists
  2. deny
  3. !verify   = sender/callout
  4. !senders  = +whitelist_senders
  5. accept domains = +local_domains
  6. endpass

Still in the middle box scroll down to the end and change:

CODE:
  1. #!!# ACL that is used after the DATA command
  2. check_message:
  3. require verify = header_sender
  4. accept

to this:

CODE:
  1. #!!# ACL that is used after the DATA command
  2. check_message:
  3. deny
  4. !verify   = header_sender
  5. !senders  = +whitelist_senders
  6. accept

Save and exit. Now try to send and receive email to make sure everything is still working. If all is ok add the address in question to the whitelist and see if it works.

Then put the sender addresses in the file /etc/whitelist_senders, one per line, e.g.

CODE:
  1. someone@domain1.tld
  2. *@domain2.tld 

activeCollab is an easy to use, web based, open source collaboration and project management tool. Set up an environment where you, your team and your clients can collaborate on active projects using a set of simple, functional tools. 100% free.

I've been using activeCollab for a month or so and it is the most adaptable, easy-to-use project management application I've ever used. Unfortunately the developer is closing up the source as of v1.0, but 0.71 is still open source and hopefully some developers will take that code and begin a new branch of activeCollab.

There is a close-knit active community that is hacking the 0.71 code to add functionality but it hasn't taken off like I'd hoped.

Recently I needed to move 19 databases from server A to sever B. The new server B was a scaled down Linux server with no web services so I couldn't use phpMyAdmin, the MySQL database administration tool. I needed to learn how to take care of this task using the command line only.

After moving 19 databases, I created a fairly easy system for exporting, transferring, importing, and creating permissions.

Step 1: Dump Database

Use SSH and log into server A. Navigate to a temporary folder or create a new folder for dumping the databases into. From the command line issue the following command

CODE:
  1. mysqldump DATABASE_NAME > DATABASE_NAME.sql

This will dump the structure and data from the database you named above into the directory you are currently in.

Step 2: Transfer File

Now you need to transfer the file to the new server.

CODE:
  1. scp DATABASE_NAME.sql USERNAME@IP_ADDRESS:DIRECTORY_ON_SERVER_B/DATABASE_NAME.sql

Replace DATABASE_NAME with the name you gave the file in step 1. Replace USERNAME with the login name on server B. I used root. Replace IP_ADDRESS with the IP of server B. DIRECTORY_ON_SERVER_B is the name of the directory on server B where you want to transfer the file to. It doesn't really matter where you put it.

Once you issue the above command, you will be asked to provide the password for the username you supplied. Once accepted, the file will be transferred.

Now log into server B and navigate to the directory where you transferred the database file to.

Step 3: Create Database

CODE:
  1. mysql -u root -p -e 'CREATE DATABASE DATABASE_NAME';

This command will create a new database with the name you provide. Should be the same name as you used on server A. After entering the above command provide the MySQL root password and the new database will be created.

Step 4: Restore Data

CODE:
  1. mysql -u root -p DATABASE_NAME < DATABASE_NAME.sql;

This command will import the structure and data from the database on server A. Again you will be asked for the MySQL root password.

Step 5: Grant Users

CODE:
  1. grant all on DATABASE_NAME.* to DATABASE_USERNAME@localhost identified by 'PASSWORD';

Now you need to create a new user and give that user permission to access the database.

Step 6: Flush Privileges

CODE:
  1. FLUSH PRIVILEGES;

Now tell MySQL to reload the new privileges you created.

That's it. Repeat for each database you are moving.

Here are a few other commands that came in handy

Show the databases:

CODE:
  1. SHOW DATABASES;

Show Grants:

CODE:
  1. select User,Host from mysql.user;

Delete Grants:

CODE:
  1. DELETE FROM mysql.user WHERE User='DATABASE_USER' and host='localhost';

Firefox has a really annoying quirk that puts a dotted line around the text in an HTML form submit button. I searched and found some CSS hacks but none of them really worked. Finally I added onfocus="blur()" to the submit button and the dotted line is gone.

Here's the form button after clicking on submit:

using the following code

JavaScript:
  1.  
  2. <input type="Submit" name="Submit" id="Submit" value="Print Order" onclick="this.disabled=true;" />
  3.  

After I add onfocus="blur()"

JavaScript:
  1.  
  2. <input type="Submit" name="Submit" id="Submit" value="Print Order" onclick="this.disabled=true;" onfocus="blur()" />
  3.  

The dotted line is gone.

I learned something interesting today. I am finishing up writing a blogging application and I wanted to transfer either a success or error message after a post was created. I was using the following code:

PHP:
  1.  
  2. if ($conn->num_rows == 0) {
  3. $_SESSION['error'] = true;
  4. $_SESSION['message'] = "Your message failed. Please contact the administrator";
  5. header("Location: index.php");
  6. } else {
  7. $_SESSION['success'] = true;
  8. $_SESSION['message'] = "Your message titled <i>$blog_title</i> was successfully created.";
  9. header("Location: index.php");
  10.  

But for some reason the session variables were not transfering to the index.php page. I Googled my problem and come to find out

PHP:
  1.  
  2. header("Location: index.php");
  3.  

gets executed so fast that the session doesn't have a chance to set the variables. The solution is to use session_write_close();. This forces session data to be saved before the browser changes to the new page. Now my code looks like:

PHP:
  1.  
  2. if ($conn->num_rows == 0) {
  3. $_SESSION['error'] = "Create New Message Failed";
  4. $_SESSION['message'] = "Your message failed. Please contact the administrator";
  5. header("Location: index.php");
  6. } else {
  7. $_SESSION['success'] = "Create New Message Success";
  8. $_SESSION['message'] = "Your message titled <i>$blog_title</i> was successfully created.";
  9. header("Location: index.php");
  10.  

Works perfectly!

I found this handy little snippet of CSS that puts a colored outline around the border of every element in an HTML/XHTML document, helping you to visualize the structure. Thanks Programming is Hard.

CSS:
  1.  
  2. * { outline: 2px dotted red }
  3. * * { outline: 2px dotted green }
  4. * * * { outline: 2px dotted orange }
  5. * * * * { outline: 2px dotted blue }
  6. * * * * * { outline: 1px solid red }
  7. * * * * * * { outline: 1px solid green }
  8. * * * * * * * { outline: 1px solid orange }
  9. * * * * * * * * { outline: 1px solid blue }
  10.  
04-25-06

GIMP cursor brushes

Posted by John

If you use the GIMP as your image editor here is a free download of a set of 50 brushes created from assorted cursors. This site also has a bunch of tutorials on using the GIMP. Including:

Making Selections

  • rectangles + ellipses
  • hand-drawn
  • fuzzy select
  • select by color
  • paths and trickiness
  • selection options

Transparency

  • when image is created
  • for one color
  • all but a selection
  • layered opacity

Using Text

  • basic text tool
  • freetype plugin
  • Xtns>Logos

Misc

  • image rotation
  • drop shadows
  • controlling contrast
  • limit colors 1
04-24-06

Quickmail: Email To Rss

Posted by John

Quickmail is a PHP script that reads email from a mail server and outputs it in RSS format.

A Whole Lotta Nothing points to a JavaScript demo on how forms should treat tab key presses within a textarea field.

This is a handy web based tool for checking how many of your web pages are indexed and how many back links to your site are listed. The tool searches Google, Yahoo, Msn, alltheweb, altavista and sympatico. You can input lists of domain names and download check report free.

04-18-06

Ajax Check Username Signup

Posted by John

I have been implementing some asynchronous JavaScript into the applications I write and so I plan on passing along some of the great resources I have run across for programming in Ajax.

This is an Ajax based script that does a Gmail-style check on the username supplied to see if it is a unique username.

Graytone | Design: Tenant Report