Diff for /loncom/loncron between versions 1.103.2.9 and 1.103.2.15

version 1.103.2.9, 2021/01/30 22:25:53 version 1.103.2.15, 2024/07/10 04:11:41
Line 43  use IO::File; Line 43  use IO::File;
 use IO::Socket;  use IO::Socket;
 use HTML::Entities;  use HTML::Entities;
 use Getopt::Long;  use Getopt::Long;
   use GDBM_File qw(GDBM_READER);
   use Storable qw(thaw);
 use File::ReadBackwards;  use File::ReadBackwards;
 use File::Copy;  use File::Copy;
 use Sys::Hostname::FQDN();  use Sys::Hostname::FQDN();
Line 227  sub log_machine_info { Line 229  sub log_machine_info {
     &log($fh,'<hr /><a name="machine" /><h2>Machine Information</h2>');      &log($fh,'<hr /><a name="machine" /><h2>Machine Information</h2>');
     &log($fh,"<h3>loadavg</h3>");      &log($fh,"<h3>loadavg</h3>");
   
       my $cpucount;
       if (open(PIPE,"lscpu |grep '^CPU(s)' 2>&1 |")) {
           my $info = <PIPE>;
           chomp($info);
           ($cpucount) = ($info =~ /^\QCPU(s):\E\s+(\d+)$/);
           close(PIPE);
       }
       if (!$cpucount) {
           $cpucount = 1;
       }
       my %loadtarget = (
                           error => 4.0*$cpucount,
                           warn  => 2.0*$cpucount,
                           note  => 1.0*$cpucount,
                        );
     open (LOADAVGH,"/proc/loadavg");      open (LOADAVGH,"/proc/loadavg");
     my $loadavg=<LOADAVGH>;      my $loadavg=<LOADAVGH>;
     close (LOADAVGH);      close (LOADAVGH);
Line 234  sub log_machine_info { Line 251  sub log_machine_info {
     &log($fh,"<tt>$loadavg</tt>");      &log($fh,"<tt>$loadavg</tt>");
   
     my @parts=split(/\s+/,$loadavg);      my @parts=split(/\s+/,$loadavg);
     if ($parts[1]>4.0) {      if ($parts[1]>$loadtarget{'error'}) {
  $errors++;   $errors++;
     } elsif ($parts[1]>2.0) {      } elsif ($parts[1]>$loadtarget{'warn'}) {
  $warnings++;   $warnings++;
     } elsif ($parts[1]>1.0) {      } elsif ($parts[1]>$loadtarget{'note'}) {
  $notices++;   $notices++;
     }      }
   
Line 318  sub start_logging { Line 335  sub start_logging {
 <li><a href="#lonc">lonc</a></li>  <li><a href="#lonc">lonc</a></li>
 <li><a href="#lonnet">lonnet</a></li>  <li><a href="#lonnet">lonnet</a></li>
 <li><a href="#connections">Connections</a></li>  <li><a href="#connections">Connections</a></li>
   <li><a href="#bashconf">bash readline config</a></li>
 <li><a href="#delayed">Delayed Messages</a></li>  <li><a href="#delayed">Delayed Messages</a></li>
 <li><a href="#errcount">Error Count</a></li>  <li><a href="#errcount">Error Count</a></li>
 </ol>  </ol>
Line 1246  sub read_serverhomeIDs { Line 1264  sub read_serverhomeIDs {
     return %server;      return %server;
 }  }
   
   sub check_bash_settings {
       my $distro = &LONCAPA::distro();
       my ($check_bracketed_paste,$bracketed_warning);
       if ($distro  =~ /^debian(\d+)$/) {
           if ($1 >= 12) {
               $check_bracketed_paste = 1;
           }
       } elsif ($distro =~ /^ubuntu(\d+)$/) {
           if ($1 >= 22) {
               $check_bracketed_paste = 1;
           }
       } elsif ($distro =~ /^(?:redhat|oracle|alma|rocky|centos-stream)(\d+)$/) {
           if ($1 >= 9) {
               $check_bracketed_paste = 1;
           }
       } elsif ($distro =~ /^fedora(\d+)/) {
           if ($1 >= 34) {
               $check_bracketed_paste = 1;
           }
       }
       if ($check_bracketed_paste) {
           if (open(PIPE,"bind -V 2>&1 | grep enable-bracketed-paste |")) {
               my $info = <PIPE>;
               chomp($info);
               my ($bracketed) = ($info =~ /^\Qenable-bracketed-paste\E\s+is\s+set\s+to\s+\W(on|off)\W$/);
               close(PIPE);
               if ($bracketed eq 'on') {
                   $bracketed_warning = 1;
               }
           } else {
               print "Unable to check if bracketed paste is set to off for www user's shell\n";
           }
       }
       return ($bracketed_warning,$check_bracketed_paste);
   }
   
   sub set_bracketed_paste_off {
       my $bash_www_cnf = '/home/www/.inputrc';
       my $result;
       if (!-e $bash_www_cnf) {
           system("touch $bash_www_cnf");
           if (open(my $cfh,'>',$bash_www_cnf)) {
               print $cfh "set enable-bracketed-paste off\n";
               close($cfh);
               $result = "Updated $bash_www_cnf";
           } else {
               $result = "Could not open $bash_www_cnf to add 'set enable-bracketed-paste to off'";
           }
           my $wwwuid = getpwnam('www');
           my $wwwgid = getgrnam('www');
           if ($wwwuid!=$<) {
               chown($wwwuid,$wwwgid,$bash_www_cnf);
           }
       } else {
           my ($bracketed_paste_on,$bracketed_paste_off,@preserve);
           if (open(my $cfh,'<',$bash_www_cnf)) {
               while (my $line=<$cfh>) {
                   chomp($line);
                   if ($line =~ /^\s*set\s+enable\-bracketed\-paste\s+(off|on)\s*$/) {
                       if ($1 eq 'off') {
                           $bracketed_paste_off = 1;
                       } else {
                           $bracketed_paste_on = 1;
                       }
                   } else {
                       push(@preserve,$line);
                   }
               }
               close($cfh);
               if ($bracketed_paste_on || !$bracketed_paste_off) {
                   if (open(my $cfh,'>',$bash_www_cnf)) {
                       print $cfh "set enable-bracketed-paste off\n";
                       if (@preserve) {
                           foreach my $entry (@preserve) {
                               print $cfh "$entry\n";
                           }
                       }
                       close($cfh);
                       $result = "Updated $bash_www_cnf";
                   } else {
                       $result = "Could not open $bash_www_cnf to add 'set enable-bracketed-paste to off'";
                   }
               } else {
                   $result = "No action needed; $bash_www_cnf already includes 'set enable-bracketed-paste to off'";
               }
           } else {
               $result = "Could not open $bash_www_cnf to check if a value is included for 'enable-bracketed-paste'.";
           }
       }
       return $result;
   }
   
 sub send_mail {  sub send_mail {
     my ($sysmail,$reportstatus) = @_;      my ($sysmail,$reportstatus) = @_;
     my $defdom = $perlvar{'lonDefDomain'};      my $defdom = $perlvar{'lonDefDomain'};
Line 1350  sub main () { Line 1460  sub main () {
     my $wwwid=getpwnam('www');      my $wwwid=getpwnam('www');
     if ($wwwid!=$<) {      if ($wwwid!=$<) {
  print("User ID mismatch. This program must be run as user 'www'.\n");   print("User ID mismatch. This program must be run as user 'www'.\n");
  my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";   my $emailto="$perlvar{'lonAdmEMail'} $perlvar{'lonSysEMail'}";
  my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";   my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
  system("echo 'User ID mismatch. loncron must be run as user www.' |".   system("echo 'User ID mismatch. loncron must be run as user www.' |".
                " mail -s '$subj' $emailto > /dev/null");                 " mail -s '$subj' $emailto > /dev/null");
Line 1437  sub main () { Line 1547  sub main () {
  &test_connections($fh);   &test_connections($fh);
     }      }
     if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {      if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
           my ($bracketed_warning,$check_bracketed_paste) = &check_bash_settings();
           if ($check_bracketed_paste) {
              &log($fh,'<hr /><a name="bashconf" /><h2>bash readline config</h2><h3>Bracketed Paste</h3>'.
                   '<p>Distros using bash readline library 8.1 or later need bracketed paste disabled for www, so R commands sent to lon daemon will be processed.</p>');
              if ($bracketed_warning) {
                  my $bash_update = &set_bracketed_paste_off();
                  if ($bash_update) {
                      &log($fh,'<p>'.$bash_update.'</p>'."\n");
                  }
              } else {
                  &log($fh,'<p>No action needed; /home/www/.inputrc already set.</p>'."\n");
              }
           } else {
               &log($fh,'<hr /><a name="bashconf" /><h2>bash readline config</h2><h3>Bracketed Paste</h3>'.
                        '<p>No action needed for distros using pre-8.1 bash readline library</p>'."\n");
           }
         my $domconf = &get_domain_config();          my $domconf = &get_domain_config();
         my ($threshold,$sysmail,$reportstatus,$weightsref,$exclusionsref) =          my ($threshold,$sysmail,$reportstatus,$weightsref,$exclusionsref) =
             &get_permcount_settings($domconf);              &get_permcount_settings($domconf);

Removed from v.1.103.2.9  
changed lines
  Added in v.1.103.2.15


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>