Monitoring\Metric\Clients\Connection\AbstractSocket
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 : hb.anti_spider.hit:1***ost:t8misc1.ny.7w7.us,env:prod,is_cli:0.
|
protected function writeToSocket(string $message): void
{
if (!is_resource($this->socket)) {
throw new SocketException($this->host, $this->port, "Couldn't write to socket");
}
fwrite($this->socket, $message);
}
protected function connect(string $host, int $port, int $timeout, bool $persistent): void
{
$errorNumber = 0;
$errorMessage = '';
|
| parent::writeToSocket($message);
| 1 : hb.anti_spider.hit:1***ost:t8misc1.ny.7w7.us,env:prod,is_cli:0.
| class UdpSocket extends AbstractSocket
{
private const HEADER_SIZE = 8;
protected function writeToSocket(string $message): void
{
parent::writeToSocket($message);
usleep(10);
}
protected function getUrl(string $host): string
{
return "udp://$host";
|
| $this->writeToSocket($packet);
| 1 : ["hb.anti_spider.hit***st:t8misc1.ny.7w7.us,env:prod,is_cli:0"]
| }
if (!$this->isConnected()) {
$this->connect($this->host, $this->port, $this->timeout, $this->isPersistent);
}
foreach ($this->cutIntoMtuSizedPackets($messages) as $packet) {
$this->writeToSocket($packet);
}
}
private function cutIntoMtuSizedPackets(array $messages): array
{
if ($this->allowFragmentation()) {
|
| $this->sendMessages([$message]);
| 1 : hb.anti_spider.hit:1***host:t8misc1.ny.7w7.us,env:prod,is_cli:0
| public function send(string $message): void
{
if (empty($message)) {
return;
}
$this->sendMessages([$message]);
}
public function sendMessages(array $messages): void
{
if (count($messages) === 0) {
return;
|
| $this->connection->send($message);
| 1 : hb.anti_spider.hit
1 : 1 1 : c 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| foreach ($tags as $tagName => $tagValue) {
$tagArray[] = ($tagName . ':' . $tagValue);
}
$message .= '|#' . implode(',', $tagArray);
}
$this->connection->send($message);
}
private function validateMetricName(string $metric): void
{
if (substr($metric, -1) === '.') {
return;
|
| $this->send($metric, $value, 'c', $tags);
| 1 : anti_spider.hit
1 : 1 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| $tags['event'] = $event;
$this->count($this->eventMetric, 1, $tags);
}
public function count(string $metric, float $value, array $tags = []): void
{
$this->send($metric, $value, 'c', $tags);
}
private function send(string $metric, $value, string $type, array $tags = []): void
{
$this->validateMetricName($metric);
if (!empty($this->namespace)) {
|
| $this->count($metric, $value, $tags);
| 1 : anti_spider.hit
1 : 1 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| $this->namespace = $config['namespace'] ?? '';
$this->eventMetric = $config['event_metric'] ?? self::DEFAULT_EVENT_METRIC;
}
public function increment(string $metric, int $value, array $tags = null): void
{
$this->count($metric, $value, $tags);
}
public function gauge(string $metric, float $value, array $tags = []): void
{
$this->send($metric, $value, 'g', $tags);
}
|
| $this->getClient($clientClass)->$method($metric, $value, $tags);
| 1 : increment
1 : anti_spider.hit 1 : 1 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| foreach (self::CLIENTS as $clientClass) {
if ($this->isDegraded($clientClass)) {
continue;
}
try {
$this->getClient($clientClass)->$method($metric, $value, $tags);
continue;
} catch (ValidateException $e) {
ErrorHandler::sentry()->captureException($e);
continue;
} catch (DisabledException $e) {
|
| static::i()->send('increment', $metric, $value, $tags);
| 1 : anti_spider.hit
1 : [] 1 : 1
| $this->config = CC('metric') ?? [];
$this->global_tags = $this->getGlobalTags();
}
public static function inc(string $metric, array $tags = [], int $value = 1): void
{
static::i()->send('increment', $metric, $value, $tags);
}
public static function gauge(string $metric, float $value, array $tags = []): void
{
static::i()->send(__FUNCTION__, $metric, $value, $tags);
}
|
| \Monitoring\Metric\Metrics::inc($metric, [], $value);
| 1 : {"bypass":1,"hit":1}
| foreach ($metrics as $name => $value) {
$metric = $this->prepareMetricName($this->name . '.' . $name);
if ($name === 'time') {
\Monitoring\Metric\Metrics::histogram($metric, $value);
} else {
\Monitoring\Metric\Metrics::inc($metric, [], $value);
}
}
}
private function prepareMetricName(string $metric): string
{
|
| $this->sendMetric($inc);
| 1 : {"bypass":1,"hit":1}
| if (! is_array($inc))
$inc = [$inc => 1];
if (! isset($inc['hit']))
$inc['hit'] = 1;
$this->save($inc, $data);
$this->sendMetric($inc);
}
// Compatibility ONLY !! - direct api-socket write
protected function save(array $inc=[], array $data=[]) {
Profiler::info("iStat/api(".$this->name.")", $inc + ($data ? ['data' => $data] : []));
$this->goApiSave($inc, $data);
|
| i('Stat', 'anti-spider')->hit($what);
| 1 : {"bypass":1}
| $this->C = $p + $c + self::$DEFAULT;
}
function iStat(/*array*/ $what) {
if (! is_array($what))
$what = [$what => 1];
i('Stat', 'anti-spider')->hit($what);
}
// check vs known spider and known offender list
// called when soft-limit is reached
// - allow -
function check() { # allow | block
|
| $this->iStat('bypass');
|
| private function _hit() { # null - OK, "block", "captcha"
if (Debug::is_admin() ||
(Debug::is_x_admin() && starts_with($_SERVER["HTTP_X_REAL_IP"] ?? "", "172.16.8"))
) { // donot block admins and ahm/ajax requests and webtests from local network
Profiler::info("anti-spider", "BYPASS");
$this->iStat('bypass');
return;
}
$k = $this->hitCounterKey();
$cnt = (int)Cache::get($k) + 1;
$this->hit = $cnt;
|
| $this->verdict[0] = $this->_hit(); // using array to store null
|
| // "block" - just block (offender)
PUBLIC function hit() { # null - OK, "block", "captcha"
// duplicate call elimination, call caching
if ($this->verdict)
return $this->verdict[0];
$this->verdict[0] = $this->_hit(); // using array to store null
return $this->verdict[0];
}
private function _hit() { # null - OK, "block", "captcha"
if (Debug::is_admin() ||
(Debug::is_x_admin() && starts_with($_SERVER["HTTP_X_REAL_IP"] ?? "", "172.16.8"))
|
| if ($verdict = $this->hit()) {
|
| *
* if (i("anti-spider")->captchaOrDie())
* return "captcha";
*/
PUBLIC function captchaOrDie() : bool {
if ($verdict = $this->hit()) {
if ($verdict == "captcha") {
header('HTTP/1.1 429 Too Many Requests');
return true; // "captcha";
}
// WE DO NOT NEED this reporting already have this in hit()
| Action_Phone_Phone
|
|
| <?php
class Action_Phone_Phone extends Action {
function _common() {
if (i("anti-spider")->captchaOrDie())
return "captcha";
// Do not show AdSense for requests without http_referer and not a google spider
if (!@$_SERVER["HTTP_REFERER"]) {
if (!i("anti-spider")->isGoogleIP(ip())) {
CD::set("NO_ADSENSE", 1);
| Action_Phone_Root
|
| ??? : phone
| break;
default:
$this->cssTableClass = 'b-area-code_table_2017';
$this->cssTableParentClass = 'table-responsive';
}
return parent::_common();
}
/**
*
* phoneowner.us - clone of phoneowner.com
*
|
| if ($c=$this->_common($method)) return $c;
| 1 : phone
1 : phone
| if (PHP_SAPI == 'cli')
$this->_forbidden("Can't call internal method");
}
// seems like a bug
if ($a=$this->_access($method)) return $this->$a($method); // common access handler
if ($c=$this->_common($method)) return $c;
$mex=1; // method exists
if (! method_exists($this, $method) ) {
$mex=0;
// missing method processing
Profiler::in("Action::missing method");
|
| $r = $A->_call($method, $path);
| 1 : phone
1 : {"p":"9038713532","c***n","cssTableParentClass":"table-scroll"}
| Profiler::disable();
CD::set("AJAX", 1);
}
Profiler::in("${class}::$method", $p);
$A = new $class($p);
$r = $A->_call($method, $path);
Profiler::out();
//respect called action's desire to act as AJAX.
$is_ajax = CD("AJAX");
// AJAX methods - default - no templates
if ($is_ajax) {
|
| $template = self::action($url, $params); // PARAM by REF!
| 1 : phone
1 : {"p":"9038713532","c***n","cssTableParentClass":"table-scroll"} 1 : _layout
| self::$layout=$layout;
if ($r = strpos($url,"?"))
$url = substr($url, 0, $r);
$url = substr($url,1); // remove leading "/"
restore_msg($params);
$template = self::action($url, $params); // PARAM by REF!
if (isset($_GET['TPL']) ) {
echo "<div style='padding-left: 3px; background: #eee'>";
vvv($params);
echo "</div>";
}
|
| Controller::dispatch($_SERVER["REDIRECT_URL"], $_GET + $_POST, "_layout");
| 1 : phone
1 : {"p":"9038713532","c***n","cssTableParentClass":"table-scroll"} 1 : _layout
| <?
Controller::dispatch($_SERVER["REDIRECT_URL"], $_GET + $_POST, "_layout");
exit; |
Error\ErrorHandler::Error\{closure}([0:ErrorException: fwri..]) Error\ErrorHandler->invokeListeners([ 0:[3 items], 1:ErrorException: fwri..]) Error\ErrorHandler->handleError([0:8, 1:fwrite..o host, 2:/rd/li..et.php, 3:20]) Monitoring\Metric\Clients\Connection\AbstractSocket->writeToSocket([0:hb.ant..cli:0 ]) Monitoring\Metric\Clients\Connection\UdpSocket->writeToSocket([0:hb.ant..cli:0 ]) Monitoring\Metric\Clients\Connection\InetSocket->sendMessages([ 0:[1 items]]) Monitoring\Metric\Clients\Connection\InetSocket->send([0:hb.ant.._cli:0]) Monitoring\Metric\Clients\StatsdClient->send([0:hb.anti_spider.hit, 1:1, 2:c 3:[3 items]])