+ Post New Thread
Results 1 to 5 of 5
Coding Thread, Perl Moodle framework in Coding and Web Development; PHP Code: #!/usr/bin/perl #moodle email script #dedicated to all junior IT techs who get all the shitty jobs #this script dedicated my senior tech, BRUVA! use  strict ; use  warnings ; use  LWP :: UserAgent ; use  HTTP :: ...
  1. #1

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    15

    Perl Moodle framework

    PHP Code:
    #!/usr/bin/perl
    #moodle email script
    #dedicated to all junior IT techs who get all the shitty jobs
    #this script dedicated my senior tech, BRUVA!
    use strict;
    use 
    warnings;
    use 
    LWP::UserAgent;
    use 
    HTTP::Request::Common;
    use 
    Getopt::Long;
    use 
    Crypt::SSLeay;
    my %options;
    #define your options here
    %options = ( 'vle' => 'vle.broughton.lancsngfl.ac.uk',
          
    'emaildomain' => '@bbec.lancs.sch.uk',
           );
    GetOptions(\%options,     'user=s',
                              
    'pass=s',
                              
    'url=s',
                  
    'newuser=s',
                  
    'newpass=s',
                  
    'createuser',
                            );

    #create useragent object
    my $ua LWP::UserAgent->newcookie_jar => ({}) );
    $ua->env_proxy();
    my $return $ua->request(POST "http://login.vle.cleo.net.uk/1.8.2/?vle=$options{vle}",
                    [ 
    username => $options{user},
                      
    password => $options{pass},
                      
    testcookies => 0,
                      
    submit => 'Login',
                    ],
                );
    my ($token) = $return->content =~ /token=([0-9a-f]+)\'/;
    push @{ $ua->requests_redirectable }, '
    POST';
    $return = $ua->request(GET "http://login.vle.cleo.net.uk/content.php?"
                    ."url=http://$options{vle}/login/secure_login.php?token=$token");
    #check if login succeeded
    $return = $ua->request(GET "http://$options{vle}");
    die "Login failed" unless $return->content =~ /User Admin/;
    my ($sesskey) = $return->content =~ /sesskey=(\S+)\"/;

    #edituser($options{newuser}, $options{newpass}, $sesskey) if $options{createuser};
    my @uids = grabbyquery($sesskey, '
    cleo');
    for my $userid (@uids) {
    print $userid . "\n";
    }

    sub edituser {
    my ($username, $password, $sesskey) = @_;
    my ($lastname, $firstname) = $username =~ /([0-9a-z]+)([a-z])$/;
    my $uid = finduid($username) || '
    -1';
    my $return = $ua->request(POST '
    http://$options{vle}/user/editadvanced.php',
                    
    Content_Type => 'form-data',
                    
    Content => [
                    
    username => $username,
                    
    newpassword => $password,
                    
    preference_auth_forcepasswordchange => 1,
                    
    firstname => $firstname,
                    
    lastname => $lastname,
                    
    email => $username $options{email},
                    
    city => 'Preston',
                    
    country => 'GB',
                    
    MAX_FILE_SIZE => 31457280,
                    
    id => $uid,
                    
    course => 1,
                    
    mform_showadvanced_last => 0,
                    
    sesskey => $sesskey,
                    
    _qf__user_editadvanced_form => 1,
                    
    auth => 'manual',
                    
    maildisplay => 2,
                    
    emailstop => 0,
                    
    mailformat => 1,
                    
    preference_mailcharset => 0,
                    
    maildigest => 0,
                    
    autosubscribe => 1,
                    
    trackforums => 0,
                    
    htmleditor => 1,
                    
    ajax => 0,
                    
    screenreader => 0,
                    
    lang => 'en_utf8'
                    ],
                    );
    }

    sub finduid {
    my $username shift;
    my $return $ua->request(GET "http://$options{vle}/admin/user.php?search=$username");
    my ($uid) = $return->content =~ /\.\.\/user\/view.php\?id=([0-9]+)/;
    return 
    $uid;
    }

    sub deluser {
    my ($username$sesskey) = @_;
    my $uid finduid($username);
    my $return $ua->request(GET "http://$options{vle}/admin/user.php?delete=$uid&sesskey=$sesskey");
    my ($verify) = $return->content =~ /confirm" value="([a-z0-9]+)"/;
    print "
    $verify\n";
    $return = $ua->request(POST 'http://$options{vle}/admin/user.php',
                Content => [
                        delete => 
    $uid,
                        confirm => 
    $verify,
                        sesskey => 
    $sesskey,
                       ],
                );
    }

    sub grabbyquery {
    my (
    $sesskey$search) = @_;
    my 
    $return = $ua->request(GET "http://$options{vle}/admin/user.php?sort=firstname&
                       
    dir=ASC&perpage=30&firstinitial=&lastinitial=&$search=cleo&page=0");
    my 
    $hits = $return->content =~ />([0-9]+) \//;
    $return = $ua->request(GET "http://$options{vle}/admin/user.php?sort=firstname&
                    
    dir=ASC&perpage=$hits&firstinitial=&lastinitial=&search=$search&page=0");
    my @uids = 
    $return->content =~ /\.\.\/user\/view.php\?id=([0-9]+)/g;
    return @uids;

    Just another quickie, I wrote this one this yesterday. Its just a simple moodle framework that can do password resets, delete users.

    its pretty self explanatory and you have to do a bit of work with the code to make it do what you want.

    the grabby() sub is nice cos you can then edit users via a search of the moodle user base...

    the reason i scripted it up is because cleo does not give us any decent database access. this means i cannot fix an error they made (alot of our users are given the @cleo.void.net.uk email which is lame, with this i can easily update all the users to their correct email.

    i know the answer is to host our own moodle but thats not viable atm, so cleo if you read this, PLEASE GIVE US PHPMYADMIN ACCESS!

    have phun!

  2. #2

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 595 Times in 446 Posts
    Rep Power
    170
    Very interesting - I think the moodle team need to give you a job

    Why don't you just use the normal user account/bulk upload facility for password/email changes?

    regards

    Simon

  3. #3

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    15
    Yeah, we've done that for a while..the problem arises when you need to delete users...e.g. at the end of the year when you need to remove a yeargroup.
    By default the SIMS upload utility creates those users with the broken email address's, at least from what i remember..

    Don't forget it also saves alot of time by making it easy to add a user in a single command, delete a user or reset the password..(it was also fun )

    anyway, any improvments, suggestions are welcomed (i know the code quality is a little shoddy, it needs tidying up )

    also, id love a job at cleo...if it paid better that is (which im sure it would)

  4. #4

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    You can bulk delete in 1.9.

  5. #5

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    15
    Thanks for the info Geoff, i dont tend to keep much of an interest in the moodle CVS :P

    but like i say, its just a framework, there is much more possibilities than just the bulk delete..iv combined it with the lgfl script too so now i can create both users at once...now for AD intergration

    Have any other idea's i could add to it anyone? Geoff?



SHARE:
+ Post New Thread

Similar Threads

  1. .net Framework 3.0
    By AnnDroyd in forum Windows
    Replies: 5
    Last Post: 25th September 2007, 10:18 AM
  2. Perl Help
    By danIT in forum Coding
    Replies: 9
    Last Post: 1st August 2007, 12:35 PM
  3. Deploying .net Framework 3
    By sidewinder in forum Windows
    Replies: 6
    Last Post: 22nd June 2007, 08:49 AM
  4. Backup Perl Script
    By ranj in forum Scripts
    Replies: 1
    Last Post: 30th April 2006, 09:02 PM
  5. Net Framework 1.1 or 2.0
    By Kyle in forum Windows
    Replies: 2
    Last Post: 6th February 2006, 01:16 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •