expire and gprobe now moved as well
This commit is contained in:
parent
27af65918e
commit
501514bd54
7 changed files with 153 additions and 143 deletions
|
@ -1,76 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
|
||||||
use Friendica\Core\Worker;
|
|
||||||
use Friendica\Database\DBM;
|
|
||||||
|
|
||||||
function expire_run(&$argv, &$argc){
|
|
||||||
global $a;
|
|
||||||
|
|
||||||
require_once('include/datetime.php');
|
|
||||||
require_once('include/items.php');
|
|
||||||
require_once('include/Contact.php');
|
|
||||||
|
|
||||||
load_hooks();
|
|
||||||
|
|
||||||
if (($argc == 2) && ($argv[1] == 'delete')) {
|
|
||||||
logger('Delete expired items', LOGGER_DEBUG);
|
|
||||||
// physically remove anything that has been deleted for more than two months
|
|
||||||
$r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
|
||||||
while ($row = dba::fetch($r)) {
|
|
||||||
dba::delete('item', array('id' => $row['id']));
|
|
||||||
}
|
|
||||||
dba::close($r);
|
|
||||||
|
|
||||||
logger('Delete expired items - done', LOGGER_DEBUG);
|
|
||||||
|
|
||||||
// make this optional as it could have a performance impact on large sites
|
|
||||||
if (intval(Config::get('system', 'optimize_items'))) {
|
|
||||||
q("OPTIMIZE TABLE `item`");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} elseif (($argc == 2) && (intval($argv[1]) > 0)) {
|
|
||||||
$user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $argv[1]), array('limit' => 1));
|
|
||||||
if (DBM::is_result($user)) {
|
|
||||||
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
|
|
||||||
item_expire($user['uid'], $user['expire']);
|
|
||||||
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} elseif (($argc == 3) && ($argv[1] == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
|
|
||||||
foreach ($a->hooks["expire"] as $hook) {
|
|
||||||
if ($hook[1] == $argv[2]) {
|
|
||||||
logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
|
|
||||||
call_single_hook($a, $name, $hook, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger('expire: start');
|
|
||||||
|
|
||||||
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
|
||||||
'expire', 'delete');
|
|
||||||
|
|
||||||
$r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
|
|
||||||
while ($row = dba::fetch($r)) {
|
|
||||||
logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
|
|
||||||
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
|
||||||
'expire', (int)$row['uid']);
|
|
||||||
}
|
|
||||||
dba::close($r);
|
|
||||||
|
|
||||||
logger('expire: calling hooks');
|
|
||||||
|
|
||||||
if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
|
|
||||||
foreach ($a->hooks['expire'] as $hook) {
|
|
||||||
logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
|
|
||||||
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
|
||||||
'expire', 'hook', $hook[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger('expire: end');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @file include/gprobe.php
|
|
||||||
*/
|
|
||||||
use Friendica\Core\Cache;
|
|
||||||
use Friendica\Core\Config;
|
|
||||||
use Friendica\Database\DBM;
|
|
||||||
use Friendica\Model\GlobalContact;
|
|
||||||
use Friendica\Network\Probe;
|
|
||||||
use Friendica\Protocol\PortableContact;
|
|
||||||
|
|
||||||
require_once 'include/datetime.php';
|
|
||||||
|
|
||||||
function gprobe_run(&$argv, &$argc)
|
|
||||||
{
|
|
||||||
if ($argc != 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$url = $argv[1];
|
|
||||||
|
|
||||||
$r = q(
|
|
||||||
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
|
||||||
dbesc(normalise_link($url))
|
|
||||||
);
|
|
||||||
|
|
||||||
logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
|
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
// Is it a DDoS attempt?
|
|
||||||
$urlparts = parse_url($url);
|
|
||||||
|
|
||||||
$result = Cache::get("gprobe:".$urlparts["host"]);
|
|
||||||
if (!is_null($result)) {
|
|
||||||
if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
|
||||||
logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$arr = Probe::uri($url);
|
|
||||||
|
|
||||||
if (is_null($result)) {
|
|
||||||
Cache::set("gprobe:".$urlparts["host"], $arr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
|
||||||
GlobalContact::update($arr);
|
|
||||||
}
|
|
||||||
|
|
||||||
$r = q(
|
|
||||||
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
|
||||||
dbesc(normalise_link($url))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
// Check for accessibility and do a poco discovery
|
|
||||||
if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
|
|
||||||
PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
|
||||||
return;
|
|
||||||
}
|
|
|
@ -939,7 +939,7 @@ function zrl_init(App $a)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
|
Worker::add(PRIORITY_LOW, 'GProbe', $tmp_str);
|
||||||
$arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
|
$arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
|
||||||
call_hooks('zrl_init', $arr);
|
call_hooks('zrl_init', $arr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -688,7 +688,7 @@ class GlobalContact
|
||||||
|
|
||||||
if ($doprobing) {
|
if ($doprobing) {
|
||||||
logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG);
|
logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG);
|
||||||
Worker::add(PRIORITY_LOW, 'gprobe', $contact["url"]);
|
Worker::add(PRIORITY_LOW, 'GProbe', $contact["url"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $gcontact_id;
|
return $gcontact_id;
|
||||||
|
|
|
@ -79,7 +79,7 @@ Class Cron {
|
||||||
|
|
||||||
Config::set('system', 'last_expire_day', $d2);
|
Config::set('system', 'last_expire_day', $d2);
|
||||||
|
|
||||||
Worker::add(PRIORITY_LOW, 'expire');
|
Worker::add(PRIORITY_LOW, 'Expire');
|
||||||
|
|
||||||
Worker::add(PRIORITY_MEDIUM, 'DBClean');
|
Worker::add(PRIORITY_MEDIUM, 'DBClean');
|
||||||
|
|
||||||
|
|
85
src/Worker/Expire.php
Normal file
85
src/Worker/Expire.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file src/Worker/Expire.php
|
||||||
|
* @brief Expires old item entries
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Worker;
|
||||||
|
|
||||||
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Database\DBM;
|
||||||
|
use dba;
|
||||||
|
|
||||||
|
class Expire {
|
||||||
|
public static function execute($param = '', $hook_name = '') {
|
||||||
|
global $a;
|
||||||
|
|
||||||
|
require_once('include/datetime.php');
|
||||||
|
require_once('include/items.php');
|
||||||
|
require_once('include/Contact.php');
|
||||||
|
|
||||||
|
load_hooks();
|
||||||
|
|
||||||
|
if ($param == 'delete') {
|
||||||
|
logger('Delete expired items', LOGGER_DEBUG);
|
||||||
|
// physically remove anything that has been deleted for more than two months
|
||||||
|
$r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
||||||
|
while ($row = dba::fetch($r)) {
|
||||||
|
dba::delete('item', array('id' => $row['id']));
|
||||||
|
}
|
||||||
|
dba::close($r);
|
||||||
|
|
||||||
|
logger('Delete expired items - done', LOGGER_DEBUG);
|
||||||
|
|
||||||
|
// make this optional as it could have a performance impact on large sites
|
||||||
|
if (intval(Config::get('system', 'optimize_items'))) {
|
||||||
|
dba::e("OPTIMIZE TABLE `item`");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} elseif (intval($param) > 0) {
|
||||||
|
$user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $param), array('limit' => 1));
|
||||||
|
if (DBM::is_result($user)) {
|
||||||
|
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
|
||||||
|
item_expire($user['uid'], $user['expire']);
|
||||||
|
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} elseif (!empty($hook_name) && ($param == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
|
||||||
|
foreach ($a->hooks["expire"] as $hook) {
|
||||||
|
if ($hook[1] == $hook_name) {
|
||||||
|
logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||||
|
call_single_hook($a, $name, $hook, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger('expire: start');
|
||||||
|
|
||||||
|
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||||
|
'expire', 'delete');
|
||||||
|
|
||||||
|
$r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
|
||||||
|
while ($row = dba::fetch($r)) {
|
||||||
|
logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
|
||||||
|
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||||
|
'expire', (int)$row['uid']);
|
||||||
|
}
|
||||||
|
dba::close($r);
|
||||||
|
|
||||||
|
logger('expire: calling hooks');
|
||||||
|
|
||||||
|
if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
|
||||||
|
foreach ($a->hooks['expire'] as $hook) {
|
||||||
|
logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||||
|
Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||||
|
'expire', 'hook', $hook[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger('expire: end');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
65
src/Worker/GProbe.php
Normal file
65
src/Worker/GProbe.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file include/gprobe.php
|
||||||
|
*/
|
||||||
|
use Friendica\Core\Cache;
|
||||||
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Database\DBM;
|
||||||
|
use Friendica\Model\GlobalContact;
|
||||||
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\PortableContact;
|
||||||
|
|
||||||
|
require_once 'include/datetime.php';
|
||||||
|
|
||||||
|
class GProbe {
|
||||||
|
function execute($url = '')
|
||||||
|
{
|
||||||
|
if (empty($url)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = q(
|
||||||
|
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||||
|
dbesc(normalise_link($url))
|
||||||
|
);
|
||||||
|
|
||||||
|
logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
|
||||||
|
|
||||||
|
if (!DBM::is_result($r)) {
|
||||||
|
// Is it a DDoS attempt?
|
||||||
|
$urlparts = parse_url($url);
|
||||||
|
|
||||||
|
$result = Cache::get("gprobe:".$urlparts["host"]);
|
||||||
|
if (!is_null($result)) {
|
||||||
|
if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
||||||
|
logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr = Probe::uri($url);
|
||||||
|
|
||||||
|
if (is_null($result)) {
|
||||||
|
Cache::set("gprobe:".$urlparts["host"], $arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
||||||
|
GlobalContact::update($arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = q(
|
||||||
|
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||||
|
dbesc(normalise_link($url))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (DBM::is_result($r)) {
|
||||||
|
// Check for accessibility and do a poco discovery
|
||||||
|
if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
|
||||||
|
PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue