update.cgi

来自「Last change: 2008-02-03 This is the sou」· CGI 代码 · 共 161 行

CGI
161
字号
#!/usr/bin/perl
#######################################################################
#
# This file is part of KCeasy (http://www.kceasy.com)
# Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#######################################################################
#
# Usage:
#
# /update.cgi?app=<application name>&version=<application version>
#
#   Returns config file with data about latest version
#
#   Where:
#   <application name>    - e.g. KCeasy
#   <application version> - e.g. 0.13
#
#######################################################################
#
# The config file is of the format:
#
# [kceasy]
# major_version = <major version number>
# minor_version = <minor version number>
# micro_version = <micro version number>
# description   = <description of update>
# filename      = <name of update file>
# filesize      = <size of update file>
# md5           = <md5 of update file>
# manual_url    = <url for manual download of update>
# auto_url      = <url for the automatic downloader>
# should_update = <1 if the client should tell the user to update>
#
# [openft]
# promote_chance = <auto promote chance>
# demote_chance  = <auto demote chance>
# impoverish_min = <auto promote time minimum>
# surplus_min    = <auto demote time minimum>
#
#######################################################################

use Fcntl ':flock'; # import LOCK_* constants

# place of log file
$log_file = "/tmp/persistent/kceasy/update.log";

# version update config
$update_major_version = 0;
$update_minor_version = 18;
$update_micro_version = 0;
$update_filename      = "kceasy-0.18-setup.exe";
$update_filesize      = 4582797;
$update_md5           = "0b656c34c42fa87475b8e51f3a728abe";

# description
$update_description = <<DESCR_DOC;

Hello everyone!

KCeasy 0.18 is here with improved connectivity to the Ares network, many
new features and some bug fixes under the hood.

Simply download and install the the new version over your current one.
All your settings will be preserved.
DESCR_DOC

# openft parameters. don't touch these!
$openft_promote_chance = 500;  # in per mille
$openft_demote_chance  = 500;  # in per mille
$openft_impoverish_min = 10;   # in minutes
$openft_surplus_min    = 30;   # in minutes

# replace all new lines with '|'
$update_description =~ s/(\r\n|\n)/\|/g;


# sourceforge mirrors
@sf_mirrors = ("switch",
               "easynews",
               "superb-west",
               "umn",
               "belnet",
               "superb-east",
               "optusnet",
               "surfnet");


# TODO: choose mirror based on location of client
$mirror = $sf_mirrors[rand(@sf_mirrors)];

# create auto update url based on mirror and filename
$update_auto_url = "http://" . $mirror . ".dl.sourceforge.net/kceasy/" . $update_filename;

# create manual update url based on filename
$update_manual_url = "http://prdownloads.sourceforge.net/kceasy/" . $update_filename . "?download";

# cgi input processing
$query_string = $ENV{'QUERY_STRING'};
$user_agent = $ENV{'HTTP_USER_AGENT'};
$remote_addr = $ENV{'REMOTE_ADDR'};
$now = localtime(time());

# log this request
if (defined $log_file && open (LOGFILE, ">>$log_file"))
{
	# don't wait for lock forever
	my $lock_attempts = 5;

	while($lock_attempts > 0)
	{
		if (flock (LOGFILE, LOCK_EX | LOCK_NB)) 
		{
			seek (LOGFILE, 0, 2); # seek to end of file
#			print LOGFILE "$now|$mirror|$remote_addr|$user_agent|$query_string\n";
			print LOGFILE "$now|$mirror|$remote_addr||$query_string\n";
			last;
		}
		else
		{
			$lock_attempts--;
			sleep 1;
		}
	}
	close (LOGFILE);
}

# send reply
print "Content-type: text/plain\n\n";

print <<CONFIG_DOC;
[kceasy]
major_version = $update_major_version
minor_version = $update_minor_version
micro_version = $update_micro_version
description = $update_description
filename = $update_filename
filesize = $update_filesize
md5 = $update_md5
manual_url = $update_manual_url
auto_url = $update_auto_url
should_update = 0

[openft]
promote_chance = $openft_promote_chance
demote_chance = $openft_demote_chance
impoverish_min = $openft_impoverish_min
surplus_min = $openft_surplus_min
CONFIG_DOC

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?