[LON-CAPA-cvs] cvs: loncom / lond /lonnet/perl lonnet.pm /metadata_database searchcat.pl

raeburn raeburn at source.lon-capa.org
Thu Jul 25 15:11:13 EDT 2013


raeburn		Thu Jul 25 19:11:13 2013 EDT

  Modified files:              
    /loncom	lond 
    /loncom/metadata_database	searchcat.pl 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - New routines to delete unwanted keys from ids.db GBDM file in a domain
    lond: &del_id_handler() called to process "iddel" request from lonc side
    -- &iddel() routine in lonnet.pm.
  - searchcat.pl will compare id => username retrieved from ids.db with
    expected id => username retrieved from each user's environment.db file
    (loops over user directories in /home/httpd/lonUsers/$dom), and updates
    ids.db based on latest data in environment.db, and logs actions.
  
  
-------------- next part --------------
Index: loncom/lond
diff -u loncom/lond:1.500 loncom/lond:1.501
--- loncom/lond:1.500	Thu Apr 11 14:59:29 2013
+++ loncom/lond	Thu Jul 25 19:11:07 2013
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.500 2013/04/11 14:59:29 bisitz Exp $
+# $Id: lond,v 1.501 2013/07/25 19:11:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,7 +61,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.500 $'; #' stupid emacs
+my $VERSION='$Revision: 1.501 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -4466,6 +4466,49 @@
 }
 &register_handler("idget", \&get_id_handler, 0, 1, 0);
 
+#   Deletes one or more ids in a domain's id database.
+#
+#   Parameters:
+#       $cmd                  - Command keyword (iddel).
+#       $tail                 - Command tail.  In this case a colon
+#                               separated list containing:
+#                               The domain for which we are deleting the id(s).
+#                               &-separated list of id(s) to delete.
+#       $client               - File open on client socket.
+# Returns:
+#     1   - Continue processing
+#     0   - Exit server.
+#     
+#
+
+sub del_id_handler {
+    my ($cmd,$tail,$client) = @_;
+
+    my $userinput = "$cmd:$tail";
+
+    my ($udom,$what)=split(/:/,$tail);
+    chomp($what);
+    my $hashref = &tie_domain_hash($udom, "ids", &GDBM_WRCREAT(),
+                                   "D", $what);
+    if ($hashref) {
+        my @keys=split(/\&/,$what);
+        foreach my $key (@keys) {
+            delete($hashref->{$key});
+        }
+        if (&untie_user_hash($hashref)) {
+            &Reply($client, "ok\n", $userinput);
+        } else {
+            &Failure($client, "error: ".($!+0)." untie(GDBM) Failed ".
+                    "while attempting iddel\n", $userinput);
+        }
+    } else {
+        &Failure( $client, "error: ".($!+0)." tie(GDBM) Failed ".
+                 "while attempting iddel\n", $userinput);
+    }
+    return 1;
+}
+&register_handler("iddel", \&del_id_handler, 0, 1, 0);
+
 #
 # Puts broadcast e-mail sent by Domain Coordinator in nohist_dcmail database 
 #
Index: loncom/metadata_database/searchcat.pl
diff -u loncom/metadata_database/searchcat.pl:1.78 loncom/metadata_database/searchcat.pl:1.79
--- loncom/metadata_database/searchcat.pl:1.78	Fri Mar 26 13:29:31 2010
+++ loncom/metadata_database/searchcat.pl	Thu Jul 25 19:11:10 2013
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # searchcat.pl "Search Catalog" batch script
 #
-# $Id: searchcat.pl,v 1.78 2010/03/26 13:29:31 raeburn Exp $
+# $Id: searchcat.pl,v 1.79 2013/07/25 19:11:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -270,12 +270,59 @@
             &portfolio_logging(%portmetalog);
         }
     }
