Marius Cramer
2015-05-04 d35b34d03ffe0d92cbaeb4410c913550150fab4e
server/lib/classes/monitor_tools.inc.php
@@ -62,6 +62,9 @@
            $mainver = array_filter($mainver);
            $mainver = current($mainver).'.'.next($mainver);
            switch ($mainver){
            case "14.10":
               $relname = "(Utopic Unicorn)";
               break;
            case "14.04":
               $relname = "(Trusty Tahr)";
               break;
@@ -256,7 +259,7 @@
      $server_id = intval($conf['server_id']);
      /**  get the "active" Services of the server from the DB */
      $services = $app->db->queryOneRecord('SELECT * FROM server WHERE server_id = ' . $server_id);
      $services = $app->db->queryOneRecord('SELECT * FROM server WHERE server_id = ?', $server_id);
      /*
       * If the DB is down, we have to set the db to "yes".
       * If we don't do this, then the monitor will NOT monitor, that the db is down and so the
@@ -667,14 +670,67 @@
       */
      $sql = 'DELETE FROM monitor_data ' .
         'WHERE ' .
         '  type =' . "'" . $app->dbmaster->quote($type) . "' " .
         '  type = ?' .
         'AND ' .
         '  created < ' . $old . ' ' .
         '  created < ? ' .
         'AND ' .
         '  server_id = ' . $serverId;
      $app->dbmaster->query($sql);
         '  server_id = ?';
      $app->dbmaster->query($sql, $type, $old, $serverId);
   }
   public function send_notification_email($template, $placeholders, $recipients) {
      global $conf;
      if(!is_array($recipients) || count($recipients) < 1) return false;
      if(!is_array($placeholders)) $placeholders = array();
      if(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt');
      } elseif(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt');
      } elseif(file_exists($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt')) {
         $lines = file($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt');
      } else {
         $lines = file($conf['rootpath'].'/conf/mail/' . $template . '_en.txt');
      }
      //* get mail headers, subject and body
      $mailHeaders = '';
      $mailBody = '';
      $mailSubject = '';
      $inHeader = true;
      for($l = 0; $l < count($lines); $l++) {
         if($lines[$l] == '') {
            $inHeader = false;
            continue;
         }
         if($inHeader == true) {
            $parts = explode(':', $lines[$l], 2);
            if(strtolower($parts[0]) == 'subject') $mailSubject = trim($parts[1]);
            unset($parts);
            $mailHeaders .= trim($lines[$l]) . "\n";
         } else {
            $mailBody .= trim($lines[$l]) . "\n";
         }
      }
      $mailBody = trim($mailBody);
      //* Replace placeholders
      $mailHeaders = strtr($mailHeaders, $placeholders);
      $mailSubject = strtr($mailSubject, $placeholders);
      $mailBody = strtr($mailBody, $placeholders);
      for($r = 0; $r < count($recipients); $r++) {
         mail($recipients[$r], $mailSubject, $mailBody, $mailHeaders);
      }
      unset($mailSubject);
      unset($mailHeaders);
      unset($mailBody);
      unset($lines);
      return true;
   }
}