NAME
CrowdSec::Client - CrowdSec client
SYNOPSIS
# Bouncer
use CrowdSec::Client;
my $client = CrowdSec::Client->new({
  apiKey => "myApiKey",
  baseUrl   => "http://127.0.0.1:8080",
});
if ( $client->testIp('1.2.3.4') ) {
  print STDERR "IP banned by crowdsec\n";
}
# Watcher
use CrowdSec::Client;
my $client = CrowdSec::Client->new({
  machineId => "myid",
  password  => "mypass",
  baseUrl   => "http://127.0.0.1:8080",
  autoLogin => 1;
});
$client->banIp('2.3.4.5') or die( $client->error );
$client->banIp('1.2.3.4', duration => '5h', reason => 'Ban by my app')
  or die( $client->error );
DESCRIPTION
CrowdSec::Client is a simple CrowdSec Client. It permits one to query Crowdsec database or to ban an IP.
Constructor
CrowdSec::Client requires a hashref as argument with the following keys:
- Common parameters
 - 
- baseUrl (required) to ban: the base URL to connect to local CrowdSec server. Example: http://localhost:8080.
 - userAgent (optional): a LWP::UserAgent object. If noone is given, a new LWP::UserAgent will be created.
 - autoLogin: indicates that CrowdSec::Client has to login automatically when 
banIp()is called. Else you should call manuallylogin()method. - strictSsl: (default: 1). If set to 0, and if userAgent isn't set, the internal LWP::UserAgent will ignore SSL errors.
 
 - Watcher parameters
 - 
- machineId (required): the watcher identifier given by Crowdsec (see "Enrollment").
 - password (required): the watcher password
 
 - Bouncer parameters
 
Methods
banIp()
banIp adds the given IP into decisions. Usage:
$client->banIp( $ip, %parameters );
Parameters:
- duration (default: 4h): the duration of the decision
 - origin (default: "CrowdSec::Client")
 - reason (default: "Banned by CrowdSec::Client")
 - scenario (default: "Banned by CrowdSec::Client"))
 - simulated (default: 0): if set to 1, the flag "simulated" is added
 - type (default: "ban")
 
Enrollment
Bouncer
To get a Crowdsec API key, you can use:
$ sudo cscli bouncers add myBouncerName
Watcher
To get a Watcher password, you can use:
$ sudo cscli machines add MyId --password myPassword
SEE ALSO
AUTHOR
Xavier Guimard <xguimard@linagora.mu>
COPYRIGHT AND LICENSE
Copyright (C) 2023 by Linagora
License: AGPL-3.0 (see LICENSE file)