/** * 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 emailAccountsEditCallback($id) { global $cyrus_used; global $pro_mysql_pop_table; $q = "SELECT * 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__); } $a = mysql_fetch_array($r); $crypted_pass = crypt($a["passwd"], dtc_makesalt()); $q = "UPDATE {$pro_mysql_pop_table} SET crypt='{$crypted_pass}',quota_couriermaildrop=CONCAT(1024000*quota_size,'S,',quota_files,'C') WHERE autoinc='{$id}';"; $r = mysql_query($q) or die("Cannot query {$q} line: " . __LINE__ . " file " . __FILE__ . " sql said:" . mysql_error()); if (!$cyrus_used) { writeDotQmailFile($a["id"], $a["mbox_host"]); } updateUsingCron("gen_qmail='yes', qmail_newu='yes'"); if ($cyrus_used) { // login to cyradm $cyr_conn = new cyradm(); $error = $cyr_conn->imap_login(); if ($error != 0) { die("imap_login Error {$error}"); } if (!$a["quota_size"]) { die("invalid quota"); } $result = $cyr_conn->setmbquota("user/" . $a["fullemail"], $a["quota_size"]); } return ""; }
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; }