# ==================================================================== # Gossamer Threads Module Library - http://gossamer-threads.com/ # # GT::Update # Author: Jason Rhinelander # CVS Info : 087,071,086,086,085 # $Id: Update.pm,v 1.13 2005/12/08 03:45:39 jagerman Exp $ # # Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. # ==================================================================== # # Description: # Module to interact with Gossamer Threads update server. # package GT::Update; use strict; use vars qw/$VERSION @ISA @EXPORT_OK %EXPORT_TAGS %ERRORS/; use Carp qw/croak/; use GT::WWW; use GT::TempFile; use GT::File::Tools qw/mkpath copy move/; use Exporter(); use Symbol qw/gensym/; use constants OPTIONAL => 1, RECOMMENDED => 2, CRITICAL => 3, VERSION => 4, GTUPDATE => 'http://www.gossamer-threads.com/perl/updates/update.cgi', GTUPDATES => 'https://www.gossamer-threads.com/perl/updates/update.cgi'; $VERSION = 1.1; @ISA = qw/Exporter/; @EXPORT_OK = qw/OPTIONAL RECOMMENDED CRITICAL VERSION %ERRORS/; %EXPORT_TAGS = ( severity => [qw/OPTIONAL RECOMMENDED CRITICAL VERSION/] ); %ERRORS = ( 100 => 'Success; update information follows', 101 => 'Success, update file follows', 200 => 'Invalid registration number', 201 => 'Registration number already in use', 202 => 'Registration number not enabled', 203 => 'Admin path does not match path stored on update server; the stored admin path can be reset from the Gossamer Threads license download area', 204 => 'Admin path does not match path stored on update server', 300 => 'Invalid product', 301 => 'Invalid product version', 302 => 'Invalid update file requested', 303 => 'Insufficient update information', 304 => 'Requested update does not exist', 400 => 'Internal update server error; please try again later', 401 => 'Update system down temporarily for upgrades; please try again later' ); my $https = eval { require Net::SSLeay; Net::SSLeay->require_version(1.06); 1; }; sub new { my ($class, %opts) = @_; bless my $self = {}, $class; for (keys %opts) { croak "Invalid option $_" unless /^[a-z][a-z_]+$/ and $self->can($_); $self->$_(ref $opts{$_} eq 'HASH' ? %{$opts{$_}} : ref $opts{$_} eq 'ARRAY' ? @{$opts{$_}} : $opts{$_}); } $self; } sub debug_level { my $self = shift; if (@_) { $self->{debug} = shift; } $self->{debug}; } sub reg_number { my $self = shift; if (@_) { $self->{reg_number} = shift; } $self->{reg_number}; } # Sets the program initialization path - typically the same path passed to # Product::init("..."). sub init_path { my $self = shift; if (@_) { $self->{init_path} = shift; } $self->{init_path}; } # Sets the product name - i.e. Links for Gossamer Links, GMail for Gossamer # Mail, GForum for Gossamer Forum, etc. This correlates to the main .pm file, # typically located in the admin or private lib path, and will be passed to the # server as the product name to check for updates. It is also used for the # package in the Product::init() line added to CGI scripts. sub product { my $self = shift; if (@_) { $self->{product} = shift; } $self->{product}; } # Sets/retrieves the current product version. sub version { my $self = shift; if (@_) { $self->{version} = shift; } $self->{version}; } # Sets the installed updates. The installed updates should be in the form of a # hash with the version as the key, and a hash reference of { ID => update # information hash reference } pairs as the value. Not required for checking # updates, required for downloading. Will only return installed updates when # called in list context, otherwise installed updates are set (even if no # update pairs are passed in - to nothing). # # Note that after installing updates, you must retrieve and store this value as # it changes when updates are installed. sub installed { my ($self, %installed) = @_; if (wantarray) { return %{$self->{installed}}; } else { $self->{installed} = \%installed; } } # Sets the path to perl - this will be used as the first line of CGI scripts, # and is required to install updates. sub perl_path { my $self = shift; if (@_) { $self->{perl_path} = shift; } $self->{perl_path}; } # Takes a hash of one or more of the following keys: # # script, library, template, static, fixed, version # # The individual meanings are described below. # # Each of the above can take either a single path, or a hash reference of named # paths. For example: # # $updater->paths( # script => '/path/to/cgis', # library => { products => '/path/to/product/libs', gt => '/path/to/gt/libs' }, # template => { '' => '/path/to/product/templates' } # ); # # The names of the directories aren't important, so long as they match up with # the named paths on the update server. Using the single path form is # equivelant to using a hash reference with a key of '' for the path - the # script_path value in the above example could instead be written as # C<{ '' =E '/path/to/product/templates' }> with no change in # functionality. Each of the three paths settings (script, library, and # template) are as follows: # # script # ------ # Replacements for files listed in C