Use composer
authorNico Kaiser <nico.kaiser@boerse-go.de>
Fri, 4 Oct 2013 12:06:35 +0000 (14:06 +0200)
committerNico Kaiser <nico.kaiser@boerse-go.de>
Fri, 4 Oct 2013 12:06:35 +0000 (14:06 +0200)
README.md
composer.json [new file with mode: 0644]
examples/index.php [new file with mode: 0644]
src/Dyndns/Helper.php [moved from web/lib/Dyndns/Helper.php with 96% similarity]
src/Dyndns/Hosts.php [moved from web/lib/Dyndns/Hosts.php with 98% similarity]
src/Dyndns/Server.php [moved from web/lib/Dyndns/Server.php with 98% similarity]
src/Dyndns/Users.php [moved from web/lib/Dyndns/Users.php with 95% similarity]
web/config.php [deleted file]
web/index.php [deleted file]

index af77d8f..6998185 100644 (file)
--- a/README.md
+++ b/README.md
@@ -69,8 +69,37 @@ Hosts are assigned to users in using the file  "dyndns.hosts":
 (So users can update multiple hosts, and a host can be updated by multiple users).
 
 
-The location of these files must be specified in  "config.php". For security reasons, don't place
-them in your Document root, otherwise every Web user can read them.
+### Installation via Composer
+
+    # Install Composer
+    curl -sS https://getcomposer.org/installer | php
+
+    # Add Dyndns as a dependency
+    php composer.phar require nicokaiser/dyndns:*
+
+Then you can create a simple `index.php` with the configuration:
+
+```php
+<?php
+
+require 'vendor/autoload.php';
+
+$dyndns = new Dyndns\Server();
+
+// Configuration
+$dyndns
+  ->setConfig('hostsFile', __DIR__ . '/../conf/dyndns.hosts') // hosts database
+  ->setConfig('userFile', __DIR__ . '/../conf/dyndns.user')   // user database
+  ->setConfig('debug', true)  // enable debugging
+  ->setConfig('debugFile', '/tmp/dyndns.log') // debug file
+  ->setConfig('bind.keyfile', __DIR__ . '/../conf/dyn.example.com.key') // secret key for BIND nsupdate ("<keyname>:<secret>")
+  ->setConfig('bind.server', 'localhost') // address of the BIND server
+  ->setConfig('bind.zone', 'dyndns.example.com') // BIND zone for the updates
+  ->setConfig('bind.ttl', '300') // TTL for DNS entries
+;
+
+$dyndns->init();
+```
 
 
 ### Usage
