Erzeuge nicht einen DynDNS-Hostname unser der Masterdomain sondern frage gleich vom User ab welcher Hostname verwendet werden soll
Bernd Wurst

Bernd Wurst commited on 2016-07-01 10:19:58
Zeige 7 geänderte Dateien mit 188 Einfügungen und 8 Löschungen.

... ...
@@ -16,6 +16,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 require_once('inc/base.php');
18 18
 require_once('inc/security.php');
19
+require_once('inc/icons.php');
19 20
 
20 21
 require_role(ROLE_SYSTEMUSER);
21 22
 
... ...
@@ -45,7 +46,7 @@ foreach ($dyndns AS $entry) {
45 46
       $method = 'HTTP';
46 47
     else
47 48
       $method = '<em>keine</em>';
48
-  output("<tr><td>".internal_link('dyndns_edit', $handle, "id={$entry['id']}")."</td><td>{$method}</td><td>{$entry['address']}</td><td>{$entry['lastchange']}</td><td>".internal_link('save', '<img src="'.$prefix.'images/delete.png" width="16" height="16" alt="löschen" title="Account löschen" />', "id={$entry['id']}&type=dyndns&action=delete")."</td></tr>\n");
49
+  output("<tr><td>".internal_link('dyndns_edit', $handle, "id={$entry['id']}")."</td><td>{$method}</td><td>{$entry['address']}</td><td>{$entry['lastchange']}</td><td>".internal_link('save', icon_delete("Account löschen"), "id={$entry['id']}&type=dyndns&action=delete").' '.internal_link('dyndns_hostnames', other_icon("world_link.png", "Hostnames verwalten"), "id={$entry['id']}")."</td></tr>\n");
49 50
 }
50 51
 output('</table>');
51 52
 
... ...
@@ -100,5 +100,6 @@ if (! $new )
100 100
   }
101 101
   
102 102
   $output .= '</ul>';
103
+  output("<p>".internal_link('dyndns_hostnames', "Liste ändern...", "id={$_REQUEST['id']}")."</p>");
103 104
 }
104 105
 
... ...
@@ -0,0 +1,48 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('inc/base.php');
18
+require_once('inc/debug.php');
19
+global $debugmode;
20
+require_once('inc/security.php');
21
+
22
+require_role(ROLE_SYSTEMUSER);
23
+
24
+require_once('dnsinclude.php');
25
+
26
+$section = 'dns_dyndns';
27
+
28
+if (!isset($_REQUEST['id']))
29
+  system_failure("Keine ID");
30
+
31
+$id = (int) $_REQUEST['id'];
32
+$dyndns = get_dyndns_account($id);
33
+
34
+  $record = blank_dns_record('a');
35
+  // Sicherheitsprüfungen passieren im Backend
36
+  
37
+  $record['hostname'] = $_REQUEST['hostname'];
38
+  $record['domain'] = (int) $_REQUEST['domain'];
39
+  $record['dyndns'] = $id;
40
+  $record['ttl'] = 120;
41
+  
42
+  save_dns_record(NULL, $record);
43
+
44
+  if (!$debugmode)
45
+    header('Location: dyndns_hostnames?id='.$dyndns['id']);
46
+
47
+
48
+
... ...
@@ -0,0 +1,56 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('inc/base.php');
18
+require_once('inc/debug.php');
19
+global $debugmode;
20
+require_once('inc/security.php');
21
+
22
+require_role(ROLE_SYSTEMUSER);
23
+
24
+require_once('dnsinclude.php');
25
+
26
+$section = 'dns_dyndns';
27
+
28
+if (!isset($_REQUEST['id']))
29
+  system_failure("Keine ID");
30
+
31
+$id = (int) $_REQUEST['id'];
32
+$record = get_dns_record($id);
33
+$dyndns = get_dyndns_account($record['dyndns']);
34
+
35
+$sure = user_is_sure();
36
+if ($sure === NULL)
37
+{
38
+  $domain = new Domain((int) $record['domain']);
39
+  $fqdn = $domain->fqdn;
40
+  if ($record['hostname'])
41
+  {
42
+    $fqdn = $record['hostname'].'.'.$fqdn;
43
+  }
44
+  are_you_sure("action=delete&id={$id}", "Möchten Sie den Hostname ".$fqdn." für den DynDNS-Account {$dyndns['handle']} wirklich löschen?");
45
+  }
46
+  elseif ($sure === true)
47
+  {
48
+    delete_dns_record($id);
49
+    if (! $debugmode)
50
+      header("Location: dyndns_hostnames?id=".$dyndns['id']);
51
+  }
52
+  elseif ($sure === false)
53
+  {
54
+    if (! $debugmode)
55
+      header("Location: dyndns_hostnames?id=".$dyndns['id']);
56
+  }
... ...
@@ -0,0 +1,62 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('inc/base.php');
18
+require_once('inc/security.php');
19
+require_once('inc/icons.php');
20
+
21
+require_role(ROLE_SYSTEMUSER);
22
+
23
+require_once('dnsinclude.php');
24
+
25
+$section = 'dns_dyndns';
26
+$dyndns = get_dyndns_account($_REQUEST['id']);
27
+
28
+title("Hostnames für DynDNS-Account ".filter_input_general($dyndns['handle']));
29
+
30
+$available_domains = array();
31
+
32
+$domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
33
+foreach ($domains as $d) {
34
+  if ($d->dns) {
35
+    $available_domains[$d->id] = $d->fqdn;
36
+  }
37
+}
38
+
39
+
40
+$records = get_dyndns_records($dyndns['id']);
41
+
42
+if ($records) {
43
+  $output .= '<h4>Folgende DNS-records sind mit diesem DynDNS-Account verknüpft:</h4>
44
+<ul>
45
+';
46
+  foreach ($records AS $record) {
47
+    $output .= '  <li>'.$record['fqdn'].' '.internal_link('dyndns_hostname_delete', icon_delete(), 'id='.$record['id']).'</li>';
48
+  }
49
+  $output .= '</ul>';
50
+}
51
+
52
+
53
+output('<h4>Neuen Hostname festlegen</h4>');
54
+
55
+$form = '<p><label for="hostname">Neuer Hostname: </label></td><td><input type="text" name="hostname" id="hostname" value="'.$dyndns['handle'].'" />&#160;.&#160;'.html_select('domain', $available_domains).' <input type="submit" value="Speichern"/></p>';
56
+
57
+
58
+output(html_form('dyndns_hostname_add', 'dyndns_hostname_add', 'id='.$dyndns['id'], $form));
59
+
60
+output('<p>'.internal_link('dyndns', 'Zurück zur Übersicht')."</p>");
61
+
62
+
... ...
@@ -62,6 +62,9 @@ function create_dyndns_account($handle, $password_http, $sshkey)
62 62
 
