autoupgrader Calculation of upgrades using CGI script
auAutoUpgrader component
Return to Introduction  Previous page  Next page
Would like to calculate the number of upgrades? Then point the InfoFileURL property to the CGI script which will calculate the program upgrades, instead of real Info-file.

Here is an example of such CGI script, in Perl. If you would like to use it — just cut and paste this script from here, or download it from http://www.appcontrols.com/misc/autoupgrade-cgi.zip



#!/usr/bin/perl
##############################################################################
# Auto-Upgrade counter script       Version 1.0                              #
# (c) 2000 UtilMind Solutions       info@utilmind.com                        #
#                                   http://www.utilmind.com                  #
# Created Jan 18, 1999              Last Modified Jan 18, 1999               #
##############################################################################
#  COPYRIGHT NOTICE                                                          #
# Copyright (c) 1999 by UtilMind Solutions. All Rights Reserved.             #
#                                                                            #
# This program distributed as server side part of AutoUpgrader component.    #
##############################################################################
#  INSTALLATION TIPS                                                         #
# Put this script to your CGI-BIN directory and chmod it to 755 (executable) #
# Create flat database file (users_served.txt) and chmod it to               #
# 666 (read-write permission) and install it to CGI-BIN too (see $database   #
# variable)                                                                  #
##############################################################################

####################
# Configuration

$database  = "users_served.txt"; # You may set any other name to this flat database

$info_file = "../autoupgrade.inf"; # !IMPORTANT: This is local path to REAL .Info-file

$use_flock = 1; # 1 - yes, 0 - no. Should be used but won't work Win95/98


####################
# Executable

print "Content-Type: text/html\n\n";

open(FILE, $database) || &error("Can't locate database file");
$count = <FILE>;
close(FILE);

$count++; # increasing the counter

open(FILE, ">$database") || &error("Can't update database file");
if ($use_flock eq 1) {
  flock(FILE, 2); # locking write accessing
}
print FILE $count;
if ($use_flock eq 1) {
  flock(FILE, 8); # unlocking
}
close(FILE);


open(FILE, "$info_file") || &error("Can't locate info-file");
@DATA = <FILE>;
close(FILE);

print @DATA;
print "#served=$count\n";


sub error {
  print "Error: $_[0]<br>\n";
  print "Reason: $!";
  exit;
}