Created
November 8, 2018 15:57
-
-
Save XianThi/5f1f56e3bd2ff265cb0ba7060975438a to your computer and use it in GitHub Desktop.
e-sim work train script
This file contains hidden or 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
<?php | |
function crul($url,$header,$cookie_path,$post=false,$cookie=false){ | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLINFO_HEADER_OUT, true); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
if($post !== false){ | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
} | |
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); | |
curl_setopt($ch, CURLOPT_REFERER, "https://alpha.e-sim.org/"); | |
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); | |
if($cookie!==false){ | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); | |
} | |
$result = curl_exec($ch); | |
return $result; | |
} | |
function cookie_to_str($data){ | |
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $data, $matches); | |
$cookies = array(); | |
foreach($matches[1] as $item) { | |
parse_str($item, $cookie); | |
$cookies = array_merge($cookies, $cookie); | |
} | |
foreach ($cookies as $name => $value) { | |
$cookie_str .= $name . " =" . $value . ";"; | |
} | |
return $cookie_str; | |
} | |
function login($username,$password,$header,$cookie_path){ | |
$result = crul("https://alpha.e-sim.org",$header,$cookie_path); | |
$cookie_str = cookie_to_str($result); | |
$header[] = 'Cookie:'.$cookie_str; | |
$post_data = array('login'=>$username,'password'=>$password); | |
$post_data = http_build_query($post_data); | |
$result = crul("https://alpha.e-sim.org/login.html",$header,$cookie_path,$post_data,true); | |
$res = ['cookie'=>$cookie_str,'res'=>$result]; | |
return $res; | |
} | |
function work($cookie_path,$header){ | |
$post_data = array('action'=>'work'); | |
$post_data = http_build_query($post_data); | |
$header[]='X-Requested-With: XMLHttpRequest'; | |
$res = crul("https://alpha.e-sim.org/work/ajax?action=work",$header,$cookie_path,$post_data,true); | |
return $res; | |
} | |
function train($cookie_path,$header){ | |
$post_data = array('action'=>'train'); | |
$post_data = http_build_query($post_data); | |
$header[]='X-Requested-With: XMLHttpRequest'; | |
$res = crul("https://alpha.e-sim.org/train/ajax",$header,$cookie_path,$post_data,true); | |
return $res; | |
} | |
$header = array( | |
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', | |
'Connection: keep-alive', | |
'Host: alpha.e-sim.org', | |
//'Origin: https://alpha.e-sim.org', | |
'Referer: https://alpha.e-sim.org/', | |
'Upgrade-Insecure-Requests: 1', | |
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36' | |
); | |
$username = $_GET["username"]; | |
$password = $_GET["password"]; | |
$cookie_path = "./cookies/".$username.".txt"; | |
$res = login($username,$password,$header,$cookie_path); | |
$work = work($cookie_path,$header); | |
$train = train($cookie_path,$header); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage :
wt.php?username=[username]&password=[password]