Novell Home

Setting Up the iPrint Client to Use the Local iPrint Printer Map

Novell Cool Solutions: Tip
By Ron Imsland

Digg This - Slashdot This

Updated: 26 Sep 2005
 

Problem:

Users would like to have the "Find/Install printers" option on the iPrint Client icon send them to their local iPrint printer map but normally that would require a different client setting for each location.

Solution:

As long as your WAN users can connect directly to your internal webserver (i.e. not going through any NAT) and each location has at least one unique octet in the IP Address, then you can use Server Side Includes for the webserver to determine the workstation's IP address along with a redirection script in your "Find/Install printers" webpage to redirect the workstation to their local iPrint map.

Example:

I'm not an expert in JavaScript or Apache by any means so there may be an easier way to do this, but I think I found a quite functional yet simple solution.

The first step is getting the IP Address. If JavaScript had the capability of reading the workstation's address, this would be a bit simpler but since it doesn't, we have to let our webserver do it for us.

Server Side Includes provide a nice array of informational variables as well as the full list of CGI Environmental variables which is what we will be using: the "REMOTE_ADDR" CGI variable which tells the webserver the IP Address of the computer accessing its webpage.

To enable SSI on Apache2 for NetWare, we simply add the directory options to the HTTPD.CONF file located in the SYS\APACHE2\CONF\ folder. For simplicity to keep my iPrint URL short, I enabled SSI on my HTDOCS folder by looking for the section titled: <Directory "SYS:/APACHE2/htdocs"> in the HTTPD.CONF file.

Under that heading is an Options statement. To turn on SSI for that folder, simply append the following to the end of the Options statement:

+Includes

Also add the following individual lines anywhere before the end of the section:

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Using those instructions, my entire htdocs directory section now looks like this:

<Directory "SYS:/APACHE2/htdocs">
#
# This should be changed to whatever you set DocumentRoot to.
#
    Options Indexes FollowSymLinks +Includes
    AllowOverride None
    Order allow,deny
    Allow from all
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</Directory>

Technically, you could enable SSI for any file extension you choose, even HTM or HTML (by changing the extensions of the two additional lines), but I've heard that there are performance issues if you make the server check too many files for SSI code so I opted to keep it only parsing SHTML files.

Once you have your HTTPD.CONF file changed, restart Apache2.

The next step is getting the REMOTE_ADDR variable. Now that we have SSI enabled, this is a simple task. We simply add some JavaScript to our new SSI-enabled IPRINT.SHTML webpage code. We declare a variable in JavaScript as follows:

ipAddress = "<!--#echo var="REMOTE_ADDR" -->";

In this line, since it's in a SHTML file, the Apache webserver parses the entire file and substitutes and SSI or CGI commands in the proper spots. We tell SSI to look at a section by beginning it with a <!--# and ending it with a -->. The webserver sees the 'echo var="REMOTE_ADDR"' SSI command and echoes the REMOTE_ADDR command which will return a string something like "192.168.1.200" or whatever your workstation's IP address is. If you are using NAT somewhere between your workstation and the internal webserver, the IP address will be whatever is configured in your NAT. After that code is parsed by SSI, JavaScript actually only sees:

ipAddress = "192.168.1.200"

Now that we have the IP Address, we can simply use the JavaScript SPLIT command to load an array with each octet of the IP Address. That takes the following two lines of code:

var octet = new Array()
octet = ipAddress.split('.');

Once that command runs, we end up with a four-valued array as follows (note: the first member of any array is always 0):

octet[0] = 192
octet[1] = 168
octet[2] = 1
octet[3] = 200

The SPLIT command used the period in the IP Address as its focus where to split up the numbers but the output of it ignores the focus character when it creates the separate array variables.

Next we simply use some IF-AND-THEN-ELSE JavaScript statements to determine which octets belong to which locations and also the WINDOW.LOCATION command for webpage redirection. Our WAN uses different octets in the first and third positions of the IP Address so we had to use "&&" in the IF command to check both octets. An example of the code looks like this:

if (octet[0]=="192" && octet[2]=="1") window.location = "ippdocs/Location1.htm";
else if (octet[0]=="192" && octet[2]=="2") window.location = "ippdocs/Location2.htm";
else if (octet[0]=="192" && octet[2]=="3") window.location = "ippdocs/Location3.htm";
else if (octet[0]=="192" && octet[2]=="31") window.location = "ippdocs/Location4.htm";
else if (octet[0]=="192" && octet[2]=="32") window.location = "ippdocs/Location5.htm";
else window.location = "ippdocs/masterlist.htm";

You can use any number of combinations of the octets and any number of "Else If" commands to match your own locations. If you need to check the first three octets, just use another && section to the IF statement like this:

if (octet[0]=="192" && octet[1]=="168" && octet[2]=="1") window.location = "ippdocs/Location5.htm";

The final ELSE command is used to direct the browser to the master site list in case the IP address doesn't match anything in the script.

That's it. Once you modify the details of the IP Address octets and the location of the HTM files for each location, the text of the entire IPRINT.SHTML webpage should look something like this:

<html>
<head>
<body>
<script language="JavaScript">

ipAddress = "<!--#echo var="REMOTE_ADDR" -->";

var octet = new Array()
octet = ipAddress.split('.');

if (octet[0]=="192" && octet[2]=="1") window.location = "ippdocs/Location1.htm";
else if (octet[0]=="192" && octet[2]=="2") window.location = "ippdocs/Location2.htm";
else if (octet[0]=="192" && octet[2]=="3") window.location = "ippdocs/Location3.htm";
else if (octet[0]=="192" && octet[2]=="31") window.location = "ippdocs/Location4.htm";
else if (octet[0]=="192" && octet[2]=="32") window.location = "ippdocs/Location5.htm";
else window.location = "ippdocs/masterlist.htm";

</script>
</body>
</html>

After that's all finished, all you need to do is distribute the one single address to all your workstations. We used a simple ZENWorks app to change the registry settings for the Novell IPrint Client. Here's the text of a .REG file that you can import into the ZENWorks app that changes the key and values you need to change:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Printers]
"Tray Icon Setting"=dword:00000001
"Tray Icon Link"="http://printing/iprint.shtml"

[HKEY_USERS\.DEFAULT\Printers]
"Tray Icon Setting"=dword:00000001
"Tray Icon Link"="http://printing/iprint.shtml"

Copy that to a text file, save it with a .REG extension and then go to the "Distribution Options" -> "Registry" tab of the new App. Hit the "File" button, select "Import" and browse to the .REG file, select it and you're all set. Associate and Force Run that app to all users of iPrint. Now, after ZEN makes the changes, when your users right click the iPrint icon and select "Find/Install printers" they'll be taken immediately to their own branch's iPrint map. Going at this from scratch, and almost no JavaScript experience, took me about 2 days of research and testing, but it shouldn't take you more than an hour or so to recreate my work.

Environment

Any browser that can run JavaScript.

Apache Webserver with Server Side Includes (SSI) enabled

iPrint


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell