#!/usr/bin/perl
# ----------------------------------------------------------------------------
# This software is Copyright (C) 2007, All Rights Reserved
# ----------------------------------------------------------------------------
# This program is protected by local and international copyright laws. Any
# use of this program is subject to the the terms of the license agreement
# included as part of this distribution archive. Any other uses are strictly
# prohibited without the written permission of the Vendor and all
# other rights are reserved.
# -----------------------------------------------------------------------------
# Warning : Modifying this program violates your license agreement!
# -----------------------------------------------------------------------------

package IT::App::License;

  use strict;

  # load core modules
  use IT::Globals;               # loads all globals ($WHICH_ARE_IN_CAPS_LIKE_THIS)

# ------------------------------------------------------------------------------
# Function    : displayLicensePage
# Description :
# Usage       : &IT::App::License::displayLicensePage();
# ------------------------------------------------------------------------------

sub displayLicensePage {

  my $allowSublicensing = &IT::App::License::isSublicensingAllowed();
  my $template          = ($allowSublicensing) ? 'admin/popups/license.html' : 'admin/popups/sublicense.html';
  my $placeholders      = {};

  print &IT::Common::contentType('text/html');
  print &templateCell($template, 'header', $placeholders);
  print &templateCell($template, 'body', $placeholders);
  print &templateCell($template, 'footer', $placeholders);
  exit;

}

# ------------------------------------------------------------------------------
# Function    : getLicenseHtml
# Description :
# Usage       : my $html = &IT::App::License::getLicenseHtml();
# ------------------------------------------------------------------------------

sub getLicenseHtml {

  my $allowSublicensing = &IT::App::License::isSublicensingAllowed();
  my $template          = ($allowSublicensing) ? 'admin/popups/license.html' : 'admin/popups/sublicense.html';
  my $placeholders      = {};

  my $html = &templateCell($template, 'body', $placeholders);
  return $html;
}


# ----------------------------------------------------------------------------
# Function    : isSublicensingAllowed
# Description :
# Usage       : my $isSublicensingAllowed = &IT::App::License::isSublicensingAllowed();
# ----------------------------------------------------------------------------

sub isSublicensingAllowed {
  my $vendorHash = &_createHashFromString( $SETTINGS->{'vendorName'} );

  # check hash against known valid hashes
  if ($vendorHash eq 'WhkMKzyGr7g0JXhsaugam24y7UOthz/E62TMdkIYlsVw') { return 1; }

  return 0;
}

# ------------------------------------------------------------------------------
# Function    : _createHashFromString
# Description :
# Usage       : my $hash = &_createHashFromString($string);
# ------------------------------------------------------------------------------

sub _createHashFromString {
  my $string = shift;

  # create hash from string
  my $hash = $string;
  $hash    =~ s/^\s+|\s+$//sg;  # remove leading/trailing whitespace
  $hash    =~ s/(.{1,8})/crypt($1,'AA')/sge;
  $hash    =~ s/AA//gs;

  return $hash;
}

# ------------------------------------------------------------------------
# Function    : isValidProductId
# Description : check if product id number is valid
# Usage       : my $isValid = &IT::App::License::isValidProductId($productId);
# ------------------------------------------------------------------------

sub isValidProductId {

  # NOTE: Disabling or modifying registration code violates your license agreement.
  # NOTE: Please don't steal our software.

  eval{my($s,$i,$n,$o,@p)=(shift,(undef)x3,265,193);my%c=map{$_,
  $i++}split(//,'P0Y5F9G4C8R3L7A2E6U1DHTNQJKXBMWVZ');$s=~
  s/-//g;my@s=split(//,$s);for(0,1){my$k;for(0..7){$k*=33;
  $k+=$c{shift@s}}$n=$k/($PROGRAM_KEY*shift(@p))-1261;(
  $n-int$n||$n<1||($o&&$n!=$o))?return undef:($o=$n)}$n};
}

# ----------------------------------------------------------------------------
# end of file
1;

