add log rotate
This commit is contained in:
+61
-44
@@ -1,54 +1,71 @@
|
||||
<?php
|
||||
echo "_____________________________ \n";
|
||||
$lines = [];
|
||||
//$lines[] = "_____________________________";
|
||||
//$lines[] = "____________start____________";
|
||||
//$lines[] = "_____________________________";
|
||||
$dateUpdate = date("Y-m-d H:i:s");
|
||||
|
||||
$lines[] = "[$dateUpdate]";
|
||||
$canUpdate = true;
|
||||
if (isset($_ENV['LOCAL']) && $_ENV['LOCAL']) {
|
||||
die("Die in local");
|
||||
$lines[] = "die in local";
|
||||
$canUpdate = false;
|
||||
}
|
||||
// old
|
||||
// https://www.duckdns.org/update?domains=rhost.duckdns.org&token=1b4ab267-b818-4407-8351-8800c6f4fd78
|
||||
$toUpdateString = $_ENV['DYNDNS_DOMAIN_UPDATE'];
|
||||
$user = $_ENV['DYNDNS_USER'];
|
||||
$pass = $_ENV['DYNDNS_PASSWORD'];
|
||||
$dateUpdate = date("Y-m-d H:i:s");
|
||||
|
||||
if (!$toUpdateString || !$user || !$pass) {
|
||||
die("[$dateUpdate] Empty ENV data!!!!!!!!!!!");
|
||||
}
|
||||
$toUpdateArray = explode(",", $toUpdateString);
|
||||
$useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://rhostoh.cluster029.hosting.ovh.net/");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
|
||||
$content = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo "[$dateUpdate] Error:" . curl_error($ch);
|
||||
$serverIp = false;
|
||||
} else {
|
||||
$serverIp = $content;
|
||||
}
|
||||
curl_close($ch);
|
||||
if ($canUpdate) {
|
||||
$toUpdateString = $_ENV['DYNDNS_DOMAIN_UPDATE'];
|
||||
$user = $_ENV['DYNDNS_USER'];
|
||||
$pass = $_ENV['DYNDNS_PASSWORD'];
|
||||
|
||||
if ($serverIp) {
|
||||
foreach ($toUpdateArray as $toUpdate) {
|
||||
$toUpdate = trim($toUpdate);
|
||||
$currentIp = trim(shell_exec("dig +short @208.67.222.222 $toUpdate A | head -n1"));
|
||||
if ($currentIp == $serverIp) {
|
||||
echo "[$dateUpdate] $toUpdate: same (not update)" . PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
$url = "https://dns.eu.ovhapis.com/nic/update?system=dyndns&hostname=$toUpdate&myip=$serverIp";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
|
||||
$response = curl_exec($ch);
|
||||
echo "[$dateUpdate] $toUpdate ($currentIp): " . $response . PHP_EOL;
|
||||
curl_close($ch);
|
||||
if (!$toUpdateString || !$user || !$pass) {
|
||||
$lines[] = "Empty ENV data!!!!!!!!!!!";
|
||||
}
|
||||
$toUpdateArray = explode(",", $toUpdateString);
|
||||
$useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://rhostoh.cluster029.hosting.ovh.net/");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
||||
$content = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$lines[] = "Error:" . curl_error($ch);
|
||||
$serverIp = false;
|
||||
} else {
|
||||
$serverIp = $content;
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
if ($serverIp) {
|
||||
foreach ($toUpdateArray as $toUpdate) {
|
||||
$toUpdate = trim($toUpdate);
|
||||
$currentIp = trim(shell_exec("dig +short @208.67.222.222 $toUpdate A | head -n1"));
|
||||
if ($currentIp == $serverIp) {
|
||||
$lines[] = "$toUpdate: same (not update)";
|
||||
continue;
|
||||
}
|
||||
$url = "https://dns.eu.ovhapis.com/nic/update?system=dyndns&hostname=$toUpdate&myip=$serverIp";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
|
||||
$response = curl_exec($ch);
|
||||
$lines[] = "$toUpdate ($currentIp): " . $response;
|
||||
curl_close($ch);
|
||||
}
|
||||
} else {
|
||||
$lines[] = "Server Error!!!!!!!!!!!!!";
|
||||
}
|
||||
} else {
|
||||
echo "[$dateUpdate] Server Error!!!!!!!!!!!!!" . PHP_EOL;
|
||||
}
|
||||
|
||||
//$lines[] = "_____________________________";
|
||||
//$lines[] = "_____________end_____________";
|
||||
//$lines[] = "_____________________________";
|
||||
|
||||
foreach ($lines as $line) {
|
||||
echo $line . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user