[LON-CAPA-cvs] cvs: doc /loncapafiles updatequery.piml

raeburn raeburn at source.lon-capa.org
Fri Jul 29 20:38:14 EDT 2016


raeburn		Sat Jul 30 00:38:14 2016 EDT

  Modified files:              
    /doc/loncapafiles	updatequery.piml 
  Log:
  - Check hostname has valid format.
  - Prompt to allow hostname to be modified.
  
  
-------------- next part --------------
Index: doc/loncapafiles/updatequery.piml
diff -u doc/loncapafiles/updatequery.piml:1.83 doc/loncapafiles/updatequery.piml:1.84
--- doc/loncapafiles/updatequery.piml:1.83	Fri Jul 29 17:26:44 2016
+++ doc/loncapafiles/updatequery.piml	Sat Jul 30 00:38:14 2016
@@ -1,6 +1,6 @@
 <!-- updatequery.piml -->
 
-<!-- $Id: updatequery.piml,v 1.83 2016/07/29 17:26:44 raeburn Exp $ -->
+<!-- $Id: updatequery.piml,v 1.84 2016/07/30 00:38:14 raeburn Exp $ -->
 
 <!--
 
@@ -33,7 +33,8 @@
 <target dist='default'>/</target>
 <perlscript mode='fg'>
 $|=1;
-  use strict;
+use strict;
+
   print(<<END);
 
 
@@ -128,6 +129,7 @@
 my $primaryLibServer;
 my $protocol;
 my $intdom;
+my $desiredhostname;
 my @libservers = ();
 unless (-e "<TARGET />") {
   print(<<END);
@@ -137,7 +139,7 @@
 or contact helpdesk\@loncapa.org.
 
 ===============================================================================
-The following 7 values are needed to configure LON-CAPA:
+The following 8 values are needed to configure LON-CAPA:
 * Machine Role
 * LON-CAPA Domain Name
 * LON-CAPA Machine ID Name
@@ -145,6 +147,7 @@
 * LON-CAPA Domain's Primary Library Server Machine ID
 * Web Server Protocol
 * Internet Domain Name of Your Institution
+* Hostname
 ===============================================================================
 
 In addition, a Support E-mail Address can also be included. If
@@ -282,7 +285,6 @@
   }
 }
 
-
 # get domain description
 # accept if valid, if not valid, tell user and repeat
 $flag=0;
@@ -547,6 +549,54 @@
   }
 }
 
+# get hostname
+# accept if valid, if not valid, tell user and repeat
+$flag=0;
+my $posshostname;
+if (($hostname =~ /^[A-Za-z0-9\-]+$/) && ($intdom ne '')) {
+    $posshostname = $hostname.'.'.$intdom;
+} 
+if (($hostname =~ /^[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/) &&
+    ($hostname =~ /^[A-Za-z0-9.\-]+$/)) {
+    $posshostname = $hostname;
+}
+while (!$flag) {
+  print(<<END);
+
+****** Hostname of the server/VM *****
+
+The hostname of the server/VM is required. This will be similar to:
+somename.ustate.edu or somename.department.ustate.edu, and would be 
+the web address which users would point their web browsers at to
+access the server.
+
+END
+
+if ($posshostname) {
+    print "ENTER HOSTNAME OF SERVER [$posshostname]:\n";
+} else {
+    print "ENTER HOSTNAME OF SERVER:\n";
+}
+
+  my $choice=<>;
+  chomp($choice);
+  if (($choice =~ /^[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/) &&
+      ($choice =~ /^[A-Za-z0-9.\-]+$/)) {
+    open(OUT,'>>/tmp/loncapa_updatequery.out');
+    print(OUT 'hostname'."\t".$choice."\n");
+    close(OUT);
+    $desiredhostname=$choice;
+    $flag=1;
+  } elsif (($choice eq '') && ($posshostname ne '')) {
+    open(OUT,'>>/tmp/loncapa_updatequery.out');
+    print(OUT 'hostname'."\t$posshostname\n");
+    close(OUT);
+    $desiredhostname = $posshostname;
+    $flag = 1;
+  } else {
+    print "Invalid input (only letters, numbers, - and . allowed, with at least one .).\n";
+  }
+}
 
 # update loncapa.conf
 my $confdir = '/etc/httpd/conf/';
@@ -710,13 +760,18 @@
 	}
     }
 
-    if (!$protocol) {
+    if ((!$protocol) || (!$desiredhostname)) {
         foreach my $file (@hosts_files) {
             open(IN,'<'.$file);
             while(my $line = <IN>) {
-                if ($line =~ /^\Q$perlvar{'lonHostID'}\E:\Q$perlvar{'lonDefDomain'}\E\:(?:access|library)\:[^:]+\:(https?)/) {
-                    $protocol = $1;
-                    chomp($protocol);
+                if ($line =~ /^\Q$perlvar{'lonHostID'}\E:\Q$perlvar{'lonDefDomain'}\E\:(?:access|library)\:([^:]+)\:(https?)/) {
+                    if (!$desiredhostname) {
+                        $desiredhostname = $1;
+                    }
+                    if (!$protocol) { 
+                        $protocol = $2;
+                        chomp($protocol);
+                    }
                     last;
                 }
             }
@@ -767,7 +822,7 @@
     }
    
 # implement editing logic below, interactively
-# update loncapa.conf until 14 is entered
+# update loncapa.conf until 15 is entered
 
 my $flag=0;
 
@@ -784,12 +839,13 @@
  6) Support E-mail Address: $perlvar{'lonSupportEMail'}
  7) Web Server Protocol (http or https): $protocol 
  8) Internet Domain Name: $intdom 
- 9) Role: $perlvar{'lonRole'}
-10) Cache Expiration Time: $perlvar{'lonExpire'}
-11) Server Load: $perlvar{'lonLoadLim'}
-12) User Load: $perlvar{'lonUserLoadLim'}
-13) Allow only secure connections: $securestatus 
-14) Everything is correct up above
+ 9) Hostname: $desiredhostname
+10) Role: $perlvar{'lonRole'}
+11) Cache Expiration Time: $perlvar{'lonExpire'}
+12) Server Load: $perlvar{'lonLoadLim'}
+13) User Load: $perlvar{'lonUserLoadLim'}
+14) Allow only secure connections: $securestatus 
+15) Everything is correct up above
 END
 
 my @error;
@@ -855,7 +911,7 @@
 
 if (@error) { print "\n*** ERRORS: \n\t".join("\n\t", at error)."\n"; }
   print(<<END);
-ENTER A CHOICE OF 1-13 TO CHANGE, otherwise ENTER 14:
+ENTER A CHOICE OF 1-14 TO CHANGE, otherwise ENTER 15:
 END
 my $choice=<>;
 chomp($choice);
@@ -947,7 +1003,18 @@
   }
   elsif ($choice==9) {
   print(<<END);
-9) Role: $perlvar{'lonRole'}
+9) Hostname of Server/VM
+ENTER NEW VALUE:
+
+END
+    my $choice2=<>;
+    chomp($choice2);
+    $desiredhostname=$choice2;
+  }
+
+  elsif ($choice==10) {
+  print(<<END);
+10) Role: $perlvar{'lonRole'}
 ENTER NEW VALUE (this should be either 'access' or 'library' 
                  if in doubt select 'library'):
 END
@@ -955,27 +1022,27 @@
     chomp($choice2);
     $perlvar{'lonRole'}=$choice2;
   }
-  elsif ($choice==10) {
+  elsif ($choice==11) {
   print(<<END);
-10) Cache Expiration Time: $perlvar{'lonExpire'}
+11) Cache Expiration Time: $perlvar{'lonExpire'}
 ENTER NEW VALUE (in seconds, 86400 is a reasonable value):
 END
     my $choice2=<>;
     chomp($choice2);
     $perlvar{'lonExpire'}=$choice2;
   }
-  elsif ($choice==11) {
+  elsif ($choice==12) {
   print(<<END);
-11) Server Load: $perlvar{'lonLoadLim'}
+12) Server Load: $perlvar{'lonLoadLim'}
 ENTER NEW VALUE:
 END
     my $choice2=<>;
     chomp($choice2);
     $perlvar{'lonLoadLim'}=$choice2;
   }
-  elsif ($choice==12) {
+  elsif ($choice==13) {
   print(<<END);
-12) User Load: $perlvar{'lonUserLoadLim'}
+13) User Load: $perlvar{'lonUserLoadLim'}
 Numer of users that can login before machine is 'overloaded'
 ENTER NEW VALUE (integer value, 0 means there is no limit):
 END
@@ -983,9 +1050,9 @@
     chomp($choice2);
     $perlvar{'lonUserLoadLim'}=$choice2;
   }
-  elsif ($choice==13) {
+  elsif ($choice==14) {
   print(<<END);
-13) Allow only secure connections: $securestatus 
+14) Allow only secure connections: $securestatus 
 The Lon-CAPA communication daemons lonc and lond can be configured to
 allow only secure connections by default.
 
@@ -1012,13 +1079,14 @@
     }
     ($securestatus,$securenum)=&securesetting(%perlvar);
   }
-  elsif (($choice==14) && (!@error)) {
+  elsif (($choice==15) && (!@error)) {
     $flag=1;
   }
   else {
     print "Invalid input.\n";
   }
 }
+
     open(OUT,">$confdir$filename") or
       die("Cannot output to $confdir$filename\n");
     foreach my $key (keys %perlvar) {
@@ -1038,14 +1106,17 @@
 <target dist='default'>loncom/hosts.tab</target>
 <perlscript mode='fg'>
 unless (-l "<TARGET />") {
-  my $hostname=`hostname -f`;chomp($hostname);
+  if ($desiredhostname eq '') { 
+      my $hostname=`hostname -f`;chomp($hostname);
+      $desiredhostname = $hostname;
+  }
   my $date=`date -I`; chomp($date);
   my $lonHostID=$perlvar{'lonHostID'};
   $lonHostID=~s/[^\w\-.]//g;
   my $lineexistflag=0;
   my $hostidexistflag=0;
   my $line2insert=<<END;
-$perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname:$protocol:$intdom
+$perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$desiredhostname:$protocol:$intdom
 END
   if (!$domainTabExtras) {
 	$domainTabExtras=':::::';
@@ -1055,7 +1126,7 @@
     open(OUT,'>../'.$lonCluster.'_hosts.tab') or
       die('file generation error');
       print(OUT $line2insert);
-      print OUT ("^$hostname:$protocol\n");
+      print OUT ("^$desiredhostname:$protocol\n");
     close(OUT);
     open(OUT,'>../'.$lonCluster.'_dns_hosts.tab') or
       die('file generation error');


More information about the LON-CAPA-cvs mailing list