Index: trunk/extensions/NetworkAuth/NetworkAuth.php |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | } |
12 | 12 | |
13 | 13 | $wgNetworkAuthUsers[] = array(); |
| 14 | +$wgNetworkAuthUser = 'HelpdeskComputer'; |
14 | 15 | |
15 | 16 | $wgExtensionCredits['other'][] = array( |
16 | 17 | 'path' => __FILE__, |
— | — | @@ -24,29 +25,29 @@ |
25 | 26 | $wgExtensionMessagesFiles['NetworkAuth'] = dirname(__FILE__) . '/NetworkAuth.i18n.php'; |
26 | 27 | |
27 | 28 | function efNetworkAuth_Setup() { |
28 | | - global $wgRequest; |
| 29 | + global $wgRequest; |
29 | 30 | |
30 | | - # $wgTitle isn't initalized yet - but we need to know where we are |
31 | | - $pageTitle = Title::newFromURL( $wgRequest->getVal('title') ); |
32 | | - |
33 | | - if (is_object($pageTitle)) { |
34 | | - # Doesn't apply to Userlogin and Userlogout pages - that breaks stuff |
35 | | - if ($pageTitle->isSpecial('Userlogin') || $pageTitle->isSpecial('Userlogout')) { |
36 | | - # bail! |
37 | | - return true; |
38 | | - } |
| 31 | + # $wgTitle isn't initalized yet - but we need to know where we are |
| 32 | + $pageTitle = Title::newFromURL( $wgRequest->getVal('title') ); |
| 33 | + |
| 34 | + if (is_object($pageTitle)) { |
| 35 | + # Doesn't apply to Userlogin and Userlogout pages - that breaks stuff |
| 36 | + if ($pageTitle->isSpecial('Userlogin') || $pageTitle->isSpecial('Userlogout')) { |
| 37 | + # bail! |
| 38 | + return true; |
39 | 39 | } |
40 | | - |
41 | | - efNetworkAuth_Authenticate(); |
42 | | - |
43 | | - return true; |
| 40 | + } |
| 41 | + |
| 42 | + efNetworkAuth_Authenticate(); |
| 43 | + |
| 44 | + return true; |
44 | 45 | } |
45 | 46 | |
46 | 47 | function efNetworkAuth_checkForNetworkAuthUser() { |
47 | 48 | global $wgNetworkAuthUsers; |
48 | | - |
| 49 | + |
49 | 50 | $ip = wfGetIP(); |
50 | | - |
| 51 | + |
51 | 52 | foreach ($wgNetworkAuthUsers as $networkAuthUser) { |
52 | 53 | if ( isset( $networkAuthUser['user'] ) ) { |
53 | 54 | if ( isset( $networkAuthUser['iprange'] ) ) { |
— | — | @@ -54,7 +55,7 @@ |
55 | 56 | $ranges = $networkAuthUser['iprange']; |
56 | 57 | else |
57 | 58 | $ranges = explode("\n", $networkAuthUser['iprange']); |
58 | | - |
| 59 | + |
59 | 60 | $hex = IP::toHex( $ip ); |
60 | 61 | foreach ( $ranges as $range ) { |
61 | 62 | $parsedRange = IP::parseRange( $range ); |
— | — | @@ -65,13 +66,13 @@ |
66 | 67 | } |
67 | 68 | } |
68 | 69 | } |
69 | | - |
| 70 | + |
70 | 71 | if ( isset( $networkAuthUser['ippattern'] ) ) { |
71 | 72 | if ( is_array( $networkAuthUser['ippattern'] ) ) |
72 | 73 | $patterns = $networkAuthUser['ippattern']; |
73 | 74 | else |
74 | 75 | $patterns = explode("\n", $networkAuthUser['ippattern']); |
75 | | - |
| 76 | + |
76 | 77 | foreach ( $patterns as $pattern ) { |
77 | 78 | if ( preg_match( $pattern, $ip) ) { |
78 | 79 | global $wgNetworkAuthHost; |
— | — | @@ -86,7 +87,7 @@ |
87 | 88 | $patterns = $networkAuthUser['hostpattern']; |
88 | 89 | else |
89 | 90 | $patterns = explode("\n", $networkAuthUser['hostpattern']); |
90 | | - |
| 91 | + |
91 | 92 | $host = gethostbyaddr( $ip ); |
92 | 93 | foreach ( $patterns as $pattern ) { |
93 | 94 | if ( preg_match( $pattern, $host) ) { |
— | — | @@ -100,76 +101,66 @@ |
101 | 102 | # No user for range - useless. |
102 | 103 | } |
103 | 104 | } |
104 | | - |
| 105 | + |
105 | 106 | return ''; |
106 | 107 | } |
107 | 108 | |
108 | 109 | function efNetworkAuth_Authenticate() { |
109 | 110 | global $wgUser; |
110 | | - |
111 | | - $wgNetworkAuthUser = 'HelpdeskComputer'; |
112 | | - |
113 | 111 | if (!$wgUser->isLoggedIn()) { |
114 | 112 | //echo 'Logged out: ' . $wgUser->getName(); |
115 | | - |
| 113 | + |
| 114 | + $u = null; |
116 | 115 | $networkAuthUser = efNetworkAuth_checkForNetworkAuthUser(); |
117 | 116 | if ( $networkAuthUser != '' ) { |
118 | 117 | global $wgNetworkAuthUser; |
119 | 118 | $wgNetworkAuthUser = $networkAuthUser; |
120 | 119 | |
121 | | - $u = User::newFromName( $wgNetworkAuthUser ); |
| 120 | + $u = User::newFromName( $wgNetworkAuthUser ); |
122 | 121 | } |
123 | | - |
124 | | - if( is_null( $u ) || !User::isUsableName( $u->getName() ) ) { |
125 | | - # Not cool. Bad config |
126 | | - } else { |
127 | | - if ( 0 == $u->getID() ) { |
128 | | - # Not cool. Bad username |
129 | | - } else { |
| 122 | + |
| 123 | + if( is_null( $u ) && !User::isUsableName( $u->getName() ) ) { |
| 124 | + if ( !$u->isAnon() ) { |
130 | 125 | # Finally. |
131 | 126 | $u->load(); |
132 | 127 | $wgUser = $u; |
133 | | - |
| 128 | + |
134 | 129 | # Since we're not really logged in, just pretending - force a logout |
135 | 130 | # before the page gets displayed. |
136 | 131 | global $wgHooks; |
137 | 132 | $wgHooks['BeforePageDisplay'][] = 'efNetworkAuth_ForceLogout'; |
138 | | - |
| 133 | + |
139 | 134 | # Add a display message to the personal URLs |
140 | 135 | $wgHooks['PersonalUrls'][] = 'efNetworkAuth_PersonalUrls'; |
141 | 136 | } |
142 | 137 | } |
143 | | - } else { |
144 | | - # Already logged in, do nothing. |
145 | 138 | } |
146 | 139 | return true; |
147 | 140 | } |
148 | 141 | |
149 | 142 | function ar_gethostbyaddr($ip) { |
150 | | - $output = `host -W 1 $ip`; |
151 | | - if (ereg('.*pointer ([A-Za-z0-9.-]+)\..*',$output,$regs)) { |
152 | | - return $regs[1]; |
153 | | - } |
154 | | - return $ip; |
| 143 | + $output = `host -W 1 $ip`; |
| 144 | + if (ereg('.*pointer ([A-Za-z0-9.-]+)\..*',$output,$regs)) { |
| 145 | + return $regs[1]; |
| 146 | + } |
| 147 | + return $ip; |
155 | 148 | } |
156 | 149 | |
157 | | -function efNetworkAuth_PersonalUrls($personal_urls, $title) { |
| 150 | +function efNetworkAuth_PersonalUrls(&$personal_urls, &$title) { |
158 | 151 | global $wgNetworkAuthUser, $wgNetworkAuthHost; |
159 | | - |
| 152 | + |
160 | 153 | // Lazy load the i18n stuff here |
161 | | - |
162 | | - |
| 154 | + |
163 | 155 | if (isset($personal_urls['anonuserpage'])) { |
164 | 156 | $personal_urls['anonuserpage']['text'] = |
165 | 157 | wfMsg('networkauth-purltext', $wgNetworkAuthUser, $wgNetworkAuthHost); |
166 | 158 | } else { |
167 | | - global $wgUser; |
168 | 159 | $newUrls['anonuserpage'] = array( |
169 | 160 | 'text' => wfMsg('networkauth-purltext', $wgNetworkAuthUser, $wgNetworkAuthHost), |
170 | 161 | 'href' => null, |
171 | 162 | 'active' => true |
172 | 163 | ); |
173 | | - |
| 164 | + |
174 | 165 | foreach($personal_urls as $key => $value) { |
175 | 166 | if ( $key == 'login' ) |
176 | 167 | $newUrls['anonlogin'] = $value; |
— | — | @@ -185,6 +176,6 @@ |
186 | 177 | # Force logout after most of the permission checks |
187 | 178 | global $wgUser; |
188 | 179 | $wgUser->logout(); |
189 | | - |
| 180 | + |
190 | 181 | return true; |
191 | 182 | } |