PHP 5.3
authorNico Kaiser <nico@kaiser.me>
Tue, 18 Jun 2013 13:49:05 +0000 (15:49 +0200)
committerNico Kaiser <nico.kaiser@boerse-go.de>
Tue, 18 Jun 2013 13:49:05 +0000 (15:49 +0200)
TODO.txt [deleted file]
htdocs/Dyndns/Helper.php [moved from htdocs/classes/DyndnsHelper.class.php with 98% similarity]
htdocs/Dyndns/Hosts.php [moved from htdocs/classes/DyndnsHosts.class.php with 94% similarity]
htdocs/Dyndns/Server.php [moved from htdocs/classes/Dyndns.class.php with 88% similarity]
htdocs/Dyndns/Users.php [moved from htdocs/classes/DyndnsUsers.class.php with 97% similarity]
htdocs/index.php

diff --git a/TODO.txt b/TODO.txt
deleted file mode 100644 (file)
index 21ebd29..0000000
--- a/TODO.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-TODO
-====
-
-- Implement Wildcards
-- Implement NOCHG
-- Implement more features from DynDNS.org
-- Provide Apache templates (for mod_rewrite, etc.)
-
similarity index 98%
rename from htdocs/classes/DyndnsHelper.class.php
rename to htdocs/Dyndns/Helper.php
index fa87048..89df79e 100644 (file)
@@ -1,12 +1,14 @@
 <?php
 
+namespace Dyndns;
+
 /**
  * Helper functions.
  * 
  * @package Dyndns
  * @author  Nico Kaiser <nico@kaiser.me>
  */
-class DyndnsHelper
+class Helper
 {    
     /**
      * Check valid IP address
similarity index 94%
rename from htdocs/classes/DyndnsHosts.class.php
rename to htdocs/Dyndns/Hosts.php
index cca9282..211aba7 100644 (file)
@@ -1,12 +1,14 @@
 <?php
 
+namespace Dyndns;
+
 /**
  * Host database.
  * 
  * @package Dyndns
  * @author  Nico Kaiser <nico@kaiser.me>
  */
-class DyndnsHosts
+class Hosts
 {    
     /**
      * Filename of the hosts file (dyndns.hosts)
@@ -74,7 +76,7 @@ class DyndnsHosts
             return false;
         }
 
-        if (! DyndnsHelper::checkValidHost($hostname)) {
+        if (! Helper::checkValidHost($hostname)) {
             $this->debug('Invalid host: ' . $hostname);
             return false;
         }
@@ -86,7 +88,7 @@ class DyndnsHosts
         if (is_array($this->hosts)) {
             foreach ($this->hosts as $line) {
                 if (preg_match("/^(.*?):(.*)/", $line, $matches)) {
-                    if (DyndnsHelper::compareHosts($matches[1], $hostname, '*') && 
+                    if (Helper::compareHosts($matches[1], $hostname, '*') && 
                             in_array($user, explode(',', strtolower($matches[2])))) {
                         return true;
                     }
@@ -145,11 +147,11 @@ class DyndnsHosts
         $key = $this->getConfig('bind.key');
 
         // sanitiy checks
-        if (! DyndnsHelper::checkValidHost($server)) {
+        if (! Helper::checkValidHost($server)) {
             $this->debug('ERROR: Invalid bind.server config value');
             return false;
         }
-        if (! DyndnsHelper::checkValidHost($zone)) {
+        if (! Helper::checkValidHost($zone)) {
             $this->debug('ERROR: Invalid bind.zone config value');
             return false;
         }
similarity index 88%
rename from htdocs/classes/Dyndns.class.php
rename to htdocs/Dyndns/Server.php
index 81e97ab..460aea6 100644 (file)
@@ -1,8 +1,6 @@
 <?php
-require_once(dirname(__FILE__) . '/DyndnsHelper.class.php');
-require_once(dirname(__FILE__) . '/DyndnsHosts.class.php');
-require_once(dirname(__FILE__) . '/DyndnsUsers.class.php');
+
+namespace Dyndns;
 
 /**
  * Simple Dynamic DNS server.
@@ -10,7 +8,7 @@ require_once(dirname(__FILE__) . '/DyndnsUsers.class.php');
  * @package Dyndns
  * @author  Nico Kaiser <nico@kaiser.me>
  */
-class Dyndns
+class Server
 {    
     /**
      * Storage for all configuration variables, set in config.php
@@ -59,16 +57,16 @@ class Dyndns
 
     public function init()
     {
-        $this->users = new DyndnsUsers($this->config['userFile']);
-        $this->hosts = new DyndnsHosts($this->config['hostsFile']);
+        $this->users = new Users($this->config['userFile']);
+        $this->hosts = new Hosts($this->config['hostsFile']);
         
         $this->checkHttpMethod();
         $this->checkAuthentication();
         
         // Get IP address, fallback to REMOTE_ADDR
-        $this->myIp = DyndnsHelper::getMyIp();
+        $this->myIp = Helper::getMyIp();
         if (array_key_exists('myip', $_REQUEST)) {
-            if (DyndnsHelper::checkValidIp($_REQUEST['myip'])) {
+            if (Helper::checkValidIp($_REQUEST['myip'])) {
                 $this->myIp = $_REQUEST['myip'];
             } else {
                 $this->debug('Invalid parameter myip. Using default REMOTE_ADDR');
@@ -133,7 +131,7 @@ class Dyndns
     {
         foreach ($this->hostnames as $hostname) {
                // check if the hostname is valid FQDN
-            if (! DyndnsHelper::checkValidHost($hostname)) {
+            if (! Helper::checkValidHost($hostname)) {
                 $this->returnCode('notfqdn');
             }
 
@@ -183,6 +181,6 @@ class Dyndns
 
     private function debug($message)
     {
-        $this->debugBuffer .= date('M j G:i:s') . ' Dyndns: ' . $message . "\n";
+        $this->debugBuffer .= @date('M j G:i:s') . ' Dyndns: ' . $message . "\n";
     }
 }
similarity index 97%
rename from htdocs/classes/DyndnsUsers.class.php
rename to htdocs/Dyndns/Users.php
index 49b4321..bd0946c 100644 (file)
@@ -1,12 +1,14 @@
 <?php
 
+namespace Dyndns;
+
 /**
  * User database.
  * 
  * @package Dyndns
  * @author  Nico Kaiser <nico@kaiser.me>
  */
-class DyndnsUsers
+class Users
 {
     private $userFile;
 
index 23691ad..49a5ff8 100644 (file)
  */
 
 error_reporting(E_ALL);
-require_once(dirname(__FILE__) . '/classes/Dyndns.class.php');
 
-$GLOBALS['dyndns'] =& new Dyndns();
-$dyndns =& $GLOBALS['dyndns'];
+require_once __DIR__ . '/Dyndns/Helper.php';
+require_once __DIR__ . '/Dyndns/Hosts.php';
+require_once __DIR__ . '/Dyndns/Users.php';
+require_once __DIR__ . '/Dyndns/Server.php';
 
-@include(dirname(__FILE__). '/config.php');
+$GLOBALS['dyndns'] = new Dyndns\Server();
+$dyndns = $GLOBALS['dyndns'];
+
+require __DIR__ . '/config.php';
 
 $dyndns->init();