[LON-CAPA-cvs] cvs: loncom / loncron

raeburn raeburn at source.lon-capa.org
Tue Jul 9 22:47:53 EDT 2024


raeburn		Wed Jul 10 02:47:53 2024 EDT

  Modified files:              
    /loncom	loncron 
  Log:
  - Nightly run of loncron checks if bash readline library;s default value for
    enable-bracketed-paste needs to be overridden using /home/www/.inputrc.
  
  
Index: loncom/loncron
diff -u loncom/loncron:1.129 loncom/loncron:1.130
--- loncom/loncron:1.129	Sat Jun 22 14:29:36 2024
+++ loncom/loncron	Wed Jul 10 02:47:53 2024
@@ -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 @@
 <li><a href="#lonc">lonc</a></li>
 <li><a href="#lonnet">lonnet</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="#errcount">Error Count</a></li>
 </ol>
@@ -1491,6 +1492,98 @@
     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, at 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 @@
 	&test_connections($fh);
     }
     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>Brackedted 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 ($threshold,$sysmail,$reportstatus,$weightsref,$exclusionsref) =
             &get_permcount_settings($domconf);




More information about the LON-CAPA-cvs mailing list