#!/usr/local/cpanel/3rdparty/bin/perl
#                                      Copyright 2025 WebPros International, LLC.
#                                                            All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package Cpanel::Plugins::ServerId;

use strict;
use warnings;

use v5.20;
use experimental qw(signatures);

=head1 MODULE

C<Cpanel::Plugins::ServerId>

=head1 DESCRIPTION

C<Cpanel::Plugins::ServerId> provides helper functions for retrieving the unique server id for a server.

=head1 SYNOPSIS

  use Cpanel::Plugins::ServerId();
  say "ServerID: " . Cpanel::Plugins::ServerId::get_server_id();

=head1 FUNCTIONS

=cut

sub get_server_id() {
    require Cpanel::DIp::MainIP;
    require Cpanel::AdminBin::Call;

    my $uuid;

    # if caller is root, fetch the UUID directly
    if ( $> == 0 ) {
        require Common::Plugins::ServerInfo;
        $uuid = Common::Plugins::ServerInfo::get_server_uuid();
    }
    else {
        $uuid = Cpanel::AdminBin::Call::call( "Cpanel", "server_id", "GET_SERVER_UUID", {} );
    }
    chomp( my $ip = Cpanel::DIp::MainIP::getpublicmainserverip() );

    return "$uuid-$ip";
}

1;
