Thread: Dynamic DNS
View Single Post
  #5  
Old 19th September 2008, 15:49
omry omry is offline
Junior Member
 
Join Date: Sep 2008
Posts: 23
Thanks: 3
Thanked 3 Times in 3 Posts
Default

great.
here is the code, if anyone is interested.
I put it in:
/usr/local/ispconfig/interface/web/tools/dyndns

PHP Code:
<?php
$user 
$_GET['user'];
$pass $_GET['pass'];
$ip = isset($_GET['ip']) ? isset($_GET['ip']) : $_SERVER['REMOTE_ADDR'];
$domain = !empty($_GET['domain']) ? $_GET['domain'] : error(500"missing domain");

require_once(
'../../../lib/config.inc.php');
require_once(
'../../../lib/classes/auth.inc.php');
require_once(
'../../../lib/app.inc.php');

global 
$app;
$ip       $app->db->quote($ip);
$user     $app->db->quote($user);
$pass     $app->db->quote($pass);
$domain   $app->db->quote($domain);

$sql "SELECT * FROM sys_user WHERE USERNAME = '$user' and ( PASSWORT = '".md5($pass)."' or PASSWORT = password('$pass') )";
$app->db->show_error_messages true;
$dbuser $app->db->queryOneRecord($sql);
if (
$dbuser === falseerror(403"authentication failed");
$groups $dbuser['groups'];

$id $app->db->queryOneRecord("SELECT id FROM dns_rr WHERE name = '$domain' AND type = 'A' AND sys_groupid IN ($groups)");
if (
$id === falseerror(404"DNS record not found");
$id $id['id'];
$app->db->query("UPDATE dns_rr SET data = '$ip' WHERE id = $id");

function 
error($code$msg)
{
    
header("HTTP/1.0 $code $msg");
    echo 
$msg;
    die();
}
?>


Client code example:

#! /bin/sh
# this code should run from cron.houry of the machine that need to update the dns
USER=username
PASS=password
DOMAINS=(domain1.com. domain2.com.)
for DOMAIN in ${DOMAINS[@]}
do
URL="http://YOUR_ISPCONFIG_SERVER:8080/tools/dyndns/update.php"
response=$(HEAD -m GET "$URL?user=$USER&pass=$PASS&domain=$DOMAIN") || echo $response
done


Note that the domains should be exactly as mentioned in the dns_rr table (including trailing dot).

Last edited by omry; 19th September 2008 at 19:49.
Reply With Quote