From 120112f107d425643344aa000f592b5bab0089d7 Mon Sep 17 00:00:00 2001 From: Nico Kaiser Date: Fri, 4 Oct 2013 14:06:35 +0200 Subject: [PATCH] Use composer --- README.md | 33 +++++++++++++++++++++++-- composer.json | 18 ++++++++++++++ examples/index.php | 19 +++++++++++++++ {web/lib => src}/Dyndns/Helper.php | 3 --- {web/lib => src}/Dyndns/Hosts.php | 3 --- {web/lib => src}/Dyndns/Server.php | 6 ++--- {web/lib => src}/Dyndns/Users.php | 3 --- web/config.php | 49 -------------------------------------- web/index.php | 28 ---------------------- 9 files changed, 71 insertions(+), 91 deletions(-) create mode 100644 composer.json create mode 100644 examples/index.php rename {web/lib => src}/Dyndns/Helper.php (96%) rename {web/lib => src}/Dyndns/Hosts.php (98%) rename {web/lib => src}/Dyndns/Server.php (98%) rename {web/lib => src}/Dyndns/Users.php (95%) delete mode 100644 web/config.php delete mode 100644 web/index.php diff --git a/README.md b/README.md index af77d8f..6998185 100644 --- 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 +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 (":") + ->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 index 0000000..db36461 --- /dev/null +++ b/composer.json @@ -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 index 0000000..be4b93e --- /dev/null +++ b/examples/index.php @@ -0,0 +1,19 @@ +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 (":") + ->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(); diff --git a/web/lib/Dyndns/Helper.php b/src/Dyndns/Helper.php similarity index 96% rename from web/lib/Dyndns/Helper.php rename to src/Dyndns/Helper.php index 2f6db04..bf59b73 100644 --- a/web/lib/Dyndns/Helper.php +++ b/src/Dyndns/Helper.php @@ -4,9 +4,6 @@ namespace Dyndns; /** * Helper functions. - * - * @package Dyndns - * @author Nico Kaiser */ class Helper { diff --git a/web/lib/Dyndns/Hosts.php b/src/Dyndns/Hosts.php similarity index 98% rename from web/lib/Dyndns/Hosts.php rename to src/Dyndns/Hosts.php index ab79dfd..ee6475b 100644 --- a/web/lib/Dyndns/Hosts.php +++ b/src/Dyndns/Hosts.php @@ -4,9 +4,6 @@ namespace Dyndns; /** * Host database. - * - * @package Dyndns - * @author Nico Kaiser */ class Hosts { diff --git a/web/lib/Dyndns/Server.php b/src/Dyndns/Server.php similarity index 98% rename from web/lib/Dyndns/Server.php rename to src/Dyndns/Server.php index 3fff7fc..87daa49 100644 --- a/web/lib/Dyndns/Server.php +++ b/src/Dyndns/Server.php @@ -4,9 +4,6 @@ namespace Dyndns; /** * Simple Dynamic DNS server. - * - * @package Dyndns - * @author Nico Kaiser */ 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) diff --git a/web/lib/Dyndns/Users.php b/src/Dyndns/Users.php similarity index 95% rename from web/lib/Dyndns/Users.php rename to src/Dyndns/Users.php index 5ff2686..81f8172 100644 --- a/web/lib/Dyndns/Users.php +++ b/src/Dyndns/Users.php @@ -4,9 +4,6 @@ namespace Dyndns; /** * User database. - * - * @package Dyndns - * @author Nico Kaiser */ class Users { diff --git a/web/config.php b/web/config.php deleted file mode 100644 index 59d632c..0000000 --- a/web/config.php +++ /dev/null @@ -1,49 +0,0 @@ -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 - * : - */ -$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 index 1ac33af..0000000 --- a/web/index.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ - -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(); -- 2.1.4