Welcome Screen add custom

ABaum

Member
Nov 2, 2018
11
0
6
45
Hello all
I have hacked a change to pvebanner so that we can add a file /etc/pve/welcome.txt

I do not want to learn how to use the development tools.

but here is the code. Somebody might get it added into upstream.
 
#!/usr/bin/perl

use strict;
use PVE::INotify;
use PVE::Cluster;

my $nodename = PVE::INotify::nodename();
my $localip = PVE::Cluster::remote_node_ip($nodename, 1);

my $xline = '-' x 78;

my $custom_welcome = '';

if (-e ("/etc/pve/welcome.txt")) {
open FILE, "/etc/pve/welcome.txt";
$custom_welcome = join '', <FILE>;
close FILE;
} else {
$custom_welcome = '';
}

my $banner = '';

if ($localip) {
$banner .= <<__EOBANNER;

$xline

Welcome to the Proxmox Virtual Environment. Please use your web browser to
configure this server - connect to:

https://${localip}:8006/

$xline

$custom_welcome

$xline

__EOBANNER

}

open(ISSUE, ">/etc/issue");

print ISSUE $banner;

close(ISSUE);

exit (0);
 
Hi, i create today my own welcome script.
It reads the current IPs and other Infos with RegEx ;)

demo.png

Bash:
nano /etc/network/if-up.d/update_loginscreen;
chmod +x /etc/network/if-up.d/update_loginscreen;

Perl:
#!/usr/bin/perl
use strict;
use warnings;

# Disable default proxmox banner
system("systemctl disable pvebanner.service");
system("rm /etc/issue");
system("clear");

my @network_interface_array = &sub_get_interfaces();
my @pveinfo_array           = &sub_get_pveversion();

# Set Colors
my $black          = "\033[0;30m";
my $gray_dark      = "\033[1;30m";
my $red            = "\033[0;31m";
my $red_light      = "\033[1;31m";
my $green          = "\033[0;32m";
my $green_light    = "\033[1;32m";
my $brown          = "\033[0;33m";
my $yellow         = "\033[1;33m";
my $blue           = "\033[0;34m";
my $blue_light     = "\033[1;34m";
my $purple         = "\033[0;35m";
my $light_purple   = "\033[1;35m";
my $cyan           = "\033[0;36m";
my $cyan_light     = "\033[1;36m";
my $white2         = "\033[1;40m";
my $white          = "\033[1;37m";
my $nocolor        = "\033[0m";

# Configue Line
my $color_line = sprintf("%s%s%s", $yellow, "_" x 78, $nocolor);

