EDIT - Just added entire cURL function for reference/more information but need help with if statements - regex
Looking for help to understand the if statements in this cURL. I've read through some python documentation and I understand each of the pieces, that this is searching with regex and replacing. Just hoping someone might be able to help give a bigger picture explanation. I don't really understand the .groups.
To give a little more background this script is accessing another site via cURL it stores a cookie and when ran checks if cookie is valid, if not it grabs a new one after posting username/password. The site recently changed and I'm trying to figure out what I need to change to get this working again.
#get auth cookie for sso
def getAuthCookie( self ):
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.SSL_VERIFYPEER, False)
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.TIMEOUT, 60)
c.setopt(c.USERPWD, self.user+":"+cred.getpasswd( self.encPasswd ) )
c.setopt(c.URL, 'https://sso.sample.com')
c.setopt(c.COOKIEJAR, self.cookieDir)
c.setopt(c.COOKIEFILE, self.cookieDir )
c.setopt(c.WRITEFUNCTION, buffer.write)
c.perform()
c.unsetopt(c.USERPWD)
c.setopt(c.URL, 'https://sample.com')
c.perform()
html = str(buffer.getvalue())
----------------------------------------------------------
if "RelayState" in html:
rex = re.compile( "input type=\"hidden\" name=\"RelayState\" value=\"(.*)\"" )
RELAY = rex.search( html ).groups()[0]
if "SAMLResponse" in html:
rex = re.compile( "input type=\"hidden\" name=\"SAMLResponse\" value=\"(.*)\"" )
SAML = rex.search( html ).groups()[0]
datastuff = {'SAMLResponse':SAML,'RelayState':RELAY,'redirect':'Redirect','show_button':'true'}
if "form method=\"POST\" action=" in html:
rex = re.compile( "form method=\"POST\" action=\"(.*)\" " )
postUrl = rex.search( html ).groups()[0]
----------------------------------------------------------
#post our saml obtained, get to our final dest
c.setopt(c.URL, postUrl )
c.setopt(c.POST, True)
c.setopt(c.POSTFIELDS, urlencode( datastuff ))
c.perform()
c.close()