function emailAccountsDeleteCallback($id) { global $cyrus_used; global $pro_mysql_pop_table; global $pro_mysql_fetchmail_table; triggerMXListUpdate(); updateUsingCron("gen_qmail='yes', qmail_newu='yes'"); $q = "SELECT id, mbox_host, home FROM {$pro_mysql_pop_table} WHERE autoinc='{$id}';"; $r = mysql_query($q) or die("Cannot query {$q} line: " . __LINE__ . " file " . __FILE__ . " sql said:" . mysql_error()); $n = mysql_num_rows($r); if ($n != 1) { die("Cannot find created email line " . __LINE__ . " file " . __FILE__); } $v = mysql_fetch_array($r); if ($cyrus_used) { # login to cyradm $cyr_conn = new cyradm(); $error = $cyr_conn->imap_login(); if ($error != 0) { die("imap_login Error {$error}"); } $result = $cyr_conn->deletemb("user/" . $v["id"] . "@" . $v["mbox_host"]); } $cmd = "rm -rf " . $v["home"]; exec($cmd, $exec_out, $return_val); $q = "DELETE FROM {$pro_mysql_fetchmail_table} WHERE domain_user='******' AND domain_name='" . $v["mbox_host"] . "';"; $r = mysql_query($q) or die("Cannot query {$q} line: " . __LINE__ . " file " . __FILE__ . " sql said:" . mysql_error()); updateUsingCron("qmail_newu='yes',restart_qmail='yes',gen_qmail='yes'"); return ""; }
ini_set('include_path', "{$elxPath}:" . ini_get('include_path')); // script que se encarga de eliminar los mensajes viaejos de las carpetas de spam require_once 'libs/misc.lib.php'; include_once "configs/email.conf.php"; include_once "libs/cyradm.php"; $days = trim($_SERVER['argv'][1]); if (isset($days) & $days != "") { // Para silenciar avisos de fecha/hora if (function_exists('date_default_timezone_get')) { load_default_timezone(); } $today = date("d-M-Y"); $sinceDate = date("d-M-Y", strtotime($today . " -{$days} day")); //realizamos la coneccion con cyrus global $CYRUS; $cyr_conn = new cyradm(); $error_msg = ""; $error = $cyr_conn->imap_login(); if ($error === FALSE) { wlog("IMAP login error: {$error} <br>"); exit(1); } //verificamos si el antispam esta activado exec("/etc/init.d/spamassassin status", $flag, $status); if ($status == 0) { //obtenemos las listas de correos $accounts = getListMailbox(); if ($accounts != false) { foreach ($accounts as $email) { deleteSpamMessages(&$cyr_conn, $email, $sinceDate); }
function obtener_quota_usuario($username, $module_name) { include_once "configs/email.conf.php"; include_once "libs/cyradm.php"; global $CYRUS; global $arrPermission; $cyr_conn = new cyradm(); $cyr_conn->imap_login(); $edit_quota = _tr("Edit quota"); $quota = $cyr_conn->getquota("user/" . $username); $tamano_usado = _tr("Could not query used disc space"); if (is_array($quota) && count($quota) > 0) { if ($quota['used'] != "NOT-SET") { $q_used = $quota['used']; $q_total = $quota['qmax']; if (!$q_total == 0) { $q_percent = number_format(100 * $q_used / $q_total, 2); $q_usada = $q_used < 1024 ? "{$q_used} KB" : $q_used / 1024 . " MB "; $q_total = $q_total < 1024 ? "{$q_total} KB" : $q_total / 1024 . " MB "; /*if(in_array('edit_user',$arrPermission)){ $tamano_usado=" $q_usada / <a href='#' onclick=changes_email_quota('$username') title='$edit_quota'> $q_total </a> ($q_percent%)"; }else*/ $tamano_usado = " {$q_usada} / {$q_total} ({$q_percent}%)"; } else { $tamano_usado = _tr("Could not obtain used disc space"); } } else { $tamano_usado = _tr("Size is not set"); } } return $tamano_usado; }
/** * Actualizar la cuota del usuario indicado, tanto en cyrus como en la DB. * * @param string $username Correo completo usuario@dominio.com * @param int $newquota Nueva cuota de correo a asignar * * @return bool VERDADERO en caso de éxito, FALSO en caso de error. */ function setAccountQuota($username, $newquota) { $this->errMsg = ''; $bPostfixElastix2 = isPostfixToElastix2(); $regexp = $bPostfixElastix2 ? '/^[a-z0-9]+([\\._\\-]?[a-z0-9]+[_\\-]?)*@[a-z0-9]+([\\._\\-]?[a-z0-9]+)*(\\.[a-z0-9]{2,6})+$/' : '/^([a-z0-9]+([\\._\\-]?[a-z0-9]+[_\\-]?)*)$/'; if (!preg_match($regexp, $username)) { $this->errMsg = _tr('Username is not valid'); return FALSE; } $cyr_conn = new cyradm(); if (!$cyr_conn->imap_login()) { $this->errMsg = _tr('Failed to login to IMAP'); return NULL; } $this->_DB->beginTransaction(); $sPeticionSQL = 'UPDATE accountuser SET quota = ? WHERE username = ?'; $bExito = $this->_DB->genQuery($sPeticionSQL, array($newquota, $username)); if (!$bExito) { $this->errMsg = $this->_DB->errMsg; } else { $bExito = $cyr_conn->setmbquota('user/' . $username, $newquota); if (!$bExito) { $this->errMsg = $cyr_conn->getMessage(); } } if ($bExito) { $this->_DB->commit(); } else { $this->_DB->rollback(); } $cyr_conn->imap_logout(); return $bExito; }
function updateQuota($old_quota, $quota, $username) { $bExito = true; if (!preg_match('/^[[:digit:]]+$/', "{$old_quota}")) { $this->errMsg = _tr("Quota must be numeric"); $bExito = false; } elseif (!preg_match('/^[[:digit:]]+$/', "{$quota}")) { $this->errMsg = _tr("Quota must be numeric"); $bExito = false; } if ($old_quota != $quota) { $cyr_conn = new cyradm(); $cyr_conn->imap_login(); $bContinuar = $cyr_conn->setmbquota("user" . "/" . $username, $quota); if (!$bContinuar) { $this->errMsg = _tr("Quota could not be changed.") . " " . $cyr_conn->getMessage(); $bExito = FALSE; } } return $bExito; }
#!/usr/bin/env php <?php $base_path = dirname(__FILE__); if ($_SERVER["argc"] < 1) { print "Syntax Error: " . $_SERVER["argv"][0] . " <root domain>\n"; exit; } $root_domain = $_SERVER["argv"][1]; require $base_path . '/../../shared/cyradm.php'; require $base_path . '/../../shared/cyrus.php'; # login to cyradm $cyr_conn = new cyradm(); $error = $cyr_conn->imap_login(); if ($error != 0) { die("imap_login Error {$error}"); } $result = $cyr_conn->createmb("user/root" . "@" . $root_domain);
function deleteSpamMessages($email, $dateSince) { global $CYRUS; $cyr_conn = new cyradm(); $error_msg = ""; $error = $cyr_conn->imap_login(); $dataEmail = explode("@", $email); if ($error === FALSE) { $error_msg = "IMAP login error: {$error} <br>"; } else { $seperator = '/'; $bValido = $cyr_conn->command(". select \"user" . $seperator . $dataEmail[0] . $seperator . "Spam@" . $dataEmail[1] . "\""); if (!$bValido) { $error_msg = "Error selected Spam folder:" . $cyr_conn->getMessage() . "<br>"; } else { $bValido = $cyr_conn->command(". SEARCH NOT SINCE {$dateSince}"); // busca los email que no empiecen desde la fecha dada if (!$bValido) { $error_msg = "error cannot be added flags Deleted to the messages of Spam folder for {$email}:" . $cyr_conn->getMessage() . "<br>"; } else { $sal = explode("SEARCH", $bValido[0]); $uids = trim($sal[1]); //ids de mensajes if ($uids != "") { //$bValido=$cyr_conn->command(". store 1:* +flags \Deleted"); $uids = trim($uids); $uids = str_replace(" ", ",", $uids); if (strlen($uids) > 100) { $arrID = explode(",", "{$uids}"); $size = count($arrID); $limitID = $arrID[0] . ":" . $arrID[$size - 1]; $bValido = $cyr_conn->command(". store {$limitID} +flags \\Deleted"); } else { $bValido = $cyr_conn->command(". store {$uids} +flags \\Deleted"); } // messages $uids = 1 2 4 5 7 8 if (!$bValido) { $error_msg = "error cannot be deleted the messages of Spam folder for {$email}:" . $cyr_conn->getMessage() . "<br>"; } else { $bValido = $cyr_conn->command(". expunge"); if (!$bValido) { $error_msg = "error cannot be deleted the messages of Spam folder for {$email}:" . $cyr_conn->getMessage() . "<br>"; } /*else{ $bValido=$cyr_conn->command(". noop"); if(!$bValido) $error_msg = "error cannot be deleted the messages of Spam folder for $email:".$cyr_conn->getMessage()."<br>"; }*/ } } } } $cyr_conn->imap_logout(); } return $error_msg; }