Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bufgix djbns #32

Merged
merged 2 commits into from

2 participants

Ángel Guzmán Maeso Walter Secco
Ángel Guzmán Maeso

See http://project.lxcenter.org/issues/797

Note: This include bugfix-926 too (still not merged on dev, only on master)

Walter Secco waltern merged commit d1f3588 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2012
  1. Ángel Guzmán Maeso
  2. Ángel Guzmán Maeso

    Write a new class DjbDNS with properly php-doc, sanitization and impr…

    shakaran authored
    …ovement of error logs messages. Also fix project issue bug #797 (Reopened)
This page is out of date. Refresh to see the latest.
Showing with 187 additions and 43 deletions.
  1. +159 −34 kloxo/bin/misc/djbdnsstart.php
  2. +28 −9 kloxo/httpdocs/htmllib/lib/linuxlib.php
193 kloxo/bin/misc/djbdnsstart.php
View
@@ -1,39 +1,164 @@
<?php
-include_once "htmllib/lib/include.php";
+include_once 'htmllib/lib/include.php';
-if (!posix_getpwnam('tinydns')) {
- system("useradd tinydns");
+class DjbDNS
+{
+ /**
+ * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
+ * @var $dns_users The users needed for DjbDNS service
+ */
+ private static $dns_users = array('tinydns', 'dnslog', 'dnscache', 'axfrdns');
+
+ /**
+ * Create the users needed for init DjbDNS.
+ *
+ * The users needed are: tinydns, dnslog, dnscache, axfrdns
+ *
+ * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ self::createDjbDNSUsers();
+ self::checkPaths();
+ self::getIPs();
+ }
+
+ /**
+ * Create the users needed for init DjbDNS.
+ *
+ * The users needed are: tinydns, dnslog, dnscache, axfrdns
+ *
+ * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
+ *
+ * @return void
+ */
+ private static function createDjbDNSUsers()
+ {
+ foreach (self::$dns_users as $user) {
+ // Create the user only if not exist previously
+ if(!posix_getpwnam($user)) {
+ $result = system('useradd ' . $user);
+
+ if($result !== 0) {
+ echo 'Error: Adding ' . $user . ' user failed.' . PHP_EOL;
+ exit();
+ }
+ else {
+ echo 'Added ' . $user . ' user.' . PHP_EOL;
+ }
+ }
+ }
+ }
+
+ /**
+ * Check if the config paths are init
+ *
+ * The config paths are:
+ * - /var/tinydns
+ * - /var/axfrdns
+ *
+ * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
+ *
+ * @return void
+ */
+ private static function checkPaths()
+ {
+ if(!file_exists('/var/tinydns')) {
+ $result = system('tinydns-conf tinydns dnslog /var/tinydns 127.0.0.1');
+
+ if($result !== 0) {
+ echo 'Error: enabling /var/tinydns config.' . PHP_EOL;
+ exit();
+ }
+ else {
+ echo 'Enabling /var/tinydns config.' . PHP_EOL;
+ }
+ }
+
+ if(!file_exists('/var/axfrdns')) {
+ $result = system('axfrdns-conf axfrdns dnslog /var/axfrdns /var/tinydns 0.0.0.0');
+
+ if($result !== 0) {
+ echo 'Error: enabling /var/axfrdns config.' . PHP_EOL;
+ exit();
+ }
+ else {
+ echo 'Enabling /var/axfrdns config.' . PHP_EOL;
+ }
+ }
+ }
+
+ /**
+ * Get the IPs availables.
+ *
+ * Configure the IP for Djbdns and write properly configs.
+ *
+ * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
+ *
+ * @return void
+ */
+ private static function getIPs()
+ {
+ echo 'Getting the list of IPs availables.' . PHP_EOL;
+
+ $ip_address_list = os_get_allips();
+ //var_dump($ip_address_list);
+
+ if(empty($ip_address_list))
+ {
+ echo 'Error: no IPs availaibles configured.' . PHP_EOL;
+ exit();
+ }
+ else
+ {
+ // If array merge as IP/IP/...
+ if(is_array($ip_address_list))
+ {
+ $ip_address_list = implode('/', $ip_address_list);
+ }
+
+ if(!lfile_put_contents('/var/tinydns/env/IP', $ip_address_list)) {
+ echo 'Error: could not write the IP ' . $ip_address_list . ' for tinydns file /var/tinydns/env/IP. ' . PHP_EOL;
+ exit();
+ }
+
+ if (!file_exists('/var/dnscache')) {
+ $result = system('dnscache-conf dnscache dnslog /var/dnscache 127.0.0.1');
+
+ if($result !== 0) {
+ echo 'Error: enabling /var/dnscache config.' . PHP_EOL;
+ exit();
+ }
+ else {
+ echo 'Enabling /var/dnscache config.' . PHP_EOL;
+ }
+ }
+
+ if(!lfile_put_contents('/var/axfrdns/tcp', ':allow')) {
+ echo 'Error: could not write the config on /var/axfrdns/tcp.' . PHP_EOL;
+ exit();
+ }
+
+ $result = system('cd /var/axfrdns; /usr/local/bin/tcprules tcp.cdb tcp.tmp < tcp');
+
+ if(intval($result) !== 0) {
+ var_dump($result);
+ echo 'Error: enabling tcprules config.' . PHP_EOL;
+ exit();
+ }
+ else {
+ echo 'Enabling tcprules config.' . PHP_EOL;
+ }
+
+ if(!lfile_put_contents('/var/dnscache/env/IP', '127.0.0.1')) {
+ echo 'Error: could not write the localhost IP on /var/dnscache/env/IP.' . PHP_EOL;
+ exit();
+ }
+ }
+ }
}
-if (!posix_getpwnam('dnslog')) {
- system("useradd dnslog");
-}
-
-if (!posix_getpwnam('dnscache')) {
- system("useradd dnscache");
-}
-if (!posix_getpwnam('axfrdns')) {
- system("useradd axfrdns");
-}
-
-if (!lxfile_exists("/var/tinydns")) {
- system("tinydns-conf tinydns dnslog /var/tinydns 127.0.0.1");
-}
-
-if (!lxfile_exists("/var/axfrdns")) {
- system("axfrdns-conf axfrdns dnslog /var/axfrdns /var/tinydns 0.0.0.0");
-}
-$list = os_get_allips();
-
-$out = implode("/", $list);
-
-lfile_put_contents("/var/tinydns/env/IP", "$out");
-
-if (!lxfile_exists("/var/dnscache")) {
- system("dnscache-conf dnscache dnslog /var/dnscache 127.0.0.1");
-}
-
-lfile_put_contents("/var/axfrdns/tcp", ":allow");
-system("cd /var/axfrdns; /usr/local/bin/tcprules tcp.cdb tcp.tmp < tcp");
-lfile_put_contents("/var/dnscache/env/IP", "127.0.0.1");
+$djbdns = new DjbDNS();
37 kloxo/httpdocs/htmllib/lib/linuxlib.php
View
@@ -192,18 +192,37 @@ function getIPs_from_ifcfg()
global $gbl, $sgbl, $login, $ghtml;
- $driverapp = $gbl->getSyncClass(null, null, 'ipaddress');
-// print($driverapp);
-
- if ($driverapp === 'redhat') {
- $list = Ipaddress__Redhat::getCurrentIps();
+ $master = NULL;
+ $sync_server = NULL;
+ // This actually does nothing, because it doesn't return any driver app on djbdns
+ // (Commented by Angel, added by Mustafa previously)
+ // @deprecated This should be deprecated and confirmed.
+ $driverapp = $gbl->getSyncClass($master, $sync_server, 'ipaddress');
+
+ $current_ip_address_list = array();
+ //var_dump($driverapp);
+
+ if(!empty($driverapp))
+ { // @deprecated This is probably always empty, just left here some time and deprecate
+ if ($driverapp === 'redhat') {
+ $current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
+ }
+ else {
+ $current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
+ }
}
-
+ else {
+ // This is the real way to get the IP from djbdns, OS detection should make previously. Assuming Redhat by default.
+ $current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
+ }
+
+ // var_dump($current_ip_address_list);
+
$iplist = array(); // Initialize return value
- if(!empty($list)) {
- foreach($list as $k => $v) {
+ if(!empty($current_ip_address_list)) {
+ foreach($current_ip_address_list as $index => $data) {
// Check ipaddr index
- $ip_address = isset($v['ipaddr']) ? $v['ipaddr'] : NULL;
+ $ip_address = isset($data['ipaddr']) ? $data['ipaddr'] : NULL;
// Skip localhost IP or empty values
if ($ip_address !== '127.0.0.1' && !empty($ip_address)) {
Something went wrong with that request. Please try again.