be1cea9ee72b9f922b907073485dd75a185ff7e4
1 <?php
3 class servdns extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account= TRUE;
12 var $attributes= array("zoneName","relativeDomainName","dNSTTL","dNSClass","sOARecord");
13 var $objectclasses= array("whatever");
15 var $RecordTypes = array();
16 var $usedRecords = array();
18 var $Zones = array();
19 var $editMode = false;
21 function servdns ($config, $dn= NULL)
22 {
23 plugin::plugin ($config, $dn);
25 $RecordTypes['ARecord'] ['name'] ="A Record";
26 $RecordTypes['ARecord'] ['type'] ="string";
27 $RecordTypes['MDRecord'] ['name'] ="MD Record";
28 $RecordTypes['MDRecord'] ['type'] ="string";
29 $RecordTypes['MXRecord'] ['name'] ="MX Record";
30 $RecordTypes['MXRecord'] ['type'] ="string";
31 $RecordTypes['NSRecord'] ['name'] ="NS Record";
32 $RecordTypes['NSRecord'] ['type'] ="string";
33 $RecordTypes['CNAMERecord'] ['name'] ="CNAME Record";
34 $RecordTypes['CNAMERecord'] ['type'] ="string";
35 $RecordTypes['PTRRecord'] ['name'] ="PTR Record";
36 $RecordTypes['PTRRecord'] ['type'] ="string";
37 $RecordTypes['HINFORecord'] ['name'] ="HINFO Record";
38 $RecordTypes['HINFORecord'] ['type'] ="string";
39 $RecordTypes['MINFORecord'] ['name'] ="MINFO Record";
40 $RecordTypes['MINFORecord'] ['type'] ="string";
41 $RecordTypes['TXTRecord'] ['name'] ="TXT Record";
42 $RecordTypes['TXTRecord'] ['type'] ="string";
43 $RecordTypes['AFSDBRecord'] ['name'] ="AFSDB Record";
44 $RecordTypes['AFSDBRecord'] ['type'] ="string";
45 $RecordTypes['SIGRecord'] ['name'] ="SIG Record";
46 $RecordTypes['SIGRecord'] ['type'] ="string";
47 $RecordTypes['KEYRecord'] ['name'] ="KEY Record";
48 $RecordTypes['KEYRecord'] ['type'] ="string";
49 $RecordTypes['AAAARecord'] ['name'] ="AAAA Record";
50 $RecordTypes['AAAARecord'] ['type'] ="string";
51 $RecordTypes['LOCRecord'] ['name'] ="LOC Record";
52 $RecordTypes['LOCRecord'] ['type'] ="string";
53 $RecordTypes['NXTRecord'] ['name'] ="NXT Record";
54 $RecordTypes['NXTRecord'] ['type'] ="string";
55 $RecordTypes['SRVRecord'] ['name'] ="SRV Record";
56 $RecordTypes['SRVRecord'] ['type'] ="string";
57 $RecordTypes['NAPTRRecord'] ['name'] ="NAPTR Record";
58 $RecordTypes['NAPTRRecord'] ['type'] ="string";
59 $RecordTypes['KXRecord'] ['name'] ="KX Record";
60 $RecordTypes['KXRecord'] ['type'] ="string";
61 $RecordTypes['CERTRecord'] ['name'] ="CERT Record";
62 $RecordTypes['CERTRecord'] ['type'] ="string";
63 $RecordTypes['A6Record'] ['name'] ="A6 Record";
64 $RecordTypes['A6Record'] ['type'] ="string";
65 $RecordTypes['DNAMERecord'] ['name'] ="DBNAME Record";
66 $RecordTypes['DNAMERecord'] ['type'] ="string";
67 $RecordTypes['DSRecord'] ['name'] ="DS Record";
68 $RecordTypes['DSRecord'] ['type'] ="string";
69 $RecordTypes['SSHFPRecord'] ['name'] ="SSHFP Record";
70 $RecordTypes['SSHFPRecord'] ['type'] ="string";
71 $RecordTypes['RRSIGRecord'] ['name'] ="RRSIG Record";
72 $RecordTypes['RRSIGRecord'] ['type'] ="string";
73 $RecordTypes['NSECRecord'] ['name'] ="NSEC Record";
74 $RecordTypes['NSECRecord'] ['type'] ="string";
75 $RecordTypes['mXRecord'] ['name'] ="MX Record";
76 $RecordTypes['mXRecord'] ['type'] ="string";
77 $RecordTypes['nSRecord'] ['name'] ="nS Record";
78 $RecordTypes['nSRecord'] ['type'] ="string";
80 $this->RecordTypes = $RecordTypes;
82 $attrs = $this->attributes;
83 foreach($RecordTypes as $name => $att){
84 $attrs2[] = $name;
85 }
86 $attrs3 = array_merge($attrs,$attrs2);
88 $ldap = $this->config->get_ldap_link();
89 $ldap->cd($this->dn);
90 $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",$attrs3);
91 while($zone = $ldap->fetch()){
92 $tmp = array();
93 foreach($attrs as $att){
94 if(isset($zone[$att]['count'])&&(is_array($zone[$att])))
95 unset($zone[$att]['count']);
97 if(isset($zone[$att])){
98 $tmp[$att] = $zone[$att][0];
99 }else{
100 $tmp[$att] = "";
101 }
102 }
104 if(isset($tmp['sOARecord'])){
105 $tmp2 = split("\ ",$tmp['sOARecord']);
106 unset($tmp['sOARecord']);
107 $tmp['sOARecord'] = array();
108 $tmp['sOARecord']['sOAprimary'] = $tmp2[0];
109 $tmp['sOARecord']['sOAmail'] = $tmp2[1];
110 $tmp['sOARecord']['sOAserial'] = $tmp2[2];
111 $tmp['sOARecord']['sOArefresh'] = $tmp2[3];
112 $tmp['sOARecord']['sOAretry'] = $tmp2[4];
113 $tmp['sOARecord']['sOAexpire'] = $tmp2[5];
114 $tmp['sOARecord']['sOAttl'] = $tmp2[6];
115 }
117 $tmp['usedRecords'] = array();
118 foreach($attrs2 as $name){
119 if(isset($zone[$name])){
120 for($i = 0 ; $i < $zone[$name]['count'] ; $i++ ){
121 $tmp['usedRecords'][] = array("type"=> $name,"value"=>$zone[$name][$i]);
122 }
123 }
124 }
125 $this->Zones[$zone['zoneName'][0]] = $tmp;
126 }
127 if(count($this->Zones > 0)){
128 $this->is_account = true;
129 }
130 }
132 function execute()
133 {
135 print_a($this->Zones);
136 /* Call parent execute */
137 plugin::execute();
139 /* Fill templating stuff */
140 $smarty= get_smarty();
141 $display= "";
143 /* Do we need to flip is_account state? */
144 if (isset($_POST['modify_state'])){
145 $this->is_account= !$this->is_account;
146 }
148 /* Show tab dialog headers */
149 if ($this->is_account){
150 $display= $this->show_header(_("Remove DNS service"),
151 _("This server has DNS features enabled. You can disable them by clicking below."));
152 } else {
153 $display= $this->show_header(_("Add DNS service"),
154 _("This server has DNS features disabled. You can enable them by clicking below."));
155 return ($display);
156 }
158 $once = false;
159 foreach( $_POST as $name => $value){
160 if(preg_match("/^editZone_/",$name)&&!$once){
161 $once =true;
162 $tmp = preg_replace("/^editZone_/","",$name);
163 $tmp = base64_decode(preg_replace("/_.*$/","...",$tmp));
164 $this->editMode = $this->Zones[$tmp];
165 }
166 }
169 $smarty->assign("editMode",$this->editMode);
170 if($this->editMode){
172 foreach($this->attributes as $attrs){
173 $smarty->assign($attrs,$this->editMode[$attrs]);
174 }
176 foreach($this->editMode['sOARecord'] as $name => $value){
177 $smarty->assign($name,$value);
178 }
179 $smarty->assign("records","");
181 }else{
182 $ZoneList = new divSelectBox("dNSZones");
183 $ZoneList -> SetHeight(254);
185 $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>";
187 foreach($this->Zones as $zone => $values ){
188 $ZoneList->AddEntry(array(array("string" => $zone.str_replace("%s",base64_encode($zone),$editImg))));
189 }
192 $smarty->assign("ZoneList",$ZoneList->DrawList());
193 }
195 $display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE));
196 return($display);
197 }
199 function remove_from_parent()
200 {
201 /* This cannot be removed... */
202 }
205 /* Save data to object */
206 function save_object()
207 {
208 //plugin::save_object();
210 if(!$this->editMode){return;}
212 foreach($this->attributes as $attr){
213 if(isset($_POST[$attr])){
214 $this->editMode[$attr] = $_POST[$attr];
215 }
216 }
218 foreach($this->editMode['sOARecord'] as $name => $value){
219 if(isset($_POST[$name])){
220 $this->editMode['sOARecord'][$name] = $_POST[$name];
221 }
222 }
224 }
227 /* Check supplied data */
228 function check()
229 {
230 $message= array();
232 return ($message);
233 }
236 /* Save to LDAP */
237 function save()
238 {
239 plugin::save();
241 /* Optionally execute a command after we're done */
242 #$this->handle_post_events($mode);
243 }
245 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>