function formAntispam($smarty, $module_name, $local_templates_dir, $arrLang, $arrLangModule, $arrConf, $arrConfModule) { $arrFormConference = createFieldForm($arrLang, $arrLangModule); $oForm = new paloForm($smarty, $arrFormConference); $smarty->assign("LEGEND", $arrLang["Legend"]); $smarty->assign("UPDATE", $arrLang["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $smarty->assign("icon", "modules/{$module_name}/images/email_antispam.png"); $objAntispam = new paloSantoAntispam($arrConfModule['path_postfix'], $arrConfModule['path_spamassassin'], $arrConfModule['file_master_cf'], $arrConfModule['file_local_cf']); $activated = $objAntispam->isActiveSpamFilter(); if ($activated) { $arrData['status'] = "on"; $smarty->assign("statusSpam", "active"); } else { $arrData['status'] = "off"; $smarty->assign("statusSpam", "desactive"); } $val = $objAntispam->getTimeDeleteSpam(); if ($val != '') { $arrData['time_spam'] = $val; } $statusSieve = $activated && $val != '' ? 'on' : 'off'; $arrData['politica'] = $statusSieve == 'on' ? 'capturar_spam' : 'marcar_asusto'; $smarty->assign("statusSieve", $statusSieve); $valueRequiredHits = $objAntispam->getValueRequiredHits(); $arrData['levelNUM'] = $valueRequiredHits['level']; $arrData['header'] = $valueRequiredHits['header']; $smarty->assign("levelNUM", $arrData['levelNUM']); $smarty->assign("level", $arrLang['Level']); $htmlForm = $oForm->fetchForm("{$local_templates_dir}/form.tpl", $arrLangModule["Antispam"], $arrData); $contenidoModulo = "<form method='POST' style='margin-bottom:0;' action='?menu={$module_name}'>" . $htmlForm . "</form>"; return $contenidoModulo; }
function saveVacationSettings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf) { global $arrCredentials; $objAntispam = new paloSantoAntispam($arrConf['path_postfix'], $arrConf['path_spamassassin'], $arrConf['file_master_cf'], $arrConf['file_local_cf']); $pVacations = new paloMyVacation($pDB, $arrCredentials['idUser']); $jsonObject = new PaloSantoJSON(); $myVacation['init_date'] = getParameter('intiDate'); $myVacation['end_date'] = getParameter('endDate'); $myVacation['email_subject'] = getParameter('emailSubject'); $myVacation['email_body'] = getParameter('emailBody'); $email = $_SESSION['elastix_user']; $subject = $myVacation['email_subject']; $body = $myVacation['email_body']; $ini_date = $myVacation['init_date']; $end_date = $myVacation['end_date']; $timestamp0 = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $timestamp1 = mktime(0, 0, 0, date("m", strtotime($ini_date)), date("d", strtotime($ini_date)), date("Y", strtotime($ini_date))); $timeSince = $timestamp0 - $timestamp1; if ($timeSince >= 0) { $myVacation['vacation'] = "yes"; } else { $myVacation['vacation'] = "no"; } $scripts = $objAntispam->existScriptSieve($email, "scriptTest.sieve"); $spamCapture = false; // si CapturaSpam=OFF y Vacations=OFF if ($scripts['actived'] != "") { // hay un script activo if (preg_match("/scriptTest.sieve/", $scripts['actived'])) { // si CapturaSpam=ON y Vacations=OFF $spamCapture = true; } // si CapturaSpam=ON y Vacations=OFF } $pVacations->_DB->beginTransaction(); if (!$pVacations->editVacation($myVacation)) { $pVacations->_DB->rollBack(); $jsonObject->set_error($pVacations->getErrorMsg()); return $jsonObject->createJSON(); } else { //mandamos a actualizar el script del sieve if ($timeSince >= 0) { $body = str_replace("{END_DATE}", $end_date, $body); $result = $pVacations->uploadVacationScript($email, $subject, $body, $objAntispam, $spamCapture); } else { $result = true; } if ($result) { $pVacations->_DB->commit(); $jsonObject->set_message("Changes were saved succefully"); } else { $pVacations->_DB->rollBack(); $jsonObject->set_error($pVacations->getErrorMsg()); } return $jsonObject->createJSON(); } }
$Id: disable_vacations.php,v 1.1 2011-05-01 05:09:57 Eduardo Cueva <*****@*****.**> Exp $ */ // script para eliminar el script de vacaciones si ya se ha pasado el periodo de vacaciones $module_name = "vacations"; $module_name2 = "antispam"; $elxPath = "/usr/share/elastix"; ini_set('include_path', "{$elxPath}:" . ini_get('include_path')); include_once "libs/misc.lib.php"; include_once "configs/default.conf.php"; include_once "libs/paloSantoDB.class.php"; include_once "configs/email.conf.php"; include_once "apps/vacations/libs/paloVacation.class.php"; include_once "apps/antispam/libs/paloSantoAntispam.class.php"; load_default_timezone(); $pDB = new paloDB($arrConf['elastix_dsn']['elastix']); $pVacations = new paloVacation($pDB); $objAntispam = new paloSantoAntispam("", "", "", ""); // obteniendo todas las cuentas de correos con el script de vacaciones activado. $emails = $pVacations->getEmailsVacationON(); $timestamp1 = mktime(0, 0, 0, date("m"), date("d"), date("Y")); if (count($emails) > 0 && is_array($emails) > 0) { foreach ($emails as $key => $value) { $id = $value['id']; $id_user = $value['id_user']; $email = $value['account']; $subject = $value['subject']; $body = $value['body']; $ini_date = $value['ini_date']; $end_date = $value['end_date']; $day_ini = date("d", strtotime($ini_date)); $month_ini = date("m", strtotime($ini_date)); $year_ini = date("Y", strtotime($ini_date));
function disactivateEmailVacations($smarty, $module_name, $local_templates_dir, &$pDB, &$pDBACL, $arrConf, $arrLang) { $pVacations = new paloSantoVacations($pDB); $pACL = new paloACL($pDBACL); $objAntispam = new paloSantoAntispam($arrConf['path_postfix'], $arrConf['path_spamassassin'], $arrConf['file_master_cf'], $arrConf['file_local_cf']); $arrFormVacations = createFieldForm($arrLang); $oForm = new paloForm($smarty, $arrFormVacations); $id = getParameter("id"); $email = getParameter("email"); $subject = getParameter("subject"); $body = getParameter("body"); $ini_date = getParameter("ini_date"); $end_date = getParameter("end_date"); $result = ""; $userAccount = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $idUserInt = $pACL->getIdUser($userAccount); $emails = $pVacations->getAccountByIdUser($idUserInt, $pDBACL); if (!$oForm->validateForm($_POST)) { // Falla la validación básica del formulario $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>"; $arrErrores = $oForm->arrErroresValidacion; if (is_array($arrErrores) && count($arrErrores) > 0) { foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> "; } } $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", $strErrorMsg); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } if (!preg_match("/^[a-z0-9]+([\\._\\-]?[a-z0-9]+[_\\-]?)*@[a-z0-9]+([\\._\\-]?[a-z0-9]+)*(\\.[a-z0-9]{2,6})+\$/", $email)) { $smarty->assign("mb_title", _tr("Error")); $smarty->assign("mb_message", _tr('Email is empty or is not correct. Please write the email account.')); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } if ($email != $emails) { if (!$pACL->isUserAdministratorGroup($userAccount)) { $smarty->assign("mb_title", _tr("Error")); $smarty->assign("mb_message", _tr('Email is not correct. Please write the email assigned to your elastix account.')); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } } $timestamp0 = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $timestamp1 = mktime(0, 0, 0, date("m", strtotime($ini_date)), date("d", strtotime($ini_date)), date("Y", strtotime($ini_date))); $timestamp2 = mktime(0, 0, 0, date("m", strtotime($end_date)), date("d", strtotime($end_date)), date("Y", strtotime($end_date))); $timeSince = $timestamp0 - $timestamp1; //resto a una fecha la otra $seconds = $timestamp2 - $timestamp1; $dias = $seconds / (60 * 60 * 24); $dias = floor($dias); $smarty->assign("num_days", $dias); if ($seconds < 0) { $smarty->assign("mb_title", _tr("Alert")); $smarty->assign("mb_message", _tr("End date should be greater than the initial date")); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } $statusSieve = $pVacations->verifySieveStatus($arrLang); if (!$statusSieve['response']) { $smarty->assign("mb_title", _tr("Alert")); $smarty->assign("mb_message", $statusSieve['message']); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } $pDB->beginTransaction(); $scripts = $objAntispam->existScriptSieve($email, "scriptTest.sieve"); $spamCapture = false; // si CapturaSpam=OFF y Vacations=OFF if ($scripts['actived'] != "") { // hay un script activo if (preg_match("/vacations.sieve/", $scripts['actived']) && $scripts['status']) { // si CapturaSpam=? y Vacations=ON $spamCapture = true; } // si CapturaSpam=ON y Vacations=OFF $band = $pVacations->existMessage($email); $res = ""; if ($band) { //actualizacion $arr_Vaca = $pVacations->getMessageVacationByUser($email); if (count($arr_Vaca) > 1) { $pVacations->deleteMessagesByUser($email, $subject, $body, $ini_date, $end_date); $res = $pVacations->insertMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } else { $res = $pVacations->updateMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } } else { // insersion $res = $pVacations->insertMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } if ($res) { if ($timeSince >= 0) { $result = $pVacations->deleteVacationScript($email, $objAntispam, $spamCapture, $arrLang); } else { $result = true; } } else { $result = false; } } if ($result) { $pDB->commit(); $smarty->assign("mb_message", _tr("Email's Vacations have been disabled")); } else { $msgError = $pVacations->errMsg; $pDB->rollBack(); $smarty->assign("mb_message", $msgError); } return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); }