diff --git a/plugins/admin/systems/class_servDNSeditZoneEntries.inc b/plugins/admin/systems/class_servDNSeditZoneEntries.inc
index fa41684f87f1d392356002951ae6b45224c7cbc5..e1d836c0c85b4bb9c3653caa8462767a4bdcb482 100644 (file)
class servDNSeditZoneEntries extends plugin
{
- /* CLI vars */
- var $cli_summary= "Manage server basic objects";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
/* attribute list for save action */
var $ignore_account = TRUE;
- var $attributes = array();
+ var $attributes = array("cn");
var $objectclasses = array("whatever");
var $Devices = array();
var $RecordTypes = array(); // Possible record type.
var $disableDialog = false; // Dialog will be disabled, if this zone is new
+ var $cn;
function servDNSeditZoneEntries ($config,$dn, $zoneObject)
{
/* Initialise class
*/
$this->RecordTypes = getDnsRecordTypes();
- $this->dn = "zoneName=".$zoneObject['InitialzoneName'].",".$dn;
+
+ /* Remove nSRecord from listed types */
+ if(isset($this->RecordTypes['nSRecord'])){
+ unset($this->RecordTypes['nSRecord']);
+ }
+ /* Remove nSRecord from listed types */
+ if(isset($this->RecordTypes['pTRRecord'])){
+ unset($this->RecordTypes['pTRRecord']);
+ }
+
+ $this->dn = "zoneName=".getNameFromMix($zoneObject['InitialzoneName']).",".$dn;
$this->zoneName = $zoneObject['InitialzoneName'];
$this->reverseName = $zoneObject['InitialReverseZone'];
$this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0];
}
- if(!count($this->Devices)){
- $this->disableDialog = true;
+ $ldap->cat($this->dn,array("objectClass"));
+
+ $this->disableDialog = true;
+ if(count($this->Devices)|| $ldap->count()){
+ $this->disableDialog = false;
}
}
{
plugin::execute();
+ /* Fill templating stuff */
+ $smarty= get_smarty();
+ $display= "";
+
+ $table = "";
+ foreach($this->Devices as $key => $dev){
+ $table .= $this->generateRecordConfigurationRow($key);
+ }
+
+ $smarty->assign("disableDialog",$this->disableDialog);
+ $smarty->assign("table",$table);;
+ $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
+ return($display);
+ }
+
+ function save_object()
+ {
/* Check posts for operations ...
*/
$once = true;
+ $ptr_updates = array();
foreach($_POST as $name => $value){
/* Add a new Record in given object
/* Add new host entry
*/
- if((preg_match("/^UserRecord_/",$name)) && ($once)){
+ if((preg_match("/^UserRecord_?/",$name)) && ($once)){
$once = false;
$entry = getDNSHostEntries($this->config,"",true);
$entry['exists'] = true;
$entry['zoneName'] = $this->zoneName;
$entry['RECORDS'][] = array("type" => "aRecord" , "value"=>"");
- $this->Devices['New Entry'] = $entry;
+ $this->Devices[_("New entry")] = $entry;
}
if(count($tmp2) != 2) continue;
if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
unset($this->Devices[$Name]['RECORDS'][$RecordID]);
}
- }
-
- }
- /* Fill templating stuff */
- $smarty= get_smarty();
- $display= "";
-
- $table = "";
- foreach($this->Devices as $key => $dev){
- $table .= $this->generateRecordConfigurationRow($key);
+ /* Check if there is at least one visible record. Else remove complete entry */
+ $visible = false;
+ foreach($this->Devices[$Name]['RECORDS'] as $rec){
+ if(in_array($rec['type'],$this->RecordTypes)){
+ $visible = true;
+ break;
+ }
+ }
+ if(!$visible && isset($this->Devices[$Name]['RECORDS'])){
+ $this->Devices[$Name]['RECORDS'] = array();
+ }
+ }
}
- $smarty->assign("disableDialog",$this->disableDialog);
- $smarty->assign("table",$table);;
- $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
- return($display);
- }
-
-
- function save_object()
- {
/* Possible attributes posted
*/
foreach($_POST as $name => $value){
*/
if(preg_match("/ValueSelection_/",$name)){
if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
+
+ /* Update value */
+ $old = $this->Devices[$Name]['RECORDS'][$RecordID]['value'];
$this->Devices[$Name]['RECORDS'][$RecordID]['value'] = $value;
+
+ /* Handle pTRRecord */
+ if(!isset($ptr_updates[$Name]) && $this->Devices[$Name]['RECORDS'][$RecordID]['type'] == "aRecord"){
+
+ $found = false;
+ $ip = $value;
+ $match = preg_replace("/^[^\/]*+\//","",$this->reverseName);
+ $ip = preg_replace("/^".normalizePreg($match)."/","",$ip);
+ $ip = preg_replace("/^\./","",$ip);
+
+ foreach($this->Devices[$Name]['RECORDS'] as $key => $dev){
+ if($dev['type'] == "pTRRecord"){
+ $ptr_updates[$Name] = $Name;
+ $this->Devices[$Name]['RECORDS'][$key]['value'] = $ip;
+ $found = true;
+ break;
+ }
+ }
+ if(!$found){
+ $dev = array('type'=> 'pTRRecord', 'value' => $ip);
+ $this->Devices[$Name]['RECORDS'][] = $dev;
+ }
+ }
}
}
*/
if(preg_match("/RenameHost_/",$name)){
if((isset($this->Devices[$Name])) && ($Name != $value)){
- $this->Devices[$value] = $this->Devices[$Name];
- unset($this->Devices[$Name]);
+
+ if(isset($this->Devices[$value])){
+ print_red(sprintf(_("Can't rename '%s' to '%s' there is already an entry with the same name in our zone editing dialog."),$Name,$value));
+ }else{
+ $this->Devices[$value] = $this->Devices[$Name];
+ unset($this->Devices[$Name]);
+ }
}
}
}
*/
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$names = array();
+
foreach($this->Devices as $DevName => $device){
+ /* skip checking empty attributes */
+ if(count($this->Devices[$DevName]['RECORDS']) == 0){
+ return;
+ }
+
/* Checking entry name
*/
- if((!is_uid($DevName)) | (empty($DevName))){
+ if(!preg_match("/^[a-z0-9_\.-]+$/i", $DevName) || (empty($DevName))){
$message[] = sprintf(_("Entry name '%s' contains invalid characters."), $DevName);
}
/* Renaming check for existing devices
*/
if(isset($device['OrigCn']) && ($DevName != $device['OrigCn'] )){
- $ldap->search("(cn=".$DevName.")",array("cn"));
+ $ldap->cd($this->dn);
+ $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
if($ldap->count()){
- $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$DevName);
+ $message[] = sprintf(_("Can not rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$DevName);
+ }
+ }elseif(!isset($device['OrigCn'])){
+ $ldap->cd($this->dn);
+ $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
+ if($ldap->count()){
+ $message[] = sprintf(_("Can not create '%s',the destination name already exists."),$DevName);
}
}
/* Names should be written in lowercase
*/
+
+
if(strtolower($DevName) != $DevName){
$message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName);
}
if(!isset($tmp[$Rec['type']])){
$tmp[$Rec['type']] = "";
}else{
- $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$type);
+ $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$Rec['type']);
}
}
$todo = array();
+
/* Create todolist
*/
foreach($this->Devices as $name => $dev){
*/
foreach($tmp['add'] as $dn => $attrs){
$ldap->cd($dn);
- $ldap->cat($dn);
+ $ldap->cat($dn, array('dn'));
if(count($ldap->fetch())){
$ldap->cd($dn);
$ldap->modify ($attrs);
/* Set title
*/
- $str = "<h3>".sprintf(_("Settings for '%s'"),$objKey)." : </h3>";
+ $str= "<br>";
$hostNameOnce = true;
$str.= "<table cellspacing='0' cellpadding='0'>";
foreach($obj['RECORDS'] as $id => $record){
+ /* Skip not selectable entries */
+ if(!isset($this->RecordTypes [$record['type']])) {
+ continue;
+ }
+
/* Create unique post name
*/
$name = base64_encode($objKey)."|".$id;
- $str .= "<tr><td style='width:80px;'>\n";
+ $str .= "<tr><td style='width:170px;'>\n";
/* Only first host entry name should be editable
*/
if($hostNameOnce){
$hostNameOnce = false;
$str .="<input type='text' name='RenameHost_".$name."' value='".$objectName."'>\n";
- }else{
- $str .=$objectName;
- }
+ }
/* Create rest. Selectbox, icons ...
*/
$str .="
</td>
- <td style='width:80px;'>
+ <td style='width:90px;'>
".$this->createRecordTypeSelection($record['type'],$name)."
</td>
<td>
<input type='text' value='".$record['value']."' name='ValueSelection_".$name."' style='width:250px;'>
</td>
- <td style='width:50px;text-align:right;'>
- <input type='image' name='AddRecord_".$name."' src='images/crossref.png' alt='"._("Add")."' title='"._("Add")."'>
+ <td style='width:75px;text-align:right;'>
+ <input type='image' name='AddRecord_".$name."' src='images/list_new.png' alt='"._("Add")."' title='"._("Add")."'>
<input type='image' name='RemoveRecord_".$name."' src='images/edittrash.png' alt='"._("Remove")."' title='"._("Remove")."'>
- </td>
+ ";
+
+# if($record['type'] == "aRecord"){
+# $str .="<input type='image' name='AddPtr_".$name."' src='images/network.png'
+# alt='"._("Add PTR")."' title='"._("Add PTR record")."'>";
+# }else{
+# $str .= "<img src='images/empty.png' alt=''>";
+# }
+
+ $str.=
+ "</td>
</tr>";
}
$str .="</table>";