The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CrowdSec::Client - CrowdSec client

SYNOPSIS

  use CrowdSec::Client;
  my $client = CrowdSec::Client->new({
    machineId => "myid",
    password  => "mypass",
    baseUrl   => "http://127.0.0.1:8080",
    autoLogin => 1;
  });
  $client->banIp({
    ip       => '1.2.3.4',
    duration => '5h',            # default 4h
    reason   => 'Ban by my app', # default: 'Banned by CrowdSec::Client'
  }) or die( $client->error );

DESCRIPTION

CrowdSec::Client is a simple CrowdSec Watcher. It permits to ban an IP.

Constructor

CrowdSec::Client requires a hashref as argument with the following keys:

machineId (required): the watcher identifier given by Crowdsec (see "Enrollment").
password (required): the watcher password
baseUrl (required): 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 manually login() method.
strictSsl: (default: 1). If set to 0, and if userAgent isn't set, the internal LWP::UserAgent will ignore SSL errors.

Methods

banIp()

banIp adds the given IP into decisions. Usage:

  $client->banIp( { %parameters } );

Parameters:

ip (required): the IP address to ban
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

SEE ALSO

CrowdSec

AUTHOR

Xavier Guimard <xguimard@linagora.mu>

COPYRIGHT AND LICENSE

Copyright (C) 2023 by Linagora

License: AGPL-3.0 (see LICENSE file)