Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shiftleader] Automatically get the list of shifters from the shift list #208

Closed
nothingface0 opened this issue Aug 24, 2022 · 1 comment
Labels
wontfix This will not be worked on

Comments

@nothingface0
Copy link
Contributor

nothingface0 commented Aug 24, 2022

This requires some kind of access to https://cmsonline.cern.ch/webcenter/portal/cmsonline/pages_common/shiftlist

What did not work:

  • cernrequests to get cookies/authenticate via SSL
  • cern-sso which does the same

It either means:

  • No SSL clients are enabled for this site (verified by authorized personnel)
  • Some black magic (which I don't know how you can conjure) is required

I have queried for API availability.


Update

  • No API is available
  • SSL authentication is not available
@nothingface0 nothingface0 changed the title is it possible to get the list of shifters from the shift list? [Shiftleader] Automatically get the list of shifters from the shift list Aug 24, 2022
@nothingface0
Copy link
Contributor Author

nothingface0 commented Aug 24, 2022

Code which I wrote to bypass the SAML (?) redirect and I don't want to let go to waste:

from html.parser import HTMLParser
import requests
import cernrequests

class LandingPageHTMLParser(HTMLParser):
    def __init__(self, *args, **kwargs):
        self._found_form_url = False
        self._found_saml_token = False
        self.form_url = None
        self.saml_token = None

        super().__init__(*args, **kwargs)

    def handle_starttag(self, tag, attrs):
        if tag == "form":
            for attr in attrs:
                if attr[0] == "action":
                    self._found_form_url = True
                    self.form_url = attr[1]
        elif tag == "input":
            if "SAMLRequest" in [v[1] for v in attrs]:
                self.saml_token = [v[1] for v in attrs if "value" in v[0]][0]
                self._found_saml_token = True

    # def handle_endtag(self, tag):
    #     pass
    # def handle_data(self, data):
    # print("Encountered some data  :", data)

    @property
    def can_continue(self):
        return self._found_form_url and self._found_saml_token

html_parser = LandingPageHTMLParser()
cert = cernrequests.certs.default_user_certificate_paths()            
ca_bundle = cernrequests.certs.where()                                
                                                                      
response = requests.get("https://cmsonline.cern.ch/webcenter/portal/cmsonline/pages_common/shiftlist", cert=cert, verify=ca_bundle)        
html_parser.feed(response.text)                                  
if html_parser.can_continue:                                     
    print("Successfully parsed SAML page")                                                         
                                                                     
data = {"SAMLRequest": html_parser.saml_token}                   
                                                                      
response = requests.post(                                             
    html_parser.form_url, data=data, cert=cert, verify=ca_bundle 
)              
# At this point the response.url is the Auth login page                                                       

This will reach the Login page, but no SSL client is allowed from this point on, meaning that the code below does not work:

url = cernrequests.cookies._construct_certificate_authentication_url(
            response.url
        )
response = requests.get(url, cert=cert, verify=ca_bundle)

@nothingface0 nothingface0 added the wontfix This will not be worked on label Aug 25, 2022
@nothingface0 nothingface0 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant