3
* Copyright (c) 2008 Zivios, LLC.
5
* This file is part of Zivios.
7
* Zivios is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* Zivios is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Zivios. If not, see <http://www.gnu.org/licenses/>.
20
* @package ZiviosInstaller
21
* @copyright Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
22
* @license http://www.zivios.org/legal/license
26
class Zivios_Installer_DnsHandler extends Zivios_Installer_LinuxCore
29
* We're hard coding certain constants for now. At some point
30
* we'll make these user definable during the installation process.
32
const VERSION = '9.5.0-P2';
33
const SRCFILE = 'bind-9.5.0-P2.tar.gz';
34
const EXTDIR = '/usr/local/src/zvcompile';
35
const COMPATVERSION = '0.5.0';
36
const SRCFILEPATH = '/usr/local/src/zivios-0.5.0/spkgs/bind-9.5.0-P2.tar.gz';
37
const PKGNAME = 'bind-9.5.0-P2';
38
const SCRIPTSDIR = '/usr/local/src/zivios-0.5.0/bind/conf';
39
const TMPDIR = '/usr/local/src/zvcompile/bind';
40
const TMPRNDCKEYDATA = 'rndckeydata';
41
const TMPRNDCKEY = '/usr/local/src/zvcompile/bind/rndc.key';
42
const TMPNAMEDCONF = '/usr/local/src/zivios-0.5.0/bind/conf/named.conf';
43
const TMPNAMEDLOCAL = '/usr/local/src/zvcompile/bind/named.conf.local';
44
const TMPNAMEDOPTIONS = '/usr/local/src/zvcompile/bind/named.conf.options';
45
const BINDDEFAULTS = '/usr/local/src/zivios-0.5.0/bind/conf/defaults';
46
const BINDINIT = '/usr/local/src/zivios-0.5.0/bind/init.d/zvbind';
48
const ZVDNSSEC = '/opt/zivios/bind/sbin/dnssec-keygen';
49
const ZVNAMEDCONF = '/opt/zivios/bind/etc/named.conf';
50
const ZVBINDINIT = '/etc/init.d/zvbind';
51
const ZVBINDETC = '/opt/zivios/bind/etc';
56
private $statusdone, $configdone;
58
public function __construct()
60
parent::__construct();
61
$this->statusdone = $this->appRoot . '/status/dns.install.stamp';
62
$this->configdone = $this->appRoot . '/status/dnsconfig.install.stamp';
65
public function runInstall()
67
if (!file_exists(self::SRCFILEPATH) || !is_readable(self::SRCFILEPATH))
68
$this->raiseError(700);
71
* Try and extract OpenLDAP source.
73
if (!$this->extractSource(self::SRCFILEPATH, self::EXTDIR,self::PKGNAME,1))
74
$this->raiseError(701);
77
* Source extraction complete. Copy over the required configuration script
78
* to the openldap extract folder.
80
if (!$this->copyConfigureScript(0755))
81
$this->raiseError(702);
84
* Distribution specific pre-processing call.
86
$srcFolder = self::EXTDIR . '/' . self::PKGNAME . '/';
87
$execScript = 'zvconfig_' . $this->zvDistroId . '.sh';
89
if (!$this->compile($srcFolder,$execScript,1,1,1))
90
$this->raiseError(703);
93
* Write install status success.
95
$this->touchInstallStamp($this->statusdone, $this->getTimestamp() . "::Zivios DNS initialized.|" .
101
public function runConfig($data)
104
* If work folder exists, purge it and recreate.
107
* Ensure the TMP dir exists.
109
if (is_dir(self::TMPDIR)) {
110
$cmd = $this->removeRecursive . ' ' . self::TMPDIR;
111
$response = $this->execRcommand($cmd,true);
112
if ($response['exitcode'] != 0)
113
$this->raiseError(707);
119
$cmd = $this->mkdir . ' ' . self::TMPDIR;
120
$response = $this->execRcommand($cmd);
121
if ($response['exitcode'] != 0)
122
$this->raiseError(708);
126
* Copy over required configuration and initialization files.
128
$cmd = $this->copy . ' ' . self::BINDINIT . ' ' . self::ZVBINDINIT;
130
$response = $this->execRcommand($cmd,true);
131
if ($response['exitcode'] != 0)
132
$this->raiseError(704);
135
* Copy over defaults, named.conf & db.* files to /opt/zivios/bind/etc
137
$confFiles = array();
138
$confFiles[] = 'defaults';
139
$confFiles[] = 'named.conf';
140
$confFiles[] = 'db.0';
141
$confFiles[] = 'db.127';
142
$confFiles[] = 'db.255';
143
$confFiles[] = 'db.empty';
144
$confFiles[] = 'db.local';
145
$confFiles[] = 'db.root';
147
foreach ($confFiles as $configFile) {
148
$cmd = $this->copy . " " . self::SCRIPTSDIR . "/". $configFile . " " . self::ZVBINDETC;
149
$response = $this->execRcommand($cmd, true);
150
if ($response['exitcode'] != 0)
151
$this->raiseError(705);
155
* Generate the RNDC key file
159
if (!chdir(self::TMPDIR))
160
$this->raiseError(709);
163
$cmd = self::ZVDNSSEC . ' -a hmac-md5 -b 256 -n HOST ' . self::TMPRNDCKEYDATA;
164
$response = $this->execRcommand($cmd);
165
if ($response['exitcode'] != 0)
166
$this->raiseError(706);
172
$this->raiseError(710);
174
$d = dir(self::TMPDIR);
176
while (false !== ($entry = $d->read())) {
177
if ($entry != '.' && $entry != '..') {
179
* Ensure the extension is .private
181
if (substr($entry, strrpos($entry, '.') + 1) == 'private') {
183
* Read file contents and get the hmac-md5 key
185
$fh = fopen(self::TMPDIR.'/'.$entry, "r");
186
$contents = fread($fh, filesize(self::TMPDIR.'/'.$entry));
192
$allC = split("\n",$contents);
193
foreach ($allC as $c) {
194
$len = (strlen($c) - 4) * -1;
196
if (substr($c, 0, $len) == 'Key:') {
200
$rndcKeyString = substr($c, 4);
206
* Write templates to tmp folder and move to zivios/bind/etc/
208
$namedlocal = $this->appRoot . '/library/Zivios/Installer/Basedata/templates/dns/'.
209
'named.conf.local.tmpl';
211
$namedoptions = $this->appRoot . '/library/Zivios/Installer/Basedata/templates/dns/'.
212
'named.conf.options.tmpl';
214
$rndckeyfile = $this->appRoot . '/library/Zivios/Installer/Basedata/templates/dns/'.
217
if (!file_exists($namedlocal) || !is_readable(($namedlocal)))
218
$this->raiseError(711);
221
* Generate template for named.conf.local and write to file.
222
* Move to zivios bind/etc/
225
$vals['base_dn'] = $data['basedn'];
226
$vals['bind_pass'] = $data['bindpass'];
227
$vals['master_ip'] = $data['ipaddress'];
229
$namedlocaltmpl = Ecl_Util::renderTmplToCfg($namedlocal, $vals);
231
if (!$fp = fopen(self::TMPNAMEDLOCAL, "w"))
232
$this->raiseError(712);
234
if (fwrite($fp, $namedlocaltmpl) === FALSE)
235
$this->raiseError(713);
239
$cmd = $this->copy . " " . self::TMPNAMEDLOCAL . " " . self::ZVBINDETC . "/named.conf.local";
240
$response = $this->execRCommand($cmd, true);
241
if ($response['exitcode'] != 0)
242
$this->raiseError(714);
245
* @todo: Give ownership to bind user & group.
250
* Generate named.conf.options.
252
if (!file_exists($namedoptions) || !is_readable(($namedoptions)))
253
$this->raiseError(715);
256
* Generate template for named.conf.local and write to file.
257
* Move to zivios bind/etc/
260
if (array_key_exists('forwarders', $data)) {
262
foreach ($data['forwarders'] as $forwarder) {
263
$forwarderLine .= "\t\t".$forwarder.";\n";
265
$vals['forwarders'] = $forwarderLine;
268
$namedoptionstmpl = Ecl_Util::renderTmplToCfg($namedoptions, $vals);
270
if (!$fp = fopen(self::TMPNAMEDOPTIONS, "w"))
271
$this->raiseError(716);
273
if (fwrite($fp, $namedoptionstmpl) === FALSE)
274
$this->raiseError(717);
278
$cmd = $this->copy . " " . self::TMPNAMEDOPTIONS . " " . self::ZVBINDETC . "/named.conf.options";
279
$response = $this->execRCommand($cmd, true);
280
if ($response['exitcode'] != 0)
281
$this->raiseError(718);
284
* Write the RNDC key file.
286
if (!file_exists($rndckeyfile) || !is_readable(($rndckeyfile)))
287
$this->raiseError(719);
290
* Generate template for named.conf.local and write to file.
291
* Move to zivios bind/etc/
294
$vals['rndc_key'] = ltrim($rndcKeyString);
296
$rndckeytmpl = Ecl_Util::renderTmplToCfg($rndckeyfile, $vals);
298
if (!$fp = fopen(self::TMPRNDCKEY, "w"))
299
$this->raiseError(720);
301
if (fwrite($fp, $rndckeytmpl) === FALSE)
302
$this->raiseError(721);
306
$cmd = $this->copy . " " . self::TMPRNDCKEY . " " . self::ZVBINDETC . "/rndc.key";
307
$response = $this->execRCommand($cmd, true);
308
if ($response['exitcode'] != 0)
309
$this->raiseError(722);
311
$cmd = self::ZVBINDINIT . ' restart';
312
$response = $this->execRcommand($cmd, true);
313
if ($response['exitcode'] != 0)
314
$this->raiseError(723);
316
$this->touchInstallStamp($this->configdone, $this->getTimestamp() . "::Zivios Bind DNS data Initialized.|" .
317
session_id() . "\n");
323
protected function copyConfigureScript($perms=0644)
325
$cfgFile = 'zvconfig_' . $this->zvDistroId . '.sh';
326
$copySrc = self::SCRIPTSDIR . '/' . $cfgFile;
327
$dstFile = self::EXTDIR . '/' . self::PKGNAME . '/' . $cfgFile;
329
if (copy($copySrc,$dstFile)) {
331
* We set permissions on the copied file to 0644 unless
332
* otherwise specified
334
chmod($dstFile, $perms);
b'\\ No newline at end of file'