"Eins ist toll", "zwei" => "Zwei ist noch besser");
/* attribute list for save action */
var $ignore_account= TRUE;
var $attributes= array("zoneName");
var $objectclasses= array("whatever");
var $Devices = array();
var $InitDevices = array();
var $FreeHosts = array();
var $InitFreeHosts= array();
var $zoneName = ""; // ZoneName of currently edited Zone
var $reverseName = ""; // ReverseZone of the currently edited Zone
var $RecordTypes= array(); // Possible record type. They will be set in contrucktor
// and some types will be added later (cName/Ptr)
function servDNSeditZoneEntries ($config, $dn= NULL,$zoneName,$reverseName,$RTypes)
{
plugin::plugin ($config, $dn);
/* Initialise class
*/
$this->zoneName = $zoneName;
$this->reverseName = $reverseName;
$this->RecordTypes = $RTypes;
/* Add records types which are not allowed in zones
*/
$this->RecordTypes['cNAMERecord'] = "relativeDomainName";
$this->RecordTypes['pTRRecord'] = "relativeDomainName";
$this->RecordTypes['tXTRecord'] = "tXTRecord";
/* Get ldap connection
*/
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
/* Get all objects using this zone
* Workstations / Terminals
*/
$res = $ldap->search("(&(objectClass=dNSZone)(|(zoneName=".$zoneName.")(zoneName=".$reverseName.".in-addr.arpa))(!(relativeDomainName=@)))");
while($attrs = $ldap->fetch($res)){
if(preg_match("/zoneName=/",$attrs['dn'])) continue;
foreach($this->RecordTypes as $atr => $val){
if((isset($attrs[$atr])) && (is_array($attrs[$atr]))){
unset($attrs[$val]['count']);
$dn = preg_replace("/^.*,cn/","cn",$attrs['dn']);
$this->Devices[$dn]['RECORDS'][$atr] = $attrs[$val];
$this->Devices[$dn]['Type'] = "Exists";
}
}
}
/* Add additional informations
to all catched objects ( ObjectInformations)
*/
foreach($this->Devices as $dn => $Recs){
$attrs = $ldap->fetch($ldap->cat($dn,array("objectClass","cn")));
$this->Devices[$dn]['OBJECT'] = $attrs;
$this->Devices[$dn]['OrigCn'] = $attrs['cn'][0];
}
/* Add Free Hand entries
* Free hand entries are entries which are not directly assigned
* to an existing network object like a WS or a Terminal.
* They will be found in a subtree within this zone.
* For example :
* The object name is FreeHand1,
* zoneName=test.de,cn=server ...
* // ObjectContainer
* relativeDomainName=FreeHand1,zoneName=....
* // Dns entry
* relativeDomainName=FreeHand1, relativeDomainName=FreeHand1,zoneName=....
* // cName entry ....
* relativeDomainName=terminal12, relativeDomainName=FreeHand1,zone...
*/
$ldap->cd ("zoneName=".$this->zoneName.",".$this->dn);
$ldap->ls ("(&(objectClass=dNSZone)(!(relativeDomainName=@)))","zoneName=".$this->zoneName.",".$this->dn,array("*"));
$GetSubInformations = array();
while($attrs = $ldap->fetch()){
unset($attrs[$val]['count']);
$dn = $attrs['dn'];
/* Split dn into relativeDomainNames
*/
$tmp = split("relativeDomainName=",trim(preg_replace("/,zoneName=.*$/","\\1",$dn)));
$tmp2 = array();
foreach($tmp as $t){
if(empty($t)) continue;
$tmp2[] = preg_replace("/,$/","",$t);
}
/* Set object Name
*/
$cn = $tmp2[0];
$dn = "relativeDomainName=".$cn.",zoneName=".$this->zoneName.",".$this->dn;
/* Create entry
*/
$this->Devices[$dn]['OBJECT'] = $attrs;
$this->Devices[$dn]['OBJECT']['cn'][0] = $cn;//attrs['relativeDomainName'];
$this->Devices[$dn]['OBJECT']['OrigCn'] = $cn;//attrs['relativeDomainName'][0];
$this->Devices[$dn]['Type'] = "Free";
$GetSubInformations [] = $dn;
}
/* Get sub informations
CName or pTR records are stored in a sub entry.
// The base entry with aRecords/tXTrecords/....
relativeDomainName=Keks, relativeDomainName=Keks, zoneName=....
// And the sub entries like this one
relativeDomainName=10.2.64.in-addr.arpa, relativeDomainName=Keks, zoneName =...
( They can't be stored in a single entry, so i decided to store them this way ).
*/
foreach($GetSubInformations as $dn){
$ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$dn,array("*"));
while($attrs= $ldap->fetch()){
foreach($this->RecordTypes as $atr => $val){
if((isset($attrs[$atr])) && (is_array($attrs[$atr]))){
unset($attrs[$val]['count']);
$this->Devices[$dn]['RECORDS'][$atr] = $attrs[$val];
}
}
}
}
$this->Devices;
$this->InitDevices = $this->Devices;
}
function execute()
{
plugin::execute();
/* Check posts for operations ...
*/
$once = true;
foreach($_POST as $name => $value){
/* Add a new Record in given object
*/
if((preg_match("/^AddRecord_/",$name)) && ($once)){
$once = false;
$tmp = preg_replace("/^AddRecord_/","",$name);
$tmp = preg_replace("/_.*$/","",$tmp);
$tmp2 = split("\|",$tmp);
$dn = base64_decode($tmp2[0]);
$record = $tmp2[1];
$numrec = $tmp2[2];
$this->Devices[$dn]['RECORDS'][$record][] = "";
}
/* Remove record from given dn
*/
if((preg_match("/^RemoveRecord_/",$name)) && ($once)){
$once = false;
$tmp = preg_replace("/^RemoveRecord_/","",$name);
$tmp = preg_replace("/_.*$/","",$tmp);
$tmp2 = split("\|",$tmp);
$dn = base64_decode($tmp2[0]);
$record = $tmp2[1];
$numrec = $tmp2[2];
unset($this->Devices[$dn]['RECORDS'][$record][$numrec]);
if(count($this->Devices[$dn]['RECORDS'][$record]) == 0){
unset($this->Devices[$dn]['RECORDS'][$record]);
if(count($this->Devices[$dn]['RECORDS']) ==0){
unset($this->Devices[$dn]);
}
}
}
/* Don't know how i should implement this ...
*/
if((preg_match("/^UserRecord_/",$name)) && ($once)){
$once = false;
$tmp['RECORDS']['aRecord'][0] = 'empty';
$tmp['Type'] = 'Free';
$tmp['OBJECT']['cn'][0] = 'Free';
$this->Devices[] = $tmp;
}
}
/* Fill templating stuff */
$smarty= get_smarty();
$display= "";
$table = "";
foreach($this->Devices as $key => $dev){
$table .= $this->generateRecordConfigurationRow($key);
}
$smarty->assign("table",$table);;
$display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
return($display);
}
/* Create html table out of given entry
*/
function generateRecordConfigurationRow($obj_dn){
/* get some basic inforamtions
*/
$obj = $this->Devices[$obj_dn];
$objectName = $obj['OBJECT']['cn'][0];
/* Set title
*/
if($obj['Type'] == "Free"){
$str = "
".sprintf(_("Settings for free host entry # %s"),($obj_dn +1))." :
";
}else{
$str = "
".sprintf(_("Settings for '%s'"),$obj_dn)." :
";
}
$hostNameOnce = true;
/* Walk through all defined records
*/
$str.= "
";
foreach($obj['RECORDS'] as $id => $types){
/* Create table
*/
foreach($types as $key => $type){
/* Create unique post name
*/
$name = base64_encode($obj_dn)."|".$id."|".$key;
$str .= "
";
return($str);
}
/* Create selectbox with all available option types
*/
function createRecordTypeSelection($id,$refID,$isFreeRecord =false){
if(!$isFreeRecord){
$str = "\n