/usr/share/gosa/plugins/admin/systems/services/dns/class_servDNS.inc is in gosa-plugin-dns 2.7.4+reloaded2-1+deb8u2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | <?php
class servdns extends goService
{
/* attribute list for save action */
var $ignore_account = FALSE;
var $attributes = array();
var $objectclasses = array("whatever");
var $RecordTypes = array();
var $Zones = array();
var $orig_dn = "";
var $initially_was_account;
/* ServerService tab vars */
var $conflicts = array("servdns");
var $DisplayName = "";
var $StatusFlag = "";
var $view_logged = FALSE;
var $dns_server_list = array("ENTRIES"=> array(),"FOR_LIST"=> array());
var $take_over_id = -1;
function servdns (&$config, $dn= NULL, $parent= NULL)
{
plugin::plugin ($config, $dn, $parent);
$this->DisplayName = _("DNS service");
$this->orig_dn = $dn;
/* Get record types for zones
*/
$this->RecordTypes = DNS::getDnsRecordTypes(true);
/* Get all zone Informations
*/
$this->Zones = DNS::getDNSZoneEntries($config,$dn);
/* If there is at least one entry in this -> types, we have DNS enabled
*/
if(count($this->Zones) == 0){
$this->is_account = false;
$this->dns_server_list = $this->get_list_of_dns_servers();
}else{
$this->is_account = true;
}
$this->initially_was_account = $this->is_account;
// Prepare lists
$this->zoneList = new sortableListing();
$this->zoneList->setDeleteable(true);
$this->zoneList->setEditable(true);
$this->zoneList->setWidth("100%");
$this->zoneList->setHeight("300px");
$this->zoneList->setHeader(array(_("Zone"),_("Reverse zone"),_("TTL"),_("Class")));
$this->zoneList->setColspecs(array('*','*','*','*','40px'));
$this->zoneList->setDefaultSortColumn(0);
}
function get_list_of_dns_servers()
{
$ret = array("ENTRIES"=> array(),"FOR_LIST"=> array());
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(&(objectClass=dNSZone)(zoneName=*))",array("dn","zoneName"));
$dns = array();
while($attrs = $ldap->fetch()){
/* Skip own config */
if($this->dn != "new" && preg_match("/".preg_quote($this->dn, '/')."$/",$attrs['dn'])){
continue;
}
$dn = preg_replace("/^zoneName=[^,]+,/","",$attrs['dn']);
if(preg_match("/^cn=/",$dn) && !in_array_strict($dn,$dns)){
$dns[] = $dn;
}
}
$i = 0;
foreach($dns as $dn){
$ldap->cat($dn,array('*'));
if($ldap->count()){
$i ++;
$attrs = $ldap->fetch();
$ret['ENTRIES'][$i] = $attrs;
$ret['FOR_LIST'][$i] = $attrs['cn'][0];
}
}
return($ret);
}
function get_dns_info_string($id)
{
$ret="";
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->dns_server_list['ENTRIES'][$id]['dn']);
$ldap->search("(|(zoneName=*)(relativeDomainName=*))",array("dn"));
while($attrs = $ldap->fetch()){
$ret .= $attrs['dn']."\n";
}
return($ret);
}
function execute()
{
/* Call parent execute
*/
plugin::execute();
if($this->is_account && !$this->view_logged){
$this->view_logged = TRUE;
new log("view","server/".get_class($this),$this->dn);
}
/* Fill templating stuff
*/
$smarty= get_smarty();
$smarty->assign("dns_take_over",FALSE);
$smarty->assign("is_createable",$this->acl_is_createable());
$display= "";
$this->initially_was_account= $this->is_account;
/*****************/
/* Handle Take Over Actions
/*****************/
/* Give smarty the required informations */
$smarty->assign("dns_server_list", $this->dns_server_list['FOR_LIST']);
$smarty->assign("dns_server_list_cnt", count($this->dns_server_list['FOR_LIST']));
/* Take over requested, save id */
if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){
$id = get_post('take_over_src');
if(isset($this->dns_server_list['ENTRIES'][$id])){
$this->take_over_id = $id;
}
}
/* Abort take over action */
if(isset($_POST['cancel_take_over'])){
$this->dialog =false;
$this->take_over_id = -1;
$this->dns_server_list = $this->get_list_of_dns_servers();
}
/* Display informartion about take over that will be started when saving this server
* and hide default dns output
*/
if($this->take_over_id != -1){
$this->dialog = FALSE;
$id = $this->take_over_id;
$info = $this->get_dns_info_string($id);
$smarty->assign("dns_take_over",TRUE);
$smarty->assign("info",$info);
$warning = sprintf(_("You are going to migrate the DNS setup from server '%s'."),$this->dns_server_list['ENTRIES'][$id]['cn'][0]);
$warning2 = _("The migration will be started when you save this system. To cancel this action, use the cancel button below.");
$smarty->assign("warning",$warning);
$smarty->assign("warning2",$warning2);
return($smarty->fetch(get_template_path('servdns.tpl', TRUE, dirname(__FILE__))));
}
/* Do we need to flip is_account state?
*/
if (isset($_POST['modify_state'])){
$this->is_account= !$this->is_account;
}
/* Edited or Added zone
*/
if(isset($_POST['SaveZoneChanges'])){
$this->dialog->save_object();
/* Check for errors
*/
if(count($this->dialog->check())){
foreach($this->dialog->check() as $msgs){
msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
}
}else{
/* add new/edited zone
*/
$ret = $this->dialog->save();
if(!$this->dialog->isNew){
unset($this->Zones[$this->dialog->OldZoneName]);
}
$this->Zones[$ret['zoneName']] = $ret;
$this->dialog = FALSE;
}
}
/* Cancel zone edit / new
*/
if(isset($_POST['CancelZoneChanges'])){
$this->dialog = FALSE;
}
/* Add empty new zone
*/
if(isset($_POST['AddZone'])){
$this->dialog = new servdnseditZone($this->config,$this->dn);
if($this->is_new){
$this->dialog->acl_base = $this->acl_base;
$this->dialog->acl_category = $this->acl_category;
}
}
/* Check for edit zone request
*/
$this->zoneList->save_object();
$action = $this->zoneList->getAction();
if($action['action'] == 'delete'){
$id = $this->zoneList->getKey($action['targets'][0]);
$this->RemoveZone($id);
}
if($action['action'] == 'edit'){
$id = $this->zoneList->getKey($action['targets'][0]);
$this->dialog= new servdnseditZone($this->config,$this->dn,$this->Zones[$id]);
$this->dialog->acl_base = $this->acl_base;
$this->dialog->acl_category = $this->acl_category;
}
/* Show dialog
*/
if(is_object($this->dialog)){
$this->dialog->save_object();
$this->dialog->parent = $this;
return($this->dialog->execute());
}
/* Create Listbox with existing Zones
*/
$this->zoneList->setAcl($this->getacl(""));
$lData = array();
foreach($this->Zones as $zone => $values ){
$lData[$zone] = array('data' => array($zone,$values['ReverseZone'],$values['sOAttl'],$values['dNSClass']));
}
$this->zoneList->setListData($this->Zones,$lData);
$this->zoneList->update();
/* Display tempalte
*/
$smarty->assign("ZoneList",$this->zoneList->render());
$display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE, dirname(__FILE__)));
return($display);
}
/* Delete specified zone
*/
function RemoveZone($id,$force = FALSE)
{
$zones = $this->getUsedZoneNames();
if(isset($this->Zones[$id]['InitialReverseZone'])){
$rev = DNS::FlipIp($this->Zones[$id]['InitialReverseZone']);
}else{
$rev = DNS::FlipIp($this->Zones[$id]['ReverseZone']);
}
$zonename = "";
if(isset($this->Zones[$id]['InitialzoneName'])){
$zonename= $this->Zones[$id]['InitialzoneName'];
}
$used = array();
/* Add Records which use this zoneName
*/
if(isset($zones[$zonename])){
$used = array_merge($used,$zones[$zonename]);
}
/* Add Records which uses this reverse zone
*/
if(isset($zones[$rev.".in-addr.arpa."])){
$used = array_merge($used,$zones[$rev.".in-addr.arpa."]);
}
/* There are still entries using this configuration
* Abort deletion
*/
if(count($used) && !$force){
$i = 2;
$str ="";
foreach($used as $dn){
if($i > 0 && !preg_match("/,relativeDomainName=/",$dn)){
$i --;
$name = preg_replace("/^[^=]+=([^,]*),.*$/","\\1",$dn);
$zone = preg_replace("/^.*zoneName=([^,]*),.*$/","\\1",$dn);
$str.= $name.".".$zone." ";
}
}
/* Only show 2 dns in the error message
*/
if(count($used)> 2) {
$str .=" ... ";
}
msg_dialog::display(_("Error"), sprintf(_("Cannot delete the selected zone. It is still in use by '%s'"), trim($str)), ERROR_DIALOG);
return(false);
}else{
unset($this->Zones[$id]);
return(true);
}
}
/* This funtion returns all used Zonenames
*/
function getUsedZoneNames()
{
$ret = array();
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(&(objectClass=dNSZone)(!(relativeDomainName=@))(zoneName=*))",array("zoneName","relativeDomainName"));
while($attr = $ldap->fetch()){
$ret[$attr['zoneName'][0]][] = $attr['dn'];
}
return($ret);
}
/* Remove dns service
*/
function remove_from_parent()
{
if($this->initially_was_account){
$bool = true;
$this->is_account = FALSE;
foreach($this->Zones as $key => $zone){
$bool= $bool & $this->RemoveZone($key,TRUE);
}
if($bool){
$this->save();
}
return($bool);
}
}
/* Save to LDAP */
function save()
{
/* Take over handling
* - Create list of zones managed by source server
* - Copy ldap entries to destination server
* - Remove old zone entries from source
*/
if($this->take_over_id != -1){
$del = array();
$id = $this->take_over_id;
$src = $this->dns_server_list['ENTRIES'][$id]['dn'];
$ldap = $this->config->get_ldap_link();
$ldap->ls("(objectClass=dnsZone)",$src,array('cn'));
while($attrs = $ldap->fetch()){
$src_zone = $attrs['dn'];
$dst_zone = preg_replace("/".preg_quote($src, '/')."$/",$this->dn,$src_zone);
$res = plugin::recursive_move($src_zone, $dst_zone);
if($res){
$del [] = $src_zone;
}
}
foreach($del as $src_zone){
$ldap->rmdir_recursive($src_zone);
}
return;
}
/* Save zone editor changes now */
foreach($this->Zones as $name => $zone){
if(isset($zone['zoneEditor'] ) && $zone['zoneEditor'] != NULL && is_object($zone['zoneEditor'])){
$zone['zoneEditor']->save();
unset($this->Zones[$name]['zoneEditor']);;
}
}
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
/* Get differences
*/
$old_dn = $this->orig_dn;
if($old_dn == "new"){
$old_dn = $this->dn;
}
/* Update dns to current object dn */
$tmp = DNS::getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
$tmp2 = array();
foreach($tmp as $key1 => $data1){
$tmp2[$key1] = array();
foreach($data1 as $key2 => $data2){
$tmp2[$key1][preg_replace("/".preg_quote($old_dn, '/')."$/",$this->dn,$key2)] = $data2;
}
}
$tmp = $tmp2;
/* Updated zone entries if reverser or forward name has changed
* Must be done before moving entries, else the given dn is invalid
*/
if(isset($tmp['zoneUpdates'])){
foreach($tmp['zoneUpdates'] as $dn => $attrs){
$ldap->cd($dn);
$ldap->modify($attrs);
new log("modify","unknown/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
}
}
}
/* Delete dns
*/
foreach($tmp['del'] as $dn => $del){
$for = $del['InitialzoneName'];
$rev = DNS::FlipIp($del['InitialReverseZone']).".in-addr.arpa.";
$ldap->cd($dn);
$ldap->rmdir_recursive($dn);
new log("remove","unknown/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
}
/* Handle Post events */
if(preg_match("/^zoneName=/",$dn)){
# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $for));
# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $rev));
}
}
/* move follwoing entries
*/
foreach($tmp['move'] as $src => $dst){
$this->recursive_move($src,$dst);
}
/* Add || Update new DNS entries
*/
foreach($tmp['add'] as $dn => $attrs){
$ldap->cd($dn);
$ldap->cat($dn, array('dn'));
if($ldap->fetch()){
$ldap->cd($dn);
$ldap->modify ($attrs);
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
}
/* Handle Post events */
if(preg_match("/^zoneName=/",$dn)){
# $this->handle_post_events("modify",array("dn" => $dn,"zoneName" => $attrs['zoneName']));
}
}else{
$ldap->cd($dn);
$ldap->add($attrs);
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_ADD, get_class()));
}
/* Handle Post events */
if(preg_match("/^zoneName=/",$dn)){
# $this->handle_post_events("add",array("dn" => $dn,"zoneName" => $attrs['zoneName']));
}
}
}
$this->handle_post_events("modify");
}
/* Directly save new status flag */
function setStatus($value)
{
if($value == "none") return;
if(!$this->initially_was_account) return;
if(empty($this->StatusFlag)) return;
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->dn);
$ldap->cat($this->dn,array("objectClass"));
if($ldap->count()){
$tmp = $ldap->fetch();
for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
$attrs['objectClass'][] = $tmp['objectClass'][$i];
}
$flag = $this->StatusFlag;
$attrs[$flag] = $value;
$this->$flag = $value;
$ldap->modify($attrs);
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
}
$this->action_hook();
}
}
function getListEntry()
{
$fields = goService::getListEntry();
$fields['Message'] = _("DNS service");
#$fields['AllowEdit'] = true;
return($fields);
}
/* Get updates for status flag */
function updateStatusState()
{
if(empty($this->StatusFlag)) return;
$attrs = array();
$flag = $this->StatusFlag;
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->cn);
$ldap->cat($this->dn,array($flag));
if($ldap->count()){
$attrs = $ldap->fetch();
}
if(isset($attrs[$flag][0])){
$this->$flag = $attrs[$flag][0];
}
}
/* Return plugin informations for acl handling */
static function plInfo()
{
return (array(
"plShortName" => _("DNS service"),
"plDescription" => _("DNS service")." ("._("Services").")",
"plSelfModify" => FALSE,
"plDepends" => array(),
"plPriority" => 83,
"plSection" => array("administration"),
"plCategory" => array("server"),
"plProvidedAcls"=> array(
"start" => _("Start service"), // Remove this to hide the start button at all.
"stop" => _("Stop service"), // Remove this to hide the stop button at all.
"restart" => _("Restart service"),// Remove this to hide the restart button at all.
"zoneName" =>_("Zone name"),
"ReverseZone" =>_("Reverse zone"),
"NetworkClass" =>_("Network class"),
"zoneEditor" =>_("Zone entry editor"),
"sOAprimary" =>_("Primary DNS server"),
"sOAmail" =>_("Mail address"),
"sOAserial" =>_("Serial"),
"sOArefresh" =>_("Refresh"),
"sOAretry" =>_("Retry"),
"sOAexpire" =>_("Expire"),
"sOAttl" =>_("TTL"),
"mXRecord" =>_("MX records"),
"zoneRecords" =>_("Zone records"))
));
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
|