--- loncom/loncron 2024/06/22 14:29:36 1.129
+++ loncom/loncron 2024/07/10 02:47:53 1.130
@@ -2,7 +2,7 @@
# Housekeeping program, started by cron, loncontrol and loncron.pl
#
-# $Id: loncron,v 1.129 2024/06/22 14:29:36 raeburn Exp $
+# $Id: loncron,v 1.130 2024/07/10 02:47:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -337,6 +337,7 @@ sub start_logging {
lonc
lonnet
Connections
+bash readline config
Delayed Messages
Error Count
@@ -1491,6 +1492,98 @@ sub read_serverhomeIDs {
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 = ;
+ 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 {
my ($sysmail,$reportstatus) = @_;
my $defdom = $perlvar{'lonDefDomain'};
@@ -1687,6 +1780,22 @@ sub main () {
&test_connections($fh);
}
if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
+ my ($bracketed_warning,$check_bracketed_paste) = &check_bash_settings();
+ if ($check_bracketed_paste) {
+ &log($fh,'
bash readline config
Brackedted Paste
'.
+ '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.
');
+ if ($bracketed_warning) {
+ my $bash_update = &set_bracketed_paste_off();
+ if ($bash_update) {
+ &log($fh,''.$bash_update.'
'."\n");
+ }
+ } else {
+ &log($fh,'No action needed; /home/www/.inputrc already set.
'."\n");
+ }
+ } else {
+ &log($fh,'
bash readline config
Bracketed Paste
'.
+ 'No action needed for distros using pre-8.1 bash readline library
'."\n");
+ }
my $domconf = &get_domain_config();
my ($threshold,$sysmail,$reportstatus,$weightsref,$exclusionsref) =
&get_permcount_settings($domconf);