Guest User

Untitled

a guest
May 6th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1.     #!/home/sahil/anaconda3/bin/python3
  2. """
  3. A simple python script to automate IIT Mandi Gateway Authentication
  4. Author : Abhishek Pandey
  5. """
  6. from __future__ import print_function
  7. import getpass
  8. import signal
  9. import time
  10. import requests
  11.  
  12.  
  13. def main():
  14.     """
  15.    This function does pretty much everything.
  16.    """
  17.     ans = -1
  18.     client = requests.session()
  19.     gateways = ['stgw.iitmandi.ac.in/ug', 'gateway.iitmandi.ac.in/facstaff']
  20.     auths = ['https://' + url + '/authenticate.php' for url in gateways]
  21.     logouts = ['http://' + url + '/logout.php' for url in gateways]
  22.     success_urls = ['http://' + url + '/success.php' for url in gateways]
  23.     print("Please Choose your proxy server")
  24.     for i, auth in enumerate(auths):
  25.         print("[{}] {}".format(i + 1, auth))
  26.     ans = input().strip()
  27.     if ans not in ('1', '2'):
  28.         print("Only 1 or 2 accepted as answers")
  29.         return
  30.     ans = int(ans) - 1
  31.     auth = auths[ans]
  32.  
  33.     def logout(signal, frame):
  34.         """
  35.        SIGINT handler. Is run on Ctrl-C or kill by User
  36.        Logs out the user.
  37.        """
  38.         print("Logging Out")
  39.         if ans == -1:
  40.             return
  41.         resp = client.get(logouts[ans])
  42.         if "Thankyou" in resp.text:
  43.             print ("Logged out successfully!")
  44.             exit(0)
  45.         else:
  46.             print ("Unable to logout!")
  47.  
  48.  
  49.     signal.signal(signal.SIGINT, logout)
  50.     print("Username: ")
  51.     user = input()
  52.     passwd = getpass.getpass()
  53.     resp = client.post(auth, dict(username=user, password=passwd, url=""))
  54.     email = "{}@students.iitmandi.ac.in".format(user)
  55.     if email in resp.text:
  56.         print("Login Successful")
  57.     else:
  58.         print("Login Failed. Please try again")
  59.         return
  60.     while True:
  61.         time.sleep(20 * 60)
  62.         client.get(success_urls[ans])
  63.  
  64.  
  65. if __name__ == '__main__':
  66.     main()
Add Comment
Please, Sign In to add comment