summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4cbd53d)
raw | patch | inline | side by side (parent: 4cbd53d)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 19 Aug 2009 11:44:55 +0000 (11:44 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 19 Aug 2009 11:44:55 +0000 (11:44 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14086 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_SnapshotHandler.inc | [new file with mode: 0644] | patch | blob |
gosa-core/include/class_config.inc | patch | blob | history | |
gosa-core/include/class_listing.inc | patch | blob | history | |
gosa-core/include/class_plugin.inc | patch | blob | history |
diff --git a/gosa-core/include/class_SnapshotHandler.inc b/gosa-core/include/class_SnapshotHandler.inc
--- /dev/null
@@ -0,0 +1,247 @@
+<?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+class SnapshotHandler {
+
+ var $config;
+ var $isEnabled= false;
+ var $snapshotBases= array();
+
+
+ /* Create handler */
+ function SnapshotHandler(&$config)
+ {
+ $this->config = &$config;
+ $config = $this->config;
+
+ if($config->get_cfg_value("enableSnapshots") == "true"){
+
+ /* Check if the snapshot_base is defined */
+ if ($config->get_cfg_value("snapshotBase") == ""){
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
+ "snapshotBase"), ERROR_DIALOG);
+ }
+ return;
+ }
+
+ /* Check if the snapshot_base is defined */
+ if (!is_callable("gzcompress")){
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install '%s'."),"php5-zip / php5-gzip"), ERROR_DIALOG);
+ }
+ return;
+ }
+
+ /* check if there are special server configurations for snapshots */
+ if ($config->get_cfg_value("snapshotURI") != ""){
+
+ /* check if all required vars are available to create a new ldap connection */
+ $missing = "";
+ foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
+ if($config->get_cfg_value($var) == ""){
+ $missing .= $var." ";
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
+ $missing), ERROR_DIALOG);
+ }
+ return;
+ }
+ }
+ }
+ $this->isEnabled= true;
+ return;
+ }
+ }
+
+
+ function enabled()
+ {
+ return $this->isEnabled;
+ }
+
+
+ function setSnapshotBases($bases)
+ {
+ $this->snapshotBases= $bases;
+ }
+
+
+ function getSnapshotBases()
+ {
+ return $this->snapshotBases;
+ }
+
+
+ function get_snapshot_link()
+ {
+ $snapshotLdap= null;
+
+ /* check if there are special server configurations for snapshots */
+ if($this->config->get_cfg_value("snapshotURI") != ""){
+ $server= $this->config->get_cfg_value("snapshotURI");
+ $user= $this->config->get_cfg_value("snapshotAdminDn");
+ $password= $this->config->get_credentials($this->config->get_cfg_value("snapshotAdminPassword"));
+ $snapshotLdap= new ldapMultiplexer(new LDAP($user,$password, $server));
+ }
+
+ /* Prepare bases */
+ $this->snapshotLdapBase= $this->config->get_cfg_value("snapshotBase");
+ $snapshotLdap->cd($this->snapshotLdapBase);
+ if (!$snapshotLdap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($snapshotLdap->get_error(), $this->snapshotLdapBase, "", get_class()));
+ }
+
+ return $snapshotLdap;
+ }
+
+
+ function getDeletedSnapshots($objectBase, $raw= false)
+ {
+ // Skip if not enabled
+ if(!$this->enabled()){
+ return(array());
+ }
+
+ // Load user info
+ $ui= get_userinfo();
+
+ /* Create an additional ldap object which
+ points to our ldap snapshot server */
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $snapshotLdap= $this->get_snapshot_link();
+ if (!$snapshotLdap) {
+ $snapshotLdap= $ldap;
+ }
+
+ // Initialize base
+ $base= preg_replace("/".preg_quote($this->config->current['BASE'], '/')."$/",
+ "", $objectBase).$this->snapshotLdapBase;
+
+ /* Fetch all objects and check if they do not exist anymore */
+ $objects= array();
+ $snapshotLdap->cd($base);
+ $snapshotLdap->ls("(objectClass=gosaSnapshotObject)", $base,
+ array("gosaSnapshotType", "gosaSnapshotTimestamp", "gosaSnapshotDN", "description"));
+ while($entry = $snapshotLdap->fetch()){
+
+ $chk = str_replace($base,"",$entry['dn']);
+ if(preg_match("/,ou=/",$chk)) continue;
+
+ if(!isset($entry['description'][0])){
+ $entry['description'][0] = "";
+ }
+ $objects[] = $entry;
+ }
+
+ /* Check if entry still exists */
+ foreach($objects as $key => $entry){
+ $ldap->cat($entry['gosaSnapshotDN'][0]);
+ if($ldap->count()){
+ unset($objects[$key]);
+ }
+ }
+
+ /* Format result as requested */
+ if($raw) {
+ return($objects);
+ }else{
+ $tmp = array();
+ foreach($objects as $key => $entry){
+ $tmp[base64_encode($entry['dn'])] = $entry['description'][0];
+ }
+ }
+ return($tmp);
+ }
+
+
+ function hasSnapshots($dn)
+ {
+ return (count($this->getSnapshots($dn)) > 0);
+ }
+
+
+ function getSnapshots($dn, $raw= false)
+ {
+ // Empty if disabled
+ if(!$this->enabled()){
+ return(array());
+ }
+
+ /* Create an additional ldap object which
+ points to our ldap snapshot server */
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+
+ // Load snapshot LDAP connection
+ $snapshotLdap= $this->get_snapshot_link();
+ if (!$snapshotLdap) {
+ $snapshotLdap= $ldap;
+ }
+
+ // Initialize base
+ $base= preg_replace("/".preg_quote($this->config->current['BASE'], '/')."$/",
+ "", $objectBase).$this->snapshotLdapBase;
+
+ /* Fetch all objects with gosaSnapshotDN=$dn */
+ $snapshotLdap->cd($base);
+ $snapshotLdap->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$base,
+ array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
+
+ /* Put results into a list and add description if missing */
+ $objects= array();
+ while($entry = $snapshotLdap->fetch()){
+ if(!isset($entry['description'][0])){
+ $entry['description'][0] = "";
+ }
+ $objects[] = $entry;
+ }
+
+ /* Return the raw array, or format the result */
+ if($raw){
+ return($objects);
+ }else{
+ $tmp = array();
+ foreach($objects as $entry){
+ $tmp[base64_encode($entry['dn'])] = $entry['description'][0];
+ }
+ }
+ return($tmp);
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index abebcb0ada92a95193256e0c1b185c5fc66260d1..6dd0527b8a45e7755245a8970ae7d97ea7a8e744 100644 (file)
return(TRUE);
}
}
+
+ /* Returns true if snapshots are enabled, and false if it is disalbed
+ There will also be some errors psoted, if the configuration failed */
+ function snapshotEnabled()
+ {
+ if($this->get_cfg_value("enableSnapshots") == "true"){
+
+ /* Check if the snapshot_base is defined */
+ if ($this->get_cfg_value("snapshotBase") == ""){
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
+ "snapshotBase"), ERROR_DIALOG);
+ }
+ return(FALSE);
+ }
+
+ /* Check if the snapshot_base is defined */
+ if (!is_callable("gzcompress")){
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install '%s'."),"php5-zip / php5-gzip"), ERROR_DIALOG);
+ }
+ return(FALSE);
+ }
+
+ /* check if there are special server configurations for snapshots */
+ if ($this->get_cfg_value("snapshotURI") != ""){
+
+ /* check if all required vars are available to create a new ldap connection */
+ $missing = "";
+ foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
+ if($this->get_cfg_value($var) == ""){
+ $missing .= $var." ";
+
+ /* Send message if not done already */
+ if(!session::is_set("snapshotFailMessageSend")){
+ session::set("snapshotFailMessageSend",TRUE);
+ msg_dialog::display(_("Configuration error"),
+ sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
+ $missing), ERROR_DIALOG);
+ }
+ return(FALSE);
+ }
+ }
+ }
+ return(TRUE);
+ }
+ return(FALSE);
+ }
+
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 63124a1945a9e7c917e23dfd0829f8aabda15e0c..c50453a8ee75fee3228fa7cb581af8febb00310b 100644 (file)
var $pid;
var $objectTypes= array();
var $objectTypeCount= array();
- var $CopyPasteHandler= null;
+ var $copyPasteHandler= null;
+ var $snapshotHandler= null;
function listing($filename)
function setCopyPasteHandler($handler)
{
- $this->CopyPasteHandler= &$handler;
+ $this->copyPasteHandler= &$handler;
+ }
+
+
+ function setSnapshotHandler($handler)
+ {
+ $this->snapshotHandler= &$handler;
+ }
+
+
+ function setFilter($filter)
+ {
+ $this->filter= &$filter;
+ if ($this->departmentBrowser){
+ $this->departments= $this->getDepartments();
+ }
+ $this->filter->setBase($this->base);
+ $this->entries= $this->filter->query();
}
function render()
{
-echo "snapshot handler, daemon handler<br>";
// Check for exeeded sizelimit
if (($message= check_sizelimit()) != ""){
return($message);
}
- function setFilter($filter)
- {
- $this->filter= &$filter;
- if ($this->departmentBrowser){
- $this->departments= $this->getDepartments();
- }
- $this->filter->setBase($this->base);
- $this->entries= $this->filter->query();
- }
-
-
function update()
{
global $config;
}
// Handle special types
- if ($action['type'] == "snapshot") {
- #TODO
- #echo "actiontriggers: snapshot missing<br>";
- }
- if ($action['type'] == "copypaste") {
+ if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
$objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
$category= $class= null;
$class= $objectType['class'];
}
- $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class);
- }
- if ($action['type'] == "daemon") {
- #TODO
- #echo "actiontriggers: daemon missing<br>";
+ if ($action['type'] == "copypaste") {
+ $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class);
+ } else {
+ $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
+ }
}
-
}
return $result;
break;
case 'snapshot':
- #TODO
- #echo "actionmenu: snapshot missing<br>";
+ $result.= $this->renderSnapshotMenu($separator);
break;
case 'daemon':
- #TODO
- #echo "actionmenu: daemon missing<br>";
+ $result.= $this->renderDaemonMenu($separator);
break;
}
{
// We can only provide information if we've got a copypaste handler
// instance
- if(!(isset($this->CopyPasteHandler) && is_object($this->CopyPasteHandler))){
+ if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
return "";
}
// Draw entries that allow pasting entries
if($paste){
- if($this->CopyPasteHandler->entries_queued()){
+ if($this->copyPasteHandler->entries_queued()){
$result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";mainform.submit();'><img src='images/lists/paste.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
}else{
$result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
{
// We can only provide information if we've got a copypaste handler
// instance
- if(!(isset($this->CopyPasteHandler) && is_object($this->CopyPasteHandler))){
+ if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
return "";
}
return($result);
}
+
+ function renderSnapshotMenu($separator)
+ {
+ // We can only provide information if we've got a snapshot handler
+ // instance
+ if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
+ return "";
+ }
+
+ // Presets
+ $result = "";
+ $ui = get_userinfo();
+
+ if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
+
+ // Check if there is something to restore
+ $restore= false;
+ foreach($this->snapshotHandler->getSnapshotBases() as $base){
+ $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
+ }
+
+ // Draw icons according to the restore flag
+ if($restore){
+ $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";mainform.submit();'><img src='images/lists/restore.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
+ }else{
+ $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
+ }
+ }
+
+ return($result);
+ }
+
+
+ function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
+ {
+ // We can only provide information if we've got a snapshot handler
+ // instance
+ if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
+ return "";
+ }
+
+ // Presets
+ $result= "";
+ $ui = get_userinfo();
+
+ // Only act if enabled here
+ if($this->snapshotHandler->enabled()){
+
+ // Draw restore button
+ if ($ui->allow_snapshot_restore($dn, $category)){
+
+ // Do we have snapshots for this dn?
+ if($this->snapshotHandler->hasSnapshots($dn)){
+ $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
+ "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
+ _("Restore snapshot")."' style='padding:1px'>";
+ } else {
+ $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
+ }
+ }
+
+ // Draw snapshot button
+ if($ui->allow_snapshot_create($dn, $category)){
+ $result.= "<input class='center' type='image' src='images/snapshot.png' ".
+ "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
+ _("Create a new snapshot from this object")."' style='padding:1px'>";
+ }else{
+ $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
+ }
+ }
+
+ return($result);
+ }
+
+
+ function renderDaemonMenu($separator)
+ {
+ $result= "";
+
+ // If there is a daemon registered, draw the menu entries
+ if(class_available("DaemonEvent")){
+ $events= DaemonEvent::get_event_types_by_category($this->categories);
+ if(count($events['BY_CLASS'])){
+ foreach($events['BY_CLASS'] as $name => $event){
+ $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$name\";mainform.submit();'><img src='".$event['MenuImage']."' alt='' border='0' class='center'> ".$event['s_Menu_Name']."</a></li>";
+ $separator= "";
+ }
+ }
+ }
+
+ return $result;
+ }
+
}
?>
index 4d8f82a595bb269d9a356749c97b005c5ed1e741..31115eced96878a3e78414b3add8fb5d3c49ebd8 100644 (file)
There will also be some errors psoted, if the configuration failed */
function snapshotEnabled()
{
- $config = $this->config;
- if($config->get_cfg_value("enableSnapshots") == "true"){
-
- /* Check if the snapshot_base is defined */
- if ($config->get_cfg_value("snapshotBase") == ""){
-
- /* Send message if not done already */
- if(!session::is_set("snapshotFailMessageSend")){
- session::set("snapshotFailMessageSend",TRUE);
- msg_dialog::display(_("Configuration error"),
- sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
- "snapshotBase"), ERROR_DIALOG);
- }
- return(FALSE);
- }
-
- /* Check if the snapshot_base is defined */
- if (!is_callable("gzcompress")){
-
- /* Send message if not done already */
- if(!session::is_set("snapshotFailMessageSend")){
- session::set("snapshotFailMessageSend",TRUE);
- msg_dialog::display(_("Configuration error"),
- sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install '%s'."),"php5-zip / php5-gzip"), ERROR_DIALOG);
- }
- return(FALSE);
- }
-
- /* check if there are special server configurations for snapshots */
- if ($config->get_cfg_value("snapshotURI") != ""){
-
- /* check if all required vars are available to create a new ldap connection */
- $missing = "";
- foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){
- if($config->get_cfg_value($var) == ""){
- $missing .= $var." ";
-
- /* Send message if not done already */
- if(!session::is_set("snapshotFailMessageSend")){
- session::set("snapshotFailMessageSend",TRUE);
- msg_dialog::display(_("Configuration error"),
- sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."),
- $missing), ERROR_DIALOG);
- }
- return(FALSE);
- }
- }
- }
- return(TRUE);
- }
- return(FALSE);
+ return $this->config->snapshotEnabled();
}