//Check file function
function checkfile()
{
//Check if file exist
if(is_file(FILE))
//Return the file content
return file_get_contents(FILE);
else
//Return localhost to force update
return '127.0.0.1';
}
//Checkip function
function checkip()
{
//The socks
$sock = @fsockopen('checkip.dyndns.org', 80, $errno, $errstr);
//Exit if socket is in bad state
if (!$sock) die("Update impossible: $errstr ($errno)\n");
Pense a copier ce code sous :
/usr/bin/ipupdate.dyndns
Puis mettre les droits suivants :
chown ton_user:root /usr/bin/ipupdate.dyndns
chmod 750 /usr/bin/ipupdate.dyndns
Puis ajouter un fichier cron qui va bien :
08,38 * * * * rapsys [ -x /usr/bin/php ] && [ -x /usr/bin/ipupdate.dyndns ] && /usr/bin/ipupdate.dyndns
Pense a changer login:password et le domaine example.com en ton domaine.dyndns.org ;)
ps : si tu veux faire un don paypal sur mon email hésite pas, j'ai pas mal bossé pour l'avoir fonctionnel...
[^] # Utiliser mon script maison \o/
Posté par Raphaël G. (site web personnel) . En réponse au message probleme rc.d. Évalué à 2.
#! /usr/bin/php
<?php
//Define the domain
define('DOMAIN', 'members.dyndns.org');
//Define the path
define('PATH', '/nic/update');
//Update file
define('FILE', '/tmp/.ipupdate.dyndns');
//Check if lock file is present
if (is_file(FILE.'.lock'))
die('Last time: '.file_get_contents(FILE.'.lock'));
//Define key and identification
define('USERINFO', base64_encode('login:password'));
define('USERAGENT', 'rapsys_php_ipupdate/0.3rc4 rapsys@free.fr');
define('DATAINFO', '?system=dyndns&hostname=exemple.com&wildcard=ON');
//Check file function
function checkfile()
{
//Check if file exist
if(is_file(FILE))
//Return the file content
return file_get_contents(FILE);
else
//Return localhost to force update
return '127.0.0.1';
}
//Checkip function
function checkip()
{
//The socks
$sock = @fsockopen('checkip.dyndns.org', 80, $errno, $errstr);
//Exit if socket is in bad state
if (!$sock) die("Update impossible: $errstr ($errno)\n");
fputs($sock, "GET / HTTP/1.1\r\n");
fputs($sock, "Host: checkip.dyndns.org\r\n");
fputs($sock, "User-Agent: ".USERAGENT."\r\n");
fputs($sock, "\r\n");
//Get the header
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
//Get the body (ip)
$remote = "";
while (!feof($sock))
$remote .= fgets($sock, 4096);
//Close the socket
fclose($sock);
//Store result for investigate
$fd = fopen(FILE.'.ip', 'w');
fwrite($fd, $headers.$remote);
fclose($fd);
//Return the answer
return preg_replace('/.*Current IP Address: ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/s', '1円', $remote);
}
if (checkip() != checkfile())
{
//Open a socket
$sock = @fsockopen('ssl://'.DOMAIN, 443, $errno, $errstr, 30);
//Exit if socket is in bad state
if (!$sock) die("Update impossible dyndns: $errstr ($errno)\n");
//Forge the request
fputs($sock, "GET ".PATH.DATAINFO." HTTP/1.1\r\n");
fputs($sock, "Host: ".DOMAIN."\r\n");
fputs($sock, "Authorization: Basic ".USERINFO."\r\n");
fputs($sock, "User-Agent: ".USERAGENT."\r\n");
fputs($sock, "\r\n");
//Get the header
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
//Get the body (ip)
$remote = "";
while (!feof($sock))
$remote .= fgets($sock, 4096);
//Close the socket
fclose($sock);
//Store result for invertigate
$fd = fopen(FILE.'.update', 'w');
fwrite($fd, $headers.$remote);
fclose($fd);
//Get the return code
$retcode = preg_replace('/(?:.*\n)([a-z]+).*/s', '1円', $remote);
//Touch lock file if something goes wrong
if ($retcode != 'good' && $retcode != 'nochg')
{
$fd = fopen(FILE.'.lock', 'w');
date_default_timezone_set('UTC');
fwrite($fd, date("l d F Y G:i:s").': Update impossible dyndns: '.$remote);
fclose($fd);
echo date("l d F Y G:i:s").': Update impossible dyndns: '.$remote;
}
//Update FILE
$fd = fopen(FILE, 'w');
fwrite($fd, preg_replace('/.*(?:good|nochg) ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/s', '1円', $remote));
fclose($fd);
}
?>
Pense a copier ce code sous :
/usr/bin/ipupdate.dyndns
Puis mettre les droits suivants :
chown ton_user:root /usr/bin/ipupdate.dyndns
chmod 750 /usr/bin/ipupdate.dyndns
Puis ajouter un fichier cron qui va bien :
08,38 * * * * rapsys [ -x /usr/bin/php ] && [ -x /usr/bin/ipupdate.dyndns ] && /usr/bin/ipupdate.dyndns
Pense a changer login:password et le domaine example.com en ton domaine.dyndns.org ;)
ps : si tu veux faire un don paypal sur mon email hésite pas, j'ai pas mal bossé pour l'avoir fonctionnel...