~fkhan-zivios/zivios/devel

« back to all changes in this revision

Viewing changes to application/modules/dns/controllers/ServiceController.php

  • Committer: Faraz Khan
  • Date: 2008-09-15 13:29:33 UTC
  • Revision ID: fkhan@zivios.org-20080915132933-d27jml5l29xw4gsr
Initial release to bazaar, code in sync with 0.5.0-release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright (c) 2008 Zivios, LLC.
 
4
 *
 
5
 * This file is part of Zivios.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 *
 
20
 * @package             mod_dns
 
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 $
 
24
 **/
 
25
 
 
26
class Dns_ServiceController extends Ecl_Controller_Service
 
27
{
 
28
    public function addServiceAction()
 
29
        {
 
30
                /**
 
31
                 * addService is no longer required as DNS is core, we leave it
 
32
                 * for reference for now.
 
33
                 */
 
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;
 
42
 
 
43
            $this->render('options');
 
44
        } else {
 
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);
 
53
            $handler->process();
 
54
 
 
55
            $this->_createPopupReturn(0,"Module successfully added");
 
56
            $this->_jsCallBack('nodeDetails', array($this->view->obj->getdn()));
 
57
        }
 
58
    }
 
59
 
 
60
    public function dashboardAction()
 
61
        {
 
62
                $this->view->dashboardData = $this->view->obj->loadDashboardData();
 
63
        $this->view->masterComputer = $this->view->obj->mastercomp;
 
64
                $this->render("dashboard");
 
65
        }
 
66
 
 
67
        public function dashviewAction()
 
68
        {
 
69
                /**
 
70
                 * Hook function.
 
71
                 */
 
72
                $this->view->dashboardData = $this->view->obj->loadDashboardData();
 
73
                $this->view->masterComputer = $this->view->obj->mastercomp;
 
74
 
 
75
                /**
 
76
                 * Render the dashboard.
 
77
                 */
 
78
                $this->render("dashview");
 
79
        }
 
80
 
 
81
 
 
82
    public function manageAction()
 
83
    {
 
84
        $this->view->zones = $this->view->obj->getAllZones();
 
85
        $this->render("manager");
 
86
    }
 
87
 
 
88
    public function addzoneAction()
 
89
    {
 
90
        $zonename = $this->json->zonename;
 
91
        $zonetype = $this->json->zonetype;
 
92
        $zone = new EMSDnsZone();
 
93
        $zone->init();
 
94
        if ($msg = $zone->setProperty('cn',$zonename)) {
 
95
                $this->_createPopupReturn(1,"Zone name must be a valid IP Subnet or Hostname");
 
96
                $this->manageAction();
 
97
                return;
 
98
        }
 
99
        $zone->setType($zonetype);
 
100
        $handler = $zone->add($this->view->obj,$handler);
 
101
 
 
102
        if ($this->processTransaction($handler)) {
 
103
                $this->_createPopupReturn(0,"DNS Zone added");
 
104
                $this->manageAction();
 
105
        }
 
106
    }
 
107
 
 
108
    public function zoneAction()
 
109
    {
 
110
        $zonedn = $this->json->zone_dn;
 
111
        $action = $this->json->action;
 
112
        $this->view->zone = Ecl_Ldap_Cache::loadDn($zonedn);
 
113
 
 
114
 
 
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');
 
120
        }
 
121
    }
 
122
 
 
123
    public function addhostAction()
 
124
    {
 
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);
 
130
 
 
131
        $dnshost = new EMSDnsHostName();
 
132
        $dnshost->init();
 
133
                if ($msg = $dnshost->setProperty('dlzhostname',$hostname)) {
 
134
                        $this->_createPopupReturn(1,$msg);
 
135
                        $this->zoneAction();
 
136
                        return;
 
137
 
 
138
                }
 
139
 
 
140
                $handler = $dnshost->add($zone);
 
141
        if ($this->processTransaction($handler))
 
142
                $this->_createPopupReturn(0,"Host added successfuilly");
 
143
 
 
144
        return $this->zoneAction();
 
145
       // $this->_jsCallBack('nodeDetails', array($this->view->obj->getdn()));
 
146
    }
 
147
 
 
148
    public function ptrAction()
 
149
    {
 
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();
 
161
                }
 
162
        }
 
163
    }
 
164
 
 
165
    public function addPtrAction()
 
166
    {
 
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";
 
173
 
 
174
        $ptrrecord = new EMSDnsPtrRecord();
 
175
        $ptrrecord->init();
 
176
        if ($msg = $ptrrecord->setHostname($ptrhn)) {
 
177
                $this->_createPopupReturn(1,"Mapped hostname must be a FQDN of the host being mapped");
 
178
                $this->zoneAction();
 
179
                return;
 
180
        }
 
181
 
 
182
        if ($msg = $ptrrecord->setProperty('dlzhostname',$ptrip)) {
 
183
                $this->_createPopupReturn(1,$msg);
 
184
                $this->zoneAction();
 
185
                return;
 
186
 
 
187
        }
 
188
        $trans = $ptrrecord->add($zone);
 
189
        if ($this->processTransaction($trans)) {
 
190
                $this->_createPopupReturn(0,"Ptr Record Added Successfully");
 
191
                return $this->zoneAction();
 
192
        }
 
193
    }
 
