Commit faa7493e authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #3997 Getting rid of old plugin class uses

DHCP will be redone later based on simplePlugin
parent eca31bab
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class dhcpAdvanced extends plugin
{
/* Used attributes */
var $options= null;
var $statements= null;
var $show_advanced= FALSE;
var $autoStatements= array();
var $autoOptions= array();
/* attribute list for save action */
var $attributes= array();
var $objectclasses= array();
var $parent;
function dhcpAdvanced()
{
/* This is always an account */
$this->is_account= TRUE;
$this->setAutoStatements();
$this->setAutoOptions();
}
function execute()
{
$acl_writeable = preg_match("/w/",$this->parent->getacl(""));
/* Check for interaction */
if ($acl_writeable && isset($_POST['add_statement']) && $_POST['addstatement'] != ""){
$key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addstatement'));
$val= preg_replace("/^$key\s*/", '', get_post('addstatement'));
$this->statements->add($key,$val);
}
if ($acl_writeable && isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
$name = preg_replace('/_[0-9]*$/', '', get_post('dhcpstatements'));
$key = preg_replace('/^.*_/', '', get_post('dhcpstatements'));
if (in_array($name, $this->autoStatements)){
msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
} else {
$this->statements->remove($name,$key);
}
}
if ($acl_writeable && isset($_POST['add_option']) && $_POST['addoption'] != ""){
$key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
$val= preg_replace("/^$key\s*/", '', get_post('addoption'));
$this->options->add($key,$val);
}
if ($acl_writeable && isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
$name = preg_replace('/_[0-9]*$/', '', get_post('dhcpoptions'));
$key = preg_replace('/^.*_/', '', get_post('dhcpoptions'));
if (in_array($name, $this->autoOptions)){
msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
} else {
$this->options->remove($name,$key);
}
}
$smarty= get_smarty();
/* Assign ACLs */
$smarty->assign("acl",$this->parent->getacl(""));
/* Assign statements */
$statements= array();
foreach ($this->statements->getAll() as $key => $val){
if (in_array($key, $this->autoStatements)){
foreach($val as $id => $entry){
$statements[$key."_".$id]= "$key $entry ["._("automatic")."]";
}
} else {
foreach($val as $id => $entry){
$statements[$key."_".$id]= "$key $entry";
}
}
}
$smarty->assign("dhcpstatements", $statements);
/* Assign options */
$options= array();
foreach ($this->options->getAll() as $key => $val){
if (in_array($key, $this->autoOptions)){
foreach($val as $id => $entry){
$options[$key."_".$id]= "$key $entry ["._("automatic")."]";
}
} else {
foreach($val as $id => $entry){
$options[$key."_".$id]= "$key $entry";
}
}
}
$smarty->assign("dhcpoptions", $options);
/* Show main page */
$smarty->assign("show_advanced", $this->show_advanced);
return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE,dirname(__FILE__))));
}
function remove_from_parent()
{
}
/* Save data to object */
function save_object()
{
if (isset($_POST['show_advanced'])){
$this->show_advanced= TRUE;
}
if (isset($_POST['hide_advanced'])){
$this->show_advanced= FALSE;
}
}
/* Check values */
function check()
{
/* Nothing to check here */
$message= array();
return $message;
}
/* Save to LDAP */
function save()
{
}
function setAutoOptions($addopt= array())
{
$options= array("routers", "domain-name", "domain-name-servers", "subnet-mask", "broadcast-address");
$this->autoOptions= array_merge($options, $addopt);
}
function setAutoStatements($addstat= array())
{
$statements= array("filename", "next-server", "get-lease-hostnames", "use-host-decl-names");
$this->autoStatements= array_merge($statements, $addstat);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class dhcpClass extends dhcpPlugin
{
/* attribute list for save action */
var $objectclasses= array('top', 'dhcpClass', 'dhcpOptions');
function dhcpClass($parent,&$attrs)
{
/* Load statements / options */
dhcpPlugin::dhcpPlugin($parent,$attrs);
}
function execute()
{
$smarty= get_smarty();
$smarty->assign("cn", $this->cn);
/* Assign ACLs */
$smarty->assign("acl",$this->parent->getacl(""));
/* Show main page */
$display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE,
dirname(__FILE__))).$this->network->execute();
$display.= $this->advanced->execute();
/* Add footer */
$display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
if(preg_match("/w/",$this->parent->getacl(""))){
$display.= "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
}
$display.= "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
$display.= "</div>";
return ($display);
}
function remove_from_parent()
{
}
/* Save data to object */
function save_object()
{
/* Save cn */
if (preg_match("/w/",$this->parent->getacl("")) && isset($_POST['cn'])){
$this->cn= validate(get_post('cn'));
}
/* Handle global saving */
dhcpPlugin::save_object();
}
/* Check values */
function check()
{
$message= array();
$cache = $this->parent->getCache();
/* All required fields are set? */
if ($this->cn == ""){
$message[]= msgPool::required(_("Name"));
}
if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
$message[]= msgPool::invalid(_("Name"),$this->cn,"/[a-z0-9_-]/i");
}
/* cn already used? */
if ($this->orig_cn != $this->cn || $this->new){
foreach($cache as $dn => $dummy){
if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
$message[]= msgPool::duplicated(_("Name"));
break;
}
}
}
/* Check external plugins */
$net= $this->network->check();
$adv= $this->advanced->check();
$message= array_merge($message, $net, $adv);
return $message;
}
/* Save to LDAP */
function save()
{
dhcpPlugin::save();
return ($this->attrs);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class dhcpDnsZone extends dhcpPlugin
{
/* Used attributes */
var $dhcpKeyDN="";
var $dhcpDnsZone="";
var $dhcpDnsZoneServer="";
var $cn="";
var $drop_down_domain= array();
var $drop_down_nameserver= array();
var $drop_down_tsigkey= array();
/* attribute list for save action */
var $objectclasses= array("top", "dhcpDnsZone");
function dhcpDnsZone($parent,$attrs,$host_exists_in_gosa = FALSE)
{
global $config;
dhcpPlugin::dhcpPlugin($parent,$attrs);
/* Load attributes */
if (!$this->new){
$this->dhcpDnsZoneServer= $attrs['dhcpDnsZoneServer'][0];
$this->dhcpKeyDN= base64_encode($attrs['dhcpKeyDN'][0]);
}
// Prepare LDAP link
$ldap= $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
/* Search for all objects, recursive, that match the given ldap filter.
each dyndns zoen have to depent of an alreday DNS Zone created so we search it
*/
// Search for domain
$ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("zoneName"));
while($attrs = $ldap->fetch()){
$this->drop_down_domain[$attrs["zoneName"][0]]= $attrs["zoneName"][0];
}
$ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("nSRecord"));
while($attrs = $ldap->fetch()){
$this->drop_down_nameserver[$attrs["nSRecord"][0]]=$attrs["nSRecord"][0];
}
$ldap->search("(objectClass=dhcpTSigKey)",array("dn","cn"));
if ($ldap->count() != 0){
while($attrs = $ldap->fetch()){
$this->drop_down_tsigkey[base64_encode($attrs["dn"])]=$attrs["cn"][0];
}
}
}
function execute()
{
$smarty= get_smarty();
$smarty->assign("cn", $this->cn);
$smarty->assign("cns",$this->drop_down_domain);
$smarty->assign("dhcpDnsZoneServer", $this->dhcpDnsZoneServer);
$smarty->assign("dhcpDnsZoneServers",$this->drop_down_nameserver);
$smarty->assign("dhcpKeyDN", $this->dhcpKeyDN);
$smarty->assign("dhcpKeyDNs",$this->drop_down_tsigkey);
/* Assign ACLs */
$smarty->assign("acl",$this->parent->getacl(""));
/* Show main page */
$display= $smarty->fetch(get_template_path('dhcp_dnszone.tpl', TRUE,dirname(__FILE__)));
/* Add footer */
$display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
if(preg_match("/w/",$this->parent->getacl(""))){
$display.= "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
}
$display.= "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
$display.= "</div>";
return ($display);
}
function remove_from_parent()
{
}
/* Save data to object */
function save_object()
{
/* Save remaining attributes */
if (isset($_POST['dhcp_dnszone_posted']) && preg_match("/w/", $this->parent->getacl(""))){
if (isset($_POST['dhcpKeyDN'])){
$this->dhcpKeyDN= get_post('dhcpKeyDN');
}
if (isset($_POST['dhcpDnsZoneServer'])){
$this->dhcpDnsZoneServer= get_post('dhcpDnsZoneServer');
}
if (isset($_POST['cn'])){
$this->cn= get_post('cn');
}
}
dhcpPlugin::save_object();
}
/* Check values */
function check()
{
$message= array();
$cache = array();
if (isset($this->parent)) {
$cache = $this->parent->getCache();
}
/* All required fields are set? */
if ($this->cn == ""){
$message[]= msgPool::required(_("DNS zone"));
}
if ($this->dhcpDnsZoneServer == ""){
$message[]= msgPool::required(_("DNS server"));
}
if ($this->dhcpKeyDN == ""){
$message[]= msgPool::required(_("Key DN"));
}
/* cn already used? */
if ($this->orig_cn != $this->cn || $this->new){
foreach($cache as $dn => $dummy){
if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
$message[]= msgPool::duplicated(_("Name"));
break;
}
}
}
/* Check external plugins */
$net= $this->network->check();
$adv= $this->advanced->check();
$message= array_merge($message, $net, $adv);
return $message;
}
/* Save to LDAP */
function save()
{
dhcpPlugin::save();
if ($this->dhcpKeyDN != ""){
$this->attrs['dhcpKeyDN']= array(base64_decode($this->dhcpKeyDN));
} else {
$this->attrs['dhcpKeyDN']= array();
}
if ($this->dhcpDnsZoneServer != ""){
$this->attrs['dhcpDnsZoneServer']= array($this->dhcpDnsZoneServer);
} else {
$this->attrs['dhcpDnsZoneServer']= array();
}
return ($this->attrs);
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class dhcpGroup extends dhcpPlugin
{
/* attribute list for save action */
var $objectclasses= array('top', 'dhcpGroup', 'dhcpOptions');
function dhcpGroup($parent,&$attrs)
{
/* Load statements / options */
dhcpPlugin::dhcpPlugin($parent,$attrs);
}
function execute()
{
$smarty= get_smarty();
$smarty->assign("cn", $this->cn);
/* Assign ACLs */
$smarty->assign("acl",$this->parent->getacl(""));
/* Show main page */
$display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE,
dirname(__FILE__))).$this->network->execute();
$display.= $this->advanced->execute();
/* Add footer */
$display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
if(preg_match("/w/",$this->parent->getacl(""))){
$display.= "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
}
$display.= "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
$display.= "</div>";
return ($display);
}
function remove_from_parent()
{
}
/* Save data to object */
function save_object()
{
/* Save cn */
if (preg_match("/w/",$this->parent->getacl("")) && isset($_POST['cn'])){
$this->cn= validate(get_post('cn'));
}
/* Handle global saving */
dhcpPlugin::save_object();
}
/* Check values */
function check()
{
$message= array();
$cache = $this->parent->getCache();
/* All required fields are set? */
if ($this->cn == ""){
$message[]= msgPool::required(_("Name"));
}
if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
$message[]= msgPool::invalid(_("Name"),$this->cn,"/[a-z0-9_-]/i");
}
/* cn already used? */
if ($this->orig_cn != $this->cn || $this->new){
foreach($cache as $dn => $dummy){
if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
$message[]= msgPool::duplicated(_("Name"));
break;