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/>.
21
* @copyright Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
22
* @license http://www.zivios.org/legal/license
23
* @version $Id: ServiceController.php 1021 2008-09-08 09:18:50Z fkhan $
26
class Dns_ServiceController extends Ecl_Controller_Service
28
public function addServiceAction()
31
* addService is no longer required as DNS is core, we leave it
32
* for reference for now.
34
if (!isset($this->json->doinstall)) {
35
// Service installation action needs to be shown
36
$this->view->computers= $this->_getCompatiableComputers();
37
//$compa = new EMSComputer($this->view->obj->newLdapObject('cn=samwise.emergen.biz,ou=servers,ou=headoffice,l=karachi,dc=emergen,dc=biz'));
38
//$compb = new EMSComputer($this->view->obj->newLdapObject('cn=merry.emergen.biz,ou=Servers,ou=Blue Area,l=Islamabad,dc=emergen,dc=biz'));
39
//$this->view->computers = array();
40
//$this->view->computers[] = $compa;
41
// $this->view->computers[] = $compb;
43
$this->render('options');
45
$mastercompdn = $this->json->mastercompdn;
46
$dnsservice = new DnsService($this->view->obj->newLdapObject(null));
47
$dnsservice->setProperty('cn','Zivios DNS Service');
48
$dnsservice->setProperty('emsdescription','Zivios DNS');
49
$dnsservice->setProperty('emsdnsrootzone',$this->json->rootzone);
50
$dnsservice->setProperty('emsdnsmastercomputerdn',$mastercompdn);
51
$dnsservice->setProperty('emsdnsreplicationmode','SYNCREPL');
52
$handler = $dnsservice->add($this->view->obj);
55
$this->_createPopupReturn(0,"Module successfully added");
56
$this->_jsCallBack('nodeDetails', array($this->view->obj->getdn()));
60
public function dashboardAction()
62
$this->view->dashboardData = $this->view->obj->loadDashboardData();
63
$this->view->masterComputer = $this->view->obj->mastercomp;
64
$this->render("dashboard");
67
public function dashviewAction()
72
$this->view->dashboardData = $this->view->obj->loadDashboardData();
73
$this->view->masterComputer = $this->view->obj->mastercomp;
76
* Render the dashboard.
78
$this->render("dashview");
82
public function manageAction()
84
$this->view->zones = $this->view->obj->getAllZones();
85
$this->render("manager");
88
public function addzoneAction()
90
$zonename = $this->json->zonename;
91
$zonetype = $this->json->zonetype;
92
$zone = new EMSDnsZone();
94
if ($msg = $zone->setProperty('cn',$zonename)) {
95
$this->_createPopupReturn(1,"Zone name must be a valid IP Subnet or Hostname");
96
$this->manageAction();
99
$zone->setType($zonetype);
100
$handler = $zone->add($this->view->obj,$handler);
102
if ($this->processTransaction($handler)) {
103
$this->_createPopupReturn(0,"DNS Zone added");
104
$this->manageAction();
108
public function zoneAction()
110
$zonedn = $this->json->zone_dn;
111
$action = $this->json->action;
112
$this->view->zone = Ecl_Ldap_Cache::loadDn($zonedn);
115
if ($action == 'manage' ) {
116
if ($this->view->zone->getType() == EMSDnsZone::TYPE_FORWARD)
117
$this->render('zonemanage');
118
else if ($this->view->zone->getType() == EMSDnsZone::TYPE_REVERSE)
119
$this->render('revzonemanage');
123
public function addhostAction()
125
$hostname = $this->json->hostname;
126
$zonedn = $this->json->zonedn;
127
$this->json->zone_dn = $zonedn;
128
$this->json->action = 'manage';
129
$zone = Ecl_Ldap_Cache::loadDn($zonedn);
131
$dnshost = new EMSDnsHostName();
133
if ($msg = $dnshost->setProperty('dlzhostname',$hostname)) {
134
$this->_createPopupReturn(1,$msg);
140
$handler = $dnshost->add($zone);
141
if ($this->processTransaction($handler))
142
$this->_createPopupReturn(0,"Host added successfuilly");
144
return $this->zoneAction();
145
// $this->_jsCallBack('nodeDetails', array($this->view->obj->getdn()));
148
public function ptrAction()
150
$ptrdn = $this->json->ptrdn;
151
$action = $this->json->action;
152
$ptr = Ecl_Ldap_Cache::loadDn($ptrdn);
153
$zonedn = $this->json->zonedn;
154
if ($action == 'delete') {
155
$trans = $ptr->delete();
156
if ($this->processTransaction($trans)) {
157
$this->_createPopupReturn(0,"Ptr Deleted Successfully");
158
$this->json->zone_dn = $zonedn;
159
$this->json->action = "manage";
160
return $this->zoneAction();
165
public function addPtrAction()
167
$ptrip = $this->json->ip;
168
$ptrhn = $this->json->hostname;
169
$zonedn = $this->json->zonedn;
170
$zone = Ecl_Ldap_Cache::loadDn($zonedn);
171
$this->json->zone_dn = $zonedn;
172
$this->json->action = "manage";
174
$ptrrecord = new EMSDnsPtrRecord();
176
if ($msg = $ptrrecord->setHostname($ptrhn)) {
177
$this->_createPopupReturn(1,"Mapped hostname must be a FQDN of the host being mapped");
182
if ($msg = $ptrrecord->setProperty('dlzhostname',$ptrip)) {
183
$this->_createPopupReturn(1,$msg);
188
$trans = $ptrrecord->add($zone);
189
if ($this->processTransaction($trans)) {
190
$this->_createPopupReturn(0,"Ptr Record Added Successfully");
191
return $this->zoneAction();
194
public function hostAction()
196
$zonedn = $this->json->zonedn;
197
$action = $this->json->action;
198
$hostdn = $this->json->hostdn;
199
$this->view->host = Ecl_Ldap_Cache::loadDn($hostdn);
201
if ($action == 'manage') {
202
$this->render('hostmanage');
205
else if ($action == 'delete') {
206
$transaction = $this->view->host->delete();
207
$transaction->process();
208
$this->_createPopupReturn(0,"Host Deleted added");
209
$this->json->zone_dn = $zonedn;
210
$this->json->action = 'manage';
211
return $this->zoneAction();
212
//$this->_jsCallBack('nodeDetails', array($this->view->obj->getdn()));
216
public function zoneaddrecordAction()
218
$zonedn = $this->json->zonedn;
219
$zone = Ecl_Ldap_Cache::loadDn($zonedn);
220
$masterhn = $zone->getMasterZoneHN()->getdn();
221
$this->json->parentdn = $masterhn;
224
$this->_createPopupReturn(0,"Zone Record added");
226
$this->json->zone_dn = $zonedn;
227
$this->json->action = "manage";
228
return $this->zoneAction();
231
public function hostaddrecordAction()
234
$this->json->parentdn = $this->json->hostdn;
238
$this->json->hostdn = $this->json->hostdn;
239
$this->json->action = "manage";
240
return $this->hostAction();
243
public function addrecord()
245
$action = $this->json->action;
246
$parentdn = $this->json->parentdn;
247
$type = $this->json->type;
249
$record = new EMSDnsRecord();
251
$host = Ecl_Ldap_Cache::loadDn($parentdn);
252
$record->setType($type);
254
case EMSDnsRecord::A_REC:
255
if ($msg = $record->setProperty('dlzipaddr',$this->json->ipaddr)) {
256
$this->_createPopupReturn(1,$msg);
260
case EMSDnsRecord::MX_REC:
261
if ($msg = $record->setProperty('dlzpreference',$this->json->mxpref)) {
262
$this->_createPopupReturn(1,$msg);
266
if ($msg = $record->setProperty('dlzdata',$this->json->mxhost)) {
267
$this->_createPopupReturn(1,$msg);
271
$record->setProperty('dlzhostname',$host->getProperty('dlzhostname'));
273
case EMSDnsRecord::NS_REC:
275
case EMSDnsRecord::SOA_REC:
277
case EMSDnsRecord::CNAME_REC:
279
case EMSDnsRecord::GENERIC_REC:
283
$transaction = $record->add($host);
284
if ($this->processTransaction($transaction)) {
285
$this->_createPopupReturn(0,'Dns Record Added Successfully');
290
public function recordAction()
292
$action = $this->json->action;
293
$hostdn = $this->json->hostdn;
294
$dn = $this->json->recorddn;
296
if ($action == 'delete') {
297
$record = Ecl_Ldap_Cache::loadDn($dn);
298
$transaction = $record->delete();
299
$transaction->process();
300
$this->_createPopupReturn(0,"Record Deleted Successfully");
301
$this->json->hostdn = $hostdn;
302
$this->json->action = "manage";
303
return $this->hostAction();
307
public function stopServiceAction()
310
if ($this->view->obj->stopDns()) {
311
$this->_createPopupReturn(0, "DNS Service <b>stopped</b> successfully");
313
$this->_createPopupReturn(1, "Could not stop DNS Service Please check logs.");
316
$this->view->dashboardData = $this->view->obj->loadDashboardData();
317
$this->view->masterComputer = $this->view->obj->mastercomp;
318
$this->render("dashview");
322
public function startServiceAction()
324
if ($this->view->obj->startDns()) {
325
$this->_createPopupReturn(0, "DNS Service <b>started</b> successfully");
327
$this->_createPopupReturn(1, "Could not DNS Service. Please check logs.");
330
$this->view->dashboardData = $this->view->obj->loadDashboardData();
331
$this->view->masterComputer = $this->view->obj->mastercomp;
332
$this->render("dashview");