⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodes.cgi

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 CGI
字号:
#!/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:
#
# /nodes.cgi?app=<application name>&version=<application version>
#
#   Returns a list of available files
#
#   Where:
#   <application name>    - e.g. KCeasy
#   <application version> - e.g. 0.13
#
#######################################################################
#
# List is a config file of the format:
#
# [<network>]
# <name>=<display name>|<type>|<last update>|<filename>|<url>|
#        <update on install>|<compression>|<challenge>
#
# Where:
#
# <network>      - network the files in this section belong to
# <name>         - unique name for the entry
# <display name> - descriptive name of file for the user
# <type>         - "banlist" or "nodes"
# <last update>  - unix seconds of last (remote) file update, 0 means
#                  unknown
# <filename>     - local name used to save the file in the plugin 
#                  config directory
# <url>          - url for getting the file
#
# <update on install> - 1 if this file should be automatically updated
#                       on first installation, 0 otherwise.
#
# <compression>  - 0 = no compression
#                  1 = gzip compressed
#
# <challenge>    - <start>-<end> range in KCeasy binary which is
#                  hashed by KCeasy and appended to file request
#
#######################################################################

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

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

# file list config for KCeasy 0.16 and earlier
$file_list_conf_pre17 = <<FILELIST_DOC;
#
# Files available for automatic update
#

[OpenFT]

1 = OpenFT nodes file|nodes|0|nodes|http://update.kceasy.com/update/openft/nodes|1

[Gnutella]

1 = Gnutella nodes file|nodes|0|nodes|http://update.kceasy.com/update/gnutella/nodes|1
2 = Gnutella webcaches|nodes|0|gwebcaches|http://update.kceasy.com/update/gnutella/gwebcaches|1
3 = Gnutella banlist|banlist|0|hostiles.txt|http://update.kceasy.com/update/gnutella/hostiles.txt|0

[FastTrack]

1 = FastTrack nodes file|nodes|0|nodes|http://update.kceasy.com/update/fasttrack/nodes|1
2 = FastTrack banlist|banlist|0|banlist|http://update.kceasy.com/update/fasttrack/banlist|0

[Ares]

1 = Ares nodes file|nodes|0|nodes|http://update.kceasy.com/update/ares/nodes-0.2|1

FILELIST_DOC


# file list config for KCeasy 0.17-rc1 and later
$file_list_conf = <<FILELIST_DOC;
#
# Files available for automatic update
#

[OpenFT]

1 = OpenFT nodes file|nodes|0|nodes|http://update.kceasy.com/update/openft/nodes.gzip|1|1|0-0

[Gnutella]

1 = Gnutella nodes file|nodes|0|nodes|http://update.kceasy.com/update/gnutella/nodes.gzip|1|1|0-0
2 = Gnutella webcaches|nodes|0|gwebcaches|http://update.kceasy.com/update/gnutella/gwebcaches.gzip|1|1|0-0
3 = Gnutella banlist|banlist|0|hostiles.txt|http://update.kceasy.com/update/gnutella/hostiles.txt.gzip|0|1|0-0

[FastTrack]

1 = FastTrack nodes file|nodes|0|nodes|http://update.kceasy.com/update/fasttrack/nodes.gzip|1|1|0-0
2 = FastTrack banlist|banlist|0|banlist|http://update.kceasy.com/update/fasttrack/banlist.gzip|0|1|0-0

[Ares]

1 = Ares nodes file|nodes|0|nodes|http://update.kceasy.com/update/ares/nodes.gzip|1|1|0-0

FILELIST_DOC


# file list config for poisoned
$file_list_conf_poisoned = <<FILELIST_DOC;
#
# Files available for automatic update
# (Poisoned)
#

[OpenFT]

1 = OpenFT nodes file|nodes|0|nodes|http://update.kceasy.com/update/openft/nodes|1|1|0-0

[Gnutella]

1 = Gnutella nodes file|nodes|0|nodes|http://update.kceasy.com/update/gnutella/nodes|1|1|0-0
2 = Gnutella webcaches|nodes|0|gwebcaches|http://update.kceasy.com/update/gnutella/gwebcaches|1|1|0-0
3 = Gnutella banlist|banlist|0|hostiles.txt|http://update.kceasy.com/update/gnutella/hostiles.txt|0|1|0-0

[FastTrack]

1 = FastTrack nodes file|nodes|0|nodes|http://update.kceasy.com/update/fasttrack/nodes|1|1|0-0
2 = FastTrack banlist|banlist|0|banlist|http://update.kceasy.com/update/fasttrack/banlist|0|1|0-0

[Ares]

1 = Ares nodes file|nodes|0|nodes|http://update.kceasy.com/update/ares/nodes|1|1|0-0

FILELIST_DOC


# cgi input processing
$query_method = $ENV{'REQUEST_METHOD'};
$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|$remote_addr|$user_agent|$query_method|$query_string\n";
			print LOGFILE "$now|$remote_addr||$query_method|$query_string\n";
			last;
		}
		else
		{
			$lock_attempts--;
			sleep 1;
		}
	}
	close (LOGFILE);
}

# only process GET
die if ($query_method ne "GET");

# force people to use this script correctly
if (not $query_string =~ /app=(.+?)&version=(.+?)(&.+)?$/)
{
	print "Content-type: text/plain\n\n";
	print "# Internal script error\n";
	print "# Usage: nodes.cgi?app=<application name>&version=<application version>\n";
	print "# WARNING: Use your real application name and version or your access will be blocked permanently\n";
	exit 0;
}

$app = $1;
$version = $2;

# parse version
$version_major = 0;
$version_minor = 0;
$version_micro = 0;

if ($version =~ /(\d+)\.?(\d+)?[\.-]?(.+)?/)
{
	$version_major = $1;
	$version_minor = $2;
	$version_micro = $3;
}

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

if ($app eq "Poisoned")
{
	print $file_list_conf_poisoned;
}
elsif ($app eq "gift-update-nodes" and $version_major >= 0 and $version_minor >= 3)
{
	print $file_list_conf;
}
elsif ($version_major <= 0 and $version_minor <= 16)
{
	print $file_list_conf_pre17;
}
else
{
	print $file_list_conf;
}

⌨️ 快捷键说明

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