forked from JosephVidal/Epi-register
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.py
executable file
·57 lines (46 loc) · 1.89 KB
/
register.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env python3
# coding: utf-8
import sys
import requests
import random
from rich.theme import Theme
from rich.console import Console
from time import sleep
theme = Theme({"success": "green", "error": "bold red", "neutral": "white"})
console = Console(theme=theme)
def register(session, url, cookies, payload, module):
for elem in cookies:
obj = elem.split('=')
payload[obj[0]] = obj[1]
rep = session.post(url, cookies=payload)
if (rep.status_code == 200):
console.log("Registration succeed to " + module, theme="success")
return True
console.log("Failed to register to " + module + " (code " + str(rep.status_code) + ")", style="error")
return False
def main(args):
cookies = args[args.index("-c") + 1].replace(' ', '').split(";") # ex : "foo=bar; name=Jhon; lastname=Doe"
modules = args[1:args.index("-c")]
payload = {}
session = requests.Session()
time = float(args[args.index("-t") + 1]) if "-t" in args else 120
step = 0
console.log(f"Timer: {time} seconds", style="neutral")
with console.status("[bold green]Progressing...") as status:
while 1:
step = step + 1
console.log("try " + str(step), style="success")
for module in modules:
url = "https://intra.epitech.eu/module/2022/" + module + "/PAR-9-2/register?format=json"
if register(session, url, cookies, payload, module):
modules.remove(module)
if (len(modules) == 0):
break
sleep(time)
console.log('Done!', style="success")
if __name__ == "__main__":
if len(sys.argv) < 3 or not "-c" in sys.argv:
print("USAGE:\n\t./register <module_id> -c <cookies> [-t <time>]\n\nEXAMPLE\n\t./register M-BDX-001 M-PRO-045 M-TRV-014 M-PRO-002 -c \"foo=bar; name=Jhon; lastname=Doe\"")
sys.exit(84)
else:
main(sys.argv)