function save($id, $vars, &$errors) { global $cfg; //very basic checks if ($id && $id != $vars['email_id']) { $errors['err'] = 'Internal error.'; } if (!$vars['email'] || !Validator::is_email($vars['email'])) { $errors['email'] = 'Valid email required'; } elseif (($eid = Email::getIdByEmail($vars['email'])) && $eid != $id) { $errors['email'] = 'Email already exits'; } elseif (!strcasecmp($cfg->getAdminEmail(), $vars['email'])) { $errors['email'] = 'Email already used as admin email!'; } else { //make sure the email doesn't belong to any of the staff $sql = 'SELECT staff_id FROM ' . STAFF_TABLE . ' WHERE email=' . db_input($vars['email']); if (($res = db_query($sql)) && db_num_rows($res)) { $errors['email'] = 'Email in-use by a staff member'; } } if (!$vars['dept_id'] || !is_numeric($vars['dept_id'])) { $errors['dept_id'] = 'You must select a Dept.'; } if (!$vars['priority_id']) { $errors['priority_id'] = 'You must select a priority'; } if ($vars['mail_active'] || $vars['smtp_active'] && $vars['smtp_auth']) { if (!$vars['userid']) { $errors['userid'] = 'Username missing'; } if (!$vars['userpass']) { $errors['userpass'] = '******'; } } if ($vars['mail_active']) { //Check pop/imapinfo only when enabled. if (!function_exists('imap_open')) { $errors['mail_active'] = 'IMAP doesn\'t exist. PHP must be compiled with IMAP enabled.'; } if (!$vars['mail_host']) { $errors['mail_host'] = 'Host name required'; } if (!$vars['mail_port']) { $errors['mail_port'] = 'Port required'; } if (!$vars['mail_protocol']) { $errors['mail_protocol'] = 'Select protocol'; } if (!$vars['mail_fetchfreq'] || !is_numeric($vars['mail_fetchfreq'])) { $errors['mail_fetchfreq'] = 'Fetch interval required'; } if (!$vars['mail_fetchmax'] || !is_numeric($vars['mail_fetchmax'])) { $errors['mail_fetchmax'] = 'Maximum emails required'; } } if ($vars['smtp_active']) { if (!$vars['smtp_host']) { $errors['smtp_host'] = 'Host name required'; } if (!$vars['smtp_port']) { $errors['smtp_port'] = 'Port required'; } } if (!$errors && ($vars['mail_host'] && $vars['userid'])) { $sql = 'SELECT email_id FROM ' . EMAIL_TABLE . ' WHERE mail_host=' . db_input($vars['mail_host']) . ' AND userid=' . db_input($vars['userid']); if ($id) { $sql .= ' AND email_id!=' . db_input($id); } if (db_num_rows(db_query($sql))) { $errors['userid'] = $errors['host'] = 'Another department using host/username combination.'; } } if (!$errors && $vars['mail_active']) { //note: password is unencrypted at this point...MailFetcher expect plain text. $fetcher = new MailFetcher($vars['userid'], $vars['userpass'], $vars['mail_host'], $vars['mail_port'], $vars['mail_protocol'], $vars['mail_encryption']); if (!$fetcher->connect()) { $errors['userpass'] = '******' . $vars['mail_protocol'] . ' settings'; $errors['mail'] = '<br>' . $fetcher->getLastError(); } } if (!$errors && $vars['smtp_active']) { //Check SMTP login only. require_once 'Mail.php'; // PEAR Mail package $smtp = mail::factory('smtp', array('host' => $vars['smtp_host'], 'port' => $vars['smtp_port'], 'auth' => $vars['smtp_auth'] ? true : false, 'username' => $vars['userid'], 'password' => $vars['userpass'], 'timeout' => 20, 'debug' => false)); $mail = $smtp->connect(); if (PEAR::isError($mail)) { $errors['userpass'] = '******'; $errors['smtp'] = '<br>' . $mail->getMessage(); } else { $smtp->disconnect(); //Thank you, sir! } } if (!$errors) { $sql = 'updated=NOW(),mail_errors=0, mail_lastfetch=NULL' . ',email=' . db_input($vars['email']) . ',name=' . db_input(Format::striptags($vars['name'])) . ',dept_id=' . db_input($vars['dept_id']) . ',priority_id=' . db_input($vars['priority_id']) . ',noautoresp=' . db_input(isset($vars['noautoresp']) ? 1 : 0) . ',userid=' . db_input($vars['userid']) . ',userpass='******'userpass'], SECRET_SALT)) . ',mail_active=' . db_input($vars['mail_active']) . ',mail_host=' . db_input($vars['mail_host']) . ',mail_protocol=' . db_input($vars['mail_protocol'] ? $vars['mail_protocol'] : 'POP') . ',mail_encryption=' . db_input($vars['mail_encryption']) . ',mail_port=' . db_input($vars['mail_port'] ? $vars['mail_port'] : 0) . ',mail_fetchfreq=' . db_input($vars['mail_fetchfreq'] ? $vars['mail_fetchfreq'] : 0) . ',mail_fetchmax=' . db_input($vars['mail_fetchmax'] ? $vars['mail_fetchmax'] : 0) . ',mail_delete=' . db_input(isset($vars['mail_delete']) ? $vars['mail_delete'] : 0) . ',smtp_active=' . db_input($vars['smtp_active']) . ',smtp_host=' . db_input($vars['smtp_host']) . ',smtp_port=' . db_input($vars['smtp_port'] ? $vars['smtp_port'] : 0) . ',smtp_auth=' . db_input($vars['smtp_auth']); if ($id) { //update $sql = 'UPDATE ' . EMAIL_TABLE . ' SET ' . $sql . ' WHERE email_id=' . db_input($id); if (!db_query($sql) || !db_affected_rows()) { $errors['err'] = 'Unable to update email. Internal error occured'; } } else { $sql = 'INSERT INTO ' . EMAIL_TABLE . ' SET ' . $sql . ',created=NOW()'; if (!db_query($sql) or !($emailID = db_insert_id())) { $errors['err'] = 'Unable to add email. Internal error'; } else { return $emailID; } //newly created email. } } else { $errors['err'] = 'Error(s) Occured. Try again'; } return $errors ? FALSE : TRUE; }
} if (!$errors) { //update version. db_query('UPDATE ' . CONFIG_TABLE . ' SET ostversion=' . db_input('1.6 RC5')); //API keys $ips = array_filter(explode(',', ereg_replace(' ', '', $vars['api_whitelist']))); foreach ($ips as $ip) { $sql = 'INSERT INTO ' . PREFIX . 'api_key SET created=NOW(), updated=NOW(), isactive=1 ' . ',ipaddr=' . db_input($ip) . ',apikey=' . db_input(strtoupper(md5($ip . md5($vars['api_key'])))); db_query($sql); } //get pop info into the improved table. $sql = 'SELECT pop3.* FROM ' . PREFIX . 'email email INNER JOIN ' . PREFIX . 'email_pop3 pop3 USING(email_id)'; if (($result = db_query($sql)) && db_num_rows($result)) { //We are disabling mail fetching on purpose while ($row = db_fetch_array($result)) { $sql = 'UPDATE ' . EMAIL_TABLE . ' SET updated=NOW(), mail_protocol="POP",mail_encryption="NONE",mail_port=110,mail_active=0 ' . ',mail_host=' . db_input($row['pophost']) . ',mail_fetchfreq=' . db_input($row['fetchfreq']) . ',mail_delete=' . db_input($row['delete_msgs']) . ',userid=' . db_input($row['popuser']) . ',userpass='******'poppasswd'] ? Misc::encrypt($row['poppasswd'], SECRET_SALT) : '') . ' WHERE email_id=' . db_input($row['email_id']); db_query($sql); } } $deptId = $vars['default_dept'] ? $vars['default_dept'] : 1; //Default dept. //Move alert and noreply emails to email table. $sql = 'INSERT INTO ' . PREFIX . 'email SET created=NOW(), updated=NOW(), priority_id=2 ' . ',dept_id=' . db_input($deptId) . ',name=' . db_input('osTicket Alerts') . ',email=' . db_input($vars['alert_email']); if (db_query($sql) && ($alertId = db_insert_id())) { db_query('UPDATE ' . PREFIX . 'config SET alert_email_id=' . db_input($alertId)); } $sql = 'INSERT INTO ' . PREFIX . 'email SET created=NOW(), updated=NOW(), priority_id=2 ' . ',dept_id=' . db_input($deptId) . ',name=' . db_input('') . ',email=' . db_input($vars['noreply_email']); if (db_query($sql) && ($noreplyId = db_insert_id())) { db_query('UPDATE ' . PREFIX . 'department SET autoresp_email_id=' . db_input($noreplyId) . ' WHERE noreply_autoresp=1'); } //Url path & variables changes on templates.
$sql='INSERT INTO '.PREFIX.'api_key SET created=NOW(), updated=NOW(), isactive=1 '. ',ipaddr='.db_input($ip). ',apikey='.db_input(strtoupper(md5($ip.md5($vars['api_key'])))); db_query($sql); } //get pop info into the improved table. $sql='SELECT pop3.* FROM '.PREFIX.'email email INNER JOIN '.PREFIX.'email_pop3 pop3 USING(email_id)'; if(($result=db_query($sql)) && db_num_rows($result)) { //We are disabling mail fetching on purpose while($row=db_fetch_array($result)) { $sql='UPDATE '.EMAIL_TABLE.' SET updated=NOW(), mail_protocol="POP",mail_encryption="NONE",mail_port=110,mail_active=0 '. ',mail_host='.db_input($row['pophost']). ',mail_fetchfreq='.db_input($row['fetchfreq']). ',mail_delete='.db_input($row['delete_msgs']). ',userid='.db_input($row['popuser']). ',userpass='******'poppasswd']?Misc::encrypt($row['poppasswd'],SECRET_SALT):''). ' WHERE email_id='.db_input($row['email_id']); db_query($sql); } } $deptId=$vars['default_dept']?$vars['default_dept']:1; //Default dept. //Move alert and noreply emails to email table. $sql='INSERT INTO '.PREFIX.'email SET created=NOW(), updated=NOW(), priority_id=2 '. ',dept_id='.db_input($deptId).',name='.db_input('osTicket Alerts').',email='.db_input($vars['alert_email']); if(db_query($sql) && ($alertId=db_insert_id())) db_query('UPDATE '.PREFIX.'config SET alert_email_id='.db_input($alertId)); $sql='INSERT INTO '.PREFIX.'email SET created=NOW(), updated=NOW(), priority_id=2 '. ',dept_id='.db_input($deptId).',name='.db_input('').',email='.db_input($vars['noreply_email']);
function save($id, $vars, &$errors) { global $cfg; //very basic checks if ($id && $id != $vars['email_id']) { $errors['err'] = 'Erro interno.'; } if (!$vars['email'] || !Validator::is_email($vars['email'])) { $errors['email'] = 'Email válido obrigatório'; } elseif (($eid = Email::getIdByEmail($vars['email'])) && $eid != $id) { $errors['email'] = 'Email já existe.'; } elseif (!strcasecmp($cfg->getAdminEmail(), $vars['email'])) { $errors['email'] = 'Email já usado como email do administrador!'; } else { //make sure the email doesn't belong to any of the staff $sql = 'SELECT staff_id FROM ' . STAFF_TABLE . ' WHERE email=' . db_input($vars['email']); if (($res = db_query($sql)) && db_num_rows($res)) { $errors['email'] = 'Email em uso por um membro do suporte.'; } } if (!$vars['dept_id'] || !is_numeric($vars['dept_id'])) { $errors['dept_id'] = 'Você deve selecionar um departamento.'; } if (!$vars['priority_id']) { $errors['priority_id'] = 'Você deve selecionar uma prioridade'; } if ($vars['mail_active'] || $vars['smtp_active'] && $vars['smtp_auth']) { if (!$vars['userid']) { $errors['userid'] = 'Nome de usuário ausente'; } if (!$vars['userpass']) { $errors['userpass'] = '******'; } } if ($vars['mail_active']) { //Check pop/imapinfo only when enabled. if (!function_exists('imap_open')) { $errors['mail_active'] = 'IMAP não existe. PHP deve ser compilado com IMAP habilitado.'; } if (!$vars['mail_host']) { $errors['mail_host'] = 'Nome do host obrigatório'; } if (!$vars['mail_port']) { $errors['mail_port'] = 'Porta obrigatória'; } if (!$vars['mail_protocol']) { $errors['mail_protocol'] = 'Selecione protocolo'; } if (!$vars['mail_fetchfreq'] || !is_numeric($vars['mail_fetchfreq'])) { $errors['mail_fetchfreq'] = 'Buscar intervalo obrigatório'; } if (!$vars['mail_fetchmax'] || !is_numeric($vars['mail_fetchmax'])) { $errors['mail_fetchmax'] = 'Máximo de emails exigidos'; } } if ($vars['smtp_active']) { if (!$vars['smtp_host']) { $errors['smtp_host'] = 'Nome do host obrigatório'; } if (!$vars['smtp_port']) { $errors['smtp_port'] = 'Porta obrigatória'; } } if (!$errors && ($vars['mail_host'] && $vars['userid'])) { $sql = 'SELECT email_id FROM ' . EMAIL_TABLE . ' WHERE mail_host=' . db_input($vars['mail_host']) . ' AND userid=' . db_input($vars['userid']); if ($id) { $sql .= ' AND email_id!=' . db_input($id); } if (db_num_rows(db_query($sql))) { $errors['userid'] = $errors['host'] = 'Outro departamento está usando combinação de nome/host.'; } } if (!$errors && $vars['mail_active']) { //note: password is unencrypted at this point...MailFetcher expect plain text. $fetcher = new MailFetcher($vars['userid'], $vars['userpass'], $vars['mail_host'], $vars['mail_port'], $vars['mail_protocol'], $vars['mail_encryption']); if (!$fetcher->connect()) { $errors['userpass'] = '******' . $vars['mail_protocol'] . ' configurações'; $errors['mail'] = '<br>' . $fetcher->getLastError(); } } if (!$errors && $vars['smtp_active']) { //Check SMTP login only. require_once 'Mail.php'; // PEAR Mail package $smtp = mail::factory('smtp', array('host' => $vars['smtp_host'], 'port' => $vars['smtp_port'], 'auth' => $vars['smtp_auth'] ? true : false, 'username' => $vars['userid'], 'password' => $vars['userpass'], 'timeout' => 20, 'debug' => false)); $mail = $smtp->connect(); if (PEAR::isError($mail)) { $errors['userpass'] = '******'; $errors['smtp'] = '<br>' . $mail->getMessage(); } else { $smtp->disconnect(); //Thank you, sir! } } if (!$errors) { $sql = 'updated=NOW(),mail_errors=0, mail_lastfetch=NULL' . ',email=' . db_input($vars['email']) . ',name=' . db_input(Format::striptags($vars['name'])) . ',dept_id=' . db_input($vars['dept_id']) . ',priority_id=' . db_input($vars['priority_id']) . ',noautoresp=' . db_input(isset($vars['noautoresp']) ? 1 : 0) . ',userid=' . db_input($vars['userid']) . ',userpass='******'userpass'], SECRET_SALT)) . ',mail_active=' . db_input($vars['mail_active']) . ',mail_host=' . db_input($vars['mail_host']) . ',mail_protocol=' . db_input($vars['mail_protocol'] ? $vars['mail_protocol'] : 'POP') . ',mail_encryption=' . db_input($vars['mail_encryption']) . ',mail_port=' . db_input($vars['mail_port'] ? $vars['mail_port'] : 0) . ',mail_fetchfreq=' . db_input($vars['mail_fetchfreq'] ? $vars['mail_fetchfreq'] : 0) . ',mail_fetchmax=' . db_input($vars['mail_fetchmax'] ? $vars['mail_fetchmax'] : 0) . ',mail_delete=' . db_input(isset($vars['mail_delete']) ? $vars['mail_delete'] : 0) . ',smtp_active=' . db_input($vars['smtp_active']) . ',smtp_host=' . db_input($vars['smtp_host']) . ',smtp_port=' . db_input($vars['smtp_port'] ? $vars['smtp_port'] : 0) . ',smtp_auth=' . db_input($vars['smtp_auth']); if ($id) { //update $sql = 'UPDATE ' . EMAIL_TABLE . ' SET ' . $sql . ' WHERE email_id=' . db_input($id); if (!db_query($sql) || !db_affected_rows()) { $errors['err'] = 'Não é possível atualizar e-mail. Erro interno'; } } else { $sql = 'INSERT INTO ' . EMAIL_TABLE . ' SET ' . $sql . ',created=NOW()'; if (!db_query($sql) or !($emailID = db_insert_id())) { $errors['err'] = 'Não é possível adicionar e-mail. Erro interno'; } else { return $emailID; } //newly created email. } } else { $errors['err'] = 'Erro(s). Tente novamente'; } return $errors ? FALSE : TRUE; }
function save($id, $vars, &$errors) { global $cfg; //very basic checks if ($id && $id != $vars['email_id']) { $errors['err'] = 'Error Interno.'; } if (!$vars['email'] || !Validator::is_email($vars['email'])) { $errors['email'] = 'Se Requiere un Email Valido'; } elseif (($eid = Email::getIdByEmail($vars['email'])) && $eid != $id) { $errors['email'] = 'Este Email ya existe'; } elseif (!strcasecmp($cfg->getAdminEmail(), $vars['email'])) { $errors['email'] = 'Este Email ya se esta usando en la cuenta de Administrador'; } else { //make sure the email doesn't belong to any of the staff $sql = 'SELECT staff_id FROM ' . STAFF_TABLE . ' WHERE email=' . db_input($vars['email']); if (($res = db_query($sql)) && db_num_rows($res)) { $errors['email'] = 'Este Email ya se esta usando por un miembro del Staff'; } } if (!$vars['dept_id'] || !is_numeric($vars['dept_id'])) { $errors['dept_id'] = 'Debes seleccionar un Departamento'; } if (!$vars['priority_id']) { $errors['priority_id'] = 'Debes seleccionar prioridad'; } if ($vars['mail_active'] || $vars['smtp_active'] && $vars['smtp_auth']) { if (!$vars['userid']) { $errors['userid'] = 'Falta nombre de Usuario'; } if (!$vars['userpass']) { $errors['userpass'] = '******'; } } if ($vars['mail_active']) { //Check pop/imapinfo only when enabled. if (!function_exists('imap_open')) { $errors['mail_active'] = 'IMAP no existe. PHP debe ser compilado con IMAP.'; } if (!$vars['mail_host']) { $errors['mail_host'] = 'Se requiere nombre del Host'; } if (!$vars['mail_port']) { $errors['mail_port'] = 'Se requiere numero de Puerto'; } if (!$vars['mail_protocol']) { $errors['mail_protocol'] = 'Selecciona Protocolo'; } if (!$vars['mail_fetchfreq'] || !is_numeric($vars['mail_fetchfreq'])) { $errors['mail_fetchfreq'] = 'Se requiere frecuencia de captura'; } if (!$vars['mail_fetchmax'] || !is_numeric($vars['mail_fetchmax'])) { $errors['mail_fetchmax'] = 'Se requiere numero máximo de correos por captura'; } } if ($vars['smtp_active']) { if (!$vars['smtp_host']) { $errors['smtp_host'] = 'Se requiere nombre del Host'; } if (!$vars['smtp_port']) { $errors['smtp_port'] = 'Se requiere numero de puerto'; } } if (!$errors && ($vars['mail_host'] && $vars['userid'])) { $sql = 'SELECT email_id FROM ' . EMAIL_TABLE . ' WHERE mail_host=' . db_input($vars['mail_host']) . ' AND userid=' . db_input($vars['userid']); if ($id) { $sql .= ' AND email_id!=' . db_input($id); } if (db_num_rows(db_query($sql))) { $errors['userid'] = $errors['host'] = 'La combinacion Host/Nombre de usuario ya esta en uso por otro departamento.'; } } if (!$errors && $vars['mail_active']) { //note: password is unencrypted at this point...MailFetcher expect plain text. $fetcher = new MailFetcher($vars['userid'], $vars['userpass'], $vars['mail_host'], $vars['mail_port'], $vars['mail_protocol'], $vars['mail_encryption']); if (!$fetcher->connect()) { $errors['userpass'] = '******' . $vars['mail_protocol'] . ''; $errors['mail'] = '<br>' . $fetcher->getLastError(); } } if (!$errors && $vars['smtp_active']) { //Check SMTP login only. require_once 'Mail.php'; // PEAR Mail package $smtp = mail::factory('smtp', array('host' => $vars['smtp_host'], 'port' => $vars['smtp_port'], 'auth' => $vars['smtp_auth'] ? true : false, 'username' => $vars['userid'], 'password' => $vars['userpass'], 'timeout' => 20, 'debug' => false)); $mail = $smtp->connect(); if (PEAR::isError($mail)) { $errors['userpass'] = '******'; $errors['smtp'] = '<br>' . $mail->getMessage(); } else { $smtp->disconnect(); //Thank you, sir! } } if (!$errors) { $sql = 'updated=NOW(),mail_errors=0, mail_lastfetch=NULL' . ',email=' . db_input($vars['email']) . ',name=' . db_input(Format::striptags($vars['name'])) . ',dept_id=' . db_input($vars['dept_id']) . ',priority_id=' . db_input($vars['priority_id']) . ',noautoresp=' . db_input(isset($vars['noautoresp']) ? 1 : 0) . ',userid=' . db_input($vars['userid']) . ',userpass='******'userpass'], SECRET_SALT)) . ',mail_active=' . db_input($vars['mail_active']) . ',mail_host=' . db_input($vars['mail_host']) . ',mail_protocol=' . db_input($vars['mail_protocol'] ? $vars['mail_protocol'] : 'POP') . ',mail_encryption=' . db_input($vars['mail_encryption']) . ',mail_port=' . db_input($vars['mail_port'] ? $vars['mail_port'] : 0) . ',mail_fetchfreq=' . db_input($vars['mail_fetchfreq'] ? $vars['mail_fetchfreq'] : 0) . ',mail_fetchmax=' . db_input($vars['mail_fetchmax'] ? $vars['mail_fetchmax'] : 0) . ',mail_delete=' . db_input(isset($vars['mail_delete']) ? $vars['mail_delete'] : 0) . ',smtp_active=' . db_input($vars['smtp_active']) . ',smtp_host=' . db_input($vars['smtp_host']) . ',smtp_port=' . db_input($vars['smtp_port'] ? $vars['smtp_port'] : 0) . ',smtp_auth=' . db_input($vars['smtp_auth']); if ($id) { //update $sql = 'UPDATE ' . EMAIL_TABLE . ' SET ' . $sql . ' WHERE email_id=' . db_input($id); if (!db_query($sql) || !db_affected_rows()) { $errors['err'] = 'No se a podido actualizar el Email, Error interno'; } } else { $sql = 'INSERT INTO ' . EMAIL_TABLE . ' SET ' . $sql . ',created=NOW()'; if (!db_query($sql) or !($emailID = db_insert_id())) { $errors['err'] = 'No se a podido añadir el Email, Error interno '; } else { return $emailID; } //newly created email. } } else { $errors['err'] = 'Se an producido Errores, intentelo de nuevo'; } return $errors ? FALSE : TRUE; }