From d0c1f32def2c072053a19cd55a2203781e7d4e31 Mon Sep 17 00:00:00 2001 From: pkriko Date: Thu, 11 Jan 2018 11:37:21 +0100 Subject: [PATCH 1/2] Enhancement NTLMv2 --- .../apps/protocols/http/mode/expectedcontent.pm | 5 +++++ centreon-plugins/apps/protocols/http/mode/jsoncontent.pm | 5 +++++ centreon-plugins/apps/protocols/http/mode/response.pm | 5 +++++ centreon-plugins/apps/protocols/http/mode/soapcontent.pm | 5 +++++ centreon-plugins/centreon/plugins/http.pm | 7 ++++++- 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm index 8290d1148..09f0860a7 100644 --- a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm @@ -43,6 +43,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, @@ -201,6 +202,10 @@ Specify this option if you access webpage over basic authentication Specify this option if you access webpage over ntlm authentication (Use with --credentials option) +=item B<--ntlmv2> + +Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options) + =item B<--username> Specify username for basic authentication (Mandatory if --credentials is specidied) diff --git a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm index ef774dd63..5a302096d 100644 --- a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm @@ -47,6 +47,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, @@ -398,6 +399,10 @@ Specify this option if you access webpage over basic authentication Specify this option if you access webpage over ntlm authentication (Use with --credentials option) +=item B<--ntlmv2> + +Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options) + =item B<--username> Specify username for basic authentication (Mandatory if --credentials is specidied) diff --git a/centreon-plugins/apps/protocols/http/mode/response.pm b/centreon-plugins/apps/protocols/http/mode/response.pm index 985dbc1ac..b30bab8f9 100644 --- a/centreon-plugins/apps/protocols/http/mode/response.pm +++ b/centreon-plugins/apps/protocols/http/mode/response.pm @@ -43,6 +43,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, @@ -179,6 +180,10 @@ Specify this option if you access webpage over basic authentication Specify this option if you access webpage over ntlm authentication (Use with --credentials option) +=item B<--ntlmv2> + +Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options) + =item B<--username> Specify username for basic authentication (Mandatory if --credentials is specidied) diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index 6671bdadf..c75cd1cf8 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -47,6 +47,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, @@ -425,6 +426,10 @@ Specify this option if you access webpage over basic authentication Specify this option if you access webpage over ntlm authentication (Use with --credentials option) +=item B<--ntlmv2> + +Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options) + =item B<--username> Specify username for basic authentication (Mandatory if --credentials is specidied) diff --git a/centreon-plugins/centreon/plugins/http.pm b/centreon-plugins/centreon/plugins/http.pm index fa6b655c6..5c0d5934b 100644 --- a/centreon-plugins/centreon/plugins/http.pm +++ b/centreon-plugins/centreon/plugins/http.pm @@ -26,6 +26,7 @@ use LWP::UserAgent; use HTTP::Cookies; use URI; use IO::Socket::SSL; +use Data::Dumper; sub new { my ($class, %options) = @_; @@ -264,9 +265,13 @@ sub request { $req->content($uri_post->query); } } - + if (defined($request_options->{credentials}) && defined($request_options->{ntlm})) { $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); + } elsif (defined($request_options->{credentials}) && defined($request_options->{ntlmv2})) { + eval "use Authen::NTLM"; die $@ if $@; + ntlmv2(1); + $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); } elsif (defined($request_options->{credentials})) { $req->authorization_basic($request_options->{username}, $request_options->{password}); } From afc00b7e5862710cb76ec4dfe895e88a6469493a Mon Sep 17 00:00:00 2001 From: pkriko Date: Thu, 11 Jan 2018 13:08:33 +0100 Subject: [PATCH 2/2] use centreon::plugins::miscs and fix indent mistakes --- .../apps/protocols/http/mode/expectedcontent.pm | 2 +- centreon-plugins/apps/protocols/http/mode/jsoncontent.pm | 2 +- centreon-plugins/apps/protocols/http/mode/response.pm | 2 +- centreon-plugins/apps/protocols/http/mode/soapcontent.pm | 2 +- centreon-plugins/centreon/plugins/http.pm | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm index 09f0860a7..47a79b8b8 100644 --- a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm @@ -43,7 +43,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, - "ntlmv2" => { name => 'ntlmv2' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, diff --git a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm index 5a302096d..6f21c23b1 100644 --- a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm @@ -47,7 +47,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, - "ntlmv2" => { name => 'ntlmv2' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, diff --git a/centreon-plugins/apps/protocols/http/mode/response.pm b/centreon-plugins/apps/protocols/http/mode/response.pm index b30bab8f9..4ca6a58b3 100644 --- a/centreon-plugins/apps/protocols/http/mode/response.pm +++ b/centreon-plugins/apps/protocols/http/mode/response.pm @@ -43,7 +43,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, - "ntlmv2" => { name => 'ntlmv2' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index c75cd1cf8..53d085650 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -47,7 +47,7 @@ sub new { "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, - "ntlmv2" => { name => 'ntlmv2' }, + "ntlmv2" => { name => 'ntlmv2' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, diff --git a/centreon-plugins/centreon/plugins/http.pm b/centreon-plugins/centreon/plugins/http.pm index 5c0d5934b..9a5762eeb 100644 --- a/centreon-plugins/centreon/plugins/http.pm +++ b/centreon-plugins/centreon/plugins/http.pm @@ -26,7 +26,6 @@ use LWP::UserAgent; use HTTP::Cookies; use URI; use IO::Socket::SSL; -use Data::Dumper; sub new { my ($class, %options) = @_; @@ -269,9 +268,10 @@ sub request { if (defined($request_options->{credentials}) && defined($request_options->{ntlm})) { $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); } elsif (defined($request_options->{credentials}) && defined($request_options->{ntlmv2})) { - eval "use Authen::NTLM"; die $@ if $@; - ntlmv2(1); - $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Authen::NTLM', + error_msg => "Cannot load module 'Authen::NTLM'."); + Authen::NTLM::ntlmv2(1); + $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); } elsif (defined($request_options->{credentials})) { $req->authorization_basic($request_options->{username}, $request_options->{password}); }