Skip to content

Commit

Permalink
Updated for security changes in MW1.15.13: https://bugzilla.wikimedia…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Apr 7, 2010
1 parent 2f44ae3 commit 6b16f7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
3 changes: 2 additions & 1 deletion modules/BaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__( self, verbose = True ):
###################
class Error( Exception ):
"""Base error class"""

class LoginTokenRequestedError( Error ):
"""Indicates a login token must be sent back to complete login (MediaWiki 1.15.3+)."""

###################
## Format argument
Expand Down
53 changes: 34 additions & 19 deletions modules/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,25 @@ def handleApiErrors( self ):
## Login
#######
elif self.parsed.getElementsByTagName( 'login' ):
result = self.parse( self.parsed.getElementsByTagName('login')[0].getAttribute('result') )
error = self.parsed.getElementsByTagName('login')[0]
result = self.parse( error.getAttribute('result') )
if result != 'Success':
raise self.Error, {
'NoName':'NoName: You didn\'t set the lgname parameter',
'Illegal':'Illegal: You provided an illegal username',
'NoName':'NoName: You didn\'t set the lgname parameter',
'Illegal':'Illegal: You provided an illegal username',
'NotExists':'NotExists: The username you provided doesn\'t exist',
'EmptyPass':'EmptyPass: You didn\'t set the lgpassword parameter or you left it empty',
'WrongPass':'WrongPass: The password you provided is incorrect',
'WrongPluginPass':'WrongPluginPass: The password you provided is incorrect; an authentication plugin rather than MediaWiki itself rejected the password',
'CreateBlocked':'CreateBlocked: The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation',
'Throttled':'Throttled: You\'ve logged in too many times in a short time'
}.get(result, 'unknown error: "%s"')
if result == 'NeedToken':
raise self.LoginTokenRequestedError, self.parse( error.getAttribute('token') )
else:
raise self.Error, {
'NoName':'NoName: You didn\'t set the lgname parameter',
'Illegal':'Illegal: You provided an illegal username',
'NoName':'NoName: You didn\'t set the lgname parameter',
'Illegal':'Illegal: You provided an illegal username',
'NotExists':'NotExists: The username you provided doesn\'t exist',
'EmptyPass':'EmptyPass: You didn\'t set the lgpassword parameter or you left it empty',
'WrongPass':'WrongPass: The password you provided is incorrect',
'WrongToken':'WrongToken: The server asked to resubmit with a confirmation token, but refused the token it was given.',
'WrongPluginPass':'WrongPluginPass: The password you provided is incorrect; an authentication plugin rather than MediaWiki itself rejected the password',
'CreateBlocked':'CreateBlocked: The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation',
'Throttled':'Throttled: You\'ve logged in too many times in a short time'
}.get(result, 'unknown error: "%s"' % result)

#######
## prop=info
Expand Down Expand Up @@ -434,12 +439,22 @@ def login( self, force_login = False ):
self.trace()

if force_login or not self.sessions[self.url_base]['logged_in']:
# log in
self.queryApi({
'action':'login',
'lgname':self.username,
'lgpassword':self.password
}, censor_url = True)
# send initial login request
try:
self.queryApi({
'action':'login',
'lgname':self.username,
'lgpassword':self.password
}, censor_url = True)

# In MediaWiki 1.15.3+, an extra step is needed
except self.LoginTokenRequestedError, token:
self.queryApi({
'action':'login',
'lgname':self.username,
'lgpassword':self.password,
'lgtoken':token
}, censor_url = True)

# store session
self.storeSession( self.url_base, self.username )
Expand Down

0 comments on commit 6b16f7c

Please sign in to comment.