mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Options -Indexes
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
function benc($obj) {
|
||||
if (!is_array($obj) || !isset($obj["type"]) || !isset($obj["value"]))
|
||||
return;
|
||||
$c = $obj["value"];
|
||||
switch ($obj["type"]) {
|
||||
case "string":
|
||||
return benc_str($c);
|
||||
case "integer":
|
||||
return benc_int($c);
|
||||
case "list":
|
||||
return benc_list($c);
|
||||
case "dictionary":
|
||||
return benc_dict($c);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
function benc_str($s) {
|
||||
return strlen($s) . ":$s";
|
||||
}
|
||||
function benc_int($i) {
|
||||
return "i" . $i . "e";
|
||||
}
|
||||
function benc_list($a) {
|
||||
$s = "l";
|
||||
foreach ($a as $e) {
|
||||
$s .= benc($e);
|
||||
}
|
||||
$s .= "e";
|
||||
return $s;
|
||||
}
|
||||
function benc_dict($d) {
|
||||
$s = "d";
|
||||
$keys = array_keys($d);
|
||||
sort($keys);
|
||||
foreach ($keys as $k) {
|
||||
$v = $d[$k];
|
||||
$s .= benc_str($k);
|
||||
$s .= benc($v);
|
||||
}
|
||||
$s .= "e";
|
||||
return $s;
|
||||
}
|
||||
function bdec_file($f, $ms) {
|
||||
$fp = fopen($f, "rb");
|
||||
if (!$fp)
|
||||
return;
|
||||
$e = fread($fp, $ms);
|
||||
fclose($fp);
|
||||
return bdec($e);
|
||||
}
|
||||
function bdec($s) {
|
||||
if (preg_match('/^(\d+):/', $s, $m)) {
|
||||
$l = $m[1];
|
||||
$pl = strlen($l) + 1;
|
||||
$v = substr($s, $pl, $l);
|
||||
$ss = substr($s, 0, $pl + $l);
|
||||
if (strlen($v) != $l)
|
||||
return;
|
||||
return array('type' => "string", 'value' => $v, 'strlen' => strlen($ss), 'string' => $ss);
|
||||
}
|
||||
if (preg_match('/^i(\d+)e/', $s, $m)) {
|
||||
$v = $m[1];
|
||||
$ss = "i" . $v . "e";
|
||||
if ($v === "-0")
|
||||
return;
|
||||
if ($v[0] == "0" && strlen($v) != 1)
|
||||
return;
|
||||
return array('type' => "integer", 'value' => $v, 'strlen' => strlen($ss), 'string' => $ss);
|
||||
}
|
||||
switch ($s[0]) {
|
||||
case "l":
|
||||
return bdec_list($s);
|
||||
case "d":
|
||||
return bdec_dict($s);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
function bdec_list($s) {
|
||||
if ($s[0] != "l")
|
||||
return;
|
||||
$sl = strlen($s);
|
||||
$i = 1;
|
||||
$v = array();
|
||||
$ss = "l";
|
||||
for (;;) {
|
||||
if ($i >= $sl)
|
||||
return;
|
||||
if ($s[$i] == "e")
|
||||
break;
|
||||
$ret = bdec(substr($s, $i));
|
||||
if (!isset($ret) || !is_array($ret))
|
||||
return;
|
||||
$v[] = $ret;
|
||||
$i += $ret["strlen"];
|
||||
$ss .= $ret["string"];
|
||||
}
|
||||
$ss .= "e";
|
||||
return array('type' => "list", 'value' => $v, 'strlen' => strlen($ss), 'string' => $ss);
|
||||
}
|
||||
function bdec_dict($s) {
|
||||
if ($s[0] != "d")
|
||||
return;
|
||||
$sl = strlen($s);
|
||||
$i = 1;
|
||||
$v = array();
|
||||
$ss = "d";
|
||||
for (;;) {
|
||||
if ($i >= $sl)
|
||||
return;
|
||||
if ($s[$i] == "e")
|
||||
break;
|
||||
$ret = bdec(substr($s, $i));
|
||||
if (!isset($ret) || !is_array($ret) || $ret["type"] != "string")
|
||||
return;
|
||||
$k = $ret["value"];
|
||||
$i += $ret["strlen"];
|
||||
$ss .= $ret["string"];
|
||||
if ($i >= $sl)
|
||||
return;
|
||||
$ret = bdec(substr($s, $i));
|
||||
if (!isset($ret) || !is_array($ret))
|
||||
return;
|
||||
$v[$k] = $ret;
|
||||
$i += $ret["strlen"];
|
||||
$ss .= $ret["string"];
|
||||
}
|
||||
$ss .= "e";
|
||||
return array('type' => "dictionary", 'value' => $v, 'strlen' => strlen($ss), 'string' => $ss);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
define('IN_TRACKER', true);
|
||||
define("PROJECTNAME","NexusPHP");
|
||||
define("NEXUSPHPURL","http://www.nexusphp.com");
|
||||
define("NEXUSWIKIURL","http://www.nexusphp.com/wiki");
|
||||
define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
||||
define("THISTRACKER","General");
|
||||
$showversion = " - Powered by ".PROJECTNAME;
|
||||
$rootpath=realpath(dirname(__FILE__) . '/..');
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
|
||||
$rootpath .= "/";
|
||||
include($rootpath . 'include/core.php');
|
||||
include_once($rootpath . 'include/functions.php');
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
# IMPORTANT: Do not edit below unless you know what you are doing!
|
||||
define('IN_TRACKER', true);
|
||||
$rootpath=realpath(dirname(__FILE__) . '/..')."/";
|
||||
include($rootpath . 'include/core.php');
|
||||
include_once($rootpath . 'include/functions_announce.php');
|
||||
?>
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
|
||||
Browser Emulating file functions v2.0
|
||||
(c) Kai Blankenhorn
|
||||
www.bitfolge.de/en
|
||||
kaib@bitfolge.de
|
||||
|
||||
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
****************************************************************************
|
||||
|
||||
|
||||
Changelog:
|
||||
|
||||
v2.0 03-09-03
|
||||
added a wrapper class; this has the advantage that you no longer need
|
||||
to specify a lot of parameters, just call the methods to set
|
||||
each option
|
||||
added option to use a special port number, may be given by setPort or
|
||||
as part of the URL (e.g. server.com:80)
|
||||
added getLastResponseHeaders()
|
||||
|
||||
v1.5
|
||||
added Basic HTTP user authorization
|
||||
minor optimizations
|
||||
|
||||
v1.0
|
||||
initial release
|
||||
|
||||
|
||||
|
||||
***************************************************************************/
|
||||
/**
|
||||
* BrowserEmulator class. Provides methods for opening urls and emulating
|
||||
* a web browser request.
|
||||
**/
|
||||
class BrowserEmulator {
|
||||
|
||||
var $headerLines = Array ();
|
||||
var $postData = Array ();
|
||||
var $authUser = "";
|
||||
var $authPass = "";
|
||||
var $port;
|
||||
var $lastResponse = Array ();
|
||||
|
||||
function BrowserEmulator () {
|
||||
$this->resetHeaderLines ();
|
||||
$this->resetPort ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single header field to the HTTP request header. The resulting header
|
||||
* line will have the format
|
||||
* $name: $value\n
|
||||
**/
|
||||
function addHeaderLine ($name, $value) {
|
||||
$this->headerLines[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all custom header lines. This will not remove the User-Agent header field,
|
||||
* which is necessary for correct operation.
|
||||
**/
|
||||
function resetHeaderLines () {
|
||||
$this->headerLines = Array ();
|
||||
|
||||
/*******************************************************************************/
|
||||
/************** YOU MAX SET THE USER AGENT STRING HERE *******************/
|
||||
/* */
|
||||
/* default is "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", */
|
||||
/* which means Internet Explorer 6.0 on WinXP */
|
||||
|
||||
$this->headerLines["User-Agent"] =
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a post parameter. Post parameters are sent in the body of an HTTP POST request.
|
||||
**/
|
||||
function addPostData ($name, $value) {
|
||||
$this->postData[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all custom post parameters.
|
||||
**/
|
||||
function resetPostData () {
|
||||
$this->postData = Array ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an auth user and password to use for the request.
|
||||
* Set both as empty strings to disable authentication.
|
||||
**/
|
||||
function setAuth ($user, $pass) {
|
||||
$this->authUser = $user;
|
||||
$this->authPass = $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a custom port to use for the request.
|
||||
**/
|
||||
function setPort ($portNumber) {
|
||||
$this->port = $portNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the port used for request to the HTTP default (80).
|
||||
**/
|
||||
function resetPort () {
|
||||
$this->port = 80;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an fopen call to $url with the parameters set by previous member
|
||||
* method calls. Send all set headers, post data and user authentication data.
|
||||
* Returns a file handle on success, or false on failure.
|
||||
**/
|
||||
function fopen ($url) {
|
||||
$debug = false;
|
||||
|
||||
$this->lastResponse = Array ();
|
||||
|
||||
preg_match ("~([a-z]*://)?([^:^/]*)(:([0-9]{1,5}))?(/.*)?~i", $url,
|
||||
$matches);
|
||||
if ($debug)
|
||||
var_dump ($matches);
|
||||
$protocol = $matches[1];
|
||||
$server = $matches[2];
|
||||
$port = $matches[4];
|
||||
$path = $matches[5];
|
||||
if ($port != "") {
|
||||
$this->setPort ($port);
|
||||
}
|
||||
if ($path == "")
|
||||
$path = "/";
|
||||
$socket = false;
|
||||
$socket = fsockopen ($server, $this->port);
|
||||
if ($socket) {
|
||||
$this->headerLines["Host"] = $server;
|
||||
|
||||
if ($this->authUser != "" AND $this->authPass != "") {
|
||||
$headers["Authorization"] =
|
||||
"Basic ".base64_encode ($this->authUser.":".$this->
|
||||
authPass);
|
||||
}
|
||||
|
||||
if (count ($this->postData) == 0) {
|
||||
$request = "GET $path HTTP/1.0\r\n";
|
||||
}
|
||||
else {
|
||||
$request = "POST $path HTTP/1.0\r\n";
|
||||
}
|
||||
|
||||
if ($debug)
|
||||
echo $request;
|
||||
fputs ($socket, $request);
|
||||
|
||||
if (count ($this->postData) > 0) {
|
||||
$PostStringArray = Array ();
|
||||
foreach ($this->postData AS $key => $value) {
|
||||
$PostStringArray[] = "$key=$value";
|
||||
}
|
||||
$PostString = join ("&", $PostStringArray);
|
||||
$this->headerLines["Content-Length"] =
|
||||
strlen ($PostString);
|
||||
}
|
||||
|
||||
foreach ($this->headerLines AS $key => $value) {
|
||||
if ($debug)
|
||||
echo "$key: $value\n";
|
||||
fputs ($socket, "$key: $value\r\n");
|
||||
}
|
||||
if ($debug)
|
||||
echo "\n";
|
||||
fputs ($socket, "\r\n");
|
||||
if (count ($this->postData) > 0) {
|
||||
if ($debug)
|
||||
echo "$PostString";
|
||||
fputs ($socket, $PostString."\r\n");
|
||||
}
|
||||
}
|
||||
if ($debug)
|
||||
echo "\n";
|
||||
if ($socket) {
|
||||
$line = fgets ($socket, 1000);
|
||||
if ($debug)
|
||||
echo $line;
|
||||
$this->lastResponse[] = $line;
|
||||
$status = substr ($line, 9, 3);
|
||||
while (trim ($line = fgets ($socket, 1000)) != "") {
|
||||
if ($debug)
|
||||
echo "$line";
|
||||
$this->lastResponse[] = $line;
|
||||
if ($status == "401" AND strpos ($line, "WWW-Authenticate: Basic realm=\"") === 0) {
|
||||
fclose ($socket);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an file call to $url with the parameters set by previous member
|
||||
* method calls. Send all set headers, post data and user authentication data.
|
||||
* Returns the requested file as an array on success, or false on failure.
|
||||
**/
|
||||
function file ($url) {
|
||||
$file = Array ();
|
||||
$socket = $this->fopen ($url);
|
||||
if ($socket) {
|
||||
$file = Array ();
|
||||
while (!feof ($socket)) {
|
||||
$file[] = fgets ($socket, 10000);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
function getLastResponseHeaders () {
|
||||
return $this->lastResponse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// example code
|
||||
/*
|
||||
$be = new BrowserEmulator();
|
||||
//$be->addHeaderLine("Referer", "http://previous.server.com/");
|
||||
//$be->addHeaderLine("Accept-Encoding", "x-compress; x-zip");
|
||||
//$be->addPostData("Submit", "OK");
|
||||
//$be->addPostData("item", "42");
|
||||
//$be->setAuth("admin", "secretpass");
|
||||
// also possible:
|
||||
// $be->setPort(10080);
|
||||
|
||||
$file = $be->fopen("http://us.imdb.com/Title?0209144");
|
||||
$response = $be->getLastResponseHeaders();
|
||||
|
||||
while ($line = fgets($file, 1024)) {
|
||||
// do something with the file
|
||||
echo $line;
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
class info_extractor{
|
||||
function info_extractor(){}
|
||||
|
||||
/** truncate a given string
|
||||
* @method truncate
|
||||
* @param string src(source string), string s_str(starting needle), string e_str(ending needle, "" for open end), integer e_offset(optional where to start finding the $e_str)
|
||||
* @return string trucated string
|
||||
*/
|
||||
function truncate($src, $s_str, $e_str = "", $e_offset = 0)
|
||||
{
|
||||
$ret = "";
|
||||
$e_offset = strlen($s_str);
|
||||
|
||||
$ret = strstr($src, $s_str);
|
||||
if($ret == false)
|
||||
return "";
|
||||
|
||||
if($e_str != "")
|
||||
{
|
||||
$endpos = strpos ($ret , $e_str, $e_offset);
|
||||
if($endpos == false)
|
||||
return "";
|
||||
}
|
||||
|
||||
return substr($ret, strlen($s_str), $endpos - strlen($s_str));
|
||||
}
|
||||
|
||||
/** find a certain pattern in a given string
|
||||
* @method find_pattern
|
||||
* @param string src(source string), string regex(regular expression), boolean multiple(if pattern has multiple occurance), array string res_where_array(where the res should be in regex, order of res_where_array and res_array should be the same, for example: res_array could be "array(array('Name' => '', 'Cloudsize' => '', 'Link' => ''))", then the first element in res_where_array could be, say, "3", which corrsponds to 'Name'), array string res_array(one or multi-dimensional array for the extraced info)
|
||||
* @return boolean found_pattern
|
||||
*/
|
||||
function find_pattern($src, $regex, $multiple, $res_where_array)
|
||||
{
|
||||
$res_array = array();
|
||||
if($multiple == true)
|
||||
{
|
||||
if(!preg_match_all($regex,$src,$info_block,PREG_SET_ORDER))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$counter_infoblock = 0;
|
||||
foreach($info_block as $info)
|
||||
{
|
||||
$counter_reswhere = 0;
|
||||
foreach ($res_where_array as $res_where_array_each)
|
||||
{
|
||||
$res_array[$counter_infoblock][$counter_reswhere] = $info[$res_where_array_each];
|
||||
$counter_reswhere++;
|
||||
}
|
||||
$counter_infoblock++;
|
||||
}
|
||||
return $res_array;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!preg_match($regex,$src,$info))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$counter = 0;
|
||||
foreach ($res_where_array as $res_where_array_each)
|
||||
{
|
||||
$res_array[$counter] = $info[$res_where_array_each];
|
||||
$counter++;
|
||||
}
|
||||
return $res_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** remove a given pattern from a given string
|
||||
* @method truncate
|
||||
* @param string src(source string), string $regex_s(starting needle), string $regex_e(ending needle), integer max(set it to 1 if you are sure the pattern only occurs once, otherwise, it indicates the maximum possible occurance in case of dead loop), boolean all(if remove all or just the pattern)
|
||||
* @return string processed string
|
||||
*/
|
||||
function remove($src, $regex_s, $regex_e, $max = 100, $all = false)
|
||||
{
|
||||
$ret = "";
|
||||
$ret = preg_replace("/" . $regex_s . "((\s|.)+?)" . $regex_e . "/i", ($all == false ? "\\1" : ""), $src, $max);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/** trim a given array of strings types from a given string
|
||||
* @method trim_str
|
||||
* @param string src(source string), string array regex_trim_array(specifies strings to be trimmed), integersafe_counter(maximum possible occurance of string to be trimmed)
|
||||
* @return string processed string
|
||||
*/
|
||||
function trim_str($src, $regex_trim_array, $safe_counter =10)
|
||||
{
|
||||
$ret = "";
|
||||
|
||||
while($safe_counter>0)
|
||||
{
|
||||
$safe_counter--;
|
||||
$break_flag = true;
|
||||
foreach($regex_trim_array as $regex_trim_array_each)
|
||||
{
|
||||
$ret = preg_replace("/^((" . $regex_trim_array_each . ")*)((\s|.)+?)((" . $regex_trim_array_each . ")*)$/i","\\3", trim($src), 1);
|
||||
if($ret != $src)
|
||||
$break_flag = false;
|
||||
$src = $ret;
|
||||
}
|
||||
if($break_flag)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,762 @@
|
||||
<?php
|
||||
# IMPORTANT: Do not edit below unless you know what you are doing!
|
||||
if(!defined('IN_TRACKER'))
|
||||
die('Hacking attempt!');
|
||||
|
||||
function printProgress($msg) {
|
||||
echo $msg.'...done<br />';
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
function docleanup($forceAll = 0, $printProgress = false) {
|
||||
//require_once(get_langfile_path("cleanup.php",true));
|
||||
global $lang_cleanup_target;
|
||||
global $torrent_dir, $signup_timeout, $max_dead_torrent_time, $autoclean_interval_one, $autoclean_interval_two, $autoclean_interval_three, $autoclean_interval_four, $autoclean_interval_five, $SITENAME,$bonus,$invite_timeout,$offervotetimeout_main,$offeruptimeout_main, $iniupload_main;
|
||||
global $donortimes_bonus, $perseeding_bonus, $maxseeding_bonus, $tzero_bonus, $nzero_bonus, $bzero_bonus, $l_bonus;
|
||||
global $expirehalfleech_torrent, $expirefree_torrent, $expiretwoup_torrent, $expiretwoupfree_torrent, $expiretwouphalfleech_torrent, $expirethirtypercentleech_torrent, $expirenormal_torrent, $hotdays_torrent, $hotseeder_torrent,$halfleechbecome_torrent,$freebecome_torrent,$twoupbecome_torrent,$twoupfreebecome_torrent, $twouphalfleechbecome_torrent, $thirtypercentleechbecome_torrent, $normalbecome_torrent, $deldeadtorrent_torrent;
|
||||
global $neverdelete_account, $neverdeletepacked_account, $deletepacked_account, $deleteunpacked_account, $deletenotransfer_account, $deletenotransfertwo_account, $deletepeasant_account, $psdlone_account, $psratioone_account, $psdltwo_account, $psratiotwo_account, $psdlthree_account, $psratiothree_account, $psdlfour_account, $psratiofour_account, $psdlfive_account, $psratiofive_account, $putime_account, $pudl_account, $puprratio_account, $puderatio_account, $eutime_account, $eudl_account, $euprratio_account, $euderatio_account, $cutime_account, $cudl_account, $cuprratio_account, $cuderatio_account, $iutime_account, $iudl_account, $iuprratio_account, $iuderatio_account, $vutime_account, $vudl_account, $vuprratio_account, $vuderatio_account, $exutime_account, $exudl_account, $exuprratio_account, $exuderatio_account, $uutime_account, $uudl_account, $uuprratio_account, $uuderatio_account, $nmtime_account, $nmdl_account, $nmprratio_account, $nmderatio_account, $getInvitesByPromotion_class;
|
||||
global $enablenoad_advertisement, $noad_advertisement;
|
||||
global $Cache;
|
||||
global $rootpath;
|
||||
|
||||
require_once($rootpath . '/lang/_target/lang_cleanup.php');
|
||||
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(1);
|
||||
$now = time();
|
||||
|
||||
//Priority Class 1: cleanup every 15 mins
|
||||
//2.update peer status
|
||||
$deadtime = deadtime();
|
||||
$deadtime = date("Y-m-d H:i:s",$deadtime);
|
||||
sql_query("DELETE FROM peers WHERE last_action < ".sqlesc($deadtime)) or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress('update peer status');
|
||||
}
|
||||
//11.calculate seeding bonus
|
||||
$res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
$sqrtof2 = sqrt(2);
|
||||
$logofpointone = log(0.1);
|
||||
$valueone = $logofpointone / $tzero_bonus;
|
||||
$pi = 3.141592653589793;
|
||||
$valuetwo = $bzero_bonus * ( 2 / $pi);
|
||||
$valuethree = $logofpointone / ($nzero_bonus - 1);
|
||||
$timenow = TIMENOW;
|
||||
$sectoweek = 7*24*60*60;
|
||||
while ($arr = mysql_fetch_assoc($res)) //loop for different users
|
||||
{
|
||||
$A = 0;
|
||||
$count = 0;
|
||||
$all_bonus = 0;
|
||||
$torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $arr[userid] AND peers.seeder ='yes'") or sqlerr(__FILE__, __LINE__);
|
||||
while ($torrent = mysql_fetch_array($torrentres))
|
||||
{
|
||||
$weeks_alive = ($timenow - strtotime($torrent[added])) / $sectoweek;
|
||||
$gb_size = $torrent[size] / 1073741824;
|
||||
$temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent[seeders] - 1)));
|
||||
$A += $temp;
|
||||
$count++;
|
||||
}
|
||||
if ($count > $maxseeding_bonus)
|
||||
$count = $maxseeding_bonus;
|
||||
$all_bonus = ($valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count)) / (3600 / $autoclean_interval_one);
|
||||
$is_donor = get_single_value("users","donor","WHERE id=".$arr['userid']);
|
||||
if ($is_donor == 'yes' && $donortimes_bonus > 0)
|
||||
$all_bonus = $all_bonus * $donortimes_bonus;
|
||||
KPS("+",$all_bonus,$arr["userid"]);
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress('calculate seeding bonus');
|
||||
}
|
||||
|
||||
//Priority Class 2: cleanup every 30 mins
|
||||
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'");
|
||||
$row = mysql_fetch_array($res);
|
||||
if (!$row) {
|
||||
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime2',".sqlesc($now).")") or sqlerr(__FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
$ts = $row[0];
|
||||
if ($ts + $autoclean_interval_two > $now && !$forceAll) {
|
||||
return 'Cleanup ends at Priority Class 1';
|
||||
} else {
|
||||
sql_query("UPDATE avps SET value_u = ".sqlesc($now)." WHERE arg='lastcleantime2'") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
//2.5.update torrents' visibility
|
||||
$deadtime = deadtime() - $max_dead_torrent_time;
|
||||
sql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime) AND seeders=0") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("update torrents' visibility");
|
||||
}
|
||||
//Priority Class 3: cleanup every 60 mins
|
||||
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime3'");
|
||||
$row = mysql_fetch_array($res);
|
||||
if (!$row) {
|
||||
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime3',$now)") or sqlerr(__FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
$ts = $row[0];
|
||||
if ($ts + $autoclean_interval_three > $now && !$forceAll) {
|
||||
return 'Cleanup ends at Priority Class 2';
|
||||
} else {
|
||||
sql_query("UPDATE avps SET value_u = ".sqlesc($now)." WHERE arg='lastcleantime3'") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
//4.update count of seeders, leechers, comments for torrents
|
||||
$torrents = array();
|
||||
$res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
if ($row["seeder"] == "yes")
|
||||
$key = "seeders";
|
||||
else
|
||||
$key = "leechers";
|
||||
$torrents[$row["torrent"]][$key] = $row["c"];
|
||||
}
|
||||
|
||||
$res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$torrents[$row["torrent"]]["comments"] = $row["c"];
|
||||
}
|
||||
|
||||
$fields = explode(":", "comments:leechers:seeders");
|
||||
$res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$id = $row["id"];
|
||||
$torr = $torrents[$id];
|
||||
foreach ($fields as $field) {
|
||||
if (!isset($torr[$field]))
|
||||
$torr[$field] = 0;
|
||||
}
|
||||
$update = array();
|
||||
foreach ($fields as $field) {
|
||||
if ($torr[$field] != $row[$field])
|
||||
$update[] = "$field = " . $torr[$field];
|
||||
}
|
||||
if (count($update))
|
||||
sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("update count of seeders, leechers, comments for torrents");
|
||||
}
|
||||
|
||||
//set no-advertisement-by-bonus time out
|
||||
sql_query("UPDATE users SET noad='no' WHERE noaduntil < ".sqlesc(date("Y-m-d H:i:s")).($enablenoad_advertisement == 'yes' ? " AND class < ".sqlesc($noad_advertisement) : ""));
|
||||
if ($printProgress) {
|
||||
printProgress("set no-advertisement-by-bonus time out");
|
||||
}
|
||||
//12. update forum post/topic count
|
||||
$forums = sql_query("select id from forums") or sqlerr(__FILE__, __LINE__);
|
||||
while ($forum = mysql_fetch_assoc($forums))
|
||||
{
|
||||
$postcount = 0;
|
||||
$topiccount = 0;
|
||||
$topics = sql_query("select id from topics where forumid=$forum[id]") or sqlerr(__FILE__, __LINE__);
|
||||
while ($topic = mysql_fetch_assoc($topics))
|
||||
{
|
||||
$res = sql_query("select count(*) from posts where topicid=$topic[id]") or sqlerr(__FILE__, __LINE__);
|
||||
$arr = mysql_fetch_row($res);
|
||||
$postcount += $arr[0];
|
||||
++$topiccount;
|
||||
}
|
||||
sql_query("update forums set postcount=$postcount, topiccount=$topiccount where id=$forum[id]") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
$Cache->delete_value('forums_list');
|
||||
if ($printProgress) {
|
||||
printProgress("update forum post/topic count");
|
||||
}
|
||||
//14.cleanup offers
|
||||
//Delete offers if not voted on after some time
|
||||
if($offervotetimeout_main){
|
||||
$secs = (int)$offervotetimeout_main;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - ($offervotetimeout_main))));
|
||||
$res = sql_query("SELECT id, name FROM offers WHERE added < $dt AND allowed <> 'allowed'") or sqlerr(__FILE__, __LINE__);
|
||||
while($arr = mysql_fetch_assoc($res)){
|
||||
sql_query("DELETE FROM offers WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("DELETE FROM offervotes WHERE offerid=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("DELETE FROM comments WHERE offer=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
write_log("Offer $arr[id] ($arr[name]) was deleted by system (vote timeout)",'normal');
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete offers if not voted on after some time");
|
||||
}
|
||||
|
||||
//Delete offers if not uploaded after being voted on for some time.
|
||||
if($offeruptimeout_main){
|
||||
$secs = (int)$offeruptimeout_main;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - ($secs))));
|
||||
$res = sql_query("SELECT id, name FROM offers WHERE allowedtime < $dt AND allowed = 'allowed'") or sqlerr(__FILE__, __LINE__);
|
||||
while($arr = mysql_fetch_assoc($res)){
|
||||
sql_query("DELETE FROM offers WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("DELETE FROM offervotes WHERE offerid=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("DELETE FROM comments WHERE offer=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
write_log("Offer $arr[id] ($arr[name]) was deleted by system (upload timeout)",'normal');
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete offers if not uploaded after being voted on for some time.");
|
||||
}
|
||||
|
||||
//15.cleanup torrents
|
||||
//Start: expire torrent promotion
|
||||
function torrent_promotion_expire($days, $type = 2, $targettype = 1){
|
||||
$secs = (int)($days * 86400); //XX days
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - ($secs))));
|
||||
$res = sql_query("SELECT id, name FROM torrents WHERE added < $dt AND sp_state = ".sqlesc($type).' AND promotion_time_type=0') or sqlerr(__FILE__, __LINE__);
|
||||
switch($targettype)
|
||||
{
|
||||
case 1: //normal
|
||||
{
|
||||
$sp_state = 1;
|
||||
$become = "normal";
|
||||
break;
|
||||
}
|
||||
case 2: //Free
|
||||
{
|
||||
$sp_state = 2;
|
||||
$become = "Free";
|
||||
break;
|
||||
}
|
||||
case 3: //2X
|
||||
{
|
||||
$sp_state = 3;
|
||||
$become = "2X";
|
||||
break;
|
||||
}
|
||||
case 4: //2X Free
|
||||
{
|
||||
$sp_state = 4;
|
||||
$become = "2X Free";
|
||||
break;
|
||||
}
|
||||
case 5: //Half Leech
|
||||
{
|
||||
$sp_state = 5;
|
||||
$become = "50%";
|
||||
break;
|
||||
}
|
||||
case 6: //2X Half Leech
|
||||
{
|
||||
$sp_state = 6;
|
||||
$become = "2X 50%";
|
||||
break;
|
||||
}
|
||||
default: //normal
|
||||
{
|
||||
$sp_state = 1;
|
||||
$become = "normal";
|
||||
break;
|
||||
}
|
||||
}
|
||||
while($arr = mysql_fetch_assoc($res)){
|
||||
sql_query("UPDATE torrents SET sp_state = ".sqlesc($sp_state)." WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
if ($sp_state == 1)
|
||||
write_log("Torrent $arr[id] ($arr[name]) is no longer on promotion (time expired)",'normal');
|
||||
else write_log("Promotion type for torrent $arr[id] ($arr[name]) is changed to ".$become." (time expired)",'normal');
|
||||
}
|
||||
}
|
||||
if ($expirehalfleech_torrent)
|
||||
torrent_promotion_expire($expirehalfleech_torrent, 5, $halfleechbecome_torrent);
|
||||
if ($expirefree_torrent)
|
||||
torrent_promotion_expire($expirefree_torrent, 2, $freebecome_torrent);
|
||||
if ($expiretwoup_torrent)
|
||||
torrent_promotion_expire($expiretwoup_torrent, 3, $twoupbecome_torrent);
|
||||
if ($expiretwoupfree_torrent)
|
||||
torrent_promotion_expire($expiretwoupfree_torrent, 4, $twoupfreebecome_torrent);
|
||||
if ($expiretwouphalfleech_torrent)
|
||||
torrent_promotion_expire($expiretwouphalfleech_torrent, 6, $twouphalfleechbecome_torrent);
|
||||
if ($expirethirtypercentleech_torrent)
|
||||
torrent_promotion_expire($expirethirtypercentleech_torrent, 7, $thirtypercentleechbecome_torrent);
|
||||
if ($expirenormal_torrent)
|
||||
torrent_promotion_expire($expirenormal_torrent, 1, $normalbecome_torrent);
|
||||
|
||||
//expire individual torrent promotion
|
||||
sql_query("UPDATE torrents SET sp_state = 1, promotion_time_type=0, promotion_until='0000-00-00 00:00:00' WHERE promotion_time_type=2 AND promotion_until < ".sqlesc(date("Y-m-d H:i:s",TIMENOW))) or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
//End: expire torrent promotion
|
||||
if ($printProgress) {
|
||||
printProgress("expire torrent promotion");
|
||||
}
|
||||
//automatically pick hot
|
||||
if ($hotdays_torrent)
|
||||
{
|
||||
$secs = (int)($hotdays_torrent * 86400); //XX days
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - ($secs))));
|
||||
sql_query("UPDATE torrents SET picktype = 'hot' WHERE added > $dt AND picktype = 'normal' AND seeders > ".sqlesc($hotseeder_torrent)) or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("automatically pick hot");
|
||||
}
|
||||
|
||||
//Priority Class 4: cleanup every 24 hours
|
||||
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime4'");
|
||||
$row = mysql_fetch_array($res);
|
||||
if (!$row) {
|
||||
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime4',$now)") or sqlerr(__FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
$ts = $row[0];
|
||||
if ($ts + $autoclean_interval_four > $now && !$forceAll) {
|
||||
return 'Cleanup ends at Priority Class 3';
|
||||
} else {
|
||||
sql_query("UPDATE avps SET value_u = ".sqlesc($now)." WHERE arg='lastcleantime4'") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
//3.delete unconfirmed accounts
|
||||
$deadtime = time() - $signup_timeout;
|
||||
sql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_login < FROM_UNIXTIME($deadtime) AND last_access < FROM_UNIXTIME($deadtime)") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete unconfirmed accounts");
|
||||
}
|
||||
|
||||
//5.delete old login attempts
|
||||
$secs = 12*60*60; // Delete failed login attempts per half day.
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs))); // calculate date.
|
||||
sql_query("DELETE FROM loginattempts WHERE banned='no' AND added < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete old login attempts");
|
||||
}
|
||||
|
||||
//6.delete old invite codes
|
||||
$secs = $invite_timeout*24*60*60; // when?
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs))); // calculate date.
|
||||
sql_query("DELETE FROM invites WHERE time_invited < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete old invite codes");
|
||||
}
|
||||
|
||||
//7.delete regimage codes
|
||||
sql_query("TRUNCATE TABLE `regimages`") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete regimage codes");
|
||||
}
|
||||
//10.clean up user accounts
|
||||
// make sure VIP or above never get deleted
|
||||
$neverdelete_account = ($neverdelete_account <= UC_VIP ? $neverdelete_account : UC_VIP);
|
||||
|
||||
//delete inactive user accounts, no transfer. Alt. 1: last access time
|
||||
if ($deletenotransfer_account){
|
||||
$secs = $deletenotransfer_account*24*60*60;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs)));
|
||||
$maxclass = $neverdelete_account;
|
||||
sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < $maxclass AND last_access < $dt AND (uploaded = 0 || uploaded = ".sqlesc($iniupload_main).") AND downloaded = 0") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete inactive user accounts, no transfer. Alt. 1: last access time");
|
||||
}
|
||||
|
||||
//delete inactive user accounts, no transfer. Alt. 2: registering time
|
||||
if ($deletenotransfertwo_account){
|
||||
$secs = $deletenotransfertwo_account*24*60*60;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs)));
|
||||
$maxclass = $neverdelete_account;
|
||||
sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < $maxclass AND added < $dt AND (uploaded = 0 || uploaded = ".sqlesc($iniupload_main).") AND downloaded = 0") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete inactive user accounts, no transfer. Alt. 2: registering time");
|
||||
}
|
||||
|
||||
//delete inactive user accounts, not parked
|
||||
if ($deleteunpacked_account){
|
||||
$secs = $deleteunpacked_account*24*60*60;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs)));
|
||||
$maxclass = $neverdelete_account;
|
||||
sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < $maxclass AND last_access < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete inactive user accounts, not parked");
|
||||
}
|
||||
|
||||
//delete parked user accounts, parked
|
||||
if ($deletepacked_account){
|
||||
$secs = $deletepacked_account*24*60*60;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs)));
|
||||
$maxclass = $neverdeletepacked_account;
|
||||
sql_query("DELETE FROM users WHERE parked='yes' AND status='confirmed' AND class < $maxclass AND last_access < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete parked user accounts, parked");
|
||||
}
|
||||
|
||||
//remove VIP status if time's up
|
||||
$res = sql_query("SELECT id, modcomment FROM users WHERE vip_added='yes' AND vip_until < NOW()") or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
$subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed']);
|
||||
$msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed_body']);
|
||||
///---AUTOSYSTEM MODCOMMENT---//
|
||||
$modcomment = htmlspecialchars($arr["modcomment"]);
|
||||
$modcomment = date("Y-m-d") . " - VIP status removed by - AutoSystem.\n". $modcomment;
|
||||
$modcom = sqlesc($modcomment);
|
||||
///---end
|
||||
sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = '0000-00-00 00:00:00', modcomment = $modcom WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("remove VIP status if time's up");
|
||||
}
|
||||
|
||||
// promote peasant back to user
|
||||
function peasant_to_user($down_floor_gb, $down_roof_gb, $minratio){
|
||||
global $lang_cleanup_target;
|
||||
|
||||
if ($down_floor_gb){
|
||||
$downlimit_floor = $down_floor_gb*1024*1024*1024;
|
||||
$downlimit_roof = $down_roof_gb*1024*1024*1024;
|
||||
$res = sql_query("SELECT id FROM users WHERE class = 0 AND downloaded >= $downlimit_floor ".($downlimit_roof > $down_floor_gb ? " AND downloaded < $downlimit_roof" : "")." AND uploaded / downloaded >= $minratio") or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_low_ratio_warning_removed']);
|
||||
$msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_your_ratio_warning_removed']);
|
||||
writecomment($arr[id],"Leech Warning removed by System.");
|
||||
sql_query("UPDATE users SET class = 1, leechwarn = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, $subject, $msg)") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
peasant_to_user($psdlfive_account,0, $psratiofive_account);
|
||||
peasant_to_user($psdlfour_account,$psdlfive_account, $psratiofour_account);
|
||||
peasant_to_user($psdlthree_account,$psdlfour_account, $psratiothree_account);
|
||||
peasant_to_user($psdltwo_account,$psdlthree_account, $psratiotwo_account);
|
||||
peasant_to_user($psdlone_account,$psdltwo_account, $psratioone_account);
|
||||
if ($printProgress) {
|
||||
printProgress("promote peasant back to user");
|
||||
}
|
||||
//end promote peasant back to user
|
||||
|
||||
// start promotion
|
||||
function promotion($class, $down_floor_gb, $minratio, $time_week, $addinvite = 0){
|
||||
global $lang_cleanup_target;
|
||||
$oriclass = $class - 1;
|
||||
|
||||
if ($down_floor_gb){
|
||||
$limit = $down_floor_gb*1024*1024*1024;
|
||||
$maxdt = date("Y-m-d H:i:s",(TIMENOW - 86400*7*$time_week));
|
||||
$res = sql_query("SELECT id, max_class_once FROM users WHERE class = $oriclass AND downloaded >= $limit AND uploaded / downloaded >= $minratio AND added < ".sqlesc($maxdt)) or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_promoted_to'].get_user_class_name($class,false,false,false));
|
||||
$msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_now_you_are'].get_user_class_name($class,false,false,false).$lang_cleanup_target[get_user_lang($arr[id])]['msg_see_faq']);
|
||||
if($class<=$arr[max_class_once])
|
||||
sql_query("UPDATE users SET class = $class WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
else
|
||||
sql_query("UPDATE users SET class = $class, max_class_once=$class, invites=invites+$addinvite WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, $subject, $msg)") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//do not change the ascending order
|
||||
promotion(UC_POWER_USER, $pudl_account, $puprratio_account, $putime_account, $getInvitesByPromotion_class[UC_POWER_USER]);
|
||||
promotion(UC_ELITE_USER, $eudl_account, $euprratio_account, $eutime_account, $getInvitesByPromotion_class[UC_ELITE_USER]);
|
||||
promotion(UC_CRAZY_USER, $cudl_account, $cuprratio_account, $cutime_account, $getInvitesByPromotion_class[UC_CRAZY_USER]);
|
||||
promotion(UC_INSANE_USER, $iudl_account, $iuprratio_account, $iutime_account, $getInvitesByPromotion_class[UC_INSANE_USER]);
|
||||
promotion(UC_VETERAN_USER, $vudl_account, $vuprratio_account, $vutime_account, $getInvitesByPromotion_class[UC_VETERAN_USER]);
|
||||
promotion(UC_EXTREME_USER, $exudl_account, $exuprratio_account, $exutime_account, $getInvitesByPromotion_class[UC_EXTREME_USER]);
|
||||
promotion(UC_ULTIMATE_USER, $uudl_account, $uuprratio_account, $uutime_account, $getInvitesByPromotion_class[UC_ULTIMATE_USER]);
|
||||
promotion(UC_NEXUS_MASTER, $nmdl_account, $nmprratio_account, $nmtime_account, $getInvitesByPromotion_class[UC_NEXUS_MASTER]);
|
||||
// end promotion
|
||||
if ($printProgress) {
|
||||
printProgress("promote users to other classes");
|
||||
}
|
||||
|
||||
// start demotion
|
||||
function demotion($class,$deratio){
|
||||
global $lang_cleanup_target;
|
||||
|
||||
$newclass = $class - 1;
|
||||
$res = sql_query("SELECT id FROM users WHERE class = $class AND uploaded / downloaded < $deratio") or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_to'].get_user_class_name($newclass,false,false,false);
|
||||
$msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_from'].get_user_class_name($class,false,false,false).$lang_cleanup_target[get_user_lang($arr[id])]['msg_to'].get_user_class_name($newclass,false,false,false).$lang_cleanup_target[get_user_lang($arr[id])]['msg_because_ratio_drop_below'].$deratio.".\n";
|
||||
sql_query("UPDATE users SET class = $newclass WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
//do not change the descending order
|
||||
demotion(UC_NEXUS_MASTER,$nmderatio_account);
|
||||
demotion(UC_ULTIMATE_USER,$uuderatio_account);
|
||||
demotion(UC_EXTREME_USER,$exuderatio_account);
|
||||
demotion(UC_VETERAN_USER,$vuderatio_account);
|
||||
demotion(UC_INSANE_USER,$iuderatio_account);
|
||||
demotion(UC_CRAZY_USER,$cuderatio_account);
|
||||
demotion(UC_ELITE_USER,$euderatio_account);
|
||||
demotion(UC_POWER_USER,$puderatio_account);
|
||||
if ($printProgress) {
|
||||
printProgress("demote users to other classes");
|
||||
}
|
||||
// end demotion
|
||||
|
||||
// start demote users to peasant
|
||||
function user_to_peasant($down_floor_gb, $minratio){
|
||||
global $lang_cleanup_target;
|
||||
global $deletepeasant_account;
|
||||
|
||||
$length = $deletepeasant_account*86400; // warn users until xxx days
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW + $length));
|
||||
$downlimit_floor = $down_floor_gb*1024*1024*1024;
|
||||
$res = sql_query("SELECT id FROM users WHERE class = 1 AND downloaded > $downlimit_floor AND uploaded / downloaded < $minratio") or sqlerr(__FILE__, __LINE__);
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_to'].get_user_class_name(UC_PEASANT,false,false,false);
|
||||
$msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_must_fix_ratio_within'].$deletepeasant_account.$lang_cleanup_target[get_user_lang($arr[id])]['msg_days_or_get_banned'];
|
||||
writecomment($arr[id],"Leech Warned by System - Low Ratio.");
|
||||
sql_query("UPDATE users SET class = 0 , leechwarn = 'yes', leechwarnuntil = ".sqlesc($until)." WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user_to_peasant($psdlone_account, $psratioone_account);
|
||||
user_to_peasant($psdltwo_account, $psratiotwo_account);
|
||||
user_to_peasant($psdlthree_account, $psratiothree_account);
|
||||
user_to_peasant($psdlfour_account, $psratiofour_account);
|
||||
user_to_peasant($psdlfive_account, $psratiofive_account);
|
||||
if ($printProgress) {
|
||||
printProgress("demote Users to peasant");
|
||||
}
|
||||
// end Users to Peasant
|
||||
|
||||
//ban users with leechwarning expired
|
||||
$dt = sqlesc(date("Y-m-d H:i:s")); // take date time
|
||||
$res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND leechwarn = 'yes' AND leechwarnuntil < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
writecomment($arr[id],"Banned by System because of Leech Warning expired.");
|
||||
|
||||
sql_query("UPDATE users SET enabled = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("ban users with leechwarning expired");
|
||||
}
|
||||
|
||||
//Remove warning of users
|
||||
$dt = sqlesc(date("Y-m-d H:i:s")); // take date time
|
||||
$res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND warned = 'yes' AND warneduntil < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
if (mysql_num_rows($res) > 0)
|
||||
{
|
||||
while ($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
$subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_warning_removed'];
|
||||
$msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_your_warning_removed'];
|
||||
writecomment($arr[id],"Warning removed by System.");
|
||||
sql_query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("remove warning of users");
|
||||
}
|
||||
|
||||
//17.update total seeding and leeching time of users
|
||||
$res = sql_query("SELECT * FROM users") or sqlerr(__FILE__, __LINE__);
|
||||
while($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
//die("s" . $arr['id']);
|
||||
$res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
|
||||
$arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
//die("ss" . $arr2['st']);
|
||||
//die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']);
|
||||
|
||||
sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("update total seeding and leeching time of users");
|
||||
}
|
||||
|
||||
// delete torrents that have been dead for a long time
|
||||
if ($deldeadtorrent_torrent > 0){
|
||||
$length = $deldeadtorrent_torrent*86400;
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW - $length));
|
||||
$dt = sqlesc(date("Y-m-d H:i:s"));
|
||||
$res = sql_query("SELECT id, name, owner FROM torrents WHERE visible = 'no' AND last_action < ".sqlesc($until)." AND seeders = 0 AND leechers = 0") or sqlerr(__FILE__, __LINE__);
|
||||
while($arr = mysql_fetch_assoc($res))
|
||||
{
|
||||
deletetorrent($arr['id']);
|
||||
$subject = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent_deleted'];
|
||||
$msg = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent']."[i]".$arr['name']."[/i]".$lang_cleanup_target[get_user_lang($arr[owner])]['msg_was_deleted_because_dead'];
|
||||
sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[owner], $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__);
|
||||
write_log("Torrent $arr[id] ($arr[name]) is deleted by system because of being dead for a long time.",'normal');
|
||||
}
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete torrents that have been dead for a long time");
|
||||
}
|
||||
|
||||
//Priority Class 5: cleanup every 15 days
|
||||
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'");
|
||||
$row = mysql_fetch_array($res);
|
||||
if (!$row) {
|
||||
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime5',$now)") or sqlerr(__FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
$ts = $row[0];
|
||||
if ($ts + $autoclean_interval_five > $now && !$forceAll) {
|
||||
return 'Cleanup ends at Priority Class 4';
|
||||
} else {
|
||||
sql_query("UPDATE avps SET value_u = ".sqlesc($now)." WHERE arg='lastcleantime5'") or sqlerr(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
//update clients' popularity
|
||||
$res = sql_query("SELECT id FROM agent_allowed_family");
|
||||
while($row = mysql_fetch_array($res)){
|
||||
$count = get_row_count("users","WHERE clientselect=".sqlesc($row['id']));
|
||||
sql_query("UPDATE agent_allowed_family SET hits=".sqlesc($count)." WHERE id=".sqlesc($row['id']));
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("update clients' popularity");
|
||||
}
|
||||
|
||||
//delete old messages sent by system
|
||||
$length = 180*86400; //half a year
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW - $length));
|
||||
sql_query("DELETE FROM messages WHERE sender = 0 AND added < ".sqlesc($until));
|
||||
if ($printProgress) {
|
||||
printProgress("delete old messages sent by system");
|
||||
}
|
||||
|
||||
//delete old readpost records
|
||||
$length = 180*86400; //half a year
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW - $length));
|
||||
$postIdHalfYearAgo = get_single_value('posts', 'id', 'WHERE added < ' . sqlesc($until).' ORDER BY added DESC');
|
||||
if ($postIdHalfYearAgo) {
|
||||
sql_query("UPDATE users SET last_catchup = ".sqlesc($postIdHalfYearAgo)." WHERE last_catchup < ".sqlesc($postIdHalfYearAgo));
|
||||
sql_query("DELETE FROM readposts WHERE lastpostread < ".sqlesc($postIdHalfYearAgo));
|
||||
}
|
||||
if ($printProgress) {
|
||||
printProgress("delete old readpost records");
|
||||
}
|
||||
|
||||
//delete old ip log
|
||||
$length = 365*86400; //a year
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW - $length));
|
||||
sql_query("DELETE FROM iplog WHERE access < ".sqlesc($until));
|
||||
if ($printProgress) {
|
||||
printProgress("delete old ip log");
|
||||
}
|
||||
|
||||
//delete old general log
|
||||
$secs = 365*86400; //a year
|
||||
$until = date("Y-m-d H:i:s",(TIMENOW - $length));
|
||||
sql_query("DELETE FROM sitelog WHERE added < ".sqlesc($until)) or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete old general log");
|
||||
}
|
||||
|
||||
//1.delete torrents that doesn't exist any more
|
||||
do {
|
||||
$res = sql_query("SELECT id FROM torrents") or sqlerr(__FILE__, __LINE__);
|
||||
$ar = array();
|
||||
while ($row = mysql_fetch_array($res)) {
|
||||
$id = $row[0];
|
||||
$ar[$id] = 1;
|
||||
}
|
||||
|
||||
if (!count($ar))
|
||||
break;
|
||||
|
||||
$dp = @opendir($torrent_dir);
|
||||
if (!$dp)
|
||||
break;
|
||||
|
||||
$ar2 = array();
|
||||
while (($file = readdir($dp)) !== false) {
|
||||
if (!preg_match('/^(\d+)\.torrent$/', $file, $m))
|
||||
continue;
|
||||
$id = $m[1];
|
||||
$ar2[$id] = 1;
|
||||
if (isset($ar[$id]) && $ar[$id])
|
||||
continue;
|
||||
$ff = $torrent_dir . "/$file";
|
||||
unlink($ff);
|
||||
}
|
||||
closedir($dp);
|
||||
|
||||
if (!count($ar2))
|
||||
break;
|
||||
|
||||
$delids = array();
|
||||
foreach (array_keys($ar) as $k) {
|
||||
if (isset($ar2[$k]) && $ar2[$k])
|
||||
continue;
|
||||
$delids[] = $k;
|
||||
unset($ar[$k]);
|
||||
}
|
||||
if (count($delids))
|
||||
sql_query("DELETE FROM torrents WHERE id IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
$res = sql_query("SELECT torrent FROM peers GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||
$delids = array();
|
||||
while ($row = mysql_fetch_array($res)) {
|
||||
$id = $row[0];
|
||||
if (isset($ar[$id]) && $ar[$id])
|
||||
continue;
|
||||
$delids[] = $id;
|
||||
}
|
||||
if (count($delids))
|
||||
sql_query("DELETE FROM peers WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
$res = sql_query("SELECT torrent FROM files GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||
$delids = array();
|
||||
while ($row = mysql_fetch_array($res)) {
|
||||
$id = $row[0];
|
||||
if ($ar[$id])
|
||||
continue;
|
||||
$delids[] = $id;
|
||||
}
|
||||
if (count($delids))
|
||||
sql_query("DELETE FROM files WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
|
||||
} while (0);
|
||||
if ($printProgress) {
|
||||
printProgress("delete torrents that doesn't exist any more");
|
||||
}
|
||||
|
||||
//8.lock topics where last post was made more than x days ago
|
||||
$secs = 365*24*60*60;
|
||||
sql_query("UPDATE topics, posts SET topics.locked='yes' WHERE topics.lastpost = posts.id AND topics.sticky = 'no' AND UNIX_TIMESTAMP(posts.added) < ".TIMENOW." - $secs") or sqlerr(__FILE__, __LINE__);
|
||||
|
||||
if ($printProgress) {
|
||||
printProgress("lock topics where last post was made more than x days ago");
|
||||
}
|
||||
|
||||
//9.delete report items older than four week
|
||||
$secs = 4*7*24*60*60;
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs)));
|
||||
sql_query("DELETE FROM reports WHERE dealtwith=1 AND added < $dt") or sqlerr(__FILE__, __LINE__);
|
||||
if ($printProgress) {
|
||||
printProgress("delete report items older than four week");
|
||||
}
|
||||
return 'Full cleanup is done';
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,403 @@
|
||||
<?php
|
||||
# IMPORTANT: Do not edit below unless you know what you are doing!
|
||||
if(!defined('IN_TRACKER'))
|
||||
die('Hacking attempt!');
|
||||
|
||||
$CONFIGURATIONS = array('ACCOUNT', 'ADVERTISEMENT', 'ATTACHMENT', 'AUTHORITY', 'BASIC', 'BONUS', 'CODE', 'MAIN', 'SECURITY', 'SMTP', 'TORRENT', 'TWEAK');
|
||||
function ReadConfig ($configname = NULL) {
|
||||
global $CONFIGURATIONS;
|
||||
if ($configname) {
|
||||
$configname = basename($configname);
|
||||
$tmp = oldReadConfig($configname);
|
||||
WriteConfig($configname, $tmp);
|
||||
@unlink('./config/'.$configname);
|
||||
return $tmp;
|
||||
} else {
|
||||
foreach ($CONFIGURATIONS as $CONFIGURATION) {
|
||||
$GLOBALS[$CONFIGURATION] = ReadConfig($CONFIGURATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function oldReadConfig ($configname) {
|
||||
if (strstr($configname, ',')) {
|
||||
$configlist = explode(',', $configname);
|
||||
foreach ($configlist as $key=>$configname) {
|
||||
ReadConfig(trim($configname));
|
||||
}
|
||||
} else {
|
||||
$configname = basename($configname);
|
||||
$path = './config/'.$configname;
|
||||
if (!file_exists($path)) {
|
||||
die("Error! File <b>".htmlspecialchars($configname)."</b> doesn't exist!</font><br /><font color=blue>Before the setup starts, please ensure that you have properly configured file and directory access permissions. Please see below.</font><br /><br />chmod 777 config/<br />chmod 777 config/".$configname);
|
||||
}
|
||||
|
||||
$fp = fopen($path, 'r');
|
||||
$content = '';
|
||||
while (!feof($fp)) {
|
||||
$content .= fread($fp, 102400);
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
if (empty($content)) {
|
||||
return array();
|
||||
}
|
||||
$tmp = @unserialize($content);
|
||||
|
||||
if (empty($tmp)) {
|
||||
die("Error! <font color=red>Cannot read configuration file <b>".htmlspecialchars($configname)."</b></font><br /><font color=blue>Before the setup starts, please ensure that you have properly configured file and directory access permissions. For *nix system, please see below.</font><br />chmod 777 config <br />chmod 777 config/".$configname."<br /><br /> If access permission is alright, perhaps there's some misconfiguration or the configuration file is corrupted. Please check config/".$configname);
|
||||
}
|
||||
$GLOBALS[$configname] = $tmp;
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (file_exists('config/allconfig.php')) {
|
||||
require('config/allconfig.php');
|
||||
} else {
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
$SITENAME = $BASIC['SITENAME'];
|
||||
$BASEURL = $BASIC['BASEURL'];
|
||||
$announce_urls = array();
|
||||
$announce_urls[] = $BASIC['announce_url'];
|
||||
$mysql_host = $BASIC['mysql_host'];
|
||||
$mysql_user = $BASIC['mysql_user'];
|
||||
$mysql_pass = $BASIC['mysql_pass'];
|
||||
$mysql_db = $BASIC['mysql_db'];
|
||||
|
||||
|
||||
$SITE_ONLINE = $MAIN['site_online'];
|
||||
$max_torrent_size = $MAIN['max_torrent_size'];
|
||||
$announce_interval = (int)$MAIN['announce_interval'];
|
||||
$annintertwoage = (int)$MAIN['annintertwoage'];
|
||||
$annintertwo = (int)$MAIN['annintertwo'];
|
||||
$anninterthreeage = (int)$MAIN['anninterthreeage'];
|
||||
$anninterthree = (int)$MAIN['anninterthree'];
|
||||
$signup_timeout = $MAIN['signup_timeout'];
|
||||
$minoffervotes = $MAIN['minoffervotes'];
|
||||
$offervotetimeout_main = $MAIN['offervotetimeout'];
|
||||
$offeruptimeout_main = $MAIN['offeruptimeout'];
|
||||
$maxsubsize_main = $MAIN['maxsubsize'];
|
||||
$maxnewsnum_main = $MAIN['maxnewsnum'];
|
||||
$forumpostsperpage = $MAIN['postsperpage'];
|
||||
$forumtopicsperpage_main = $MAIN['topicsperpage'];
|
||||
$torrentsperpage_main = (int)$MAIN['torrentsperpage'];
|
||||
$max_dead_torrent_time = $MAIN['max_dead_torrent_time'];
|
||||
$maxusers = $MAIN['maxusers'];
|
||||
$torrent_dir = $MAIN['torrent_dir'];
|
||||
$iniupload_main = $MAIN['iniupload'];
|
||||
$SITEEMAIL = $MAIN['SITEEMAIL'];
|
||||
$ACCOUNTANTID = (int)$MAIN['ACCOUNTANTID'];
|
||||
$ALIPAYACCOUNT = $MAIN['ALIPAYACCOUNT'];
|
||||
$PAYPALACCOUNT = $MAIN['PAYPALACCOUNT'];
|
||||
$SLOGAN = $MAIN['SLOGAN'];
|
||||
$icplicense_main = $MAIN['icplicense'];
|
||||
$autoclean_interval_one = $MAIN['autoclean_interval_one'];
|
||||
$autoclean_interval_two = $MAIN['autoclean_interval_two'];
|
||||
$autoclean_interval_three = $MAIN['autoclean_interval_three'];
|
||||
$autoclean_interval_four = $MAIN['autoclean_interval_four'];
|
||||
$autoclean_interval_five = $MAIN['autoclean_interval_five'];
|
||||
$REPORTMAIL = $MAIN['reportemail'];
|
||||
$invitesystem = $MAIN['invitesystem'];
|
||||
$registration = $MAIN['registration'];
|
||||
$showmovies['hot'] = $MAIN['showhotmovies'];
|
||||
$showmovies['classic'] = $MAIN['showclassicmovies'];
|
||||
$showextinfo['imdb'] = $MAIN['showimdbinfo'];
|
||||
$enablenfo_main = $MAIN['enablenfo'];
|
||||
$showschool = $MAIN['enableschool'];
|
||||
$restrictemaildomain = $MAIN['restrictemail'];
|
||||
$showpolls_main = $MAIN['showpolls'];
|
||||
$showstats_main = $MAIN['showstats'];
|
||||
//$showlastxforumposts_main = $MAIN['showlastxforumposts'];
|
||||
$showlastxtorrents_main = $MAIN['showlastxtorrents'];
|
||||
$showtrackerload = $MAIN['showtrackerload'];
|
||||
$showshoutbox_main = $MAIN['showshoutbox'];
|
||||
$showfunbox_main = $MAIN['showfunbox'];
|
||||
$enableoffer = $MAIN['showoffer'];
|
||||
$sptime = $MAIN['sptime'];
|
||||
$showhelpbox_main = $MAIN['showhelpbox'];
|
||||
$enablebitbucket_main = $MAIN['enablebitbucket'];
|
||||
$smalldescription_main = $MAIN['smalldescription'];
|
||||
$altname_main = $MAIN['altname'];
|
||||
$enableextforum = $MAIN['extforum'];
|
||||
$extforumurl = $MAIN['extforumurl'];
|
||||
$deflang = $MAIN['defaultlang'];
|
||||
$defcss = $MAIN['defstylesheet'];
|
||||
$enabledonation = $MAIN['donation'];
|
||||
$enablespecial = $MAIN['spsct'];
|
||||
$browsecatmode = (int)$MAIN['browsecat'];
|
||||
$specialcatmode = (int)$MAIN['specialcat'];
|
||||
$waitsystem = $MAIN['waitsystem'];
|
||||
$maxdlsystem = $MAIN['maxdlsystem'];
|
||||
$bitbucket = $MAIN['bitbucket'];
|
||||
$torrentnameprefix = $MAIN['torrentnameprefix'];
|
||||
$showforumstats_main = $MAIN['showforumstats'];
|
||||
$verification = $MAIN['verification'];
|
||||
$invite_count = $MAIN['invite_count'];
|
||||
$invite_timeout = $MAIN['invite_timeout'];
|
||||
$seeding_leeching_time_calc_start = $MAIN['seeding_leeching_time_calc_start'];
|
||||
$logo_main = $MAIN['logo'];
|
||||
|
||||
|
||||
$emailnotify_smtp = $SMTP['emailnotify'];
|
||||
$smtptype = $SMTP['smtptype'];
|
||||
$smtp_host = $SMTP['smtp_host'];
|
||||
$smtp_port = $SMTP['smtp_port'];
|
||||
if (strtoupper(substr(PHP_OS,0,3)=='WIN'))
|
||||
$smtp_from = $SMTP['smtp_from'];
|
||||
$smtpaddress = $SMTP['smtpaddress'];
|
||||
$smtpport = $SMTP['smtpport'];
|
||||
$accountname = $SMTP['accountname'];
|
||||
$accountpassword = $SMTP['accountpassword'];
|
||||
|
||||
$securelogin = $SECURITY['securelogin'];
|
||||
$securetracker = $SECURITY['securetracker'];
|
||||
$https_announce_urls = array();
|
||||
$https_announce_urls[] = $SECURITY['https_announce_url'];
|
||||
$iv = $SECURITY['iv'];
|
||||
$maxip = $SECURITY['maxip'];
|
||||
$maxloginattempts = $SECURITY['maxloginattempts'];
|
||||
$disableemailchange = $SECURITY['changeemail'];
|
||||
$cheaterdet_security = $SECURITY['cheaterdet'];
|
||||
$nodetect_security = $SECURITY['nodetect'];
|
||||
|
||||
$defaultclass_class = $AUTHORITY['defaultclass'];
|
||||
$staffmem_class = $AUTHORITY['staffmem'];
|
||||
$newsmanage_class = $AUTHORITY['newsmanage'];
|
||||
$newfunitem_class = $AUTHORITY['newfunitem'];
|
||||
$funmanage_class = $AUTHORITY['funmanage'];
|
||||
$sbmanage_class = $AUTHORITY['sbmanage'];
|
||||
$pollmanage_class = $AUTHORITY['pollmanage'];
|
||||
$applylink_class = $AUTHORITY['applylink'];
|
||||
$linkmanage_class = $AUTHORITY['linkmanage'];
|
||||
$postmanage_class = $AUTHORITY['postmanage'];
|
||||
$commanage_class = $AUTHORITY['commanage'];
|
||||
$forummanage_class = $AUTHORITY['forummanage'];
|
||||
$viewuserlist_class = $AUTHORITY['viewuserlist'];
|
||||
$torrentmanage_class = $AUTHORITY['torrentmanage'];
|
||||
$torrentsticky_class = $AUTHORITY['torrentsticky'];
|
||||
$torrentonpromotion_class = $AUTHORITY['torrentonpromotion'];
|
||||
$askreseed_class = $AUTHORITY['askreseed'];
|
||||
$viewnfo_class = $AUTHORITY['viewnfo'];
|
||||
$torrentstructure_class = $AUTHORITY['torrentstructure'];
|
||||
$sendinvite_class = $AUTHORITY['sendinvite'];
|
||||
$viewhistory_class = $AUTHORITY['viewhistory'];
|
||||
$topten_class = $AUTHORITY['topten'];
|
||||
$log_class = $AUTHORITY['log'];
|
||||
$confilog_class = $AUTHORITY['confilog'];
|
||||
$userprofile_class = $AUTHORITY['userprofile'];
|
||||
$torrenthistory_class = $AUTHORITY['torrenthistory'];
|
||||
$prfmanage_class = $AUTHORITY['prfmanage'];
|
||||
$cruprfmanage_class = $AUTHORITY['cruprfmanage'];
|
||||
$uploadsub_class = $AUTHORITY['uploadsub'];
|
||||
$delownsub_class = $AUTHORITY['delownsub'];
|
||||
$submanage_class = $AUTHORITY['submanage'];
|
||||
$updateextinfo_class = $AUTHORITY['updateextinfo'];
|
||||
$viewanonymous_class = $AUTHORITY['viewanonymous'];
|
||||
$beanonymous_class = $AUTHORITY['beanonymous'];
|
||||
$addoffer_class = $AUTHORITY['addoffer'];
|
||||
$offermanage_class = $AUTHORITY['offermanage'];
|
||||
$upload_class = $AUTHORITY['upload'];
|
||||
$uploadspecial_class = $AUTHORITY['uploadspecial'];
|
||||
$movetorrent_class = $AUTHORITY['movetorrent'];
|
||||
$chrmanage_class = $AUTHORITY['chrmanage'];
|
||||
$viewinvite_class = $AUTHORITY['viewinvite'];
|
||||
$buyinvite_class = $AUTHORITY['buyinvite'];
|
||||
$seebanned_class = $AUTHORITY['seebanned'];
|
||||
$againstoffer_class = $AUTHORITY['againstoffer'];
|
||||
$userbar_class = $AUTHORITY['userbar'];
|
||||
|
||||
$where_tweak = $TWEAK['where'];
|
||||
$iplog1 = $TWEAK['iplog1'];
|
||||
$bonus_tweak = $TWEAK['bonus'];
|
||||
$titlekeywords_tweak = $TWEAK['titlekeywords'];
|
||||
$metakeywords_tweak = $TWEAK['metakeywords'];
|
||||
$metadescription_tweak = $TWEAK['metadescription'];
|
||||
$datefounded = $TWEAK['datefounded'];
|
||||
$enablelocation_tweak = $TWEAK['enablelocation'];
|
||||
$enablesqldebug_tweak = $TWEAK['enablesqldebug'];
|
||||
$sqldebug_tweak = $TWEAK['sqldebug'];
|
||||
$cssdate_tweak = $TWEAK['cssdate'];
|
||||
$enabletooltip_tweak = $TWEAK['enabletooltip'];
|
||||
$prolinkimg = $TWEAK['prolinkimg'];
|
||||
$analyticscode_tweak = $TWEAK['analyticscode'];
|
||||
|
||||
$enableattach_attachment = $ATTACHMENT['enableattach'];
|
||||
$classone_attachment = $ATTACHMENT['classone'];
|
||||
$countone_attachment = $ATTACHMENT['countone'];
|
||||
$sizeone_attachment = $ATTACHMENT['sizeone'];
|
||||
$extone_attachment = $ATTACHMENT['extone'];
|
||||
$classtwo_attachment = $ATTACHMENT['classtwo'];
|
||||
$counttwo_attachment = $ATTACHMENT['counttwo'];
|
||||
$sizetwo_attachment = $ATTACHMENT['sizetwo'];
|
||||
$exttwo_attachment = $ATTACHMENT['exttwo'];
|
||||
$classthree_attachment = $ATTACHMENT['classthree'];
|
||||
$countthree_attachment = $ATTACHMENT['countthree'];
|
||||
$sizethree_attachment = $ATTACHMENT['sizethree'];
|
||||
$extthree_attachment = $ATTACHMENT['extthree'];
|
||||
$classfour_attachment = $ATTACHMENT['classfour'];
|
||||
$countfour_attachment = $ATTACHMENT['countfour'];
|
||||
$sizefour_attachment = $ATTACHMENT['sizefour'];
|
||||
$extfour_attachment = $ATTACHMENT['extfour'];
|
||||
$savedirectory_attachment = $ATTACHMENT['savedirectory'];
|
||||
$httpdirectory_attachment = $ATTACHMENT['httpdirectory'];
|
||||
$savedirectorytype_attachment = $ATTACHMENT['savedirectorytype'];
|
||||
$thumbnailtype_attachment = $ATTACHMENT['thumbnailtype'];
|
||||
$thumbquality_attachment = $ATTACHMENT['thumbquality'];
|
||||
$thumbwidth_attachment = $ATTACHMENT['thumbwidth'];
|
||||
$thumbheight_attachment = $ATTACHMENT['thumbheight'];
|
||||
$watermarkpos_attachment = $ATTACHMENT['watermarkpos'];
|
||||
$watermarkwidth_attachment = $ATTACHMENT['watermarkwidth'];
|
||||
$watermarkheight_attachment = $ATTACHMENT['watermarkheight'];
|
||||
$watermarkquality_attachment = $ATTACHMENT['watermarkquality'];
|
||||
$altthumbwidth_attachment = $ATTACHMENT['altthumbwidth'];
|
||||
$altthumbheight_attachment = $ATTACHMENT['altthumbheight'];
|
||||
|
||||
|
||||
$enablead_advertisement = $ADVERTISEMENT['enablead'];
|
||||
$enablenoad_advertisement = $ADVERTISEMENT['enablenoad'];
|
||||
$noad_advertisement = $ADVERTISEMENT['noad'];
|
||||
$enablebonusnoad_advertisement = $ADVERTISEMENT['enablebonusnoad'];
|
||||
$bonusnoad_advertisement = $ADVERTISEMENT['bonusnoad'];
|
||||
$bonusnoadpoint_advertisement = $ADVERTISEMENT['bonusnoadpoint'];
|
||||
$bonusnoadtime_advertisement = $ADVERTISEMENT['bonusnoadtime'];
|
||||
$adclickbonus_advertisement = $ADVERTISEMENT['adclickbonus'];
|
||||
|
||||
$mainversion_code = $CODE['mainversion'];
|
||||
$subversion_code = $CODE['subversion'];
|
||||
$releasedate_code = $CODE['releasedate'];
|
||||
$website_code = $CODE['website'];
|
||||
|
||||
$donortimes_bonus = $BONUS['donortimes'];
|
||||
$perseeding_bonus = $BONUS['perseeding'];
|
||||
$maxseeding_bonus = $BONUS['maxseeding'];
|
||||
$tzero_bonus = $BONUS['tzero'];
|
||||
$nzero_bonus = $BONUS['nzero'];
|
||||
$bzero_bonus = $BONUS['bzero'];
|
||||
$l_bonus = $BONUS['l'];
|
||||
$uploadtorrent_bonus = $BONUS['uploadtorrent'];
|
||||
$uploadsubtitle_bonus = $BONUS['uploadsubtitle'];
|
||||
$starttopic_bonus = $BONUS['starttopic'];
|
||||
$makepost_bonus = $BONUS['makepost'];
|
||||
$addcomment_bonus = $BONUS['addcomment'];
|
||||
$pollvote_bonus = $BONUS['pollvote'];
|
||||
$offervote_bonus = $BONUS['offervote'];
|
||||
$funboxvote_bonus = $BONUS['funboxvote'];
|
||||
$saythanks_bonus = $BONUS['saythanks'];
|
||||
$receivethanks_bonus = $BONUS['receivethanks'];
|
||||
$funboxreward_bonus = $BONUS['funboxreward'];
|
||||
$onegbupload_bonus = $BONUS['onegbupload'];
|
||||
$fivegbupload_bonus = $BONUS['fivegbupload'];
|
||||
$tengbupload_bonus = $BONUS['tengbupload'];
|
||||
$ratiolimit_bonus = $BONUS['ratiolimit'];
|
||||
$dlamountlimit_bonus = $BONUS['dlamountlimit'];
|
||||
$oneinvite_bonus = $BONUS['oneinvite'];
|
||||
$customtitle_bonus = $BONUS['customtitle'];
|
||||
$vipstatus_bonus = $BONUS['vipstatus'];
|
||||
$bonusgift_bonus = $BONUS['bonusgift'];
|
||||
$basictax_bonus = 0+$BONUS['basictax'];
|
||||
$taxpercentage_bonus = 0+$BONUS['taxpercentage'];
|
||||
$prolinkpoint_bonus = $BONUS['prolinkpoint'];
|
||||
$prolinktime_bonus = $BONUS['prolinktime'];
|
||||
|
||||
$neverdelete_account = $ACCOUNT['neverdelete'];
|
||||
$neverdeletepacked_account = $ACCOUNT['neverdeletepacked'];
|
||||
$deletepacked_account = $ACCOUNT['deletepacked'];
|
||||
$deleteunpacked_account = $ACCOUNT['deleteunpacked'];
|
||||
$deletenotransfer_account = $ACCOUNT['deletenotransfer'];
|
||||
$deletenotransfertwo_account = $ACCOUNT['deletenotransfertwo'];
|
||||
$deletepeasant_account = $ACCOUNT['deletepeasant'];
|
||||
$psdlone_account = $ACCOUNT['psdlone'];
|
||||
$psratioone_account = $ACCOUNT['psratioone'];
|
||||
$psdltwo_account = $ACCOUNT['psdltwo'];
|
||||
$psratiotwo_account = $ACCOUNT['psratiotwo'];
|
||||
$psdlthree_account = $ACCOUNT['psdlthree'];
|
||||
$psratiothree_account = $ACCOUNT['psratiothree'];
|
||||
$psdlfour_account = $ACCOUNT['psdlfour'];
|
||||
$psratiofour_account = $ACCOUNT['psratiofour'];
|
||||
$psdlfive_account = $ACCOUNT['psdlfive'];
|
||||
$psratiofive_account = $ACCOUNT['psratiofive'];
|
||||
$putime_account = $ACCOUNT['putime'];
|
||||
$pudl_account = $ACCOUNT['pudl'];
|
||||
$puprratio_account = $ACCOUNT['puprratio'];
|
||||
$puderatio_account = $ACCOUNT['puderatio'];
|
||||
$eutime_account = $ACCOUNT['eutime'];
|
||||
$eudl_account = $ACCOUNT['eudl'];
|
||||
$euprratio_account = $ACCOUNT['euprratio'];
|
||||
$euderatio_account = $ACCOUNT['euderatio'];
|
||||
$cutime_account = $ACCOUNT['cutime'];
|
||||
$cudl_account = $ACCOUNT['cudl'];
|
||||
$cuprratio_account = $ACCOUNT['cuprratio'];
|
||||
$cuderatio_account = $ACCOUNT['cuderatio'];
|
||||
$iutime_account = $ACCOUNT['iutime'];
|
||||
$iudl_account = $ACCOUNT['iudl'];
|
||||
$iuprratio_account = $ACCOUNT['iuprratio'];
|
||||
$iuderatio_account = $ACCOUNT['iuderatio'];
|
||||
$vutime_account = $ACCOUNT['vutime'];
|
||||
$vudl_account = $ACCOUNT['vudl'];
|
||||
$vuprratio_account = $ACCOUNT['vuprratio'];
|
||||
$vuderatio_account = $ACCOUNT['vuderatio'];
|
||||
$exutime_account = $ACCOUNT['exutime'];
|
||||
$exudl_account = $ACCOUNT['exudl'];
|
||||
$exuprratio_account = $ACCOUNT['exuprratio'];
|
||||
$exuderatio_account = $ACCOUNT['exuderatio'];
|
||||
$uutime_account = $ACCOUNT['uutime'];
|
||||
$uudl_account = $ACCOUNT['uudl'];
|
||||
$uuprratio_account = $ACCOUNT['uuprratio'];
|
||||
$uuderatio_account = $ACCOUNT['uuderatio'];
|
||||
$nmtime_account = $ACCOUNT['nmtime'];
|
||||
$nmdl_account = $ACCOUNT['nmdl'];
|
||||
$nmprratio_account = $ACCOUNT['nmprratio'];
|
||||
$nmderatio_account = $ACCOUNT['nmderatio'];
|
||||
$getInvitesByPromotion_class = $ACCOUNT['getInvitesByPromotion'];
|
||||
|
||||
$prorules_torrent = $TORRENT['prorules'];
|
||||
$randomhalfleech_torrent = $TORRENT['randomhalfleech'];
|
||||
$randomfree_torrent = $TORRENT['randomfree'];
|
||||
$randomtwoup_torrent = $TORRENT['randomtwoup'];
|
||||
$randomtwoupfree_torrent = $TORRENT['randomtwoupfree'];
|
||||
$randomtwouphalfdown_torrent = $TORRENT['randomtwouphalfdown'];
|
||||
$randomthirtypercentdown_torrent = $TORRENT['randomthirtypercentdown'];
|
||||
$largesize_torrent = $TORRENT['largesize'];
|
||||
$largepro_torrent = $TORRENT['largepro'];
|
||||
$expirehalfleech_torrent = $TORRENT['expirehalfleech'];
|
||||
$expirefree_torrent = $TORRENT['expirefree'];
|
||||
$expiretwoup_torrent = $TORRENT['expiretwoup'];
|
||||
$expiretwoupfree_torrent = $TORRENT['expiretwoupfree'];
|
||||
$expiretwouphalfleech_torrent = $TORRENT['expiretwouphalfleech'];
|
||||
$expirethirtypercentleech_torrent = $TORRENT['expirethirtypercentleech'];
|
||||
$expirenormal_torrent = $TORRENT['expirenormal'];
|
||||
$hotdays_torrent = $TORRENT['hotdays'];
|
||||
$hotseeder_torrent = $TORRENT['hotseeder'];
|
||||
$halfleechbecome_torrent = $TORRENT['halfleechbecome'];
|
||||
$freebecome_torrent = $TORRENT['freebecome'];
|
||||
$twoupbecome_torrent = $TORRENT['twoupbecome'];
|
||||
$twoupfreebecome_torrent = $TORRENT['twoupfreebecome'];
|
||||
$twouphalfleechbecome_torrent = $TORRENT['twouphalfleechbecome'];
|
||||
$thirtypercentleechbecome_torrent = $TORRENT['thirtypercentleechbecome'];
|
||||
$normalbecome_torrent = $TORRENT['normalbecome'];
|
||||
$uploaderdouble_torrent = $TORRENT['uploaderdouble'];
|
||||
$deldeadtorrent_torrent = $TORRENT['deldeadtorrent'];
|
||||
|
||||
foreach ($CONFIGURATIONS as $CONFIGURATION) {
|
||||
unset($GLOBALS[$CONFIGURATION]);
|
||||
}
|
||||
|
||||
//Directory for subs
|
||||
$SUBSPATH = "subs";
|
||||
//Whether clean-up is triggered by cron, instead of the default browser clicks.
|
||||
//Set this to true ONLY if you have setup other method to schedule the clean-up process.
|
||||
//e.g. cron on *nix, add the following line (without "") in your crontab file
|
||||
//"*/5 * * * * wget -O - -q -t 1 http://www.nexusphp.com/cron.php"
|
||||
//NOTE:
|
||||
//Make sure you have wget installed on your OS
|
||||
//replace "http://www.nexusphp.com/" with your own site address
|
||||
|
||||
$useCronTriggerCleanUp = false;
|
||||
//some promotion rules
|
||||
//$promotionrules_torrent = array(0 => array("mediumid" => array(1), "promotion" => 5), 1 => array("mediumid" => array(3), "promotion" => 5), 2 => array("catid" => array(402), "standardid" => array(3), "promotion" => 4), 3 => array("catid" => array(403), "standardid" => array(3), "promotion" => 4));
|
||||
$promotionrules_torrent = array();
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
if(!defined('IN_TRACKER'))
|
||||
die('Hacking attempt!');
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
ini_set('display_errors', 0);
|
||||
include_once($rootpath . 'classes/class_cache.php'); //Require the caching class
|
||||
$Cache = NEW CACHE(); //Load the caching class
|
||||
$Cache->setLanguageFolderArray(get_langfolder_list());
|
||||
define('TIMENOW', time());
|
||||
$USERUPDATESET = array();
|
||||
$query_name=array();
|
||||
|
||||
define ("UC_PEASANT", 0);
|
||||
define ("UC_USER", 1);
|
||||
define ("UC_POWER_USER", 2);
|
||||
define ("UC_ELITE_USER", 3);
|
||||
define ("UC_CRAZY_USER", 4);
|
||||
define ("UC_INSANE_USER", 5);
|
||||
define ("UC_VETERAN_USER", 6);
|
||||
define ("UC_EXTREME_USER", 7);
|
||||
define ("UC_ULTIMATE_USER", 8);
|
||||
define ("UC_NEXUS_MASTER", 9);
|
||||
define ("UC_VIP", 10);
|
||||
define ("UC_RETIREE",11);
|
||||
define ("UC_UPLOADER",12);
|
||||
//define ("UC_FORUM_MODERATOR", 12);
|
||||
define ("UC_MODERATOR",13);
|
||||
define ("UC_ADMINISTRATOR",14);
|
||||
define ("UC_SYSOP",15);
|
||||
define ("UC_STAFFLEADER",16);
|
||||
ignore_user_abort(1);
|
||||
@set_time_limit(60);
|
||||
|
||||
function strip_magic_quotes($arr)
|
||||
{
|
||||
foreach ($arr as $k => $v)
|
||||
{
|
||||
if (is_array($v))
|
||||
{
|
||||
$arr[$k] = strip_magic_quotes($v);
|
||||
} else {
|
||||
$arr[$k] = stripslashes($v);
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
|
||||
{
|
||||
if (!empty($_GET)) {
|
||||
$_GET = strip_magic_quotes($_GET);
|
||||
}
|
||||
if (!empty($_POST)) {
|
||||
$_POST = strip_magic_quotes($_POST);
|
||||
}
|
||||
if (!empty($_COOKIE)) {
|
||||
$_COOKIE = strip_magic_quotes($_COOKIE);
|
||||
}
|
||||
}
|
||||
|
||||
function get_langfolder_list()
|
||||
{
|
||||
//do not access db for speed up, or for flexibility
|
||||
return array("en", "chs", "cht", "ko", "ja");
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
# IMPORTANT: Do not edit below unless you know what you are doing!
|
||||
if(!defined('IN_TRACKER'))
|
||||
die('Hacking attempt!');
|
||||
include_once($rootpath . 'include/globalfunctions.php');
|
||||
include_once($rootpath . 'include/config.php');
|
||||
|
||||
function dbconn_announce() {
|
||||
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
|
||||
|
||||
if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass))
|
||||
{
|
||||
die('dbconn: mysql_connect: ' . mysql_error());
|
||||
}
|
||||
mysql_query("SET NAMES UTF8");
|
||||
mysql_query("SET collation_connection = 'utf8_general_ci'");
|
||||
mysql_query("SET sql_mode=''");
|
||||
mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
|
||||
}
|
||||
|
||||
function hash_where_arr($name, $hash_arr) {
|
||||
$new_hash_arr = Array();
|
||||
foreach ($hash_arr as $hash) {
|
||||
$new_hash_arr[] = sqlesc((urldecode($hash)));
|
||||
}
|
||||
return $name." IN ( ".implode(", ",$new_hash_arr)." )";
|
||||
}
|
||||
|
||||
function emu_getallheaders() {
|
||||
foreach($_SERVER as $name => $value)
|
||||
if(substr($name, 0, 5) == 'HTTP_')
|
||||
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
||||
return $headers;
|
||||
}
|
||||
|
||||
function block_browser()
|
||||
{
|
||||
$agent = $_SERVER["HTTP_USER_AGENT"];
|
||||
if (preg_match("/^Mozilla/", $agent) || preg_match("/^Opera/", $agent) || preg_match("/^Links/", $agent) || preg_match("/^Lynx/", $agent) )
|
||||
err("Browser access blocked!");
|
||||
// check headers
|
||||
if (function_exists('getallheaders')){ //getallheaders() is only supported when PHP is installed as an Apache module
|
||||
$headers = getallheaders();
|
||||
//else
|
||||
// $headers = emu_getallheaders();
|
||||
|
||||
if($_SERVER["HTTPS"] != "on")
|
||||
{
|
||||
if (isset($headers["Cookie"]) || isset($headers["Accept-Language"]) || isset($headers["Accept-Charset"]))
|
||||
err("Anti-Cheater: You cannot use this agent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function benc_resp($d)
|
||||
{
|
||||
benc_resp_raw(benc(array('type' => 'dictionary', 'value' => $d)));
|
||||
}
|
||||
function benc_resp_raw($x) {
|
||||
|
||||
header("Content-Type: text/plain; charset=utf-8");
|
||||
header("Pragma: no-cache");
|
||||
|
||||
if ($_SERVER["HTTP_ACCEPT_ENCODING"] == "gzip" && function_exists('gzencode')) {
|
||||
header("Content-Encoding: gzip");
|
||||
echo gzencode($x, 9, FORCE_GZIP);
|
||||
}
|
||||
else
|
||||
echo $x;
|
||||
}
|
||||
function err($msg, $userid = 0, $torrentid = 0)
|
||||
{
|
||||
benc_resp(array('failure reason' => array('type' => 'string', 'value' => $msg)));
|
||||
exit();
|
||||
}
|
||||
function check_cheater($userid, $torrentid, $uploaded, $downloaded, $anctime, $seeders=0, $leechers=0){
|
||||
global $cheaterdet_security,$nodetect_security;
|
||||
|
||||
$time = date("Y-m-d H:i:s");
|
||||
$upspeed = ($uploaded > 0 ? $uploaded / $anctime : 0);
|
||||
|
||||
if ($uploaded > 1073741824 && $upspeed > (104857600/$cheaterdet_security)) //Uploaded more than 1 GB with uploading rate higher than 100 MByte/S (For Consertive level). This is no doubt cheating.
|
||||
{
|
||||
$comment = "User account was automatically disabled by system";
|
||||
mysql_query("INSERT INTO cheaters (added, userid, torrentid, uploaded, downloaded, anctime, seeders, leechers, comment) VALUES (".sqlesc($time).", $userid, $torrentid, $uploaded, $downloaded, $anctime, $seeders, $leechers, ".sqlesc($comment).")") or err("Tracker error 51");
|
||||
mysql_query("UPDATE users SET enabled = 'no' WHERE id=$userid") or err("Tracker error 50"); //automatically disable user account;
|
||||
err("We believe you're trying to cheat. And your account is disabled.");
|
||||
return true;
|
||||
}
|
||||
if ($uploaded > 1073741824 && $upspeed > (10485760/$cheaterdet_security)) //Uploaded more than 1 GB with uploading rate higher than 10 MByte/S (For Consertive level). This is likely cheating.
|
||||
{
|
||||
$secs = 24*60*60; //24 hours
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(strtotime(date("Y-m-d H:i:s")) - $secs))); // calculate date.
|
||||
$countres = mysql_query("SELECT id FROM cheaters WHERE userid=$userid AND torrentid=$torrentid AND added > $dt");
|
||||
if (mysql_num_rows($countres) == 0)
|
||||
{
|
||||
$comment = "Abnormally high uploading rate";
|
||||
mysql_query("INSERT INTO cheaters (added, userid, torrentid, uploaded, downloaded, anctime, seeders, leechers, hit, comment) VALUES (".sqlesc($time).", $userid, $torrentid, $uploaded, $downloaded, $anctime, $seeders, $leechers, 1,".sqlesc($comment).")") or err("Tracker error 52");
|
||||
}
|
||||
else{
|
||||
$row = mysql_fetch_row($countres);
|
||||
mysql_query("UPDATE cheaters SET hit=hit+1, dealtwith = 0 WHERE id=".$row[0]);
|
||||
}
|
||||
//mysql_query("UPDATE users SET downloadpos = 'no' WHERE id=$userid") or err("Tracker error 53"); //automatically remove user's downloading privileges;
|
||||
return false;
|
||||
}
|
||||
if ($cheaterdet_security > 1){// do not check this with consertive level
|
||||
if ($uploaded > 1073741824 && $upspeed > 1048576 && $leechers < (2 * $cheaterdet_security)) //Uploaded more than 1 GB with uploading rate higher than 1 MByte/S when there is less than 8 leechers (For Consertive level). This is likely cheating.
|
||||
{
|
||||
$secs = 24*60*60; //24 hours
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(strtotime(date("Y-m-d H:i:s")) - $secs))); // calculate date.
|
||||
$countres = mysql_query("SELECT id FROM cheaters WHERE userid=$userid AND torrentid=$torrentid AND added > $dt");
|
||||
if (mysql_num_rows($countres) == 0)
|
||||
{
|
||||
$comment = "User is uploading fast when there is few leechers";
|
||||
mysql_query("INSERT INTO cheaters (added, userid, torrentid, uploaded, downloaded, anctime, seeders, leechers, comment) VALUES (".sqlesc($time).", $userid, $torrentid, $uploaded, $downloaded, $anctime, $seeders, $leechers, ".sqlesc($comment).")") or err("Tracker error 52");
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = mysql_fetch_row($countres);
|
||||
mysql_query("UPDATE cheaters SET hit=hit+1, dealtwith = 0 WHERE id=".$row[0]);
|
||||
}
|
||||
//mysql_query("UPDATE users SET downloadpos = 'no' WHERE id=$userid") or err("Tracker error 53"); //automatically remove user's downloading privileges;
|
||||
return false;
|
||||
}
|
||||
if ($uploaded > 10485760 && $upspeed > 102400 && $leechers == 0) //Uploaded more than 10 MB with uploading speed faster than 100 KByte/S when there is no leecher. This is likely cheating.
|
||||
{
|
||||
$secs = 24*60*60; //24 hours
|
||||
$dt = sqlesc(date("Y-m-d H:i:s",(strtotime(date("Y-m-d H:i:s")) - $secs))); // calculate date.
|
||||
$countres = mysql_query("SELECT id FROM cheaters WHERE userid=$userid AND torrentid=$torrentid AND added > $dt");
|
||||
if (mysql_num_rows($countres) == 0)
|
||||
{
|
||||
$comment = "User is uploading when there is no leecher";
|
||||
mysql_query("INSERT INTO cheaters (added, userid, torrentid, uploaded, downloaded, anctime, seeders, leechers, comment) VALUES (".sqlesc($time).", $userid, $torrentid, $uploaded, $downloaded, $anctime, $seeders, $leechers, ".sqlesc($comment).")") or err("Tracker error 52");
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = mysql_fetch_row($countres);
|
||||
mysql_query("UPDATE cheaters SET hit=hit+1, dealtwith = 0 WHERE id=".$row[0]);
|
||||
}
|
||||
//mysql_query("UPDATE users SET downloadpos = 'no' WHERE id=$userid") or err("Tracker error 53"); //automatically remove user's downloading privileges;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function portblacklisted($port)
|
||||
{
|
||||
// direct connect
|
||||
if ($port >= 411 && $port <= 413) return true;
|
||||
// bittorrent
|
||||
if ($port >= 6881 && $port <= 6889) return true;
|
||||
// kazaa
|
||||
if ($port == 1214) return true;
|
||||
// gnutella
|
||||
if ($port >= 6346 && $port <= 6347) return true;
|
||||
// emule
|
||||
if ($port == 4662) return true;
|
||||
// winmx
|
||||
if ($port == 6699) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function ipv4_to_compact($ip, $port)
|
||||
{
|
||||
$compact = pack("Nn", sprintf("%d",ip2long($ip)), $port);
|
||||
return $compact;
|
||||
}
|
||||
|
||||
function check_client($peer_id, $agent, &$agent_familyid)
|
||||
{
|
||||
global $BASEURL, $Cache;
|
||||
|
||||
if (!$clients = $Cache->get_value('allowed_client_list')){
|
||||
$clients = array();
|
||||
$res = mysql_query("SELECT * FROM agent_allowed_family ORDER BY hits DESC") or err("check err");
|
||||
while ($row = mysql_fetch_array($res))
|
||||
$clients[] = $row;
|
||||
$Cache->cache_value('allowed_client_list', $clients, 86400);
|
||||
}
|
||||
foreach ($clients as $row_allowed_ua)
|
||||
{
|
||||
$allowed_flag_peer_id = false;
|
||||
$allowed_flag_agent = false;
|
||||
$version_low_peer_id = false;
|
||||
$version_low_agent = false;
|
||||
|
||||
if($row_allowed_ua['peer_id_pattern'] != '')
|
||||
{
|
||||
if(!preg_match($row_allowed_ua['peer_id_pattern'], $row_allowed_ua['peer_id_start'], $match_bench))
|
||||
err("regular expression err for: " . $row_allowed_ua['peer_id_start'] . ", please ask sysop to fix this");
|
||||
|
||||
if(preg_match($row_allowed_ua['peer_id_pattern'], $peer_id, $match_target))
|
||||
{
|
||||
if($row_allowed_ua['peer_id_match_num'] != 0)
|
||||
{
|
||||
for($i = 0 ; $i < $row_allowed_ua['peer_id_match_num']; $i++)
|
||||
{
|
||||
if($row_allowed_ua['peer_id_matchtype'] == 'dec')
|
||||
{
|
||||
$match_target[$i+1] = 0 + $match_target[$i+1];
|
||||
$match_bench[$i+1] = 0 + $match_bench[$i+1];
|
||||
}
|
||||
else if($row_allowed_ua['peer_id_matchtype'] == 'hex')
|
||||
{
|
||||
$match_target[$i+1] = hexdec($match_target[$i+1]);
|
||||
$match_bench[$i+1] = hexdec($match_bench[$i+1]);
|
||||
}
|
||||
|
||||
if ($match_target[$i+1] > $match_bench[$i+1])
|
||||
{
|
||||
$allowed_flag_peer_id = true;
|
||||
break;
|
||||
}
|
||||
else if($match_target[$i+1] < $match_bench[$i+1])
|
||||
{
|
||||
$allowed_flag_peer_id = false;
|
||||
$version_low_peer_id = true;
|
||||
$low_version = "Your " . $row_allowed_ua['family'] . " 's version is too low, please update it after " . $row_allowed_ua['start_name'];
|
||||
break;
|
||||
}
|
||||
else if($match_target[$i+1] == $match_bench[$i+1])//equal
|
||||
{
|
||||
if($i+1 == $row_allowed_ua['peer_id_match_num']) //last
|
||||
{
|
||||
$allowed_flag_peer_id = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // no need to compare version
|
||||
$allowed_flag_peer_id = true;
|
||||
}
|
||||
}
|
||||
else // not need to match pattern
|
||||
$allowed_flag_peer_id = true;
|
||||
|
||||
if($row_allowed_ua['agent_pattern'] != '')
|
||||
{
|
||||
if(!preg_match($row_allowed_ua['agent_pattern'], $row_allowed_ua['agent_start'], $match_bench))
|
||||
err("regular expression err for: " . $row_allowed_ua['agent_start'] . ", please ask sysop to fix this");
|
||||
|
||||
if(preg_match($row_allowed_ua['agent_pattern'], $agent, $match_target))
|
||||
{
|
||||
if( $row_allowed_ua['agent_match_num'] != 0)
|
||||
{
|
||||
for($i = 0 ; $i < $row_allowed_ua['agent_match_num']; $i++)
|
||||
{
|
||||
if($row_allowed_ua['agent_matchtype'] == 'dec')
|
||||
{
|
||||
$match_target[$i+1] = 0 + $match_target[$i+1];
|
||||
$match_bench[$i+1] = 0 + $match_bench[$i+1];
|
||||
}
|
||||
else if($row_allowed_ua['agent_matchtype'] == 'hex')
|
||||
{
|
||||
$match_target[$i+1] = hexdec($match_target[$i+1]);
|
||||
$match_bench[$i+1] = hexdec($match_bench[$i+1]);
|
||||
}
|
||||
|
||||
if ($match_target[$i+1] > $match_bench[$i+1])
|
||||
{
|
||||
$allowed_flag_agent = true;
|
||||
break;
|
||||
}
|
||||
else if($match_target[$i+1] < $match_bench[$i+1])
|
||||
{
|
||||
$allowed_flag_agent = false;
|
||||
$version_low_agent = true;
|
||||
$low_version = "Your " . $row_allowed_ua['family'] . " 's version is too low, please update it after " . $row_allowed_ua['start_name'];
|
||||
break;
|
||||
}
|
||||
else //equal
|
||||
{
|
||||
if($i+1 == $row_allowed_ua['agent_match_num']) //last
|
||||
$allowed_flag_agent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // no need to compare version
|
||||
$allowed_flag_agent = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
$allowed_flag_agent = true;
|
||||
|
||||
if($allowed_flag_peer_id && $allowed_flag_agent)
|
||||
{
|
||||
$exception = $row_allowed_ua['exception'];
|
||||
$family_id = $row_allowed_ua['id'];
|
||||
$allow_https = $row_allowed_ua['allowhttps'];
|
||||
break;
|
||||
}
|
||||
elseif(($allowed_flag_peer_id || $allowed_flag_agent) || ($version_low_peer_id || $version_low_agent)) //client spoofing possible
|
||||
;//add anti-cheat code here
|
||||
}
|
||||
|
||||
if($allowed_flag_peer_id && $allowed_flag_agent)
|
||||
{
|
||||
if($exception == 'yes')
|
||||
{
|
||||
if (!$clients_exp = $Cache->get_value('allowed_client_exception_family_'.$family_id.'_list')){
|
||||
$clients_exp = array();
|
||||
$res = mysql_query("SELECT * FROM agent_allowed_exception WHERE family_id = $family_id") or err("check err");
|
||||
while ($row = mysql_fetch_array($res))
|
||||
$clients_exp[] = $row;
|
||||
$Cache->cache_value('allowed_client_exception_family_'.$family_id.'_list', $clients_exp, 86400);
|
||||
}
|
||||
if($clients_exp)
|
||||
{
|
||||
foreach ($clients_exp as $row_allowed_ua_exp)
|
||||
{
|
||||
if($row_allowed_ua_exp['agent'] == $agent && preg_match("/^" . $row_allowed_ua_exp['peer_id'] . "/", $peer_id))
|
||||
return "Client " . $row_allowed_ua_exp['name'] . " is banned due to: " . $row_allowed_ua_exp['comment'] . ".";
|
||||
}
|
||||
}
|
||||
$agent_familyid = $row_allowed_ua['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$agent_familyid = $row_allowed_ua['id'];
|
||||
}
|
||||
|
||||
if($_SERVER["HTTPS"] == "on")
|
||||
{
|
||||
if($allow_https == 'yes')
|
||||
return 0;
|
||||
else
|
||||
return "This client does not support https well, Please goto $BASEURL/faq.php#id29 for a list of proper clients";
|
||||
}
|
||||
else
|
||||
return 0; // no exception found, so allowed or just allowed
|
||||
}
|
||||
else
|
||||
{
|
||||
if($version_low_peer_id && $version_low_agent)
|
||||
return $low_version;
|
||||
else
|
||||
return "Banned Client, Please goto $BASEURL/faq.php#id29 for a list of acceptable clients";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
if(!defined('IN_TRACKER'))
|
||||
die('Hacking attempt!');
|
||||
|
||||
function get_global_sp_state()
|
||||
{
|
||||
global $Cache;
|
||||
static $global_promotion_state;
|
||||
if (!$global_promotion_state){
|
||||
if (!$global_promotion_state = $Cache->get_value('global_promotion_state')){
|
||||
$res = mysql_query("SELECT * FROM torrents_state");
|
||||
$row = mysql_fetch_assoc($res);
|
||||
$global_promotion_state = $row["global_sp_state"];
|
||||
$Cache->cache_value('global_promotion_state', $global_promotion_state, 57226);
|
||||
}
|
||||
}
|
||||
return $global_promotion_state;
|
||||
}
|
||||
|
||||
// IP Validation
|
||||
function validip($ip)
|
||||
{
|
||||
if (!ip2long($ip)) //IPv6
|
||||
return true;
|
||||
if (!empty($ip) && $ip == long2ip(ip2long($ip)))
|
||||
{
|
||||
// reserved IANA IPv4 addresses
|
||||
// http://www.iana.org/assignments/ipv4-address-space
|
||||
$reserved_ips = array (
|
||||
array('192.0.2.0','192.0.2.255'),
|
||||
array('192.168.0.0','192.168.255.255'),
|
||||
array('255.255.255.0','255.255.255.255')
|
||||
);
|
||||
|
||||
foreach ($reserved_ips as $r)
|
||||
{
|
||||
$min = ip2long($r[0]);
|
||||
$max = ip2long($r[1]);
|
||||
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
function getip() {
|
||||
if (isset($_SERVER)) {
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && validip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && validip($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} else {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
} else {
|
||||
if (getenv('HTTP_X_FORWARDED_FOR') && validip(getenv('HTTP_X_FORWARDED_FOR'))) {
|
||||
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
||||
} elseif (getenv('HTTP_CLIENT_IP') && validip(getenv('HTTP_CLIENT_IP'))) {
|
||||
$ip = getenv('HTTP_CLIENT_IP');
|
||||
} else {
|
||||
$ip = getenv('REMOTE_ADDR');
|
||||
}
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
function sql_query($query)
|
||||
{
|
||||
global $query_name;
|
||||
$query_name[] = $query;
|
||||
return mysql_query($query);
|
||||
}
|
||||
|
||||
function sqlesc($value) {
|
||||
$value = "'" . mysql_real_escape_string($value) . "'";
|
||||
return $value;
|
||||
}
|
||||
|
||||
function hash_pad($hash) {
|
||||
return str_pad($hash, 20);
|
||||
}
|
||||
|
||||
function hash_where($name, $hash) {
|
||||
$shhash = preg_replace('/ *$/s', "", $hash);
|
||||
return "($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$mechs = array('LOGIN', 'PLAIN', 'CRAM_MD5');
|
||||
|
||||
foreach ($mechs as $mech) {
|
||||
if (!defined($mech)) {
|
||||
define($mech, $mech);
|
||||
} elseif (constant($mech) != $mech) {
|
||||
trigger_error(sprintf("Constant %s already defined, can't proceed", $mech), E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SASL Mechanisms
|
||||
* @package SASL
|
||||
* @author Fredrik Haugbergsmyr <smtp.lib@lagnut.net>
|
||||
*/
|
||||
$rootpath = './';
|
||||
require_once ($rootpath . 'include/smtp/net.const.php');
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @access public
|
||||
* @todo phpdoc
|
||||
*/
|
||||
class sasl
|
||||
{
|
||||
|
||||
|
||||
function _hmac_md5($key, $data)
|
||||
{
|
||||
if (strlen($key) > 64) {
|
||||
$key = pack('H32', md5($key));
|
||||
}
|
||||
|
||||
if (strlen($key) < 64) {
|
||||
$key = str_pad($key, 64, chr(0));
|
||||
}
|
||||
|
||||
$k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
|
||||
$k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
|
||||
|
||||
$inner = pack('H32', md5($k_ipad . $data));
|
||||
$digest = md5($k_opad . $inner);
|
||||
|
||||
return $digest;
|
||||
}
|
||||
|
||||
function cram_md5($user, $pass, $challenge)
|
||||
{
|
||||
var_dump($challenge);
|
||||
$chall = base64_decode($challenge);
|
||||
var_dump($chall);
|
||||
return base64_encode(sprintf('%s %s', $user, $this->_hmac_md5($pass, $chall)));
|
||||
}
|
||||
|
||||
function plain($username, $password)
|
||||
{
|
||||
return base64_encode(sprintf('%c%s%c%s', 0, $username, 0, $password));
|
||||
}
|
||||
|
||||
function login($input)
|
||||
{
|
||||
return base64_encode(sprintf('%s', $input));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,531 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Allows users to send email without e-mailserver on the localmachine
|
||||
* @package SMTP
|
||||
* @author Fredrik Haugbergsmyr <smtp.lib@lagnut.net>
|
||||
*/
|
||||
|
||||
require_once ('net.const.php');
|
||||
|
||||
/**
|
||||
* @version 0.0.2.2
|
||||
* @access public
|
||||
* @todo split messages, attachments
|
||||
*/
|
||||
class smtp
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* lagnut-smtp version, send in the headers
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_version = '0.0.2.2';
|
||||
|
||||
|
||||
/**
|
||||
* Turn debugon / off
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $_debug = false;
|
||||
|
||||
|
||||
/**
|
||||
* Serverconnection resource
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $_connection = null;
|
||||
|
||||
|
||||
/**
|
||||
* E-mailheaders
|
||||
*
|
||||
* @var array headers
|
||||
* @access private
|
||||
*/
|
||||
var $_hdrs = array();
|
||||
|
||||
|
||||
/**
|
||||
* E-mailbody
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_body = '';
|
||||
|
||||
|
||||
/**
|
||||
* Default Content type
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_mime = 'text/html';
|
||||
|
||||
|
||||
/**
|
||||
* Default Charset
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Default Transfer-Content-Encoding
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_CTEncoding = 'base64';
|
||||
|
||||
// These are actually not necessary, but for the shitty eYou email system
|
||||
/**
|
||||
* Charset for Special Case
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_charset_eYou = 'GBK';
|
||||
|
||||
/**
|
||||
* Charset for Special Case
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_specialcase = 'eYou';
|
||||
|
||||
/**
|
||||
* Class contruction, sets client headers
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function smtp($charset = 'UTF-8', $specialcase = "")
|
||||
{
|
||||
$this->_specialcase = $specialcase;
|
||||
$this->_charset = $charset;
|
||||
$this->_add_hdr('X-Mailer', sprintf('LAGNUT-SMTP/%s', $this->_version));
|
||||
$this->_add_hdr('User-Agent', sprintf('LAGNUT-SMTP/%s', $this->_version));
|
||||
$this->_add_hdr('MIME-Version', '1.0');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Turn debugging on/off
|
||||
*
|
||||
* @access public
|
||||
* @param bool $debug command
|
||||
*/
|
||||
function debug($debug)
|
||||
{
|
||||
$this->_debug = (bool)$debug;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean input to prevent injection
|
||||
*
|
||||
* @param string $input User data
|
||||
*/
|
||||
function _clean(&$input)
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
$input = urldecode($input);
|
||||
$input = str_replace("\n", '', str_replace("\r", '', $input));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send command to server
|
||||
*
|
||||
* @access private
|
||||
* @param string $cmdcommand
|
||||
* @param optional $data data
|
||||
*/
|
||||
function _cmd($cmd, $data = false)
|
||||
{
|
||||
$this->_clean($cmd);
|
||||
$this->_clean($data);
|
||||
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$command = sprintf("%s\r\n", $cmd);
|
||||
}else {
|
||||
$command = sprintf("%s: %s\r\n", $cmd,$data);
|
||||
}
|
||||
|
||||
fwrite($this->_connection, $command);
|
||||
$resp = $this->_read();
|
||||
if ($this->_debug){
|
||||
printf($command);
|
||||
printf($resp);
|
||||
}
|
||||
if ($this->_is_closed($resp)) {
|
||||
return false;
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collects header
|
||||
*
|
||||
* @access private
|
||||
* @param string$key
|
||||
* @param string $data
|
||||
*/
|
||||
function _add_hdr($key, $data)
|
||||
{
|
||||
$this->_clean($key);
|
||||
$this->_clean($data);
|
||||
$this->_hdrs[$key] = sprintf("%s: %s\r\n", $key, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read server output
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _read()
|
||||
{
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
$o = '';
|
||||
do {
|
||||
$str = @fgets($this->_connection, 515);
|
||||
if (!$str) {
|
||||
break;
|
||||
}
|
||||
$o .= $str;
|
||||
if (substr($str, 3, 1) == ' ') {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if server denies more commands
|
||||
*
|
||||
* @access private
|
||||
* @param $int
|
||||
* @return bool true if connection is closed
|
||||
*/
|
||||
function _is_closed($response = false)
|
||||
{
|
||||
if (!$this->_connection) {
|
||||
return true;
|
||||
}
|
||||
if (isset($response{0}) && ($response{0} == 4|| $response{0}== 5)) {
|
||||
$this->close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open connection to server
|
||||
*
|
||||
* @access public
|
||||
* @param string $server SMTP server
|
||||
* @param int $port Server port
|
||||
*/
|
||||
function open($server, $port = 25)
|
||||
{
|
||||
$this->_connection = fsockopen($server, $port, $e, $er, 8);
|
||||
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$init= $this->_read();
|
||||
if ($this->_debug){
|
||||
printf($init);
|
||||
}
|
||||
|
||||
if ($this->_is_closed($init)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lhost = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1');
|
||||
|
||||
if (strpos($init,'ESMTP') === false){
|
||||
$this->_cmd('HELO '. gethostbyaddr($lhost));
|
||||
} else {
|
||||
$this->_cmd('EHLO '. gethostbyaddr($lhost));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start TLS communication
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function start_tls()
|
||||
{
|
||||
if (!function_exists('stream_socket_enable_crypto')) {
|
||||
trigger_error('TLS is not supported', E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$this->_cmd('STARTTLS');
|
||||
stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs SMTP authentication
|
||||
*
|
||||
* @access public
|
||||
* @param string $username username
|
||||
* @param string $password password
|
||||
* @param int authentication mecanism
|
||||
*/
|
||||
function auth($username, $password, $type = LOGIN)
|
||||
{
|
||||
|
||||
include_once ('sasl.lib.php');
|
||||
$sasl =& new sasl($sasl, $username, $password);
|
||||
switch ($type) {
|
||||
case PLAIN:
|
||||
$this->_cmd('AUTH PLAIN');
|
||||
$this->_cmd($sasl->plain($username, $password));
|
||||
break;
|
||||
case LOGIN:
|
||||
$this->_cmd('AUTH LOGIN');
|
||||
$this->_cmd($sasl->login($username));
|
||||
$this->_cmd($sasl->login($password));
|
||||
break;
|
||||
case CRAM_MD5:
|
||||
$resp = explode(' ', $this->_cmd('AUTH CRAM-MD5'));
|
||||
$this->_cmd($sasl->cram_md5($username, $password, trim($resp[1])));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes connection to the server
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_cmd('RSET');
|
||||
$this->_cmd('QUIT');
|
||||
fclose($this->_connection);
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail sender
|
||||
*
|
||||
* @access public
|
||||
* @param string $from Sender
|
||||
*/
|
||||
function from($email, $name = '')
|
||||
{
|
||||
$from = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_cmd('MAIL FROM', sprintf('<%s>', $email));
|
||||
$this->_add_hdr('FROM', $from);
|
||||
$this->_add_hdr('Return-path', $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set BCC header
|
||||
*
|
||||
* @access public
|
||||
* @param string $tolist recipients whose email address should be concealed
|
||||
*/
|
||||
function bcc($tolist)
|
||||
{
|
||||
$this->_add_hdr('Bcc', $tolist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send reply-to header
|
||||
*
|
||||
* @param string $to
|
||||
*/
|
||||
function reply_to($email, $name = '')
|
||||
{
|
||||
$to = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_add_hdr('REPLY-TO', $to);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $to Reciever
|
||||
*/
|
||||
function to($email, $name = '')
|
||||
{
|
||||
$to = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_cmd('RCPT TO', sprintf('<%s>', $email));
|
||||
$this->_add_hdr('TO', $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $email Reciever, with out other recepients info disclosed
|
||||
*/
|
||||
function multi_to($email)
|
||||
{
|
||||
$this->_cmd('RCPT TO', sprintf('<%s>', $email));
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $email TO head on mass mailing
|
||||
*/
|
||||
function multi_to_head($to)
|
||||
{
|
||||
$this->_add_hdr('TO', $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIME type
|
||||
*
|
||||
* @access public
|
||||
* @param string $mime MIME type
|
||||
*/
|
||||
function mime_charset($mime = 'text/html',$charset = 'UTF-8')
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_mime = $mime;
|
||||
$this->_add_hdr('Content-type', sprintf('%s; charset=%s', $this->_mime, $this->_charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* MIME Content-Transfer-Encoding
|
||||
*
|
||||
* @access public
|
||||
* @param string $mime MIME type
|
||||
*/
|
||||
function mime_content_transfer_encoding($CTEncoding = 'base64')
|
||||
{
|
||||
$this->_CTEncoding = $CTEncoding;
|
||||
$this->_add_hdr('Content-Transfer-Encoding', sprintf('%s', $this->_CTEncoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail subject
|
||||
*
|
||||
* @access public
|
||||
* @param string $subject subject
|
||||
*/
|
||||
function subject($subject)
|
||||
{
|
||||
$this->_clean($subject);
|
||||
|
||||
if($this->_specialcase = "")
|
||||
$this->_add_hdr('SUBJECT', $this->encode_hdrs($subject));
|
||||
elseif($this->_specialcase = "eYou")
|
||||
{
|
||||
$temp = $this->_charset;
|
||||
$this->_charset = $this->_charset_eYou;
|
||||
$this->_add_hdr('SUBJECT', $this->encode_hdrs($subject));
|
||||
$this->_charset = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail body
|
||||
*
|
||||
* @access public
|
||||
* @param string $body body
|
||||
*/
|
||||
function body($body)
|
||||
{
|
||||
$body = preg_replace("/([\n|\r])\.([\n|\r])/", "$1..$2", $body);
|
||||
|
||||
if($this->_CTEncoding == 'base64')
|
||||
$this->_body = sprintf("\r\n%s", base64_encode($body));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send the mail
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function send()
|
||||
{
|
||||
$resp = $this->_cmd('DATA');
|
||||
if ($this->_is_closed($resp)) {
|
||||
$this->close();
|
||||
return false;
|
||||
}
|
||||
foreach ($this->_hdrs as $header) {
|
||||
fwrite($this->_connection, $header);
|
||||
if ($this->_debug) {
|
||||
printf($header);
|
||||
}
|
||||
}
|
||||
fwrite($this->_connection,$this->_body);
|
||||
fwrite($this->_connection, "\r\n.\r\n");
|
||||
$resp = trim($this->_read());
|
||||
if ($this->_debug){
|
||||
printf("%s\r\n", $this->_body);
|
||||
printf("\r\n.\r\n");
|
||||
printf('%s', $resp);
|
||||
}
|
||||
if ((int)$resp{0} != 2) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* encode headers
|
||||
*
|
||||
* @access private
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
function encode_hdrs($input)
|
||||
{
|
||||
$replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $input);
|
||||
|
||||
$input = str_replace($input, sprintf('=?%s?Q?%s?=', $this->_charset, $replacement), $input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user