[LON-CAPA-cvs] cvs: loncom / lonsql /enrollment Autoupdate.pl /lonnet/perl lonnet.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 03 Apr 2007 17:51:53 -0000


This is a MIME encoded message

--raeburn1175622713
Content-Type: text/plain

raeburn		Tue Apr  3 13:51:53 2007 EDT

  Modified files:              
    /loncom	lonsql 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/enrollment	Autoupdate.pl 
  Log:
  - lonsql
    - Need to escape results from userlog queries (escaping of all results from lonsql eliminated in 1.50).
    - Allow filtering of user's activity.log for 'Role'
    - Include host in information returned for userlog query
  
  - Autoupdate.pl
    - &lonnet::get_my_roles() by default gets roles from nohist_userroles.  Use in Autoupdate wants information about a user's own roles (from roles.db) - use context as argument
    - warning messagea when username changed (assumes fixed student ID). prints to screen
  for now (log to file would be preferred)
  
  - lonnet.pm
    - documentation for &userfileupload
    - get_my_roles() now includes optional context which determines which db file is target for dump (default is nohist_userroles, context of 'userroles' sets target to roles.db
    - documentation for &userlog_query() - now includes hostID
    - documentation updated for &get_my_roles().
  
  
--raeburn1175622713
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070403135153.txt"

Index: loncom/lonsql
diff -u loncom/lonsql:1.79 loncom/lonsql:1.80
--- loncom/lonsql:1.79	Tue Jan  2 20:59:42 2007
+++ loncom/lonsql	Tue Apr  3 13:51:45 2007
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.79 2007/01/03 01:59:42 raeburn Exp $
+# $Id: lonsql,v 1.80 2007/04/03 17:51:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -425,6 +425,7 @@
                     } else {
                         $result=&courselog($path,$command);
                     }
+                    $result = &escape($result);
                 } else {
                     &logthis('Unable to do log query: '.$uname.'@'.$udom);
                     $result='no_such_file';
@@ -1051,11 +1052,13 @@
                                                              { $include=0; }
         if (($filters{'end'}) && ($timestamp>$filters{'end'})) 
                                                              { $include=0; }
+        if (($filters{'action'} eq 'Role') && ($log !~/^Role/))
+                                                             { $include=0; }
         if (($filters{'action'} eq 'log') && ($log!~/^Log/)) { $include=0; }
         if (($filters{'action'} eq 'check') && ($log!~/^Check/)) 
                                                              { $include=0; }
         if ($include) {
-	   push(@results,$timestamp.':'.$log);
+	   push(@results,$timestamp.':'.$host.':'.&escape($log));
         }
     }
     close IN;
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.857 loncom/lonnet/perl/lonnet.pm:1.858
--- loncom/lonnet/perl/lonnet.pm:1.857	Mon Apr  2 20:49:14 2007
+++ loncom/lonnet/perl/lonnet.pm	Tue Apr  3 13:51:50 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.857 2007/04/03 00:49:14 albertel Exp $
+# $Id: lonnet.pm,v 1.858 2007/04/03 17:51:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1516,8 +1516,12 @@
 #        $coursedoc - if true up to the current course
 #                     if false
 #        $subdir - directory in userfile to store the file into
-#        $parser, $allfiles, $codebase - unknown
-#
+#        $parser - instruction to parse file for objects ($parser = parse)    
+#        $allfiles - reference to hash for embedded objects
+#        $codebase - reference to hash for codebase of java objects
+#        $desuname - username for permanent storage of uploaded file
+#        $dsetudom - domain for permanaent storage of uploaded file
+# 
 # output: url of file in userspace, or error: <message> 
 #             or /adm/notfound.html if failure to upload occurse
 
@@ -1635,6 +1639,7 @@
 		     ' for embedded media: '.$parse_result); 
         }
     }
+ 
 # Notify homeserver to grep it
 #
     my $docuhome=&homeserver($docuname,$docudom);
@@ -1647,7 +1652,7 @@
         &logthis('Failed to transfer '.$path.$file.' to host '.$docuhome.
 		 ': '.$fetchresult);
         return '/adm/notfound.html';