63 63
   $handle = filter_input_username($handle);
64 64
   $sshkey = filter_input_general($sshkey);
65
+  if (strlen($sshkey) == 0) {
66
+    $sshkey = NULL;
67
+  }
65 68
 
66 69
   $pwhash = NULL;
67 70
   if ($password_http)
... ...
@@ -71,11 +74,12 @@ function create_dyndns_account($handle, $password_http, $sshkey)
71 74
            "(:uid, :handle, :pwhash, :sshkey)",
72 75
            array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey));
73 76
   $dyndns_id = db_insert_id();
74
-  $masterdomain = new Domain(config('masterdomain'));
75
-  db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
76
-           "('a', :dom, :hostname, :dyndns, 120)",
77
-           array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
78
-  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account");
77
+  //$masterdomain = new Domain(config('masterdomain'));
78
+  //db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
79
+  //         "('a', :dom, :hostname, :dyndns, 120)",
80
+  //         array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
81
+  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account {$dyndns_id}");
82
+  return $dyndns_id;
79 83
 }
80 84
 
81 85
 
... ...
@@ -52,14 +52,22 @@ if (isset($_GET['type']) && $_GET['type'] == 'dyndns') {
52 52
   if ($_GET['action'] == 'edit') {
53 53
     check_form_token('dyndns_edit');
54 54
       
55
+    $newid = NULL;
55 56
     if ($id) {
56 57
       edit_dyndns_account($id, $_POST['handle'], $_POST['password_http'], $_POST['sshkey']);
57 58
     } else {
58
-      create_dyndns_account($_POST['handle'], $_POST['password_http'], $_POST['sshkey']);
59
+      $newid = create_dyndns_account($_POST['handle'], $_POST['password_http'], $_POST['sshkey']);
59 60
     }
60 61
   
61
-    if (! ($debugmode || we_have_an_error()))
62
+    if (! ($debugmode || we_have_an_error())) {
63
+      if ($id) { 
64
+        // Bearbeitung
62 65
         header('Location: dyndns');
66
+      } else {
67
+        // Neu angelegt
68
+        header('Location: dyndns_hostnames?id='.$newid);
69
+      }
70
+    }
63 71
   }
64 72
 }
65 73
 
66 74