~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to auth/cas/auth.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        }
49
49
    }
50
50
    /**
51
 
     * Authenticates user againt CAS 
 
51
     * Authenticates user againt CAS
52
52
     * Returns true if the username and password work and false if they are
53
53
     * wrong or don't exist.
54
54
     *
57
57
     * @return bool Authentication success or failure.
58
58
     */
59
59
    function user_login ($username, $password) {
60
 
                $this->connectCAS();
 
60
                $this->connectCAS();    
61
61
        return phpCAS::isAuthenticated();
62
62
    }
63
63
    /**
84
84
     */
85
85
    function loginpage_hook() {
86
86
      global $frm;
87
 
      global $test;
88
87
      global $CFG;
 
88
          global $SESSION;
 
89
 
89
90
      $site = get_site();
90
91
      $CASform = get_string("CASform","auth");
91
92
      $username = optional_param("username");
 
93
 
92
94
      if (!empty($username)) {
93
 
          return;
 
95
                  if (strstr($SESSION->wantsurl,'ticket') || strstr($SESSION->wantsurl,'NOCAS'))
 
96
                          unset($SESSION->wantsurl);
 
97
          return;               
94
98
        }
95
99
 
 
100
 
 
101
                
 
102
                // Test si cas activ� et param�tres non remplis
 
103
          if (empty($this->config->hostname)) {
 
104
                  return;
 
105
                  }
 
106
 
96
107
// Connection to CAS server
97
108
         $this->connectCAS();
98
109
 
99
 
          // Gestion de la connection CAS si acc�s direct d'un ent ou autre      
 
110
          // Gestion de la connection CAS si acc�s direct d'un ent ou autre     
100
111
         if (phpCAS::checkAuthentication()) {
101
112
                $frm->username=phpCAS::getUser();
102
 
                $frm->password="cas";             
 
113
//              if (phpCAS::getUser()=='esup9992')
 
114
//                      $frm->username='erhar0062';
 
115
                $frm->password="passwdCas";             
103
116
                return;
104
 
         }
 
117
         }              
 
118
 
 
119
          if ($_GET["loginguest"]== true) {
 
120
                        $frm->username="guest";
 
121
                        $frm->password="guest";
 
122
                        return;
 
123
          }             
105
124
         
