From: cajus Date: Tue, 31 Jul 2007 14:38:10 +0000 (+0000) Subject: Temporary checking. This isn't meant to work at all X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7538a5687c78a6b6adabec8e688bb51772c30e6d;p=gosa.git Temporary checking. This isn't meant to work at all git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6949 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc new file mode 100644 index 000000000..cdc529251 --- /dev/null +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -0,0 +1,244 @@ +$attr= $attrs[$attr][0]; + } + } + + /* Load options */ + if (isset($attrs['dhcpOption'])){ + for($i= 0; $i<$attrs['dhcpOption']['count']; $i++){ + $tmp= $attrs['dhcpOption'][$i]; + $idx= preg_replace('/\s.+$/', '', $tmp); + $value= preg_replace('/^[^\s]+\s/', '', $tmp); + $this->options[$idx]= $value; + } + } + + /* Load statements */ + if (isset($attrs['dhcpStatements'])){ + for($i= 0; $i<$attrs['dhcpStatements']['count']; $i++){ + $tmp= $attrs['dhcpStatements'][$i]; + $idx= preg_replace('/\s.+$/', '', $tmp); + $value= preg_replace('/^[^\s]+\s/', '', $tmp); + $this->statements[$idx]= $value; + } + } + + } + } + + function execute() + { + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("dhcpHWAddress", preg_replace('/^[^ ]+ /', '', $this->dhcpHWAddress)); + + /* Create fixed address */ + if (isset($this->statements['fixed-address'])){ + $smarty->assign("fixedaddr", $this->statements['fixed-address']); + } else { + $smarty->assign("fixedaddr", ""); + } + + /* Prepare hw type selector */ + $hwtype= preg_replace('/\s.*$/', '', $this->dhcpHWAddress); + $smarty->assign("hwtype", $hwtype); + $smarty->assign("hwtypes", array("ethernet" => _("Ethernet"), + "fddi" => _("FDDI"), + "token-ring" => _("Token Ring"))); + + /* Prepare mac address */ + if ($this->dhcpHWAddress != ""){ + list($hw0, $hw1, $hw2, $hw3, $hw4, $hw5)= + split (":", preg_replace('/^[^\s]+\s/', '', $this->dhcpHWAddress)); + for ($i= 0; $i<6; $i++){ + $name= "hw$i"; + $smarty->assign("$name", $$name); + } + } + + /* Show main page */ + return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE))); + } + + +#------------------- + + function remove_from_parent() + { + /* Just remove the dn from the ldap, then we're done. Host + entries do not have any entries below themselfes. */ + $ldap= $this->config->get_ldap_link(); + $ldap->rmDir($this->orig_dn); + show_ldap_error($ldap->get_error()); + + /* Optionally execute a command after we're done */ + $this->postremove(); + } + + + /* Save data to object */ + function save_object() + { + plugin::save_object(); + + /* Save remaining attributes */ + if (isset($_POST['hwtype'])){ + + /* Assemble hwAddress */ + $addr= $_POST['hwtype']." "; + for ($i= 0; $i<6; $i++){ + $addr.= $_POST["hw$i"].":"; + } + $this->dhcpHWAddress= preg_replace('/:$/', '', $addr); + + /* Save fixed address */ + if ($_POST['fixedaddr'] != ""){ + $this->statements['fixed-address']= $_POST['fixedaddr']; + } else { + unset ($this->statements['fixed-address']); + } + } + } + + + /* Check values */ + function check() + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + + /* cn already used? */ + if ($this->dn != "new"){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=dhcpHost)(cn=".$this->cn."))"); + if ($ldap->count() >= 1){ + while ($attrs= $ldap->fetch()){ + if ($ldap->getDN() != $this->dn){ + $message[]= _("The name for this host section is already used!"); + break; + } + + } + } + $ldap->fetch(); + } + + /* Check syntax of MAC address */ + $check= preg_replace('/^[^\s]*\s/', '', $this->dhcpHWAddress); + if (!preg_match('/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/', $check)){ + $message[]= _("The hardware address specified by you is not valid!"); + } + + return $message; + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + /* Generate new dn */ + if ($this->parent->parent != NULL){ + $this->dn= "cn=".$this->cn.",".$this->parent->parent; + } else { + $tmp= preg_replace('/^cn=[^,]+/', '', $this->dn); + $this->dn= "cn=".$this->cn.$tmp; + } + + /* Get ldap mode */ + if ($this->orig_dn != $this->dn){ + $mode= "add"; + } else { + $mode= "modify"; + } + + /* Assemble new entry - options */ + if (isset ($this->options) && count ($this->options)){ + $this->attrs['dhcpOption']= array(); + foreach ($this->options as $key => $val){ + $this->attrs['dhcpOption'][]= "$key $val"; + } + } else { + if ($mode == "modify"){ + $this->attrs['dhcpOption']= array(); + } + } + + /* Assemble new entry - statements */ + if (isset ($this->statements) && count ($this->statements)){ + $this->attrs['dhcpStatements']= array(); + foreach ($this->statements as $key => $val){ + $this->attrs['dhcpStatements'][]= "$key $val"; + } + } else { + if ($mode == "modify"){ + $this->attrs['dhcpStatements']= array(); + } + } + + /* Do LDAP action */ + $ldap= $this->config->get_ldap_link(); + if ($mode == "add"){ + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + } + $ldap->cd($this->dn); + $ldap->$mode($this->attrs); + show_ldap_error($ldap->get_error()); + + /* Name changed? Remove orig? */ + if ($this->orig_dn != $this->dn && $this->orig_dn != "new"){ + echo "Remove old
"; + $ldap->rmdir($this->orig_dn); + show_ldap_error($ldap->get_error()); + } + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpNewSectionDialog.inc b/plugins/admin/systems/class_dhcpNewSectionDialog.inc new file mode 100644 index 000000000..1b675e5d8 --- /dev/null +++ b/plugins/admin/systems/class_dhcpNewSectionDialog.inc @@ -0,0 +1,83 @@ + array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost", "dhcpClass", "dhcpLeases"), + "dhcpClass" => array("dhcpSubClass"), + "dhcpSubClass" => array(), + "dhcpLeases" => array(), + "dhcpHost" => array(), + "dhcpGroup" => array("dhcpHost"), + "dhcpPool" => array("dhcpLeases"), + "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost", "dhcpClass", "dhcpLeases"), + "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool")); + + + + function dhcpNewSectionDialog($type) + { + $this->types= array( "dhcpLog" => _("Logging"), + "dhcpService" => _("Global options"), + "dhcpClass" => _("Class"), + "dhcpSubClass" => _("Subclass"), + "dhcpLeases" => _("Lease"), + "dhcpHost" => _("Host"), + "dhcpGroup" => _("Group"), + "dhcpPool" => _("Pool"), + "dhcpSubnet" => _("Subnet"), + "dhcpFailOverPeer" => _("Failover peer"), + "dhcpSharedNetwork" => _("Shared network")); + + $this->classtype= $type; + } + + function execute() + { + /* Fill templating stuff */ + $smarty = get_smarty(); + $display= ""; + + $sections= dhcpNewSectionDialog::$sectionMap[$this->classtype]; + $t_sections= array(); + foreach ($sections as $section){ + $t_sections[$section]= $this->types[$section]; + } + $smarty->assign("sections", $t_sections); + $smarty->assign("dhcpSectionACL", chkacl($this->acl,"DHCP")); + $display.= $smarty->fetch(get_template_path('dhcpNewSection.tpl', TRUE)); + return($display); + } + + /* Get posts and set class name + */ + function save_object() + { + } + + /* Check given class name */ + function check() + { + /* Call common method to give check the hook */ + $message= ""; + + return ($message); + } + + + /* Return the class name */ + function save() + { + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index be93e60c1..e0bd6988e 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -5,22 +5,100 @@ class servdhcp extends plugin /* attribute list for save action */ var $ignore_account= TRUE; var $attributes= array(); - var $objectclasses= array("whatever"); + var $objectclasses= array(); + + /* Section storage */ + var $dhcpSections= array(); + var $dhcpObjectCache= array(); + var $current_object= ""; function servdhcp ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); + + /* Load information about available services */ + $this->reload(); } + function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; + /* Section Creation? */ + if (isset($_POST['create_section']) && isset($_POST['section'])){ + $section= $_POST['section']; + if (isset(dhcpNewSectionDialog::$sectionMap[$section])){ + $this->dialog= new $section(NULL); + } else { + $this->dialog= NULL; + } + } + + /* Cancel section creation? */ + if (isset($_POST['cancel_section'])){ + $this->dialog= NULL; + } + + /* Remove section? */ + if (isset($_POST['delete_dhcp_confirm'])){ + if (chkacl($this->acl, "delete") == ""){ + unset($this->dhcpSections[$this->current_object]); + unset($this->dhcpObjectCache[$this->current_object]); + $this->dhcpObjectCache[$this->current_object]= array(); + foreach ($this->dhcpSections as $key => $value){ + if (preg_match("/".$this->current_object."$/", $key)){ + unset($this->dhcpSections[$key]); + unset($this->dhcpObjectCache[$key]); + $this->dhcpObjectCache[$key]= array(); + } + } + } else { + print_red(_("You're not allowed to remove DHCP sections!")); + } + $this->dialog= NULL; + } + + /* Look for post entries */ + foreach($_POST as $name => $value){ + + /* Insert new section? */ + if (preg_match('/^insertDhcp_.*_x$/', $name)){ + $dn= base64_decode(preg_replace('/^insertDhcp_([^_]+)_x$/', '\1', $name)); + if (isset($this->dhcpObjectCache[$dn])){ + $this->dialog= new dhcpNewSectionDialog($this->objectType($dn)); + $this->current_object= $dn; + $this->dialog->acl= $this->acl; + } + } + + /* Edit section? */ + if (preg_match('/^editDhcp_.*_x$/', $name)){ + $dn= base64_decode(preg_replace('/^editDhcp_([^_]+)_x$/', '\1', $name)); + if (isset($this->dhcpObjectCache[$dn])){ + $section= $this->objectType($dn); + $this->dialog= new $section($this->dhcpObjectCache[$dn]); + } + } + + /* Remove section? */ + if (preg_match('/^delDhcp_.*_x$/', $name)){ + $dn= base64_decode(preg_replace('/^delDhcp_([^_]+)_x$/', '\1', $name)); + if (isset($this->dhcpObjectCache[$dn])){ + $this->current_object= $dn; + $this->dialog= 1; + $smarty->assign("warning", sprintf(_("You're about to delete the DHCP section '%s'."), $dn)); + return($smarty->fetch(get_template_path('remove_dhcp.tpl', TRUE))); + } + } + + } + /* Do we need to flip is_account state? */ if (isset($_POST['modify_state'])){ $this->is_account= !$this->is_account; @@ -36,6 +114,45 @@ class servdhcp extends plugin return ($display); } + + /* Show dialog + */ + if($this->dialog != NULL && !is_int($this->dialog)){ + $this->dialog->save_object(); + $this->dialog->parent = $this; + return($this->dialog->execute()); + } + + /* Create Listbox with existing Zones + */ + $DhcpList = new divSelectBox("dhcpSections"); + $DhcpList->SetHeight(300); + + /* Add entries to divlist + */ + $editImgIns = "". + "". + ""; + $editImg = "". + ""; + foreach($this->dhcpSections as $section => $values ){ + if (count(dhcpNewSectionDialog::$sectionMap[$this->objectType($section)])){ + $DhcpList->AddEntry(array( + array("string" => $values), + array("string" => str_replace("%s",base64_encode($section),$editImgIns), "attach" => "style='text-align:right;'") + )); + } else { + $DhcpList->AddEntry(array( + array("string" => $values), + array("string" => str_replace("%s",base64_encode($section),$editImg), "attach" => "style='text-align:right;'") + )); + } + } + + $smarty->assign("dhcpACL",chkacl($this->acl,"servdhcp")); + + /* Display tempalte */ + $smarty->assign("DhcpList",$DhcpList->DrawList()); $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE)); return($display); } @@ -72,7 +189,96 @@ class servdhcp extends plugin #$this->handle_post_events($mode); } + + function reload() + { + /* Init LDAP and load list */ + $ldap= $this->config->get_ldap_link(); + $ui= get_userinfo(); + $me= $this->dn; + + $list= get_list("(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))", $ui->subtreeACL, $this->config->current['BASE'], array("cn")); + $final= array(); + foreach ($list as $value){ + + /* Set header */ + $sortpart= split(",", $value['dn']); + $sortpart= array_reverse($sortpart); + $tmp= implode(",", $sortpart); + + $final[$value['dn']]= $tmp."!"._("Global options"); + + /* Read all sub entries to place here */ + $ldap->cd($value['dn']); + $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpLeases)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array()); + + while ($attrs= $ldap->fetch()){ + $this->dhcpObjectCache[$ldap->getDN()]= $attrs; + $tmp= preg_replace("/".$value['dn']."/", "", $ldap->getDN()); + $indent= substr_count($tmp, ","); + $spaces= ""; + for ($i= 0; $i<$indent; $i++){ + $spaces.= "    "; + } + $types= array( "dhcpLog" => _("Logging"), + "dhcpService" => _("Global options"), + "dhcpClass" => _("Class"), + "dhcpSubClass" => _("Subclass"), + "dhcpLeases" => _("Lease"), + "dhcpHost" => _("Host"), + "dhcpGroup" => _("Group"), + "dhcpPool" => _("Pool"), + "dhcpSubnet" => _("Subnet"), + "dhcpFailOverPeer" => _("Failover peer"), + "dhcpSharedNetwork" => _("Shared network")); + + foreach ($types as $key => $val){ + if (in_array("$key", $attrs['objectClass'])){ + $type= $val; + break; + } + } + + /* Prepare for sorting... */ + $sortpart= split(",", $ldap->getDN()); + $sortpart= array_reverse($sortpart); + $tmp= implode(",", $sortpart); + $final[$ldap->getDN()]= $tmp."!".$spaces.$type." '".$attrs['cn'][0]."'"; + } + } + + /* Sort it... */ + natsort($final); + $this->dhcpSections= array(); + foreach ($final as $key => $val){ + $this->dhcpSections[$key]= preg_replace('/^[^!]+!(.*)$/', '\\1', $val); + } + + } + + + function objectType($dn) + { + $type= ""; + $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost", + "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork"); + + foreach ($this->dhcpObjectCache[$dn]['objectClass'] as $oc){ + if (in_array($oc, $types)){ + $type= $oc; + break; + } + } + + /* That should not happen... */ + if ($type == ""){ + print_red(_("DHCP configuration set is unknown. Please contact your system administrator.")); + } + + return ($type); + } + } -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +//vim:tabstop=2:expandtab:softtab=2:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc index 36975637d..f12ad0f8b 100644 --- a/plugins/admin/systems/class_servDNS.inc +++ b/plugins/admin/systems/class_servDNS.inc @@ -150,7 +150,7 @@ class servdns extends plugin /* Create Listbox with existing Zones */ $ZoneList = new divSelectBox("dNSZones"); - $ZoneList -> SetHeight(254); + $ZoneList -> SetHeight(300); /* Add entries to divlist */ diff --git a/plugins/admin/systems/dhcpNewSection.tpl b/plugins/admin/systems/dhcpNewSection.tpl new file mode 100644 index 000000000..2f4f83b00 --- /dev/null +++ b/plugins/admin/systems/dhcpNewSection.tpl @@ -0,0 +1,25 @@ +
+ {t}Create new DHCP section{/t} +
+
+