diff --git a/composer.json b/composer.json
new file mode 100644 (file)
index 0000000..db36461
--- /dev/null
@@ -0,0 +1,18 @@
+{
+    "name": "nicokaiser/dyndns",
+    "description": "A simple dynamic DNS that updates an existing BIND",
+    "keywords": ["dns", "dyndns"],
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "Nico Kaiser",
+            "email": "nico@kaiser.me",
+            "homepage": "http://kaiser.me"
+        }
+    ],
+    "autoload": {
+        "psr-0": {
+            "Dyndns": "src/",
+        }
+    }
+}
diff --git a/examples/index.php b/examples/index.php
new file mode 100644 (file)
index 0000000..be4b93e
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+require 'vendor/autoload.php';
+
+$dyndns = new Dyndns\Server();
+
+// Configuration
+$dyndns
+  ->setConfig('hostsFile', __DIR__ . '/../conf/dyndns.hosts') // hosts database
+  ->setConfig('userFile', __DIR__ . '/../conf/dyndns.user')   // user database
+  ->setConfig('debug', true)  // enable debugging
+  ->setConfig('debugFile', '/tmp/dyndns.log') // debug file
+  ->setConfig('bind.keyfile', __DIR__ . '/../conf/dyn.example.com.key') // secret key for BIND nsupdate ("<keyname>:<secret>")
+  ->setConfig('bind.server', 'localhost') // address of the BIND server
+  ->setConfig('bind.zone', 'dyndns.example.com') // BIND zone for the updates
+  ->setConfig('bind.ttl', '300') // TTL for DNS entries
+;
+
+$dyndns->init();
similarity index 96%
rename from web/lib/Dyndns/Helper.php
rename to src/Dyndns/Helper.php
index 2f6db04..bf59b73 100644 (file)
@@ -4,9 +4,6 @@ namespace Dyndns;
 
 /**
  * Helper functions.
- *
- * @package Dyndns
- * @author  Nico Kaiser <nico@kaiser.me>
  */
 class Helper
 {
similarity index 98%
rename from web/lib/Dyndns/Hosts.php
rename to src/Dyndns/Hosts.php
index ab79dfd..ee6475b 100644 (file)
@@ -4,9 +4,6 @@ namespace Dyndns;
 
 /**
  * Host database.
- *
- * @package Dyndns
- * @author  Nico Kaiser <nico@kaiser.me>
  */
 class Hosts
 {
similarity index 98%
rename from web/lib/Dyndns/Server.php
rename to src/Dyndns/Server.php
index 3fff7fc..87daa49 100644 (file)
@@ -4,9 +4,6 @@ namespace Dyndns;
 
 /**
  * Simple Dynamic DNS server.
- *
- * @package Dyndns
- * @author  Nico Kaiser <nico@kaiser.me>
  */
 class Server
 {
@@ -86,11 +83,14 @@ class Server
 
         // Return "good" code as everything seems to be ok now
         $this->returnCode('good');
+
+        return $this;
     }
 
     public function setConfig($key, $value)
     {
         $this->config[$key] = $value;
+        return $this;
     }
 
     public function getConfig($key)
similarity index 95%
rename from web/lib/Dyndns/Users.php
rename to src/Dyndns/Users.php
index 5ff2686..81f8172 100644 (file)
@@ -4,9 +4,6 @@ namespace Dyndns;
 
 /**
  * User database.
- * 
- * @package Dyndns
- * @author  Nico Kaiser <nico@kaiser.me>
  */
 class Users
 {
diff --git a/web/config.php b/web/config.php
deleted file mode 100644 (file)
index 59d632c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-@ini_set('display_errors', 0);
-
-if (!isset($dyndns) || !method_exists($dyndns, 'setConfig')) {
-       exit;
-}
-
-/* 
- * Location of the hosts database
- */
-$dyndns->setConfig('hostsFile', __DIR__ . '/../conf/dyndns.hosts');
-
-/* 
- * Location of the user database
- */
-$dyndns->setConfig('userFile', __DIR__ . '/../conf/dyndns.user');
-
-/* 
- * Enable debugging?
- */
-$dyndns->setConfig('debug', true);     
-
-/* 
- * Debug filename
- */
-$dyndns->setConfig('debugFile', '/tmp/dyndns.log');                    
-
-/*
- * Secret Key for BIND nsupdate
- * <keyname>:<secret>
- */
-$dyndns->setConfig('bind.keyfile', __DIR__ . '/../conf/dyn.example.com.key');
-
-/*
- * Address of the BIND server. You can specify any remote DNS server here, 
- * if the server allows you to update data using bind.key
- */
-$dyndns->setConfig('bind.server', 'localhost');
-
-/*
- * The BIND zone which retrieves the updates
- */
-$dyndns->setConfig('bind.zone', 'dyndns.example.com');
-
-/*
- * Dynamic DNS entries will get this TTL
- */
-$dyndns->setConfig('bind.ttl', '300');
diff --git a/web/index.php b/web/index.php
deleted file mode 100644 (file)
index 1ac33af..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-/**
- * This script takes the same parameters as the original members.dyndns.org 
- * server does. It can update a BIND DNS server.
- * 
- * The syntax is described here:
- * http://www.dyndns.com/developers/specs/syntax.html
- * 
- * Remember: This script must be run as 
- *     http://members.dyndns.org/nic/update
- * 
- * @author  Nico Kaiser <nico@kaiser.me>
- */
-
-error_reporting(E_ALL);
-
-require_once __DIR__ . '/lib/Dyndns/Helper.php';
-require_once __DIR__ . '/lib/Dyndns/Hosts.php';
-require_once __DIR__ . '/lib/Dyndns/Users.php';
-require_once __DIR__ . '/lib/Dyndns/Server.php';
-
-$GLOBALS['dyndns'] = new Dyndns\Server();
-$dyndns = $GLOBALS['dyndns'];
-
-require __DIR__ . '/config.php';
-
-$dyndns->init();