2023-05-13 19:58:48 +02:00
|
|
|
open Pusk.Net
|
|
|
|
open Pusk.Utils
|
2023-05-14 01:57:29 +02:00
|
|
|
(* open Twostep *)
|
2023-05-13 19:58:48 +02:00
|
|
|
|
2023-05-14 01:57:29 +02:00
|
|
|
let login_twitter ctx username password _secret =
|
2023-05-13 22:13:26 +02:00
|
|
|
(* Navigate to login page and wait for page loaded*)
|
2023-05-13 20:31:46 +02:00
|
|
|
ignore (navigate ctx.session_id "https://twitter.com/i/flow/login");
|
|
|
|
Unix.sleep 5;
|
2023-05-13 22:13:26 +02:00
|
|
|
(* Find username input *)
|
2023-05-14 01:44:11 +02:00
|
|
|
let input_username =
|
2023-05-13 22:13:26 +02:00
|
|
|
match
|
|
|
|
find
|
|
|
|
ctx.session_id
|
|
|
|
(XPath
|
|
|
|
"/html/body/div[1]/div/div/div[1]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div/div/div/div[5]/label/div/div[2]/div/input")
|
|
|
|
with
|
|
|
|
| [] -> raise (Any "Username input not found")
|
|
|
|
| _ as l ->
|
|
|
|
if List.length l > 1
|
|
|
|
then raise (Any "Too many element found as the username input")
|
|
|
|
else List.nth l 0
|
|
|
|
in
|
|
|
|
(* Insert the username *)
|
2023-05-14 01:44:11 +02:00
|
|
|
send_keys ctx.session_id input_username username;
|
|
|
|
Unix.sleep 1;
|
|
|
|
send_keys ctx.session_id input_username Keys.return;
|
|
|
|
Unix.sleep 3;
|
|
|
|
(* Find password input *)
|
|
|
|
let input_password =
|
|
|
|
match
|
|
|
|
find
|
|
|
|
ctx.session_id
|
|
|
|
(XPath
|
|
|
|
"/html/body/div[1]/div/div/div[1]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div/div[3]/div/label/div/div[2]/div[1]/input")
|
|
|
|
with
|
|
|
|
| [] -> raise (Any "Password input not found")
|
|
|
|
| _ as l ->
|
|
|
|
if List.length l > 1
|
|
|
|
then raise (Any "Too many element found as the password input")
|
|
|
|
else List.nth l 0
|
|
|
|
in
|
|
|
|
(* Insert password *)
|
|
|
|
send_keys ctx.session_id input_password password;
|
|
|
|
Unix.sleep 1;
|
|
|
|
send_keys ctx.session_id input_password Keys.return;
|
2023-05-14 01:57:29 +02:00
|
|
|
Unix.sleep 5;
|
|
|
|
(* Detection of 2FA *)
|
|
|
|
(* TODO *)
|
|
|
|
(* Generate code if possible *)
|
|
|
|
(* let code =
|
|
|
|
match secret with
|
|
|
|
| Some seed -> Twostep.TOTP.code ~secret:seed ()
|
|
|
|
| None -> raise (Any "No TOTP code given, but TOTP required")
|
|
|
|
in *)
|
|
|
|
()
|
2023-05-13 19:58:48 +02:00
|
|
|
;;
|