Beispiel #1
0
} elseif ($action == 'backup') {
///////////////////////////////////////////////////////////////////////////////
  // lang file include for backup
  $lang = strtolower(get_lang());
  include_once("obminclude/lang/$lang/backup.inc");
  try {
    $backup = new Backup('user', $params['user_id']);
    $dis_form = true;

    $options = array();
    if (!empty($params['retrieveAll'])) {
      $backup->retrieveBackups($options);
      $display['msg'] .= display_ok_msg($l_retrieve_from_ftp_success);
    } elseif (!empty($params['execute'])) {
      $result = $backup->doBackup($options);
      $display['msg'] .= display_ok_msg($l_backup_complete);
      if (!$result['pushFtp']['success']) {
        $display['msg'] .= display_warn_msg($l_push_backup_ftp_failed.' ('.$result['pushFtp']['msg'].')');
      }
    }
  } catch (Exception $e) {
    $display['msg'] .= display_err_msg($e->getMessage());
  }

  if ($dis_form) {
    $display['detail'] = dis_user_backup_form($backup, $params);
  }

} elseif ($action == 'restore') {
///////////////////////////////////////////////////////////////////////////////
Beispiel #2
0
 protected function processDomain($domain_id, $domain_name)
 {
     global $obminclude;
     include "{$obminclude}/lang/en/backup.inc";
     $this->logger->debug("Processing users and mailshares of domain {$domain_name} (id: {$domain_id})");
     $GLOBALS['obm']['domain_id'] = $domain_id;
     $options = array('sendMail' => false);
     $errors = array('ftp' => 0, 'users' => 0, 'mailshares' => 0);
     $count = array('users' => 0, 'mailshares' => 0);
     $mailBody = "";
     $users = $this->getDomainUsers($domain_id);
     $count['users'] = count($users);
     $this->logger->debug($count['users'] . " users found in domain {$domain_name} (id: {$domain_id})");
     foreach ($users as $user_id => $login) {
         $this->logger->debug("Processing user {$login} (id: {$user_id})...");
         try {
             $backup = new Backup('user', $user_id);
             $result = $backup->doBackup($options);
             $this->logger->debug($result['content']);
             if (!$result['pushFtp']['success']) {
                 $errors['ftp']++;
                 $this->logger->warn($l_push_backup_ftp_failed);
                 $this->logger->warn($result['pushFtp']['msg']);
                 if ($errors['ftp'] >= MAX_FTP_ERRORS) {
                     $this->logger->warn(MAX_FTP_ERRORS . ' ftp errors: disable FTP push');
                     $options['noFtp'] = true;
                 }
             } else {
                 $this->logger->debug($result['pushFtp']['msg']);
             }
             $this->logger->debug("User {$login} (id: {$user_id}) backup finished");
         } catch (Exception $e) {
             $errors['users']++;
             $mailBody .= __("error when processing user %login%@%domain_name% (id: %user_id%)\n", array("login" => $login, "domain_name" => $domain_name, "user_id" => $user_id)) . "\n";
             $this->logger->error("error when processing user {$login}@{$domain_name} (id: {$user_id})");
             $mailBody .= $e->getMessage() . "\n";
             $this->logger->error($e->getMessage());
         }
     }
     $mailshares = $this->getDomainMailshares($domain_id);
     $count['mailshares'] = count($mailshares);
     $this->logger->debug($count['mailshares'] . " mailshares found in domain {$domain_name} (id: {$domain_id})");
     foreach ($mailshares as $mailshare_id => $mailshare_name) {
         $this->logger->debug("Processing mailshare {$mailshare_name} (id: {$mailshare_id})...");
         try {
             $backup = new Backup('mailshare', $mailshare_id);
             $result = $backup->doBackup($options);
             $this->logger->debug($result['content']);
             if (!$result['pushFtp']['success']) {
                 $errors['ftp']++;
                 $this->logger->warn($l_push_backup_ftp_failed);
                 $this->logger->warn($result['pushFtp']['msg']);
                 if ($errors['ftp'] >= MAX_FTP_ERRORS) {
                     $this->logger->warn(MAX_FTP_ERRORS . ' ftp errors: disable FTP push');
                     $options['noFtp'] = true;
                 }
             } else {
                 $this->logger->debug($result['pushFtp']['msg']);
             }
             $this->logger->debug("Mailshare {$mailshare_name} (id: {$mailshare_id}) backup finished");
         } catch (Exception $e) {
             $errors['mailshares']++;
             $mailBody .= __("error when processing mailshare %mailshare_name%@%domain_name% (id: %user_id%)", array("mailshare_name" => $mailshare_name, "domain_name" => $domain_name, "user_id" => $mailshare_id)) . "\n";
             $this->logger->error("error when processing mailshare {$mailshare_name}@{$domain_name} (id: {$mailshare_id})");
             $mailBody .= $e->getMessage();
             $this->logger->error($e->getMessage());
         }
     }
     $mailIntro = __("%count% users backuped successfully", array("count" => $count['users'] - $errors['users'])) . "\n";
     if ($errors['users'] > 0) {
         $mailIntro .= __("%count% errors on users", array("count" => $errors['users'])) . "\n";
     }
     $mailIntro .= __("%count% mailshares backuped successfully", array("count" => $count['mailshares'] - $errors['mailshares'])) . "\n";
     if ($errors['mailshares'] > 0) {
         $mailIntro .= __("%count% errors on mailshares", array("count" => $errors['mailshares'])) . "\n";
     }
     if ($errors['ftp'] >= MAX_FTP_ERRORS) {
         $mailIntro .= __("%count% ftp errors", array("count" => $errors['ftp'])) . "\n";
         $mailIntro .= __("FTP push has been disabled after %count% errors", array("count" => MAX_FTP_ERRORS)) . "\n";
     }
     $totalErrors = array_sum($errors);
     if ($totalErrors > 0) {
         $mailSubject = __("backup of users and mailshares of domain %domain_name% completed with %count% errors", array("%domain_name%" => $domain_name, "count" => $totalErrors));
     } else {
         $mailSubject = __("backup of users and mailshares of domain %domain_name% completed successfully", array("%domain_name%" => $domain_name));
     }
     $mailTo = "x-obm-backup@{$domain_name}";
     $mailFrom = $mailTo;
     $mailBody = $mailIntro . "\n" . $mailBody;
     send_mail_from($mailSubject, $mailBody, $mailFrom, array(), array($mailTo), false);
 }