Commit c06a9e7c authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2169 Fixed snapshots

Showing with 83 additions and 18 deletions
+83 -18
......@@ -146,6 +146,70 @@ class SnapShotDialog extends plugin
return($tmp2);
}
/*
* \brief Return available snapshots for the given base
*
* \param string $dn The DN
*
* \param string boolean $raw FALSE
*/
function Available_SnapsShots($dn,$raw = false)
{
if(!$this->snapshotEnabled()) 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']);
$cfg= &$this->config->current;
/* check if there are special server configurations for snapshots */
if($this->config->get_cfg_value("snapshotURI") == ""){
$ldap_to = $ldap;
}else{
$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"));
$snapldapbase = $this->config->get_cfg_value("snapshotBase");
$ldap_to = new ldapMultiplexer(new LDAP($user,$password, $server));
$ldap_to -> cd($snapldapbase);
if (!$ldap_to->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
}
}
/* Prepare bases and some other infos */
$base = $this->config->current['BASE'];
$snap_base = $this->config->get_cfg_value("snapshotBase");
$base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
$new_base = preg_replace("/".preg_quote($base, '/')."$/","",$base_of_object).$snap_base;
$tmp = array();
/* Fetch all objects with gosaSnapshotDN=$dn */
$ldap_to->cd($new_base);
$ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
/* Put results into a list and add description if missing */
while($entry = $ldap_to->fetch()){
if(!isset($entry['description'][0])){
$entry['description'][0] = "";
}
$tmp[] = $entry;
}
/* Return the raw array, or format the result */
if($raw){
return($tmp);
}else{
$tmp2 = array();
foreach($tmp as $entry){
$tmp2[base64_encode($entry['dn'])] = $entry['description'][0];
}
}
return($tmp2);
}
/*!
* \brief Set a snapshot base
......
......@@ -294,7 +294,7 @@ class SnapshotHandler {
*
* \param array $description Snapshot description
*/
function create_snapshot($dn, $description= array())
function create_snapshot($dn, $description = array())
{
if (is_array($dn)) {
$dns = $dn;
......@@ -304,7 +304,7 @@ class SnapshotHandler {
}
/* Check if snapshot functionality is enabled */
if(!$this->snapshotEnabled()){
if (!$this->snapshotEnabled()) {
return;
}
......@@ -312,52 +312,53 @@ class SnapshotHandler {
$config = $this->config;
/* Create lokal ldap connection */
$ldap= $this->config->get_ldap_link();
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
/* check if there are special server configurations for snapshots */
if($config->get_cfg_value("snapshotURI") == ""){
if ($config->get_cfg_value("snapshotURI") == "") {
/* Source and destination server are both the same, just copy source to dest obj */
$ldap_to = $ldap;
$snapldapbase = $this->config->current['BASE'];
}else{
} else {
$server = $config->get_cfg_value("snapshotURI");
$user = $config->get_cfg_value("snapshotAdminDn");
$password = $this->config->get_credentials($config->get_cfg_value("snapshotAdminPassword"));
$snapldapbase = $config->get_cfg_value("snapshotBase");
$ldap_to = new ldapMultiplexer(new LDAP($user,$password, $server));
$ldap_to = new ldapMultiplexer(new LDAP($user, $password, $server));
$ldap_to -> cd($snapldapbase);
if (!$ldap_to->success()){
if (!$ldap_to->success()) {
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
}
}
/* check if the dn exists */
if ($ldap->dn_exists($dn)){
if ($ldap->dn_exists($dn)) {
/* Extract seconds & mysecs, they are used as entry index */
list($usec, $sec)= explode(" ", microtime());
list($usec, $sec) = explode(" ", microtime());
/* Collect some infos */
$base = $this->config->current['BASE'];
$snap_base = $config->get_cfg_value("snapshotBase");
$base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
$new_base = preg_replace("/".preg_quote($base, '/')."$/","",$base_of_object).$snap_base;
$new_base = preg_replace("/".preg_quote($base, '/')."$/", "", $base_of_object).$snap_base;
/* Create object */
$data = '';
foreach ($dns as $dn) {
$data .= $ldap->generateLdif(LDAP::fix($dn),
foreach ($dns as $tmp_dn) {
$data .= $ldap->generateLdif(LDAP::fix($tmp_dn),
'(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))', array(), 'sub');
}
$newName = str_replace(".", "", $sec."-".$usec);
$target = array();
$newName = str_replace(".", "", $sec."-".$usec);
$target = array();
$target['objectClass'] = array("top", "gosaSnapshotObject");
$target['gosaSnapshotData'] = gzcompress($data, 6);
$target['gosaSnapshotType'] = "snapshot";
......@@ -371,9 +372,9 @@ class SnapshotHandler {
an unused value. */
$new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
$ldap_to->cat($new_dn);
while($ldap_to->count()){
while ($ldap_to->count()) {
$ldap_to->cat($new_dn);
$newName = str_replace(".", "", $sec."-".($usec++));
$newName = str_replace(".", "", $sec."-".(++$usec));
$new_dn = "gosaSnapshotTimestamp=".$newName.",".$new_base;
$target['gosaSnapshotTimestamp'] = $newName;
}
......@@ -383,11 +384,11 @@ class SnapshotHandler {
$ldap_to->create_missing_trees($new_base);
$ldap_to->cd($new_dn);
$ldap_to->add($target);
if (!$ldap_to->success()){
if (!$ldap_to->success()) {
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $new_dn, LDAP_ADD, get_class()));
}
if (!$ldap->success()){
if (!$ldap->success()) {
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $new_base, "", get_class()));
}
......
  • bmortier @bmortier

    mentioned in issue #748

    By Côme Chilliet on 2017-09-02T14:57:38 (imported from GitLab)

    ·

    mentioned in issue #748

    By Côme Chilliet on 2017-09-02T14:57:38 (imported from GitLab)

    Toggle commit list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment