Wednesday, December 18, 2013

ActiveState's Perl Package Manager can't connect (a fix)

Starting a new position at Dell, I found that the website restrictions weren't as Spartan as I remembered them to be (compared to 2010 when I worked there last). Nonetheless, I stubbed my toe when trying to update packages with ActiveState's Perl Package Manager because the low-level proxy information wasn't available system-wide.

The Fix


  1. Determine what your corporate proxy URL is. I did this by downloading the configuration file (see Find the Proxy Info below).
  2. Right-click on your computer icon on the desktop and select Properties (or select the Control Panel -> System via the Start menu); select Advanced system settings.
  3. Click on Environment Variables...
  4. Assuming it doesn't already exist, create a new system variable. 
    1. The Variable name is: http_proxy
    2. The Variable value is:  http://username:password@your.proxy.info
      where username is your actual username
      where password is your password (see Password Note about escaping unusual characters below)
      where your.proxy.info is the canonical name or IP address of your corporate proxy
  5. Click OK and OK to save the values and you should be set.

Password Note

If your password contains anything out of the ordinary (e.g., @, #, !, etc.), you need to use HTML escapes to pass it along. Here's a decent reference to help you get going.

Find the Proxy Info

These instructions are for Chrome on Windows 7. You'll have to figure it out for Internet Explorer, Firefox, Safari, etc.

  1. Under the Chrome "everything" menu widget (the floating label text says Customize and control Google Chrome), select Settings.
  2. Click the small link at the bottom titled Show advanced settings...
  3. Scroll down until you see Network and click Change proxy settings... This will open up the Connections tab of the Internet Properties dialog.
  4. Click on the Settings button.
  5. If the proxy server information is entered in directly - you have the information you need! Otherwise, grab the address from the automatic configuration script, paste it into a blank tab of your browser, and the file will download.
  6. You'll have to parse this file yourself. In my case, I had to wait through all the "if" statements to get to the final "else" which contained the default proxy address at the end.


Friday, October 18, 2013

Monday, July 25, 2011

Encoding URL Strings with Escaped Codes with Perl

You've probably seen websites that when you do searches or submit something wherein some of the characters in the URL get replaced with %NN where NN is a two-digit Hex number. The reason being is that there are 22 characters that have special meaning in a URL string, so they have to be replaced with a Hex value equivalent.

In writing an API test harness, I had to include the username and password to send to a site for testing purposes and I started running across passwords that had some of these "illegal" characters. To allow my script to log in correctly, I had to write a routine which would escape those characters but still send along the equivalent to the website.

Here's the Perl subroutine I wrote to deal with this problem:

############################## url_escape #############################
#                                                                     #
# Send in a string; have the illegal URL characters replaced.         #
#                                                                     #
# Author:        Greg Meece                                           #
# Creation Date: 07/25/2011                                           #
# Last Mod Date: 07/25/2011                                           #
# ------------------------------------------------------------------- #
#                                                                     #
# input: URL string                                                   #
#                                                                     #
# Example usage:                                                      #
# my $urlStr = "H%t^@=";                                              #
# url_escape($urlStr);                                                #
# returns: HTML escaped string - 'H%25t%5E%40%3D'                     #
#                                                                     #
#######################################################################
sub url_escape
{
  my ($inString) = @_;
  my $htmlChar;
 
  # These are all the illegal characters for URL strings:
  my %urlEscapers =
  (
   # "%" => "%25",
   " " => "%20",
   "<" => "%3C",
   ">" => "%3E",
   "#" => "%23",
   "\{" => "%7B",
   "}" => "%7D",
   "|" => "%7C",
   "\\" => "%5C",
   "^" => "%5E",
   "~" => "%7E",
   "[" => "%5B",
   "]" => "%5D",
   "`" => "%60",
   ";" => "%3B",
   "/" => "%2F",
   "?" => "%3F",
   ":" => "%3A",
   "@" => "%40",
   "=" => "%3D",
   "&" => "%26",
   "\$" => "%24"
  );
  # Replace '%' first before iterating through the hash
  $inString =~ s/%/%25/;
 
  # Iterate through hash with no RegEx metacharacters
  foreach $htmlChar (keys %urlEscapers)
  {
    $inString =~ s/\Q$htmlChar\E/$urlEscapers{$htmlChar}/g;
  }
 
  return($inString);
}