mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 02:01:33 +00:00
Adjust variables for sphinx in NameFixer class
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2018-02-08 DariusIII
|
||||
* Chg: Adjust variables for sphinx in NameFixer class
|
||||
* Chg: Remove extra argumnet for sphinxsearch deletRelease function
|
||||
* Chg: Update logging configuration
|
||||
* Chg: Make sphinx only search engine, use foolz/sphinxql-query-builder to add files to sphinx index
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace nntmux;
|
||||
|
||||
use nntmux\db\DB;
|
||||
use App\Models\Settings;
|
||||
|
||||
/**
|
||||
* Logs/Reports stuff.
|
||||
*/
|
||||
class Logging
|
||||
{
|
||||
/**
|
||||
* @var string If windows "\r\n" if unix "\n".
|
||||
*/
|
||||
private $newLine;
|
||||
|
||||
/**
|
||||
* @var DB Class instance.
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @var ColorCLI
|
||||
*/
|
||||
public $colorCLI;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$defaults = [
|
||||
'Settings' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
|
||||
$this->newLine = PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rows from logging table.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
return $this->pdo->query('SELECT * FROM logging');
|
||||
}
|
||||
|
||||
/**
|
||||
* Log bad login attempts.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $host
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function LogBadPasswd($username = '', $host = ''): void
|
||||
{
|
||||
// If logggingopt is = 0, then we do nothing, 0 = logging off.
|
||||
$loggingOpt = Settings::settingValue('site.main.loggingopt');
|
||||
$logFile = Settings::settingValue('site.main.logfile');
|
||||
if ((int) $loggingOpt === 1) {
|
||||
$this->pdo->queryInsert(sprintf('INSERT INTO logging (time, username, host) VALUES (NOW(), %s, %s)',
|
||||
$this->pdo->escapeString($username), $this->pdo->escapeString($host)));
|
||||
} elseif ((int) $loggingOpt === 2) {
|
||||
$this->pdo->queryInsert(sprintf('INSERT INTO logging (time, username, host) VALUES (NOW(), %s, %s)',
|
||||
$this->pdo->escapeString($username), $this->pdo->escapeString($host)));
|
||||
$logData = date('M d H:i:s ').'Login Failed for '.$username.' from '.$host.'.'.
|
||||
$this->newLine;
|
||||
if ($logFile !== null) {
|
||||
file_put_contents($logFile, $logData, FILE_APPEND);
|
||||
}
|
||||
} elseif ((int) $loggingOpt === 3) {
|
||||
$logData = date('M d H:i:s ').'Login Failed for '.$username.' from '.$host.'.'.$this->newLine;
|
||||
if ($logFile !== null) {
|
||||
file_put_contents($logFile, $logData, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTopCombined(): array
|
||||
{
|
||||
return $this->pdo->query('SELECT MAX(time) AS time, username, host, COUNT(host) AS count FROM logging GROUP BY host, username ORDER BY count DESC LIMIT 10');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTopIPs(): array
|
||||
{
|
||||
return $this->pdo->query('SELECT MAX(time) AS time, host, COUNT(host) AS count FROM logging GROUP BY host ORDER BY count DESC LIMIT 10');
|
||||
}
|
||||
}
|
||||
@@ -980,7 +980,7 @@ class NameFixer
|
||||
$release['releases_id']
|
||||
)
|
||||
);
|
||||
$this->sphinx->updateRelease($release['releases_id'], $this->pdo);
|
||||
$this->sphinx->updateRelease($release['releases_id']);
|
||||
} else {
|
||||
$newTitle = $this->pdo->escapeString(substr($newName, 0, 299));
|
||||
$this->pdo->queryExec(
|
||||
@@ -997,7 +997,7 @@ class NameFixer
|
||||
$release['releases_id']
|
||||
)
|
||||
);
|
||||
$this->sphinx->updateRelease($release['releases_id'], $this->pdo);
|
||||
$this->sphinx->updateRelease($release['releases_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user