+{t}Please choose one of the following DHCP section types.{/t} +

+
+{t}Section{/t}  + + +

+ +   + +

+ + + diff --git a/plugins/admin/systems/dhcphost.tpl b/plugins/admin/systems/dhcphost.tpl new file mode 100644 index 000000000..21511c0d4 --- /dev/null +++ b/plugins/admin/systems/dhcphost.tpl @@ -0,0 +1,60 @@ +{* GOsa dhcp host - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ + + + + + + + + +
{t}Name{/t}{$must} + +
{t}Fixed address{/t} + +
+
+ + + + + + + + + +
{t}Hardware type{/t} + +
{t}Hardware address{/t} + +
+
+ +

+ + + + + + +Temporary escape: + + + + + diff --git a/plugins/admin/systems/remove_dhcp.tpl b/plugins/admin/systems/remove_dhcp.tpl new file mode 100644 index 000000000..39fb19bb6 --- /dev/null +++ b/plugins/admin/systems/remove_dhcp.tpl @@ -0,0 +1,17 @@ +
+ {t}Warning{/t} +
+

+ {$warning} + {t}This includes 'all' DHCP subsections that are located within this section. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}Best thing to do before performing this action would be to save the current contents of your LDAP tree in a file. So - if you've done so - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ +   + +

diff --git a/plugins/admin/systems/servdhcp.tpl b/plugins/admin/systems/servdhcp.tpl index de9e44474..76739f150 100644 --- a/plugins/admin/systems/servdhcp.tpl +++ b/plugins/admin/systems/servdhcp.tpl @@ -1 +1,9 @@ -DHCP functionality here.. +

{t}DHCP sections{/t}

+ + + + +
+ {$DhcpList} + +
diff --git a/plugins/admin/systems/servdns.tpl b/plugins/admin/systems/servdns.tpl index 88a6f582c..f9b0cb329 100644 --- a/plugins/admin/systems/servdns.tpl +++ b/plugins/admin/systems/servdns.tpl @@ -4,8 +4,7 @@ {$ZoneList} - - +