Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Bufgix djbns #32

Merged
merged 2 commits into from about 2 years ago

2 participants

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

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 March 13, 2012
Walter Secco waltern closed this March 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Mar 13, 2012
Ángel Guzmán Maeso Merge branch 'bugfix-926' into bufgix-djbns 871bb5d
Ángel Guzmán Maeso Write a new class DjbDNS with properly php-doc, sanitization and impr…
…ovement of error logs messages. Also fix project issue bug #797 (Reopened)
406e168
This page is out of date. Refresh to see the latest.
193  kloxo/bin/misc/djbdnsstart.php
... ...
@@ -1,39 +1,164 @@
1 1
 <?php 
2 2
 
3  
-include_once "htmllib/lib/include.php"; 
  3
+include_once 'htmllib/lib/include.php'; 
4 4
 
5  
-if (!posix_getpwnam('tinydns')) {
6  
-	system("useradd tinydns");
  5
+class DjbDNS
  6
+{
  7
+	/**
  8
+	 * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
  9
+	 * @var $dns_users The users needed for DjbDNS service
  10
+	 */
  11
+	private static $dns_users = array('tinydns', 'dnslog', 'dnscache', 'axfrdns');
  12
+	
  13
+	/**
  14
+	* Create the users needed for init DjbDNS.
  15
+	*
  16
+	* The users needed are: tinydns, dnslog, dnscache, axfrdns
  17
+	*
  18
+	* @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
  19
+	*
  20
+	* @return void
  21
+	*/
  22
+	public function __construct() 
  23
+	{
  24
+		self::createDjbDNSUsers();
  25
+		self::checkPaths();
  26
+		self::getIPs();
  27
+	}
  28
+	
  29
+	/**
  30
+	 * Create the users needed for init DjbDNS.
  31
+	 * 
  32
+	 * The users needed are: tinydns, dnslog, dnscache, axfrdns
  33
+	 * 
  34
+	 * @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
  35
+	 * 
  36
+	 * @return void
  37
+	 */
  38
+	private static function createDjbDNSUsers()
  39
+	{
  40
+		foreach (self::$dns_users as $user) {
  41
+			// Create the user only if not exist previously
  42
+			if(!posix_getpwnam($user)) {
  43
+				$result = system('useradd ' . $user);
  44
+				
  45
+				if($result !== 0) {
  46
+					echo 'Error: Adding ' . $user . ' user failed.' . PHP_EOL;
  47
+					exit();
  48
+				}
  49
+				else {
  50
+					echo 'Added ' . $user . ' user.' . PHP_EOL;
  51
+				}
  52
+			}
  53
+		}
  54
+	}
  55
+	
  56
+	/**
  57
+	* Check if the config paths are init
  58
+	*
  59
+	* The config paths are:
  60
+	* 	- /var/tinydns
  61
+	*   - /var/axfrdns
  62
+	*
  63
+	* @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
  64
+	*
  65
+	* @return void
  66
+	*/
  67
+	private static function checkPaths()
  68
+	{
  69
+		if(!file_exists('/var/tinydns')) {
  70
+			$result = system('tinydns-conf tinydns dnslog /var/tinydns 127.0.0.1');
  71
+			
  72
+			if($result !== 0) {
  73
+				echo 'Error: enabling /var/tinydns config.' . PHP_EOL;
  74
+				exit();
  75
+			}
  76
+			else {
  77
+				echo 'Enabling /var/tinydns config.' . PHP_EOL;
  78
+			}
  79
+		}
  80
+		
  81
+		if(!file_exists('/var/axfrdns')) {
  82
+			$result = system('axfrdns-conf axfrdns dnslog /var/axfrdns /var/tinydns 0.0.0.0');
  83
+			
  84
+			if($result !== 0) {
  85
+				echo 'Error: enabling /var/axfrdns config.' . PHP_EOL;
  86
+				exit();
  87
+			}
  88
+			else {
  89
+				echo 'Enabling /var/axfrdns config.' . PHP_EOL;
  90
+			}
  91
+		}
  92
+	}
  93
+	
  94
+	/**
  95
+	* Get the IPs availables.
  96
+	* 
  97
+	* Configure the IP for Djbdns and write properly configs.
  98
+	*
  99
+	* @author Ángel Guzmán Maeso <angel.guzman@lxcenter.org>
  100
+	*
  101
+	* @return void
  102
+	*/
  103
+	private static function getIPs()
  104
+	{
  105
+		echo 'Getting the list of IPs availables.' . PHP_EOL;
  106
+		
  107
+		$ip_address_list = os_get_allips();
  108
+		//var_dump($ip_address_list);
  109
+		
  110
+		if(empty($ip_address_list))
  111
+		{
  112
+			echo 'Error: no IPs availaibles configured.' . PHP_EOL;
  113
+			exit();
  114
+		}
  115
+		else
  116
+		{
  117
+			// If array merge as IP/IP/...
  118
+			if(is_array($ip_address_list))
  119
+			{
  120
+				$ip_address_list = implode('/', $ip_address_list);
  121
+			}
  122
+		
  123
+			if(!lfile_put_contents('/var/tinydns/env/IP', $ip_address_list)) {
  124
+				echo 'Error: could not write the IP ' . $ip_address_list . ' for tinydns file /var/tinydns/env/IP. ' . PHP_EOL;
  125
+				exit();
  126
+			}
  127
+		
  128
+			if (!file_exists('/var/dnscache')) {
  129
+				$result = system('dnscache-conf dnscache dnslog /var/dnscache 127.0.0.1');
  130
+				
  131
+				if($result !== 0) {
  132
+					echo 'Error: enabling /var/dnscache config.' . PHP_EOL;
  133
+					exit();
  134
+				}
  135
+				else {
  136
+					echo 'Enabling /var/dnscache config.' . PHP_EOL;
  137
+				}
  138
+			}
  139
+		
  140
+			if(!lfile_put_contents('/var/axfrdns/tcp', ':allow')) {
  141
+				echo 'Error: could not write the config on /var/axfrdns/tcp.' . PHP_EOL;
  142
+				exit();
  143
+			}
  144
+			
  145
+			$result = system('cd /var/axfrdns;  /usr/local/bin/tcprules tcp.cdb tcp.tmp < tcp');
  146
+			
  147
+			if(intval($result) !== 0) {
  148
+				var_dump($result);
  149
+				echo 'Error: enabling tcprules config.' . PHP_EOL;
  150
+				exit();
  151
+			}
  152
+			else {
  153
+				echo 'Enabling tcprules config.' . PHP_EOL;
  154
+			}
  155
+			
  156
+			if(!lfile_put_contents('/var/dnscache/env/IP', '127.0.0.1')) {
  157
+				echo 'Error: could not write the localhost IP on /var/dnscache/env/IP.' . PHP_EOL;
  158
+				exit();
  159
+			}
  160
+		}
  161
+	}
7 162
 }
8  
-if (!posix_getpwnam('dnslog')) {
9  
-	system("useradd dnslog");
10  
-}
11  
-
12  
-if (!posix_getpwnam('dnscache')) {
13  
-	system("useradd dnscache");
14  
-}
15  
-if (!posix_getpwnam('axfrdns')) {
16  
-	system("useradd axfrdns");
17  
-}
18  
-
19  
-if (!lxfile_exists("/var/tinydns")) {
20  
-	system("tinydns-conf tinydns dnslog /var/tinydns 127.0.0.1");
21  
-}
22  
-
23  
-if (!lxfile_exists("/var/axfrdns")) {
24  
-	system("axfrdns-conf axfrdns dnslog /var/axfrdns /var/tinydns 0.0.0.0");
25  
-}
26  
-$list = os_get_allips();
27  
-
28  
-$out = implode("/", $list);
29  
-
30  
-lfile_put_contents("/var/tinydns/env/IP", "$out");
31  
-
32  
-if (!lxfile_exists("/var/dnscache")) {
33  
-	system("dnscache-conf dnscache dnslog /var/dnscache 127.0.0.1"); 
34  
-}
35  
-
36  
-lfile_put_contents("/var/axfrdns/tcp", ":allow");
37  
-system("cd /var/axfrdns;  /usr/local/bin/tcprules tcp.cdb tcp.tmp < tcp");
38 163
 
39  
-lfile_put_contents("/var/dnscache/env/IP", "127.0.0.1");
  164
+$djbdns = new DjbDNS();
37  kloxo/httpdocs/htmllib/lib/linuxlib.php
@@ -192,18 +192,37 @@ function getIPs_from_ifcfg()
192 192
 
193 193
 	global $gbl, $sgbl, $login, $ghtml;
194 194
 
195  
-	$driverapp = $gbl->getSyncClass(null, null, 'ipaddress');
196  
-//	print($driverapp);
197  
-
198  
-	if ($driverapp === 'redhat') {
199  
-		$list = Ipaddress__Redhat::getCurrentIps();
  195
+	$master      = NULL;
  196
+	$sync_server = NULL;
  197
+	// This actually does nothing, because it doesn't return any driver app on djbdns 
  198
+	// (Commented by Angel, added by Mustafa previously)
  199
+	// @deprecated This should be deprecated and confirmed.
  200
+	$driverapp = $gbl->getSyncClass($master, $sync_server, 'ipaddress');
  201
+
  202
+	$current_ip_address_list = array();
  203
+	//var_dump($driverapp);
  204
+	
  205
+	if(!empty($driverapp))
  206
+	{   // @deprecated This is probably always empty, just left here some time and deprecate
  207
+		if ($driverapp === 'redhat') {
  208
+			$current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
  209
+		}
  210
+		else {
  211
+			$current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
  212
+		}
200 213
 	}
201  
-
  214
+	else {
  215
+		// This is the real way to get the IP from djbdns, OS detection should make previously. Assuming Redhat by default.
  216
+		$current_ip_address_list = Ipaddress__Redhat::getCurrentIps();
  217
+	}
  218
+	
  219
+	// var_dump($current_ip_address_list);
  220
+	
202 221
 	$iplist = array(); // Initialize return value
203  
-	if(!empty($list)) {
204  
-		foreach($list as $k => $v) {
  222
+	if(!empty($current_ip_address_list)) {
  223
+		foreach($current_ip_address_list as $index => $data) {
205 224
 			// Check ipaddr index
206  
-			$ip_address = isset($v['ipaddr']) ? $v['ipaddr'] : NULL;
  225
+			$ip_address = isset($data['ipaddr']) ? $data['ipaddr'] : NULL;
207 226
 			
208 227
 			// Skip localhost IP or empty values
209 228
 			if ($ip_address !== '127.0.0.1' && !empty($ip_address)) { 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.