Last active
March 7, 2016 17:21
-
-
Save magnuspedro/4589dc947e850913114d to your computer and use it in GitHub Desktop.
Auto Login UTFPR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import requests | |
import re | |
import logging | |
import sys | |
import os | |
import getpass | |
from os.path import expanduser | |
logging.captureWarnings(True) | |
requests.packages.urllib3.disable_warnings() | |
HOME = expanduser("~") | |
urlLogin = "https://1.1.1.1/login.html" | |
urlLogout = "https://1.1.1.1/logout.html" | |
ra = "" | |
senha = "" | |
def Login(urlLogin,ra,senha): | |
try: | |
payload = {'buttonClicked':'4','err_flag':'0','err_msg':'','info_flag':0,'info_msg':'','redirect_url':'','username':ra,'password':senha} | |
headers = {'Referer': urlLogin} | |
response = requests.post(urlLogin, data=payload, headers=headers, verify=False) | |
data = response.text | |
result = open("/tmp/result.html",'w') | |
result.write(data) | |
except Exception as e: | |
raise | |
finally: | |
if re.search("Login Successful",data): | |
print ("\033[1;32mLogin Successful\033[0m") | |
else: | |
print ("\033[1;31mLogin Fail ;-;\033[0m") | |
def Logout(urlLogout): | |
try: | |
payload = {'userStatus':'1','err_flag':'0','err_msg':''} | |
headers = {'Referer':urlLogout} | |
response = requests.post(urlLogout, data=payload, headers=headers, verify=False) | |
data = response.text | |
except Exception as e: | |
pass | |
finally: | |
if re.search("To complete the log off process and to prevent access to unauthorize",data): | |
print ("\033[1;32mLogout Successful\033[0m") | |
else: | |
print ("\033[1;31mLogout Fail ;-;\033[0m") | |
def SignUp(ra,senha): | |
newra = "" | |
newsenha="" | |
ra = input("Digite o RA com a: ") | |
senha = getpass.getpass(); | |
for r in ra: | |
newra += chr(ord(r)-13) | |
for s in senha: | |
newsenha += chr(ord(s)+3) | |
with open(HOME+'/.person','w') as fopen: | |
print(newra+" "+newsenha,file = fopen) | |
def Descript(): | |
global ra | |
global senha | |
new_ra = "" | |
new_senha = "" | |
with open(HOME+'/.person') as fopen: | |
for user in fopen: | |
user = user.strip().split(' ') | |
ra = user[0] | |
senha = user[1] | |
for r in ra: | |
new_ra += chr(ord(r)+13) | |
for s in senha: | |
new_senha += chr(ord(s)-3) | |
ra = new_ra.strip() | |
senha = new_senha.strip() | |
def Delete(): | |
os.remove(HOME+'/.person') | |
print ("\033[1;31mFile Revomed (Y)\033[0m") | |
if __name__ == '__main__': | |
newra = "" | |
newsenha = "" | |
if len(sys.argv) > 1: | |
argv = sys.argv[1] | |
if(argv == "-s"): | |
SignUp(ra,senha) | |
if os.path.isfile(HOME+'/.person'): | |
Descript() | |
if(argv == "-h"): | |
print("\033[1mUTFPR - PG\033[0m\n Login Service\n -s Cadastro\n -i Login\n -o Logout") | |
if(argv == "-i"): | |
Login(urlLogin,ra,senha) | |
if(argv == "-o"): | |
Logout(urlLogout) | |
if(argv == "-d"): | |
Delete() | |
else: | |
print ("\033[1mFavor Fazer o Cadastro [-s]\033[0m") | |
else: | |
if os.path.isfile(HOME+'/.person'): | |
Descript() | |
Login(urlLogin,ra,senha) | |
else: | |
print ("\033[1mFavor Fazer o Cadastro [-s]\033[0m") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment