Eigenen DynDNS Server: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Script) |
|||
Zeile 28: | Zeile 28: | ||
<pre> | <pre> | ||
<?php | <?php | ||
$mysqli = new mysqli("127.0.0.1", "powerdns", " | $mysqli = new mysqli("127.0.0.1", "powerdns", "M7kWxyTCct", "ddns"); | ||
/* check connection */ | /* check connection */ | ||
if (mysqli_connect_errno()) { | if (mysqli_connect_errno()) { | ||
die("Verbindung fehlgeschlagen: " . | die("Verbindung fehlgeschlagen: " . mysqli_connect_error()); | ||
} | } | ||
$ | $host = mysqli_real_escape_string($mysqli, $_GET['host']); | ||
$pass1 = mysqli_real_escape_string($mysqli, $_GET['pass']); | |||
$ | /* Select queries return a resultset */ | ||
if ($query = $mysqli->query("SELECT password FROM ddns_hosts WHERE hostname = '" . $host . "'")) { | |||
if ($row = mysqli_fetch_assoc($query)) { | |||
$pass2 = $row["password"]; | |||
} else { | |||
invalidCredentials(); | |||
} | |||
$ | |||
/* free result set */ | |||
$query->close(); | |||
} else { | |||
printf("Invalid query: %s\nWhole query: %s\n", $mysqli->error, $pass2); | |||
} | } | ||
if | if ($pass1 != $pass2) { | ||
invalidCredentials(); | |||
} else { | |||
} | /* change db to powerdns_admin db */ | ||
$mysqli->select_db("powerdns_admin"); | |||
if (!$ip=$_SERVER['HTTP_X_FORWARDED_FOR']) { | |||
$ip=$_SERVER['REMOTE_ADDR']; | |||
} | |||
printf("IP = %s\n", $ip); | |||
//$domain=$host.".dyn.klenzel.de"; | //$domain=$host.".dyn.klenzel.de"; | ||
//$domain2="*.".$domain; | //$domain2="*.".$domain; | ||
Zeile 60: | Zeile 70: | ||
//$result1=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain';"); | //$result1=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain';"); | ||
//$result2=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain2';"); | //$result2=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain2';"); | ||
} | |||
function invalidCredentials() { | |||
die("Falsches Passwort oder unbekannter Host"); | |||
} | |||
?> | ?> | ||
</pre> | </pre> |
Version vom 2. Februar 2020, 14:18 Uhr
Noch in Bearbeitung
Script
Datenbank erstellen
create database if not exists ddns; grant all on ddns.* to 'powerdns'@'localhost';
CREATE TABLE ddns_hosts ( id INT NOT NULL AUTO_INCREMENT, hostname VARCHAR(64) NOT NULL, password VARCHAR(64) NOT NULL, PRIMARY KEY (id) );
INSERT INTO ddns_hosts ( hostname, password ) VALUES ( 'zuhause', 'abc123' );
Script
<?php $mysqli = new mysqli("127.0.0.1", "powerdns", "M7kWxyTCct", "ddns"); /* check connection */ if (mysqli_connect_errno()) { die("Verbindung fehlgeschlagen: " . mysqli_connect_error()); } $host = mysqli_real_escape_string($mysqli, $_GET['host']); $pass1 = mysqli_real_escape_string($mysqli, $_GET['pass']); /* Select queries return a resultset */ if ($query = $mysqli->query("SELECT password FROM ddns_hosts WHERE hostname = '" . $host . "'")) { if ($row = mysqli_fetch_assoc($query)) { $pass2 = $row["password"]; } else { invalidCredentials(); } /* free result set */ $query->close(); } else { printf("Invalid query: %s\nWhole query: %s\n", $mysqli->error, $pass2); } if ($pass1 != $pass2) { invalidCredentials(); } else { /* change db to powerdns_admin db */ $mysqli->select_db("powerdns_admin"); if (!$ip=$_SERVER['HTTP_X_FORWARDED_FOR']) { $ip=$_SERVER['REMOTE_ADDR']; } printf("IP = %s\n", $ip); //$domain=$host.".dyn.klenzel.de"; //$domain2="*.".$domain; //$result1=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain';"); //$result2=mysql_query("UPDATE records SET content='$ip' WHERE name='$domain2';"); } function invalidCredentials() { die("Falsches Passwort oder unbekannter Host"); } ?>
http://ddns1.kirner.or.at/?host=zuhause&pass=abc123
Mit PowerDNS
Links
https://www.debacher.de/wiki/Mein_eigenes_DynDNS
https://controlc.de/2013/09/10/debian-selbstgehosteter-dyndns-dienst/
https://controlc.de/2014/08/25/debian-selbstgehosteter-dyndns-dienst-der-client-teil/#more-2532)
http://www.keentech.de/2013/11/der-eigene-selbstgehostete-dynamische-dns-service/
http://nicht-traeumen-sondern-machen.de/RaspberryPi_Basteleien/DynDNS_mit_Fritzbox.php
Zurück zu Ubuntu