/** * Enviar un email utilizando la clase PHPMailer. * * @param Log $log con el objeto del tipo Log * @param string $mailTo con el destinatario * @param bool $isEvent para indicar si es um * @return bool */ public static function sendEmail(Log $log, $mailTo = '', $isEvent = true) { if (!Util::mailIsEnabled()) { return false; } $mail = self::getEmailObject($mailTo, utf8_decode($log->getAction())); if (!is_object($mail)) { return false; } $mail->isHTML(); $log->setNewLineHtml(true); if ($isEvent === true) { $performer = Session::getUserLogin() ? Session::getUserLogin() : _('N/D'); $body[] = Html::strongText(_('Acción') . ": ") . utf8_decode($log->getAction()); $body[] = Html::strongText(_('Realizado por') . ": ") . $performer . ' (' . $_SERVER['REMOTE_ADDR'] . ')'; $mail->addCC(Config::getValue('mail_from')); } $body[] = utf8_decode($log->getDescription()); $body[] = ''; $body[] = '--'; $body[] = Util::getAppInfo('appname') . ' - ' . Util::getAppInfo('appdesc'); $body[] = Html::anchorText(Init::$WEBURI); $mail->Body = implode(Log::NEWLINE_HTML, $body); $sendMail = $mail->send(); $logEmail = new Log(_('Enviar Email')); // Enviar correo if ($sendMail) { $logEmail->addDescription(_('Correo enviado')); } else { $logEmail->addDescription(_('Error al enviar correo')); $logEmail->addDescription('ERROR: ' . $mail->ErrorInfo); } $logEmail->addDescription(_('Destinatario') . ': ' . $mailTo); if ($isEvent === true) { $logEmail->addDescription(_('CC') . ': ' . Config::getValue('mail_from')); } $logEmail->writeLog(); return $sendMail; }
/** * Escribir un nuevo evento en el registro de eventos * * @param bool $resetDescription Restablecer la descripción * @return bool */ public function writeLog($resetDescription = false) { if (defined('IS_INSTALLER') && IS_INSTALLER === 1) { error_log('Action: ' . $this->getAction() . ' -- Description: ' . $this->getDescription()); } if (!Util::logIsEnabled()) { return false; } $query = 'INSERT INTO log SET ' . 'log_date = UNIX_TIMESTAMP(),' . 'log_login = :login,' . 'log_userId = :userId,' . 'log_ipAddress = :ipAddress,' . 'log_action = :action,' . 'log_description = :description'; $data['login'] = Session::getUserLogin(); $data['userId'] = Session::getUserId(); $data['ipAddress'] = $_SERVER['REMOTE_ADDR']; $data['action'] = $this->getAction(); $data['description'] = $this->getDescription(); if ($resetDescription === true) { $this->resetDescription(); } return DB::getQuery($query, __FUNCTION__, $data); }
/** * Crear el nodo con metainformación del archivo XML * * @throws SPException */ private function createMeta() { try { $nodeMeta = $this->_xml->createElement('Meta'); $metaGenerator = $this->_xml->createElement('Generator', 'sysPass'); $metaVersion = $this->_xml->createElement('Version', implode('.', Util::getVersion())); $metaTime = $this->_xml->createElement('Time', time()); $metaUser = $this->_xml->createElement('User', Session::getUserLogin()); $metaUser->setAttribute('id', Session::getUserId()); $metaGroup = $this->_xml->createElement('Group', Session::getUserGroupName()); $metaGroup->setAttribute('id', Session::getUserGroupId()); $nodeMeta->appendChild($metaGenerator); $nodeMeta->appendChild($metaVersion); $nodeMeta->appendChild($metaTime); $nodeMeta->appendChild($metaUser); $nodeMeta->appendChild($metaGroup); $this->_root->appendChild($nodeMeta); } catch (\DOMException $e) { throw new SPException(SPException::SP_WARNING, $e->getMessage(), __FUNCTION__); } }