Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Merge requests
!1632
Resolve "Include Dynamic Spam rules"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Include Dynamic Spam rules"
991-include-dynamic-spam-rules
into
development
Overview
0
Commits
1
Pipelines
2
Changes
6
Merged
Dominik Hebeler
requested to merge
991-include-dynamic-spam-rules
into
development
4 years ago
Overview
0
Commits
1
Pipelines
2
Changes
6
Expand
Closes
#991 (closed)
Edited
4 years ago
by
Dominik Hebeler
0
0
Merge request reports
Compare
development
development (base)
and
latest version
latest version
29c3c29c
1 commit,
4 years ago
6 files
+
422
−
11
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
app/Console/Commands/LoadSpam.php
0 → 100644
+
64
−
0
Options
<?php
namespace
App\Console\Commands
;
use
Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Redis
;
class
LoadSpam
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'spam:load'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Loads a list of current Spams into redis'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$filePath
=
\storage_path
(
'logs/metager/ban.txt'
);
$bans
=
[];
if
(
\file_exists
(
$filePath
))
{
$bans
=
json_decode
(
file_get_contents
(
$filePath
),
true
);
}
$bansToLoad
=
[];
foreach
(
$bans
as
$ban
)
{
$bannedUntil
=
Carbon
::
createFromFormat
(
"Y-m-d H:i:s"
,
$ban
[
"banned-until"
]);
if
(
$bannedUntil
->
isAfter
(
Carbon
::
now
()))
{
$bansToLoad
[]
=
$ban
[
"regexp"
];
}
}
Redis
::
pipeline
(
function
(
$redis
)
use
(
$bansToLoad
)
{
$redis
->
del
(
"spam"
);
foreach
(
$bansToLoad
as
$ban
)
{
$redis
->
rpush
(
"spam"
,
$ban
);
}
});
}
}
Loading