106
125
     if ($this->config->multiauth) {
107
126
          $authCAS = optional_param("authCAS");
108
 
          if ($authCAS=="NOCAS") 
 
127
          if ($authCAS=="NOCAS")
109
128
            return;
110
 
            
 
129
 
111
130
// choice authentication form for multi-authentication
112
131
// test pgtIou parameter for proxy mode (https connection
113
132
// in background from CAS server to the php server)
114
133
      if ($authCAS!="CAS" && !isset($_GET["pgtIou"])) {
115
 
            print_header("$site->fullname: $CASform", $site->fullname, $CASform);
 
134
            $navlinks = array();
 
135
            $navlinks[] = array('name' => $CASform, 'link' => null, 'type' => 'misc');
 
136
            $navigation = build_navigation($navlinks);
 
137
 
 
138
            print_header("$site->fullname: $CASform", $site->fullname, $navigation);
116
139
            include($CFG->dirroot."/auth/cas/cas_form.html");
117
140
            print_footer();
118
141
            exit();
123
146
        {phpCAS::forceAuthentication();}
124
147
}
125
148
    /**
126
 
     * logout from the cas 
 
149
     * logout from the cas
127
150
     *
128
151
     * This function is called from admin/auth.php
129
152
     *
133
156
          if ($this->config->logoutcas ) {
134
157
                $backurl = $CFG->wwwroot;
135
158
                  $this->connectCAS();
136
 
                phpCAS::logout($backurl);        
 
159
                phpCAS::logout($backurl);
137
160
             }
138
161
    }
139
162
    /**
140
 
     * Connect to the cas (clientcas connection or proxycas connection 
 
163
     * Connect to the cas (clientcas connection or proxycas connection
141
164
     *
142
165
     * This function is called from admin/auth.php
143
166
     *
198
221
    function process_config($config) {
199
222
        // set to defaults if undefined
200
223
        // CAS settings
201
 
        if (!isset ($config->hostname)) 
 
224
        if (!isset ($config->hostname))
202
225
            $config->hostname = '';
203
 
        if (!isset ($config->port)) 
 
226
        if (!isset ($config->port))
204
227
            $config->port = '';
205
 
        if (!isset ($config->casversion)) 
 
228
        if (!isset ($config->casversion))
206
229
            $config->casversion = '';
207
 
        if (!isset ($config->baseuri)) 
 
230
        if (!isset ($config->baseuri))
208
231
            $config->baseuri = '';
209
 
        if (!isset ($config->language)) 
 
232
        if (!isset ($config->language))
210
233
            $config->language = '';
211
 
        if (!isset ($config->use_cas)) 
212
 
            $config->use_cas = '';
213
 
        if (!isset ($config->proxycas)) 
 
234
        if (!isset ($config->proxycas))
214
235
            $config->proxycas = '';
215
 
        if (!isset ($config->logoutcas)) 
 
236
        if (!isset ($config->logoutcas))
216
237
            $config->logoutcas = '';
217
238
        if (!isset ($config->multiauth))
218
239
            $config->multiauth = '';
255
276
        set_config('casversion',     $config->casversion,     'auth/cas');
256
277
        set_config('baseuri',     $config->baseuri,     'auth/cas');
257
278
        set_config('language',    $config->language,    'auth/cas');
258
 
        set_config('use_cas',     $config->use_cas,     'auth/cas');
259
279
        set_config('proxycas',     $config->proxycas,     'auth/cas');
260
280
        set_config('logoutcas',     $config->logoutcas,     'auth/cas');
261
281
        set_config('multiauth',     $config->multiauth,     'auth/cas');
467
487
     * @return array
468
488
     */
469
489
    function ldap_attributes () {
470
 
        $fields = array("firstname", "lastname", "email", "phone1", "phone2",
471
 
                        "department", "address", "city", "country", "description",
472
 
                        "idnumber", "lang" );
473
490
        $moodleattributes = array();
474
 
        foreach ($fields as $field) {
 
491
        foreach ($this->userfields as $field) {
475
492
            if (!empty($this->config->{"field_map_$field"})) {
476
493
                $moodleattributes[$field] = $this->config->{"field_map_$field"};
477
494
                if (preg_match('/,/',$moodleattributes[$field])) {
678
695
        // find users in DB that aren't in ldap -- to be removed!
679
696
        // this is still not as scalable (but how often do we mass delete?)
680
697
        if (!empty($this->config->removeuser)) {
681
 
            $sql = "SELECT u.id, u.username, u.email
 
698
            $sql = "SELECT u.id, u.username, u.email, u.auth
682
699
                    FROM {$CFG->prefix}user u
683
700
                        LEFT JOIN $temptable e ON u.username = e.username
684
701
                    WHERE u.auth='cas'
687
704
            $remove_users = get_records_sql($sql);
688
705
            if (!empty($remove_users)) {
689
706
                print "User entries to remove: ". count($remove_users) . "\n";
690
 
                begin_sql();
691
707
                foreach ($remove_users as $user) {
692
708
                    if ($this->config->removeuser == 2) {
693
 
                        //following is copy pasted from admin/user.php
694
 
                        //maybe this should moved to function in lib/datalib.php
695
 
                        $updateuser = new object();
696
 
                        $updateuser->id           = $user->id;
697
 
                        $updateuser->deleted      = 1;
698
 
                        $updateuser->username     = addslashes("$user->email.".time());  // Remember it just in case
699
 
                        $updateuser->email        = '';               // Clear this field to free it up
700
 
                        $updateuser->idnumber     = '';               // Clear this field to free it up
701
 
                        $updateuser->timemodified = time();
702
 
                        if (update_record('user', $updateuser)) {
703
 
                            delete_records('role_assignments', 'userid', $user->id); // unassign all roles
704
 
                        //copy pasted part ends
 
709
                        if (delete_user($user)) {
705
710
                            echo "\t"; print_string('auth_dbdeleteuser', 'auth', array($user->username, $user->id)); echo "\n";
706
711
                        } else {
707
712
                            echo "\t"; print_string('auth_dbdeleteusererror', 'auth', $user->username); echo "\n";
717
722
                        }
718
723
                    }
719
724
                }
720
 
                commit_sql();
721
725
            } else {
722
726
                print "No user entries to be removed\n";
723
727
            }