Python script for HINET login without SSO/logout (Hiroshima-univ)
Pour pratiquer Python et sélénium Pour vous connecter et vous déconnecter de l'authentification non SSO de l'Université d'Hiroshima sur le terminal A écrit le programme
s'identifier)
./nsso.py login
Se déconnecter
./nsso.py logout
Si vous ne souhaitez pas utiliser le transfert X11
DISPLAY=unix:0.0 ./nsso.py login
Et...
nsso.py
#!/usr/bin/env python2
# coding: utf-8
# program for Only "without SSO" !!!!!!
#sudo pip install selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from getpass import getpass
import sys
#import re
# https://idp.media.hiroshima-u.ac.jp/idp/Authn/UserPassword
# https://hinet.hiroshima-u.ac.jp/loginweb.html
def logout(browser):
try:
browser.get('https://hinet.hiroshima-u.ac.jp/cgi-bin/Logout.cgi')
browser.close()
print "logout success!"
except:
print "ERROR!!!"
browser.close()
def without_sso_login(browser):
try:
browser.get('https://hinet.hiroshima-u.ac.jp/login_frame.html')
username = raw_input("Username :")
password = getpass( "Password :")
browser.find_element(By.NAME,"uid").send_keys(username)
browser.find_element(By.NAME,"pwd").send_keys(password)
#raw_input("y:")
browser.find_element_by_xpath("//input[@type='submit']").click()
page=browser.page_source
if page.count("Login succeeded") >= 1 :
print "login success!"
else:
print "login filure..."
browser.close()
except:
print "ERROR!!!"
browser.close()
if __name__ == '__main__':
param = sys.argv
print "login : [./nsso.py] or [./nsso.py login]"
print "logout: [./nsso.py logout]"
print "SSO :https://idp.media.hiroshima-u.ac.jp/idp/Authn/UserPassword"
print "Not SSO:https://hinet.hiroshima-u.ac.jp/loginweb.html"
print " ---> https://hinet.hiroshima-u.ac.jp/login_frame.html"
browser = webdriver.Firefox()
if len(param) == 2 and param[1]=="logout":
print "=======LOGOUT========="
logout(browser)
print "======= END ========="
elif (len(param)==2 and param[1]=="login") or len(param)==1:
print "=======LOGIN========="
without_sso_login(browser)
print "======= END ========="