-
-
Save hermesthecat/0e67d918c602067a74224090d9930711 to your computer and use it in GitHub Desktop.
Auto Plesk Trial Renewal (using Anti-Captcha to solve ReCaptcha)
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 | |
/* | |
Make sure to enter $anticaptcha_key before upload to server. | |
Upload "auto_plesk_trial.php" file to "/home/centos/auto_plesk_trial.php" | |
Then create Schedule Task in Root account of Plesk. | |
Task Type: Run a PHP script | |
Script path: /home/centos/auto_plesk_trial.php | |
Use PHP version: 7.x.x / 8.x.x | |
Run: Cron style * * * * * | |
Notify: Errors only | |
*/ | |
$update_frequency = 60 * 60 * 24 * 14; // Update Every 14 Days | |
$anticaptcha_key = ""; // Anti-Recaptcha Key | |
set_time_limit(600); | |
$filename = dirname($_SERVER["PHP_SELF"])."/".pathinfo($_SERVER["PHP_SELF"], PATHINFO_FILENAME).".json"; | |
function update_log ($text) { | |
$fh = fopen(dirname($_SERVER["PHP_SELF"])."/".pathinfo($_SERVER["PHP_SELF"], PATHINFO_FILENAME).".log", "a"); | |
fwrite($fh, date("[Y-m-d H:i:s] ").$text."\n"); | |
fclose($fh); | |
echo date("[Y-m-d H:i:s] ").$text."\n"; | |
} | |
$info = json_decode(@file_get_contents($filename), true); | |
if (!is_array($info)) $info = array(); | |
if (!isset($info["last_updated"])) $info["last_updated"] = 0; | |
if ($info["last_updated"] + $update_frequency > time()) { | |
exit(); | |
} | |
$curl_options = array( | |
CURLOPT_RETURNTRANSFER => true | |
); | |
$ch = curl_init(); | |
if (!isset($info["email_address"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.1secmail.com/api/v1/?action=genRandomMailbox&count=1" | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200) { | |
$data = json_decode($response, true); | |
if (is_array($data) && isset($data[0])) { | |
$info["email_address"] = $data[0]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: email_address = ".$info["email_address"]); | |
} else { | |
update_log("Error: email_address = null"); | |
exit(); | |
} | |
} else { | |
update_log("Error: email_address = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["task_id"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_URL => "https://api.anti-captcha.com/createTask", | |
CURLOPT_HTTPHEADER => array( | |
"Content-Type: application/json" | |
), | |
CURLOPT_POSTFIELDS => json_encode(array( | |
"clientKey" => $anticaptcha_key, | |
"task" => array( | |
"type" => "RecaptchaV2TaskProxyless", | |
"websiteURL" => "https://www.plesk.com/plesk-free-download/", | |
"websiteKey" => "6LfC_lQaAAAAAES5qQ5CZbVfE1_RoA_azMlBZQkN" | |
) | |
)) | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 200 && $result = json_decode($response, true)) { | |
if (isset($result["errorId"]) && $result["errorId"] == 0 && isset($result["taskId"])) { | |
$info["task_id"] = $result["taskId"]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: task_id = ".$info["task_id"]); | |
exit(); | |
} else { | |
update_log("Error: task_id = null"); | |
exit(); | |
} | |
} else { | |
update_log("Error: task_id = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["g_recaptcha_response"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_URL => "https://api.anti-captcha.com/getTaskResult", | |
CURLOPT_HTTPHEADER => array( | |
"Content-Type: application/json" | |
), | |
CURLOPT_POSTFIELDS => json_encode(array( | |
"clientKey" => $anticaptcha_key, | |
"taskId" => $info["task_id"] | |
)) | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 200 && $result = json_decode($response, true)) { | |
if (isset($result["errorId"]) && $result["errorId"] == 0 && isset($result["status"])) { | |
if ($result["status"] == "ready" && isset($result["solution"]["gRecaptchaResponse"])) { | |
$info["g_recaptcha_response"] = $result["solution"]["gRecaptchaResponse"]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: g_recaptcha_response = ".$info["g_recaptcha_response"]); | |
} elseif ($result["status"] !== "processing") { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: g_recaptcha_response = null"); | |
exit(); | |
} else { | |
exit(); | |
} | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: g_recaptcha_response = null"); | |
exit(); | |
} | |
} else { | |
update_log("Error: task_id = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["confirm_requested"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_URL => "https://www.plesk.com/plesk-free-download/", | |
CURLOPT_POSTFIELDS => http_build_query(array( | |
"input_1.3" => "Teerapong", | |
"input_1.6" => "Pongsai", | |
"input_2" => $info["email_address"], | |
"input_15" => "Developer", | |
"input_16" => "Junior", | |
"input_17" => "Thailand", | |
"input_21.1" => "true", | |
"g-recaptcha-response" => $info["g_recaptcha_response"], | |
"is_submit_55" => "1", | |
"gform_submit" => "55", | |
"gf_zero_spam_key" => "eN4*@MnEel3KQ!o!zyCZK5j*Om\$wQ82kI10BI$*AW7\$IKutxZerPTGUoGTRKxor@" | |
)), | |
CURLOPT_HEADER => true | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 302 && preg_match("/[Ll]ocation: https:\/\/www\.plesk\.com\/free-trial-for-web-professionals-thank-you-page\//", $response)) { | |
$info["confirm_requested"] = true; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: confirm_requested = true"); | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: confirm_requested = false"); | |
exit(); | |
} | |
} | |
if (!isset($info["trial_requested"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.plesk.com/free-trial-for-web-professionals-thank-you-page/", | |
CURLOPT_HTTPHEADER => array( | |
"Cookie: Plesk_TrialFormData=".urlencode(base64_encode(json_encode(array( | |
"name" => "Teerapong", | |
"lastname" => "Pongsai", | |
"email" => $info["email_address"] | |
)))) | |
), | |
CURLOPT_HEADER => true | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 200 && preg_match("/[Ss]et-[Cc]ookie: Plesk_TrialForm_Status=1;/", $response)) { | |
$info["trial_requested"] = true; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: trial_requested = true"); | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: trial_requested = false"); | |
exit(); | |
} | |
} | |
list($login, $domain) = explode("@", $info["email_address"]); | |
if (!isset($info["email_id"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.1secmail.com/api/v1/?action=getMessages&login=".$login."&domain=".$domain | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200) { | |
$data = json_decode($response, true); | |
if (is_array($data) && isset($data[0])) { | |
foreach ($data as $mail) { | |
if ($mail["subject"] === "Please confirm your email address") { | |
$info["email_id"] = $mail["id"]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: email_id = ".$info["email_id"]); | |
break; | |
} | |
} | |
if (!isset($info["email_id"])) { | |
exit(); | |
} | |
} else { | |
exit(); | |
} | |
} else { | |
update_log("Error: email_id = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["confirm_link"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.1secmail.com/api/v1/?action=readMessage&login=".$login."&domain=".$domain."&id=".$info["email_id"] | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200 && $data = json_decode($response, true)) { | |
if (isset($data["body"]) && preg_match("/please confirm your email address by clicking on the link below:(?:.*?)<a(?:.*?)href=\"(.*?)\"(?:.*?)>(?:.*?)CONFIRM MY EMAIL(?:.*?)<\/a>/s", $data["body"], $matches)) { | |
$info["confirm_link"] = $matches[1]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: confirm_link = ".$info["confirm_link"]); | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: confirm_link = null"); | |
exit(); | |
} | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: confirm_link = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["confirm_link2"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => $info["confirm_link"] | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200 && preg_match("/window\.location\.replace\(\"(.*?)\"\);/", $response, $matches)) { | |
$info["confirm_link2"] = $matches[1]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: confirm_link2 = ".$info["confirm_link2"]); | |
} else { | |
update_log("Error: confirm_link2 = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["confirm_link3"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => $info["confirm_link2"], | |
CURLOPT_HEADER => true | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 307 && preg_match("/[Ll]ocation: (https:\/\/api(.*)\.hubapi\.com\/email\/v1\/optin\/confirm\/doi\?(?:[^\r\n]*))/", $response, $matches)) { | |
$info["confirm_link3"] = $matches[1]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: confirm_link3 = ".$info["confirm_link3"]); | |
} else { | |
update_log("Error: confirm_link3 = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["email_confirmed"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => $info["confirm_link3"], | |
CURLOPT_HEADER => true | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code == 307 && preg_match("/[Ll]ocation: https:\/\/page\.plesk\.com\/confirmsubscribe/", $response)) { | |
$info["email_confirmed"] = true; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: email_confirmed = true"); | |
} else { | |
update_log("Error: email_confirmed = false"); | |
exit(); | |
} | |
} | |
if (!isset($info["email_id2"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.1secmail.com/api/v1/?action=getMessages&login=".$login."&domain=".$domain | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200) { | |
$data = json_decode($response, true); | |
if (is_array($data) && isset($data[0])) { | |
foreach ($data as $mail) { | |
if ($mail["subject"] === "Your Plesk Trial Activation Code") { | |
$info["email_id2"] = $mail["id"]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: email_id2 = ".$info["email_id2"]); | |
break; | |
} | |
} | |
if (!isset($info["email_id2"])) { | |
exit(); | |
} | |
} else { | |
exit(); | |
} | |
} else { | |
update_log("Error: email_id2 = null"); | |
exit(); | |
} | |
} | |
if (!isset($info["activation_code"])) { | |
curl_reset($ch); | |
curl_setopt_array($ch, $curl_options + array( | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_URL => "https://www.1secmail.com/api/v1/?action=readMessage&login=".$login."&domain=".$domain."&id=".$info["email_id2"] | |
)); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($http_code === 200 && $data = json_decode($response, true)) { | |
if (isset($data["body"]) && preg_match("/Now here's your unique activation code:(?:.*?)<strong>(.*?)<\/strong>/s", $data["body"], $matches)) { | |
$info["activation_code"] = $matches[1]; | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: activation_code = ".$info["activation_code"]); | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: activation_code = null"); | |
exit(); | |
} | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: activation_code = null"); | |
exit(); | |
} | |
} | |
$status = trim(shell_exec("/usr/sbin/plesk bin license --install ".$info["activation_code"])); | |
if ($status === "The license key was successfully installed.") { | |
$info = array( | |
"last_updated" => time() | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Update: status = ".$status); | |
update_log("Update: last_updated = ".$info["last_updated"]); | |
} else { | |
$info = array( | |
"last_updated" => $info["last_updated"] | |
); | |
file_put_contents($filename, json_encode($info)); | |
update_log("Error: status = ".$status); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The email. I tried and it doesn't work. Is there a way for someone to fix this?