-    }    
+    }
 }
 
 sub extract_embedded_items {
@@ -2069,11 +2074,16 @@
 }
 
 sub get_my_roles {
-    my ($uname,$udom,$types,$roles,$roledoms)=@_;
+    my ($uname,$udom,$context,$types,$roles,$roledoms)=@_;
     unless (defined($uname)) { $uname=$env{'user.name'}; }
     unless (defined($udom)) { $udom=$env{'user.domain'}; }
-    my %dumphash=
+    my %dumphash;
+    if ($context eq 'userroles') { 
+        %dumphash = &dump('roles',$udom,$uname);
+    } else {
+        %dumphash=
             &dump('nohist_userroles',$udom,$uname);
+    }
     my %returnhash=();
     my $now=time;
     foreach my $entry (keys(%dumphash)) {
@@ -4349,6 +4359,12 @@
 }
 
 sub userlog_query {
+#
+# possible filters:
+# action: log check role
+# start: timestamp
+# end: timestamp
+#
     my ($uname,$udom,%filters)=@_;
     return &log_query($uname,$udom,'userlog',%filters);
 }
@@ -6917,7 +6933,6 @@
 
 sub rndseed {
     my ($symb,$courseid,$domain,$username)=@_;
-
     my ($wsymb,$wcourseid,$wdomain,$wusername)=&whichuser();
     if (!$symb) {
 	unless ($symb=$wsymb) { return time; }
@@ -8142,6 +8157,10 @@
 B<userenvironment($udom,$uname,@what)>: gets the values of the keys
 passed in @what from the requested user's environment, returns a hash
 
+=item * 
+X<userlog_query()>
+B<userlog_query($uname,$udom,%filters)>: retrieves data from a user's activity.log file. %filters defines filters applied when parsing the log file. These can be start or end timestamps, or the type of action - log to look for Login or Logout events, check for Checkin or Checkout, role for role selection. The response is in the form timestamp1:hostid1:event1&timestamp2:hostid2:event2 where events are escaped strings of the action recorded in the activity.log file.
+
 =back
 
 =head2 User Roles
@@ -8171,16 +8190,18 @@
 
 =item *
 
-get_my_roles($uname,$udom,$types,$roles,$roledoms) : All arguments are
-optional.  Returns a hash of a user's roles, with keys set to
-colon-sparated $uname,$udom,and $role, and value set to
-colon-separated start and end times for the role. If no username and
-domain are specified, will default to current user/domain. Types,
-roles, and roledoms are references to arrays, of role statuses
-(active, future or previous), roles (e.g., cc,in, st etc.) and domains
-of the roles which can be used to restrict the list if roles
-reported. If no array ref is provided for types, will default to
-return only active roles.
+get_my_roles($uname,$udom,$context,$types,$roles,$roledoms) :
+All arguments are optional. Returns a hash of a roles, either for
+co-author/assistant author roles for a user's Construction Space
+(default), or if $context is 'user', roles for the user himself,
+In the hash, keys are set to colon-sparated $uname,$udom,and $role,
+and value is set to colon-separated start and end times for the role.
+If no username and domain are specified, will default to current
+user/domain. Types, roles, and roledoms are references to arrays,
+of role statuses (active, future or previous), roles 
+(e.g., cc,in, st etc.) and domains of the roles which can be used
+to restrict the list of roles reported. If no array ref is 
+provided for types, will default to return only active roles.
 
 =back
 
Index: loncom/enrollment/Autoupdate.pl
diff -u loncom/enrollment/Autoupdate.pl:1.3 loncom/enrollment/Autoupdate.pl:1.4
--- loncom/enrollment/Autoupdate.pl:1.3	Thu Mar  1 14:20:45 2007
+++ loncom/enrollment/Autoupdate.pl	Tue Apr  3 13:51:52 2007
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 # Automated Userinfo update script
-# $Id: Autoupdate.pl,v 1.3 2007/03/01 19:20:45 raeburn Exp $
+# $Id: Autoupdate.pl,v 1.4 2007/04/03 17:51:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,6 +30,7 @@
     use localenroll;
     use Apache::lonnet;
     use Apache::loncommon;
+    use Apache::lonlocal;
     use LONCAPA;
 
     my @info = ('inststatus','lockedname','lastname','firstname','id');
@@ -113,7 +114,7 @@
                                 if ($changes{'id'} || $changes{'fullname'}) {
                                     my %roleshash = 
                                         &Apache::lonnet::get_my_roles($uname,
-                                                  $dom,\@types,\@roles,\@cdoms);
+                                                  $dom,'userroles',\@types,\@roles,\@cdoms);
                                     foreach my $item (%roleshash) {
                                         my ($cnum,$cdom,$role) = split(/:/,$item);
                                         my ($start,$end) = split(/:/,$roleshash{$item});
@@ -137,15 +138,21 @@
                         } else {
                             if (!exists($users{$instids{$userhash{'id'}}})) {
                                 $unamechg{$uname} = $instids{$userhash{'id'}};
+                                print &mt('Username change to [_1] detected for [_2] in domain [_3].',$unamechg{$uname},$uname,$dom)."\n";
                             }
                         }
                     }
                 }
             }
         }
+        if (keys(%possnames) > 0) {
+            foreach my $uname (keys(%possnames)) {
+                my $altnames = join(' or ',@{$possnames{$uname}});
+                print &mt('Possible username change to [_1] detected for [_2] in domain [_3].',$altnames,$uname,$dom)."\n";
+            }
+        }
     }
 
-
 sub descend_tree {
     my ($dir,$depth,$alldomusers) = @_;
     if (-d $dir) {

--raeburn1175622713--