194
    public function hostAction()
 
195
    {
 
196
        $zonedn = $this->json->zonedn;
 
197
        $action = $this->json->action;
 
198
        $hostdn = $this->json->hostdn;
 
199
        $this->view->host = Ecl_Ldap_Cache::loadDn($hostdn);
 
200
 
 
201
        if ($action == 'manage') {
 
202
            $this->render('hostmanage');
 
203
        }
 
204
 
 
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()));
 
213
        }
 
214
    }
 
215
 
 
216
    public function zoneaddrecordAction()
 
217
    {
 
218
        $zonedn = $this->json->zonedn;
 
219
        $zone = Ecl_Ldap_Cache::loadDn($zonedn);
 
220
        $masterhn = $zone->getMasterZoneHN()->getdn();
 
221
        $this->json->parentdn = $masterhn;
 
222
        $this->addrecord();
 
223
 
 
224
        $this->_createPopupReturn(0,"Zone Record added");
 
225
 
 
226
       $this->json->zone_dn = $zonedn;
 
227
       $this->json->action = "manage";
 
228
       return $this->zoneAction();
 
229
    }
 
230
 
 
231
    public function hostaddrecordAction()
 
232
    {
 
233
 
 
234
       $this->json->parentdn = $this->json->hostdn;
 
235
 
 
236
       $this->addrecord();
 
237
 
 
238
       $this->json->hostdn = $this->json->hostdn;
 
239
       $this->json->action = "manage";
 
240
       return $this->hostAction();
 
241
    }
 
242
 
 
243
    public function addrecord()
 
244
    {
 
245
        $action = $this->json->action;
 
246
        $parentdn = $this->json->parentdn;
 
247
        $type = $this->json->type;
 
248
 
 
249
        $record = new EMSDnsRecord();
 
250
        $record->init();
 
251
        $host = Ecl_Ldap_Cache::loadDn($parentdn);
 
252
        $record->setType($type);
 
253
        switch ($type) {
 
254
                case EMSDnsRecord::A_REC:
 
255
                                        if ($msg = $record->setProperty('dlzipaddr',$this->json->ipaddr)) {
 
256
                                                $this->_createPopupReturn(1,$msg);
 
257
                                                return;
 
258
                                        }
 
259
                                        break;
 
260
                                case EMSDnsRecord::MX_REC:
 
261
                                        if ($msg = $record->setProperty('dlzpreference',$this->json->mxpref)) {
 
262
                                                $this->_createPopupReturn(1,$msg);
 
263
                                                return;
 
264
                                        }
 
265
 
 
266
                    if ($msg = $record->setProperty('dlzdata',$this->json->mxhost)) {
 
267
                        $this->_createPopupReturn(1,$msg);
 
268
                        return;
 
269
                    }
 
270
 
 
271
                    $record->setProperty('dlzhostname',$host->getProperty('dlzhostname'));
 
272
                    break ;
 
273
                                case EMSDnsRecord::NS_REC:
 
274
                                        break;
 
275
                                case EMSDnsRecord::SOA_REC:
 
276
                                        break;
 
277
                                case EMSDnsRecord::CNAME_REC:
 
278
                                        break;
 
279
                                case EMSDnsRecord::GENERIC_REC:
 
280
                                        break;
 
281
                        }
 
282
 
 
283
       $transaction = $record->add($host);
 
284
                if ($this->processTransaction($transaction)) {
 
285
                        $this->_createPopupReturn(0,'Dns Record Added Successfully');
 
286
 
 
287
       }
 
288
    }
 
289
 
 
290
    public function recordAction()
 
291
    {
 
292
        $action = $this->json->action;
 
293
        $hostdn = $this->json->hostdn;
 
294
        $dn = $this->json->recorddn;
 
295
 
 
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();
 
304
        }
 
305
    }
 
306
 
 
307
        public function stopServiceAction()
 
308
        {
 
309
 
 
310
                if ($this->view->obj->stopDns()) {
 
311
                        $this->_createPopupReturn(0, "DNS Service <b>stopped</b> successfully");
 
312
                } else {
 
313
                        $this->_createPopupReturn(1, "Could not stop DNS Service Please check logs.");
 
314
                }
 
315
 
 
316
                $this->view->dashboardData = $this->view->obj->loadDashboardData();
 
317
                $this->view->masterComputer = $this->view->obj->mastercomp;
 
318
                $this->render("dashview");
 
319
                return;
 
320
        }
 
321
 
 
322
        public function startServiceAction()
 
323
        {
 
324
                if ($this->view->obj->startDns()) {
 
325
                        $this->_createPopupReturn(0, "DNS Service <b>started</b> successfully");
 
326
                } else {
 
327
                        $this->_createPopupReturn(1, "Could not DNS Service. Please check logs.");
 
328
                }
 
329
 
 
330
                $this->view->dashboardData = $this->view->obj->loadDashboardData();
 
331
                $this->view->masterComputer = $this->view->obj->mastercomp;
 
332
                $this->render("dashview");
 
333
 
 
334
                return;
 
335
        }
 
336
 
 
337
}