#1  
Old 17th September 2008, 21:55
omry omry is offline
Junior Member
 
Join Date: Sep 2008
Posts: 23
Thanks: 3
Thanked 3 Times in 3 Posts
Default Dynamic DNS

Hi,
I am writing a small script to update a DNS entry remotely, to be used to update the IP address of machine with dynamic IP.

my client script will authenticate via the url, which will look something like:
http://server:8080/tools/dyndns/upda...name&pass=pswd

I managed to authenticate against the sys_user table, and I was wondering what values should I check to know the user has access to a particular row in the dns_rr table.

if anyone is interested, I will share the result (client and server side scripts).
Reply With Quote
The Following User Says Thank You to omry For This Useful Post:
adamassasda291 (28th June 2013)
Sponsored Links
  #2  
Old 18th September 2008, 19:14
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Is this an ISPConfig or MyDNSConfig question?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 18th September 2008, 19:21
omry omry is offline
Junior Member
 
Join Date: Sep 2008
Posts: 23
Thanks: 3
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by falko View Post
Is this an ISPConfig or MyDNSConfig question?
mathematically speaking, the answer is yes.
in other words, both.

This is what I ended up doing:
PHP Code:
$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)"); 
I verify that the dns record row sys_groupid is one of the user groups.
what do you think?
Reply With Quote
The Following User Says Thank You to omry For This Useful Post:
adamassasda291 (29th June 2013)
  #4  
Old 19th September 2008, 09:58
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,006
Thanks: 826
Thanked 5,377 Times in 4,224 Posts
Default

This looks correct.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
The Following User Says Thank You to till For This Useful Post:
adamassasda291 (2nd June 2013)
  #5  
Old 19th September 2008, 14: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 18:49.
Reply With Quote
The Following User Says Thank You to omry For This Useful Post:
till (19th September 2008)
  #6  
Old 19th September 2008, 15:27
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,006
Thanks: 826
Thanked 5,377 Times in 4,224 Posts
Default

There is one small modification that I would recommend. Instead of calling:

Code:
$app->db->query("UPDATE  SET  WHERE id = $id");
better use:

Code:
$app->db->datalogUpdate('dns_rr', "data = '$ip'", 'id', $id);
This will update the data in the dns_rr table and additionally create a record in the sys_datalog table which is read by the server process. This does not bring you any benefit at the moment, but your code will later benefit when:

- Other DNS plugins are available e.g. support for bind.
- If plugins at the server have to be called when a dns record changes. Without using the datalogUpdate function, your manual change would be simply ignored by all server related code.
- There is a history and undo function planned for the interface to track user interactions and to make it possible to revert changes. Without using this update function, your changes will not be tracked.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.

Last edited by till; 19th September 2008 at 15:29.
Reply With Quote
The Following User Says Thank You to till For This Useful Post:
adamassasda291 (25th June 2013)
  #7  
Old 19th September 2008, 18:52
omry omry is offline
Junior Member
 
Join Date: Sep 2008
Posts: 23
Thanks: 3
Thanked 3 Times in 3 Posts
Default

I do see some benefits in doing it as you described, but the undo and history would probably be more harm than good.
this is expected to be called every hour, it will create 24 changes/day.

can really spam the change log.
Reply With Quote
  #8  
Old 19th September 2008, 18:59
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,006
Thanks: 826
Thanked 5,377 Times in 4,224 Posts
 
Default

Thats up to you. It just may happen that your addon becomes incompatible with future versions of ISPConfig that might require to log all activity to datalog. For example your plugin will not work on multi server setups of the next ispconfig release.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
The Following User Says Thank You to till For This Useful Post:
adamassasda291 (29th June 2013)
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid Proxy Caching on Linux obzerver Installation/Configuration 4 13th August 2008 19:51
Google Apps dayjahone General 19 29th March 2008 17:25
DNS Configuration Problems VMartins Installation/Configuration 10 24th July 2007 14:40
Howto suggestion suse PhP ver 4 + Ver 5 wwparrish Suggest HOWTO 11 7th August 2006 13:29
Using a different DNS server with Dynamic DNS CombatGod Installation/Configuration 1 11th May 2006 17:43


All times are GMT +2. The time now is 23:42.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.