Skip to content

Instantly share code, notes, and snippets.

@BANKA2017
Last active February 19, 2023 01:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BANKA2017/a71ef2a9f5087ac6330336fff5638910 to your computer and use it in GitHub Desktop.
Save BANKA2017/a71ef2a9f5087ac6330336fff5638910 to your computer and use it in GitHub Desktop.
freenom_renewer
<?php
$username = '';//email
$password = '';//password
$months = '12';//months (1-12)
$telegram_bot_token = "";
$telegram_chat_id = "";
if(!$username || !$password){
die("freenom_renewer: no username or password...\n");
}
if($months <1){
$months = 1;
}elseif($months >12){
$months = 12;
}
function scurl(string $url = "localhost", string $type = "get", array $header = [], array $data = [], bool $return_header = false, bool $nobody = false, bool $follow_location = true): string {
$ch = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => $follow_location,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => $return_header,
CURLOPT_NOBODY => $nobody
];
if(strtolower($type) == "post"){
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = http_build_query($data);
}
curl_setopt_array($ch, $options);
return curl_exec($ch);
}
//first request
preg_match_all('/Set-Cookie: ([^;]+);/i',scurl('https://my.freenom.com/clientarea.php', "get", [], [], true, true, false), $getCookie);
$Cookies = '';
foreach ($getCookie[1] as $key) {
$Cookies .= $key.';';
}
//get token
preg_match('/name="token" value="([^"]+)"/i', scurl('https://my.freenom.com/clientarea.php', "get", ["Cookie: {$Cookies}"]), $b);
$token = $b[1];
echo "freenom_renewer: logining...\n";
preg_match_all('/Set-Cookie: (.+);/iU',scurl('https://my.freenom.com/dologin.php', "post", ["Cookie: {$Cookies}", "Referer: https://my.freenom.com/clientarea.php"], ["token" => $token , "username" => $username , "password" => $password , "rememberme" => true], true, true, false), $getCookie);
foreach ($getCookie[1] as $key) {
$Cookies .= $key.';';
}
$a = scurl('https://my.freenom.com/domains.php?a=renewals', "get", ["Cookie: {$Cookies}"]);
preg_match_all('/<tr><td>(.*)<\/td><td>Active<\/td><td>/iU',$a,$b);
preg_match_all('/>([0-9]+) Days<\/span>/iU',$a,$e);
preg_match_all('/href="domains.php\?a=renewdomain&domain=([0-9]+)"/iU',$a,$d);
$x = 0;
$bd = [];
foreach ($e[1] as $day) {
if ($day <= 14) {
$bd[] = [$b[1][$x],$d[1][$x]];
}
$x++;
}
$pushText = "#freenom_renewer \n";
if (count($bd) == 1) {
echo "freenom_renewer: 1 domain renewable...\n";
$pushText .= "freenom_renewer: 1 domain renewable...\n";
} elseif(count($bd) > 1) {
echo "freenom_renewer: " . count($bd) . " domains renewable...\n";
$pushText .= "freenom_renewer: " . count($bd) . " domains renewable...\n";
} else{
echo "freenom_renewer: no renewable domain...\n";
$pushText .= "freenom_renewer: no renewable domain...\n";
}
foreach ($bd as $key) {
preg_match('/name="token" value="([^"]+)"/i', scurl('https://my.freenom.com/domains.php?a=renewdomain&domain=' . $key[1], "get", ["Cookie: {$Cookies}"]),$b);
$token = $b[1];
if (preg_match('/Location: cart.php\?a=complete/i', scurl('https://my.freenom.com/domains.php?submitrenewals=true', "post", ["Cookie: {$Cookies}"], ["token" => $token , "renewalid" => $key[1],"renewalperiod[" . $key[1] . "]" => $months . 'M', "paymentmethod" => "credit"], true, true))) {
echo $key[0].": success\n";
$pushText .= $key[0].": success\n";
} else {
echo $key[0].": false\n";
$pushText .= $key[0].": false\n";
}
}
if ($telegram_chat_id && $telegram_bot_token) {
kd_push($pushText, $telegram_bot_token, $telegram_chat_id);
}
//push server
function kd_push(string $text = "", string $token = "", string $to = ""){
//切割文字防止无法发送
$textLength = strlen($text);
$partCount = ceil($textLength / 3000);
for ($x = 1; $x <= $partCount; $x++) {
$r = json_decode(scurl("https://api.telegram.org/bot{$token}/sendMessage", "post", [], ["chat_id" => $to, "text" => mb_substr($text, ($x - 1) * 3000, 2999)]), true);
if($r["ok"] ?? false){
echo "KDboT: Successful to push log #part{$x} to master channel\n";
}else{
echo "KDboT: Error #{$r["description"]}\n";
}
}
}
@BANKA2017
Copy link
Author

设置 $username $password $months 后运行即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment