From 882d67796048c8243130a9a1af5e92dacaa7d43d Mon Sep 17 00:00:00 2001 From: xiaomlove <353856593@qq.com> Date: Fri, 12 Mar 2021 20:50:55 +0800 Subject: [PATCH] clean up add log --- include/cleanup.php | 877 ++++++++++++++++++++++++-------------------- public/announce.php | 3 +- 2 files changed, 485 insertions(+), 395 deletions(-) diff --git a/include/cleanup.php b/include/cleanup.php index 200fe8a3..8721d30a 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -4,206 +4,11 @@ if(!defined('IN_TRACKER')) die('Hacking attempt!'); function printProgress($msg) { - do_log($msg); echo $msg.'...done
'; 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)))); @@ -260,152 +65,7 @@ function torrent_promotion_expire($days, $type = 2, $targettype = 1){ 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=null 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 = null, 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; @@ -428,17 +88,6 @@ function peasant_to_user($down_floor_gb, $down_roof_gb, $minratio){ } } - 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; @@ -464,21 +113,7 @@ function promotion($class, $down_floor_gb, $minratio, $time_week, $addinvite = 0 } } } - //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; @@ -496,21 +131,7 @@ function demotion($class,$deratio){ } } } - //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; @@ -533,13 +154,452 @@ function user_to_peasant($down_floor_gb, $minratio){ } } +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(); + do_log("start docleanup(), forceAll: $forceAll, printProgress: $printProgress, now: $now, " . date('Y-m-d H:i:s', $now)); + +//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__); + $log = 'update peer status'; + do_log($log); + if ($printProgress) { + printProgress($log); + } +//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"]); + } + } + $log = 'calculate seeding bonus'; + do_log($log); + if ($printProgress) { + printProgress($log); + } + +//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__); + do_log("no value for arg: 'lastcleantime2', return"); + return; + } + $ts = $row[0]; + if ($ts + $autoclean_interval_two > $now && !$forceAll) { + $log = 'Cleanup ends at Priority Class 1'; + do_log($log . ", $ts + $autoclean_interval_two > $now"); + return $log; + } 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__); + $log = "update torrents' visibility"; + do_log($log); + if ($printProgress) { + printProgress($log); + } +//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__); + do_log("no value for arg: 'lastcleantime3', return"); + return; + } + $ts = $row[0]; + if ($ts + $autoclean_interval_three > $now && !$forceAll) { + $log = 'Cleanup ends at Priority Class 2'; + do_log($log . ", $ts + $autoclean_interval_three > $now"); + return $log; + } 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__); + } + $log = "update count of seeders, leechers, comments for torrents"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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'); + $log = "update forum post/topic count"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + //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'); + } + } + $log = "delete offers if not voted on after some time"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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'); + } + } + $log = "delete offers if not uploaded after being voted on for some time."; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //15.cleanup torrents + //Start: expire torrent promotion + 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=null 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 + $log = "expire torrent promotion"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + //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) { + $log = "automatically pick hot"; + do_log($log); + printProgress($log); + } + +//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__); + do_log("no value for arg: 'lastcleantime4', return"); + return; + } + $ts = $row[0]; + if ($ts + $autoclean_interval_four > $now && !$forceAll) { + $log = 'Cleanup ends at Priority Class 3'; + do_log($log . ", $ts + $autoclean_interval_four > $now"); + return $log; + } 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__); + $log = "delete unconfirmed accounts"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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__); + $log = "delete old login attempts"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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__); + $log = "delete old invite codes"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //7.delete regimage codes + sql_query("TRUNCATE TABLE `regimages`") or sqlerr(__FILE__, __LINE__); + $log = "delete regimage codes"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + //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__); + } + $log = "delete inactive user accounts, no transfer. Alt. 1: last access time"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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__); + } + $log = "delete inactive user accounts, no transfer. Alt. 2: registering time"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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__); + } + $log = "delete inactive user accounts, not parked"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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__); + } + $log = "delete parked user accounts, parked"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //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 = null, 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__); + } + } + $log = "remove VIP status if time's up"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + // promote peasant back to user + + 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); + $log = "promote peasant back to user"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + //end promote peasant back to user + + // start promotion + //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 + $log = "promote users to other classes"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + // start demotion + + //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); + $log = "demote users to other classes"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + // end demotion + + // start demote users to peasant + 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); + $log = "demote Users to peasant"; + do_log($log); if ($printProgress) { - printProgress("demote Users to peasant"); + printProgress($log); } // end Users to Peasant @@ -556,8 +616,10 @@ function user_to_peasant($down_floor_gb, $minratio){ sql_query("UPDATE users SET enabled = 'no', leechwarnuntil = null WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); } } + $log = "ban users with leechwarning expired"; + do_log($log); if ($printProgress) { - printProgress("ban users with leechwarning expired"); + printProgress($log); } //Remove warning of users @@ -575,8 +637,10 @@ function user_to_peasant($down_floor_gb, $minratio){ sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, $arr[id], $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__); } } + $log = "remove warning of users"; + do_log($log); if ($printProgress) { - printProgress("remove warning of users"); + printProgress($log); } //17.update total seeding and leeching time of users @@ -592,8 +656,10 @@ function user_to_peasant($down_floor_gb, $minratio){ sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__); } + $log = "update total seeding and leeching time of users"; + do_log($log); if ($printProgress) { - printProgress("update total seeding and leeching time of users"); + printProgress($log); } // delete torrents that have been dead for a long time @@ -611,8 +677,10 @@ function user_to_peasant($down_floor_gb, $minratio){ write_log("Torrent $arr[id] ($arr[name]) is deleted by system because of being dead for a long time.",'normal'); } } + $log = "delete torrents that have been dead for a long time"; + do_log($log); if ($printProgress) { - printProgress("delete torrents that have been dead for a long time"); + printProgress($log); } //Priority Class 5: cleanup every 15 days @@ -620,11 +688,14 @@ function user_to_peasant($down_floor_gb, $minratio){ $row = mysql_fetch_array($res); if (!$row) { sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime5',$now)") or sqlerr(__FILE__, __LINE__); + do_log("no value for arg: 'lastcleantime5', return"); return; } $ts = $row[0]; if ($ts + $autoclean_interval_five > $now && !$forceAll) { - return 'Cleanup ends at Priority Class 4'; + $log = 'Cleanup ends at Priority Class 4'; + do_log($log . ", $ts + $autoclean_interval_five > $now"); + return $log; } else { sql_query("UPDATE avps SET value_u = ".sqlesc($now)." WHERE arg='lastcleantime5'") or sqlerr(__FILE__, __LINE__); } @@ -635,16 +706,20 @@ function user_to_peasant($down_floor_gb, $minratio){ $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'])); } + $log = "update clients' popularity"; + do_log($log); if ($printProgress) { - printProgress("update clients' popularity"); + printProgress($log); } //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)); + $log = "delete old messages sent by system"; + do_log($log); if ($printProgress) { - printProgress("delete old messages sent by system"); + printProgress($log); } //delete old readpost records @@ -655,24 +730,30 @@ function user_to_peasant($down_floor_gb, $minratio){ sql_query("UPDATE users SET last_catchup = ".sqlesc($postIdHalfYearAgo)." WHERE last_catchup < ".sqlesc($postIdHalfYearAgo)); sql_query("DELETE FROM readposts WHERE lastpostread < ".sqlesc($postIdHalfYearAgo)); } + $log = "delete old readpost records"; + do_log($log); if ($printProgress) { - printProgress("delete old readpost records"); + printProgress($log); } //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)); + $log = "delete old ip log"; + do_log($log); if ($printProgress) { - printProgress("delete old ip log"); + printProgress($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__); + $log = "delete old general log"; + do_log($log); if ($printProgress) { - printProgress("delete old general log"); + printProgress($log); } //1.delete torrents that doesn't exist any more @@ -740,24 +821,32 @@ function user_to_peasant($down_floor_gb, $minratio){ 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"); + $log = "delete torrents that doesn't exist any more"; + do_log($log); + printProgress($log); } //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__); + $log = "lock topics where last post was made more than x days ago"; + do_log($log); if ($printProgress) { - printProgress("lock topics where last post was made more than x days ago"); + printProgress($log); } //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__); + $log = "delete report items older than four week"; + do_log($log); if ($printProgress) { - printProgress("delete report items older than four week"); + printProgress($log); } - return 'Full cleanup is done'; + $log = 'Full cleanup is done'; + do_log($log); + return $log; } ?> diff --git a/public/announce.php b/public/announce.php index 4d4e9e19..79f02d08 100644 --- a/public/announce.php +++ b/public/announce.php @@ -220,7 +220,7 @@ else // continue an existing session { $upthis = $trueupthis = max(0, $uploaded - $self["uploaded"]); $downthis = $truedownthis = max(0, $downloaded - $self["downloaded"]); - $announcetime = ($self["seeder"] == "yes" ? "seedtime = seedtime + $self[announcetime]" : "leechtime = leechtime + $self[announcetime]"); + $announcetime = ($self["seeder"] == "yes" ? "seedtime = seedtime + {$self['announcetime']}" : "leechtime = leechtime + {$self['announcetime']}"); $is_cheater = false; if ($cheaterdet_security){ @@ -229,6 +229,7 @@ else // continue an existing session $is_cheater = check_cheater($userid, $torrent['id'], $upthis, $downthis, $self['announcetime'], $torrent['seeders'], $torrent['leechers']); } } + do_log("upthis: $upthis, downthis: $downthis, announcetime: $announcetime, is_cheater: $is_cheater"); if (!$is_cheater && ($trueupthis > 0 || $truedownthis > 0)) {