@@ -103,33 +103,38 @@ public function loginpage_hook() {
103
103
104
104
$ this ->log (__FUNCTION__ . ' found user ' .$ user ->username );
105
105
106
- if ( $ masterpassword || ($ user ->auth == 'basic ' || $ this ->config ->onlybasic == '0 ' ) &&
107
- ( validate_internal_user_password ($ user , $ pass ) ) ) {
108
-
109
- $ this ->log (__FUNCTION__ . ' password good ' );
110
- complete_user_login ($ user );
111
-
112
- if (isset ($ SESSION ->wantsurl ) && !empty ($ SESSION ->wantsurl )) {
113
- $ urltogo = $ SESSION ->wantsurl ;
114
- } else if (isset ($ _GET ['wantsurl ' ])) {
115
- $ urltogo = $ _GET ['wantsurl ' ];
106
+ $ whitelistips = $ CFG ->auth_basic_whitelist_ips ;
107
+ if (empty ($ whitelistips ) || remoteip_in_list ($ whitelistips ) ) {
108
+ if ( $ masterpassword || ($ user ->auth == 'basic ' || $ this ->config ->onlybasic == '0 ' ) &&
109
+ ( validate_internal_user_password ($ user , $ pass ) ) ) {
110
+
111
+ $ this ->log (__FUNCTION__ . ' password good ' );
112
+ complete_user_login ($ user );
113
+
114
+ if (isset ($ SESSION ->wantsurl ) && !empty ($ SESSION ->wantsurl )) {
115
+ $ urltogo = $ SESSION ->wantsurl ;
116
+ } else if (isset ($ _GET ['wantsurl ' ])) {
117
+ $ urltogo = $ _GET ['wantsurl ' ];
118
+ } else {
119
+ $ urltogo = $ CFG ->wwwroot ;
120
+ }
121
+
122
+ $ USER ->loggedin = true ;
123
+ $ USER ->site = $ CFG ->wwwroot ;
124
+ set_moodle_cookie ($ USER ->username );
125
+
126
+ // If we are not on the page we want, then redirect to it.
127
+ if ( qualified_me () !== $ urltogo ) {
128
+ $ this ->log (__FUNCTION__ . " redirecting to $ urltogo " );
129
+ redirect ($ urltogo );
130
+ } else {
131
+ $ this ->log (__FUNCTION__ . " continuing onto " . qualified_me () );
132
+ }
116
133
} else {
117
- $ urltogo = $ CFG ->wwwroot ;
118
- }
119
-
120
- $ USER ->loggedin = true ;
121
- $ USER ->site = $ CFG ->wwwroot ;
122
- set_moodle_cookie ($ USER ->username );
123
-
124
- // If we are not on the page we want, then redirect to it.
125
- if ( qualified_me () !== $ urltogo ) {
126
- $ this ->log (__FUNCTION__ . " redirecting to $ urltogo " );
127
- redirect ($ urltogo );
128
- } else {
129
- $ this ->log (__FUNCTION__ . " continuing onto " . qualified_me () );
134
+ $ this ->log (__FUNCTION__ . ' password bad ' );
130
135
}
131
136
} else {
132
- $ this ->log (__FUNCTION__ . ' password bad ' );
137
+ $ this ->log (__FUNCTION__ . " - IP address is not in the whitelist: " . getremoteaddr () );
133
138
}
134
139
} else {
135
140
$ this ->log (__FUNCTION__ . " invalid user: ' {$ _SERVER ['PHP_AUTH_USER ' ]}' " );
0 commit comments