# Create Banner
my $proxmox_logo = "";
$proxmox_logo = sprintf("%s        %s██████╗ %s██████╗ %s ██████╗ %s██╗  ██╗%s███╗   ███╗%s ██████╗ %s██╗  ██╗%s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);
$proxmox_logo = sprintf("%s        %s██╔══██╗%s██╔══██╗%s██╔═══██╗%s╚██╗██╔╝%s████╗ ████║%s██╔═══██╗%s╚██╗██╔╝%s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);
$proxmox_logo = sprintf("%s        %s██████╔╝%s██████╔╝%s██║   ██║%s ╚███╔╝ %s██╔████╔██║%s██║   ██║%s ╚███╔╝ %s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);
$proxmox_logo = sprintf("%s        %s██╔═══╝ %s██╔══██╗%s██║   ██║%s ██╔██╗ %s██║╚██╔╝██║%s██║   ██║%s ██╔██╗ %s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);
$proxmox_logo = sprintf("%s        %s██║     %s██║  ██║%s╚██████╔╝%s██╔╝ ██╗%s██║ ╚═╝ ██║%s╚██████╔╝%s██╔╝ ██╗%s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);
$proxmox_logo = sprintf("%s        %s╚═╝     %s╚═╝  ╚═╝%s ╚═════╝ %s╚═╝  ╚═╝%s╚═╝     ╚═╝%s ╚═════╝ %s╚═╝  ╚═╝%s\n",$proxmox_logo, $white,$white,$white,$brown,$white,$white,$brown,$nocolor);

# Create Message String
my $message = sprintf("%s\n\n%s%s\n",$color_line,$proxmox_logo,$color_line);

# Print PVE Infos
if (@pveinfo_array) {
  $message = sprintf("%s%s       Version:%s %s%s%-5s%s %sBuild:%s %s%s%-5s%s %sKernel:%s %s%s%-5s%s\n\n", $message, $brown, $nocolor, $blue_light, $pveinfo_array[0], "", $nocolor, $brown, $nocolor, $blue_light, $pveinfo_array[1], "", $nocolor, $brown, $nocolor, $blue_light, $pveinfo_array[2], "", $nocolor);
}

$message = sprintf ("%s%s  Welcome to the Proxmox Virtual Environment Server%s\n", $message, $brown, $nocolor);

# Print Network Infos
if (@network_interface_array) {
  $message = sprintf("%s%s  Please use your web browser to configure this server - connect to:%s\n\n", $message, $brown, $nocolor);
  for ( my $i=0; $i < @network_interface_array; $i+=2) {
    $message = sprintf("%s%s      [%s] %shttps://%s%s%s%s:8006%s\n",$message, $cyan, $network_interface_array[$i], $green_light, $red_light, $network_interface_array[$i+1],$nocolor, $green_light, $nocolor)
  }
}
else {
  $message = sprintf("%s%s  WARNING: No Network Connection found !!!%s\n", $message, $red, $nocolor);
}

$message = sprintf("%s\n", $message);

# Write Message to Console for Test
print ($message);

# Write to Issue File
my $filenamepath = "/etc/issue";

if (open (FILE_HANDLE,">$filenamepath")) {
  printf (FILE_HANDLE "%s", $message);
  close (FILE_HANDLE);
}
else {
  printf ("[ERROR] in %s:%s -\> can not open file \"%s\" !!!\n", __FILE__, __LINE__, $filenamepath);
}

exit (0);

#########################################################################################################
# SubRoutines
#########################################################################################################

sub sub_get_pveversion {
  my @pveversion;
  my $cmd_out = &sub_get_cmd_output("pveversion");
  if ((defined $cmd_out) && ($cmd_out =~ /pve-manager\/(.*?)\/(.*?)\s\(running kernel:\s(.*?)\)/)) {
    push (@pveversion,$1);   # 7.4-3
    push (@pveversion,$2);   # 9002ab8a
    push (@pveversion,$3);   # 5.15.107-2-pve   
  }
  return(@pveversion);
}

sub sub_get_interfaces {
  my @network_interface_ip_array;
  my $cmd_out = &sub_get_cmd_output("ip -o l");
  if ((defined $cmd_out) && ($cmd_out =~ /[\d].*?:\s([\w\d]*)?:/)) {
      my (@network_interface_array) = $cmd_out =~ /[\d].*?:\s([\w\d]*)?:/g;
      foreach my $network_interface (sort @network_interface_array) {
          if ((defined $network_interface) && ($network_interface ne "lo")) {
            my $ip = &get_interface_address($network_interface);
            if ($ip) {
                push (@network_interface_ip_array,$network_interface);
                push (@network_interface_ip_array,$ip);
            }
          }
      }
  }
  return(@network_interface_ip_array);
}

sub get_interface_address {
  my $iface = $_[0];
  my $ReturnValue = 0;
  if (defined $iface) {
    my $cmd = sprintf("ip -4 addr show dev %s", $iface);
    my $cmd_out = &sub_get_cmd_output($cmd);
    if ((defined $cmd_out) && ($cmd_out =~ /inet\s((?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)\.?\b){4})\/[\d]{2}/)) {
      $ReturnValue = $1;
    }
  }
  return($ReturnValue);
}

sub sub_get_cmd_output {
    my $command     = $_[0];
    my $command_out = "";

    if (defined $command) {
        open (CMD_HANDLE, "${command} 2>nul|");
        undef $/;
        $command_out = <CMD_HANDLE>;
        $/="\n";
        close (CMD_HANDLE);
    }
    return($command_out);
}
 
  • Like
Reactions: _gabriel

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!