+    my (%names_by_id,,%ids_by_name,%idstodelete,%idstoadd,%duplicates);
+    unless ($simulate || $oneuser) {
+        my $idshashref;
+        $idshashref = &tie_domain_hash($dom, "ids", &GDBM_WRCREAT());
+        if (ref($idshashref) eq 'HASH') {
+            %names_by_id = %{$idshashref};
+            while (my ($id,$uname) = each(%{$idshashref}) ) {
+                $id = &unescape($id);
+                $uname = &unescape($uname); 
+                $names_by_id{$id} = $uname;
+                push(@{$ids_by_name{$uname}},$id);
+            }
+            &untie_domain_hash($idshashref);
+        }
+    }
     # Update allusers
     foreach my $uname (keys(%allusers)) {
         next if (exists($courses{$dom.'_'.$uname}));
         my %userdata = 
             &Apache::lonnet::get('environment',['firstname','lastname',
                 'middlename','generation','id','permanentemail'],$dom,$uname);
+        unless ($simulate || $oneuser) {
+            my $addid;
+            if ($userdata{'id'} ne '') {
+                $addid = $userdata{'id'};
+                $addid=~tr/A-Z/a-z/;
+            }
+            if (exists($ids_by_name{$uname})) {
+                if (ref($ids_by_name{$uname}) eq 'ARRAY') {
+                    if (scalar(@{$ids_by_name{$uname}}) > 1) {
+                        &log(0,"Multiple employee/student IDs found in ids.db for $uname:$dom -- ".join(', ',@{$ids_by_name{$uname}}));
+                    }
+                    foreach my $id (@{$ids_by_name{$uname}}) {
+                        if ($id eq $userdata{'id'}) {
+                            undef($addid);
+                        } else { 
+                            $idstodelete{$id} = $uname;
+                        }
+                    }
+                }
+            }
+            if ($addid ne '') {
+                if (exists($idstoadd{$addid})) {
+                    push(@{$duplicates{$addid}},$uname);
+                } else {
+                    if ((exists($names_by_id{$addid})) && ($names_by_id{$addid} ne $uname)) {
+                        &log(0,"In ids.db ($dom) $addid => $names_by_id{$addid} will be replaced by $addid => $uname");
+                    }
+                    $idstoadd{$addid} = $uname;
+                }
+            }
+        }
+        
         $userdata{'username'} = $uname;
         $userdata{'domain'} = $dom;
         my %alluserslog = 
@@ -285,6 +332,33 @@
             &log(0,$alluserslog{$item});
         }
     }
+    unless ($simulate || $oneuser) {
+        if (keys(%idstodelete) > 0) {
+            my %resulthash = &Apache::lonnet::iddel($dom,\%idstodelete,$hostid);
+            if ($resulthash{$hostid} eq 'ok') {
+                foreach my $id (sort(keys(%idstodelete))) {
+                    &log(0,"Record deleted from ids.db for $dom -- $id => ".$idstodelete{$id});
+                }
+            } else {
+                &log(0,"Error: '$resulthash{$hostid}' occurred when attempting to delete records from ids.db for $dom");
+            }
+        }
+        if (keys(%idstoadd) > 0) {
+            my $putresult = &Apache::lonnet::put_dom('ids',\%idstoadd,$dom,$hostid);
+            if ($putresult eq 'ok') {
+                foreach my $id (sort(keys(%idstoadd))) {
+                    &log(0,"Record added to ids.db for $dom -- $id => ".$idstoadd{$id});
+                }
+            } else {
+                &log(0,"Error: '$putresult' occurred when attempting to add records to ids.db for $dom"); 
+            }
+        }
+        if (keys(%duplicates) > 0) {
+            foreach my $id (sort(keys(%duplicates))) {
+                &log(0,"Duplicate IDs found for entries to add to ids.db in $dom -- $id => $idstodelete{$id}");
+            }
+        }
+    }
 }
 
 #
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1230 loncom/lonnet/perl/lonnet.pm:1.1231
--- loncom/lonnet/perl/lonnet.pm:1.1230	Tue Jul  9 00:17:27 2013
+++ loncom/lonnet/perl/lonnet.pm	Thu Jul 25 19:11:12 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1230 2013/07/09 00:17:27 raeburn Exp $
+# $Id: lonnet.pm,v 1.1231 2013/07/25 19:11:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1578,6 +1578,36 @@
     }
 }
 
+# ---------------------------------------- Delete unwanted IDs from ids.db file 
+
+sub iddel {
+    my ($udom,$idshashref,$uhome)=@_;
+    my %result=();
+    unless (ref($idshashref) eq 'HASH') {
+        return %result;
+    }
+    my %servers=();
+    while (my ($id,$uname) = each(%{$idshashref})) {
+        my $uhom;
+        if ($uhome) {
+            $uhom = $uhome;
+        } else {
+            $uhom=&homeserver($uname,$udom);
+        }
+        if ($uhom ne 'no_host') {
+            if ($servers{$uhom}) {
+                $servers{$uhom}.='&'.&escape($id);
+            } else {
+                $servers{$uhom}=&escape($id);
+            }
+        }
+    }
+    foreach my $server (keys(%servers)) {
+        $result{$server} = &critical('iddel:'.$udom.':'.$servers{$server},$uhome);
+    }
+    return %result;
+}
+
 # ------------------------------dump from db file owned by domainconfig user
 sub dump_dom {
     my ($namespace, $udom, $regexp) = @_;


More information about the LON-CAPA-cvs mailing list