Exemplo n.º 1
1
 public static function run()
 {
     spl_autoload_register(['Bootstrap', 'autoload']);
     putenv('LANG=en_US.UTF-8');
     setlocale(LC_CTYPE, 'en_US.UTF-8');
     date_default_timezone_set(@date_default_timezone_get());
     session_start();
     $session = new Session($_SESSION);
     $request = new Request($_REQUEST);
     $setup = new Setup($request->query_boolean('refresh', false));
     $context = new Context($session, $request, $setup);
     if ($context->is_api_request()) {
         (new Api($context))->apply();
     } else {
         if ($context->is_info_request()) {
             $public_href = $setup->get('PUBLIC_HREF');
             $x_head_tags = $context->get_x_head_html();
             require __DIR__ . '/pages/info.php';
         } else {
             $public_href = $setup->get('PUBLIC_HREF');
             $x_head_tags = $context->get_x_head_html();
             $fallback_html = (new Fallback($context))->get_html();
             require __DIR__ . '/pages/index.php';
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Get database config.
  * load it from setup, fall back to legacy config.php constants
  *
  * @return array
  */
 public static function getConfig()
 {
     $setup = Setup::get();
     if (isset($setup['database'])) {
         $config = $setup['database']->toArray();
     } else {
         // legacy: import from constants
         $config = array('driver' => APP_SQL_DBTYPE, 'hostname' => APP_SQL_DBHOST, 'database' => APP_SQL_DBNAME, 'username' => APP_SQL_DBUSER, 'password' => APP_SQL_DBPASS, 'port' => APP_SQL_DBPORT, 'table_prefix' => APP_TABLE_PREFIX);
         // save it back. this will effectively do the migration
         Setup::save(array('database' => $config));
     }
     return $config;
 }
 /**
  * loadConfig()
  * merges the workflow's default settings with any local settings
  * this function is automatically called through getConfig()
  */
 private function loadConfig()
 {
     $defaults = $this->getConfigDefaults();
     $name = $this->getWorkflowName();
     $setup = Setup::get();
     if (!isset($setup['workflow'])) {
         $setup['workflow'] = array();
     }
     // create copy, this avoids the "indirect" error
     $config = $setup['workflow'][$name];
     // merge defaults
     foreach ($defaults as $key => $value) {
         if (isset($config[$key])) {
             continue;
         }
         $config[$key] = $value;
     }
     // save back to config tree
     $this->config = $setup['workflow'][$name] = $config;
 }
Exemplo n.º 4
0
 /**
  * Creates a lock file for the given name.
  * Returns FALSE if lock couldn't be created (lock already exists)
  *
  * @param int $issue_id Issue Id what is being locked
  * @param string $usr_id User Id who locked the issue
  * @return bool
  */
 public static function acquire($issue_id, $usr_id)
 {
     $setup = Setup::get();
     $lock_ttl = $setup['issue_lock'];
     $expires = time() + $lock_ttl;
     if (self::isLocked($issue_id)) {
         $info = self::getInfo($issue_id);
         // allow lock, if locked by user himself
         if ($info['usr_id'] != $usr_id) {
             return false;
         }
     }
     $lockfile = self::getLockFilename($issue_id);
     $info = array('usr_id' => $usr_id, 'expires' => $expires);
     $fp = fopen($lockfile, 'w');
     flock($fp, LOCK_EX);
     fwrite($fp, serialize($info));
     flock($fp, LOCK_UN);
     fclose($fp);
     return true;
 }
Exemplo n.º 5
0
 /**
  * Logs the error condition to a specific file and if asked and possible
  * queue error in mail queue for reporting.
  *
  * @param  mixed $error_msg The error message
  * @param  string $script The script name where the error happened
  * @param  integer $line The line number where the error happened
  * @param  boolean $notify_error Whether error should be notified by email.
  */
 public static function logError($error_msg = 'unknown', $script = 'unknown', $line = 0, $notify_error = true)
 {
     $msg =& self::_createErrorReport($error_msg, $script, $line);
     if (is_resource(APP_ERROR_LOG)) {
         fwrite(APP_ERROR_LOG, date('[D M d H:i:s Y] '));
         fwrite(APP_ERROR_LOG, $msg);
     } else {
         file_put_contents(APP_ERROR_LOG, array(date('[D M d H:i:s Y] '), $msg), FILE_APPEND);
     }
     // if there's no database connection, then we cannot possibly queue up the error emails
     $dbh = DB_Helper::getInstance();
     if ($notify_error === false || !$dbh) {
         return;
     }
     $setup = Setup::get();
     if (isset($setup['email_error']['status']) && $setup['email_error']['status'] == 'enabled') {
         $notify_list = trim($setup['email_error']['addresses']);
         if (empty($notify_list)) {
             return;
         }
         self::_notify($msg, $setup['smtp']['from'], $notify_list);
     }
 }
Exemplo n.º 6
0
 /**
  * Get mail handler if configured
  *
  * @return \Monolog\Handler\MailHandler
  */
 private static function createMailHandler()
 {
     $setup = Setup::get();
     if ($setup['email_error']['status'] != 'enabled') {
         return null;
     }
     $notify_list = trim($setup['email_error']['addresses']);
     if (!$notify_list) {
         return null;
     }
     // recipient list can be comma separated
     $to = Misc::trim(explode(',', $notify_list));
     $subject = APP_SITE_NAME . ' - Error found!';
     $handler = new Monolog\Handler\NativeMailerHandler($to, $subject, $setup['smtp']['from'], Monolog\Logger::ERROR);
     return $handler;
 }
Exemplo n.º 7
0
<?php

/*
 * This file is part of the Eventum (Issue Tracking System) package.
 *
 * @copyright (c) Eventum Team
 * @license GNU General Public License, version 2 or later (GPL-2+)
 *
 * For the full copyright and license information,
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/scm.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_REPORTER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
if (@$_POST['cat'] == 'update') {
    $res = Setup::save(array('scm_integration' => $_POST['scm_integration']));
    $tpl->assign('result', $res);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the setup information was saved successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to create the configuration file in the setup directory (%1\$s). " . 'Please contact your local system administrator and ask for write privileges on the provided path.', APP_CONFIG_PATH), Misc::MSG_NOTE_BOX), -2 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to update the configuration file in the setup directory (%1\$s). " . 'Please contact your local system administrator and ask for write privileges on the provided filename.', APP_SETUP_FILE), Misc::MSG_NOTE_BOX)));
}
$tpl->assign('setup', Setup::get());
$tpl->displayTemplate();
 /**
  * Processes the template and assign common variables automatically.
  *
  * @return $this
  */
 private function processTemplate()
 {
     $core = array('rel_url' => APP_RELATIVE_URL, 'base_url' => APP_BASE_URL, 'app_title' => APP_NAME, 'app_version' => APP_VERSION, 'app_setup' => Setup::get(), 'messages' => Misc::getMessages(), 'roles' => User::getAssocRoleIDs(), 'auth_backend' => APP_AUTH_BACKEND, 'current_url' => $_SERVER['PHP_SELF']);
     // If VCS version is present "Eventum 2.3.3-148-g78b3368", link ref to github
     $vcsVersion = self::getVcsVersion();
     if ($vcsVersion) {
         $link = "https://github.com/eventum/eventum/commit/{$vcsVersion}";
         $core['application_version_link'] = $link;
         // append VCS version if not yet there
         if (!preg_match('/-g[0-9a-f]+$/', APP_VERSION)) {
             $core['app_version'] = "v{$core['app_version']}-g{$vcsVersion}";
         }
     }
     $usr_id = Auth::getUserID();
     if ($usr_id) {
         $core['user'] = User::getDetails($usr_id);
         $prj_id = Auth::getCurrentProject();
         $setup = Setup::get();
         if (!empty($prj_id)) {
             $role_id = User::getRoleByUser($usr_id, $prj_id);
             $has_crm = CRM::hasCustomerIntegration($prj_id);
             $core = $core + array('project_id' => $prj_id, 'project_name' => Auth::getCurrentProjectName(), 'has_crm' => $has_crm, 'current_role' => $role_id, 'current_role_name' => User::getRole($role_id), 'feature_access' => Access::getFeatureAccessArray($usr_id));
             if ($has_crm) {
                 $crm = CRM::getInstance($prj_id);
                 $core['crm_template_path'] = $crm->getTemplatePath();
                 if ($role_id == User::ROLE_CUSTOMER) {
                     try {
                         $contact = $crm->getContact($core['user']['usr_customer_contact_id']);
                         $core['allowed_customers'] = $contact->getCustomers();
                         $core['current_customer'] = $crm->getCustomer(Auth::getCurrentCustomerID(false));
                     } catch (CRMException $e) {
                     }
                 }
             }
         }
         $info = User::getDetails($usr_id);
         $raw_projects = Project::getAssocList($usr_id, false, true);
         $active_projects = array();
         foreach ($raw_projects as $prj_id => $prj_info) {
             if ($prj_info['status'] == 'archived') {
                 $prj_info['prj_title'] .= ' ' . ev_gettext('(archived)');
             }
             $active_projects[$prj_id] = $prj_info['prj_title'];
         }
         $core += array('active_projects' => $active_projects, 'current_full_name' => $info['usr_full_name'], 'current_email' => $info['usr_email'], 'current_user_id' => $usr_id, 'current_user_datetime' => Date_Helper::getISO8601date('now', '', true), 'is_current_user_clocked_in' => User::isCLockedIn($usr_id), 'is_anon_user' => Auth::isAnonUser(), 'is_current_user_partner' => !empty($info['usr_par_code']), 'roles' => User::getAssocRoleIDs(), 'current_user_prefs' => Prefs::get($usr_id));
         $this->assign('current_full_name', $core['user']['usr_full_name']);
         $this->assign('current_email', $core['user']['usr_email']);
         $this->assign('current_user_id', $usr_id);
         $this->assign('handle_clock_in', $setup['handle_clock_in'] == 'enabled');
         $this->assign('is_current_user_clocked_in', User::isClockedIn($usr_id));
         $this->assign('roles', User::getAssocRoleIDs());
     }
     $this->assign('core', $core);
     if (isset($role_id) && $role_id >= User::ROLE_ADMINISTRATOR) {
         DebugBar::register($this->smarty);
     }
     return $this;
 }
 /**
  * Create new local user.
  *
  * @param array $remote
  * @return int usr_id
  */
 private function createUser($remote)
 {
     $emails = $remote['emails'];
     if (!$emails) {
         throw new AuthException('E-mail is required');
     }
     // set first email as default
     $data['email'] = array_shift($emails);
     $data['role'] = Setup::get()->ldap->default_role;
     if (!empty($data['customer_id']) && !empty($data['contact_id'])) {
         foreach ($data['role'] as $prj_id => $role) {
             if ($role > 0) {
                 $data['role'][$prj_id] = User::ROLE_CUSTOMER;
             }
         }
     }
     $usr_id = User::insert($data);
     if ($usr_id > 0 && $emails) {
         $this->updateAliases($usr_id, $emails);
     }
     return $usr_id;
 }
Exemplo n.º 10
0
 /**
  * Method used to perform a specific action to an issue.
  *
  * @param   integer $issue_id The issue ID
  * @param   array $reminder The reminder details
  * @param   array $action The action details
  * @return  boolean
  */
 public static function perform($issue_id, $reminder, $action)
 {
     $type = '';
     // - see which action type we're talking about here...
     $action_type = self::getActionType($action['rma_rmt_id']);
     // - do we also need to alert the group leader about this?
     $group_leader_usr_id = 0;
     if ($action['rma_alert_group_leader']) {
         if (Reminder::isDebug()) {
             echo '  - ' . ev_gettext('Processing Group Leader notification') . "\n";
         }
         $group_id = Issue::getGroupID($issue_id);
         // check if there's even a group associated with this issue
         if (empty($group_id)) {
             if (Reminder::isDebug()) {
                 echo '  - ' . ev_gettext('No group associated with issue %1$s', $issue_id) . "\n";
             }
         } else {
             $group_details = Group::getDetails($group_id);
             if (!empty($group_details['grp_manager_usr_id'])) {
                 $group_leader_usr_id = $group_details['grp_manager_usr_id'];
             }
         }
     }
     if (Reminder::isDebug()) {
         echo '  - ' . ev_gettext('Performing action %1$s for issue # %2$s', $action_type, $issue_id) . "\n";
     }
     switch ($action_type) {
         case 'email_assignee':
             $type = 'email';
             $assignees = Issue::getAssignedUserIDs($issue_id);
             $to = array();
             foreach ($assignees as $assignee) {
                 $to[] = User::getFromHeader($assignee);
             }
             // add the group leader to the recipient list, if needed
             if (!empty($group_leader_usr_id)) {
                 $leader_email = User::getFromHeader($group_leader_usr_id);
                 if (!empty($leader_email) && !in_array($leader_email, $to)) {
                     $to[] = $leader_email;
                 }
             }
             break;
         case 'email_list':
             $type = 'email';
             $list = self::getUserList($action['rma_id']);
             $to = array();
             foreach ($list as $key => $value) {
                 // add the recipient to the list if it's a simple email address
                 if (Validation::isEmail($key)) {
                     $to[] = $key;
                 } else {
                     $to[] = User::getFromHeader($key);
                 }
             }
             // add the group leader to the recipient list, if needed
             if (!empty($group_leader_usr_id)) {
                 $leader_email = User::getFromHeader($group_leader_usr_id);
                 if (!empty($leader_email) && !in_array($leader_email, $to)) {
                     $to[] = $leader_email;
                 }
             }
             break;
         case 'sms_assignee':
             $type = 'sms';
             $assignees = Issue::getAssignedUserIDs($issue_id);
             $to = array();
             foreach ($assignees as $assignee) {
                 if (User::isClockedIn($assignee)) {
                     $sms_email = User::getSMS($assignee);
                     if (!empty($sms_email)) {
                         $to[] = $sms_email;
                     }
                 }
             }
             // add the group leader to the recipient list, if needed
             if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) {
                 $leader_sms_email = User::getSMS($group_leader_usr_id);
                 if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) {
                     $to[] = $leader_sms_email;
                 }
             }
             break;
         case 'sms_list':
             $type = 'sms';
             $list = self::getUserList($action['rma_id']);
             $to = array();
             foreach ($list as $key => $value) {
                 // add the recipient to the list if it's a simple email address
                 if (Validation::isEmail($key)) {
                     $to[] = $key;
                 } else {
                     // otherwise, check for the clocked-in status
                     if (User::isClockedIn($key)) {
                         $sms_email = User::getSMS($key);
                         if (!empty($sms_email)) {
                             $to[] = $sms_email;
                         }
                     }
                 }
             }
             // add the group leader to the recipient list, if needed
             if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) {
                 $leader_sms_email = User::getSMS($group_leader_usr_id);
                 if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) {
                     $to[] = $leader_sms_email;
                 }
             }
             break;
     }
     $data = Issue::getDetails($issue_id);
     $conditions = Reminder_Condition::getAdminList($action['rma_id']);
     // alert IRC if needed
     if ($action['rma_alert_irc']) {
         if (Reminder::isDebug()) {
             echo "  - Processing IRC notification\n";
         }
         $irc_notice = "Issue #{$issue_id} (";
         if (!empty($data['pri_title'])) {
             $irc_notice .= 'Priority: ' . $data['pri_title'];
         }
         if (!empty($data['sev_title'])) {
             $irc_notice .= 'Severity: ' . $data['sev_title'];
         }
         // also add information about the assignee, if any
         $assignment = Issue::getAssignedUsers($issue_id);
         if (count($assignment) > 0) {
             $irc_notice .= '; Assignment: ' . implode(', ', $assignment);
         }
         if (!empty($data['iss_grp_id'])) {
             $irc_notice .= '; Group: ' . Group::getName($data['iss_grp_id']);
         }
         $irc_notice .= "), Reminder action '" . $action['rma_title'] . "' was just triggered; " . $action['rma_boilerplate'];
         Notification::notifyIRC(Issue::getProjectID($issue_id), $irc_notice, $issue_id, false, APP_EVENTUM_IRC_CATEGORY_REMINDER);
     }
     $setup = Setup::get();
     // if there are no recipients, then just skip to the next action
     if (count($to) == 0) {
         if (Reminder::isDebug()) {
             echo "  - No recipients could be found\n";
         }
         // if not even an irc alert was sent, then save
         // a notice about this on reminder_sent@, if needed
         if (!$action['rma_alert_irc']) {
             if ($setup['email_reminder']['status'] == 'enabled') {
                 self::_recordNoRecipientError($issue_id, $type, $reminder, $action, $data, $conditions);
             }
             return false;
         }
     }
     // - save a history entry about this action
     self::saveHistory($issue_id, $action['rma_id']);
     // - save this action as the latest triggered one for the given issue ID
     self::recordLastTriggered($issue_id, $action['rma_id']);
     // - perform the action
     if (count($to) > 0) {
         // send a copy of this reminder to reminder_sent@, if needed
         if ($setup['email_reminder']['status'] == 'enabled' && $setup['email_reminder']['addresses']) {
             $addresses = Reminder::_getReminderAlertAddresses();
             if (count($addresses) > 0) {
                 $to = array_merge($to, $addresses);
             }
         }
         $tpl = new Template_Helper();
         $tpl->setTemplate('reminders/' . $type . '_alert.tpl.text');
         $tpl->assign(array('data' => $data, 'reminder' => $reminder, 'action' => $action, 'conditions' => $conditions, 'has_customer_integration' => CRM::hasCustomerIntegration(Issue::getProjectID($issue_id))));
         $text_message = $tpl->getTemplateContents();
         foreach ($to as $address) {
             // send email (use PEAR's classes)
             $mail = new Mail_Helper();
             $mail->setTextBody($text_message);
             $setup = $mail->getSMTPSettings();
             // TRANSLATORS: %1 - issue_id, %2 - rma_title
             $subject = ev_gettext('[#%1$s] Reminder: %2$s', $issue_id, $action['rma_title']);
             $mail->send($setup['from'], $address, $subject, 0, $issue_id, 'reminder');
         }
     }
     // - eventum saves the day once again
     return true;
 }
Exemplo n.º 11
0
 /**
  * Method used to get the full list of default notification
  * actions.
  *
  * @param   integer $issue_id The ID of the issue the user is being subscribed too
  * @param   string  $email The email address of the user to be subscribed
  * @param   string  $source The source of this call, "add_unknown_user", "self_assign", "remote_assign", "anon_issue", "issue_update", "issue_from_email", "new_issue", "note", "add_extra_recipients"
  * @return  array The list of default notification actions
  */
 public static function getDefaultActions($issue_id = null, $email = null, $source = null)
 {
     $prj_id = Auth::getCurrentProject();
     $workflow = Workflow::getNotificationActions($prj_id, $issue_id, $email, $source);
     if ($workflow !== null) {
         return $workflow;
     }
     $actions = array();
     $setup = Setup::get();
     if ($setup['update'] == 1) {
         $actions[] = 'updated';
     }
     if ($setup['closed'] == 1) {
         $actions[] = 'closed';
     }
     if ($setup['files'] == 1) {
         $actions[] = 'files';
     }
     if ($setup['emails'] == 1) {
         $actions[] = 'emails';
     }
     return $actions;
 }
Exemplo n.º 12
0
 /**
  * Creates a new issue from an email if appropriate. Also returns if this message is related
  * to a previous message.
  *
  * @param   array   $info An array of info about the email account.
  * @param   string  $headers The headers of the email.
  * @param   string  $message_body The body of the message.
  * @param   string  $date The date this message was sent
  * @param   string  $from The name and email address of the sender.
  * @param   string  $subject The subject of this message.
  * @param   array   $to An array of to addresses
  * @param   array   $cc An array of cc addresses
  * @return  array   An array of information about the message
  */
 public function createIssueFromEmail($info, $headers, $message_body, $date, $from, $subject, $to, $cc)
 {
     $should_create_issue = false;
     $issue_id = '';
     $associate_email = '';
     $type = 'email';
     $parent_id = '';
     $customer_id = false;
     $contact_id = false;
     $contract_id = false;
     $severity = false;
     // we can't trust the in-reply-to from the imap c-client, so let's
     // try to manually parse that value from the full headers
     $references = Mail_Helper::getAllReferences($headers);
     $message_id = Mail_Helper::getMessageID($headers, $message_body);
     $workflow = Workflow::getIssueIDforNewEmail($info['ema_prj_id'], $info, $headers, $message_body, $date, $from, $subject, $to, $cc);
     if (is_array($workflow)) {
         if (isset($workflow['customer_id'])) {
             $customer_id = $workflow['customer_id'];
         }
         if (isset($workflow['contract_id'])) {
             $contract_id = $workflow['contract_id'];
         }
         if (isset($workflow['contact_id'])) {
             $contact_id = $workflow['contact_id'];
         }
         if (isset($workflow['severity'])) {
             $severity = $workflow['severity'];
         }
         if (isset($workflow['should_create_issue'])) {
             $should_create_issue = $workflow['should_create_issue'];
         } else {
             $should_create_issue = true;
         }
     } elseif ($workflow == 'new') {
         $should_create_issue = true;
     } elseif (is_numeric($workflow)) {
         $issue_id = $workflow;
     } else {
         $setup = Setup::get();
         if ($setup['subject_based_routing']['status'] == 'enabled') {
             // Look for issue ID in the subject line
             // look for [#XXXX] in the subject line
             if (preg_match("/\\[#(\\d+)\\]( Note| BLOCKED)*/", $subject, $matches)) {
                 $should_create_issue = false;
                 $issue_id = $matches[1];
                 if (!Issue::exists($issue_id, false)) {
                     $issue_id = '';
                 } elseif (!empty($matches[2])) {
                     $type = 'note';
                 }
             } else {
                 $should_create_issue = true;
             }
         } else {
             // - if this email is a reply:
             if (count($references) > 0) {
                 foreach ($references as $reference_msg_id) {
                     //  -> check if the replied email exists in the database:
                     if (Note::exists($reference_msg_id)) {
                         // note exists
                         // get what issue it belongs too.
                         $issue_id = Note::getIssueByMessageID($reference_msg_id);
                         $should_create_issue = false;
                         $type = 'note';
                         $parent_id = Note::getIDByMessageID($reference_msg_id);
                         break;
                     } elseif (self::exists($reference_msg_id) || Issue::getIssueByRootMessageID($reference_msg_id) != false) {
                         // email or issue exists
                         $issue_id = self::getIssueByMessageID($reference_msg_id);
                         if (empty($issue_id)) {
                             $issue_id = Issue::getIssueByRootMessageID($reference_msg_id);
                         }
                         if (empty($issue_id)) {
                             // parent email isn't associated with issue.
                             //      --> create new issue, associate current email and replied email to this issue
                             $should_create_issue = true;
                             $associate_email = $reference_msg_id;
                         } else {
                             // parent email is associated with issue:
                             //      --> associate current email with existing issue
                             $should_create_issue = false;
                         }
                         break;
                     } else {
                         //  no matching note, email or issue:
                         //    => create new issue and associate current email with it
                         $should_create_issue = true;
                     }
                 }
             } else {
                 // - if this email is not a reply:
                 //  -> create new issue and associate current email with it
                 $should_create_issue = true;
             }
         }
     }
     $sender_email = Mail_Helper::getEmailAddress($from);
     if (Misc::isError($sender_email)) {
         $sender_email = 'Error Parsing Email <>';
     }
     // only create a new issue if this email is coming from a known customer
     if ($should_create_issue && $info['ema_issue_auto_creation_options']['only_known_customers'] == 'yes' && CRM::hasCustomerIntegration($info['ema_prj_id']) && !$customer_id) {
         try {
             $crm = CRM::getInstance($info['ema_prj_id']);
             $should_create_issue = true;
         } catch (CRMException $e) {
             $should_create_issue = false;
         }
     }
     // check whether we need to create a new issue or not
     if ($info['ema_issue_auto_creation'] == 'enabled' && $should_create_issue && !Notification::isBounceMessage($sender_email)) {
         $options = Email_Account::getIssueAutoCreationOptions($info['ema_id']);
         AuthCookie::setAuthCookie(APP_SYSTEM_USER_ID);
         AuthCookie::setProjectCookie($info['ema_prj_id']);
         $issue_id = Issue::createFromEmail($info['ema_prj_id'], APP_SYSTEM_USER_ID, $from, Mime_Helper::decodeQuotedPrintable($subject), $message_body, @$options['category'], @$options['priority'], @$options['users'], $date, $message_id, $severity, $customer_id, $contact_id, $contract_id);
         // add sender to authorized repliers list if they are not a real user
         $sender_usr_id = User::getUserIDByEmail($sender_email, true);
         if (empty($sender_usr_id)) {
             Authorized_Replier::manualInsert($issue_id, $sender_email, false);
         }
         // associate any existing replied-to email with this new issue
         if (!empty($associate_email) && !empty($reference_issue_id)) {
             $reference_sup_id = self::getIDByMessageID($associate_email);
             self::associate(APP_SYSTEM_USER_ID, $issue_id, array($reference_sup_id));
         }
     }
     // need to check crm for customer association
     if (!empty($from)) {
         if (CRM::hasCustomerIntegration($info['ema_prj_id']) && !$customer_id) {
             // check for any customer contact association
             try {
                 $crm = CRM::getInstance($info['ema_prj_id']);
                 $contact = $crm->getContactByEmail($sender_email);
                 $contact_id = $contact->getContactID();
                 $contracts = $contact->getContracts(array(CRM_EXCLUDE_EXPIRED));
                 $contract = $contracts[0];
                 $customer_id = $contract->getCustomerID();
             } catch (CRMException $e) {
                 $customer_id = null;
                 $contact_id = null;
             }
         }
     }
     return array('should_create_issue' => $should_create_issue, 'associate_email' => $associate_email, 'issue_id' => $issue_id, 'customer_id' => $customer_id, 'contact_id' => $contact_id, 'type' => $type, 'parent_id' => $parent_id);
 }
Exemplo n.º 13
0
 /**
  * Check for $adresses for matches
  *
  * @param   mixed   $addresses to check
  * @param   string  $type Type of address match to find (email, note, draft)
  * @return  int|bool $issue_id in case of match otherwise false
  */
 public static function getMatchingIssueIDs($addresses, $type)
 {
     $setup = Setup::get();
     $settings = $setup["{$type}_routing"];
     if (!$settings) {
         return false;
     }
     if (empty($settings['address_prefix'])) {
         return false;
     }
     // escape plus signs so '*****@*****.**' becomes a valid routing address
     $prefix = quotemeta($settings['address_prefix']);
     if (empty($settings['address_host'])) {
         return false;
     }
     $mail_domain = quotemeta($settings['address_host']);
     if (!empty($settings['host_alias'])) {
         // XXX: legacy split by '|' as well
         if (strstr($settings['host_alias'], '|')) {
             $host_aliases = explode('|', $settings['host_alias']);
         } else {
             $host_aliases = explode(' ', $settings['host_alias']);
         }
         $host_aliases = implode('|', array_map(function ($s) {
             return quotemeta($s);
         }, $host_aliases));
         $mail_domain = '(?:' . $mail_domain . '|' . $host_aliases . ')';
     }
     // if there are multiple CC or To headers Mail_Mime creates array.
     // handle both cases (strings and arrays).
     if (!is_array($addresses)) {
         $addresses = array($addresses);
     }
     // everything safely escaped and checked, try matching address
     foreach ($addresses as $address) {
         if (preg_match("/{$prefix}(\\d*)@{$mail_domain}/i", $address, $matches)) {
             return (int) $matches[1];
         }
     }
     return false;
 }
Exemplo n.º 14
0
 */
require_once __DIR__ . '/../init.php';
// Nagios compatible exit codes
define('STATE_OK', 0);
define('STATE_WARNING', 1);
define('STATE_CRITICAL', 2);
define('STATE_UNKNOWN', 3);
define('STATE_DEPENDENT', 4);
// the owner, group and filesize settings should be changed to match the correct permissions on your server.
$required_files = array(APP_CONFIG_PATH . '/config.php' => array('check_owner' => true, 'owner' => 'apache', 'check_group' => true, 'group' => 'apache', 'check_permission' => true, 'permission' => 640), APP_CONFIG_PATH . '/setup.php' => array('check_owner' => true, 'owner' => 'apache', 'check_group' => true, 'group' => 'apache', 'check_permission' => true, 'permission' => 660, 'check_filesize' => true, 'filesize' => 1024));
$required_directories = array(APP_PATH . '/misc/routed_emails' => array('check_permission' => true, 'permission' => 770), APP_PATH . '/misc/routed_notes' => array('check_permission' => true, 'permission' => 770));
$opt = getopt('q');
$quiet = isset($opt['q']);
$errors = 0;
// load prefs
$setup = Setup::get();
$prefs = $setup['monitor'];
$errors += Monitor::checkDatabase();
$errors += Monitor::checkMailQueue();
$errors += Monitor::checkMailAssociation();
if ($prefs['diskcheck']['status'] == 'enabled') {
    $errors += Monitor::checkDiskspace($prefs['diskcheck']['partition']);
}
if ($prefs['paths']['status'] == 'enabled') {
    $errors += Monitor::checkRequiredFiles($required_files);
    $errors += Monitor::checkRequiredDirs($required_directories);
}
if ($prefs['ircbot']['status'] == 'enabled') {
    $errors += Monitor::checkIRCBot();
}
if ($errors) {
Exemplo n.º 15
0
 /**
  * Method used to get the title given to the current installation of Eventum.
  *
  * @return  string The installation title
  */
 public static function getToolCaption()
 {
     $setup = Setup::get();
     return !empty($setup['tool_caption']) ? $setup['tool_caption'] : APP_NAME;
 }
Exemplo n.º 16
0
 /**
  * Method used to get the list of email addresses to use
  * to send diagnostic information about the reminder system.
  *
  * @return  array The list of alert email addresses
  */
 public static function _getReminderAlertAddresses()
 {
     $emails = array();
     $setup = Setup::get();
     if ($setup['email_reminder']['status'] == 'enabled' && $setup['email_reminder']['addresses']) {
         $emails = explode(',', $setup['email_reminder']['addresses']);
         $emails = Misc::trim($emails);
     }
     return $emails;
 }
Exemplo n.º 17
0
 /**
  * Returns true if a user is clocked in.
  *
  * @param   integer $usr_id The id of the user to clock out.
  * @return  boolean True if the user is logged in, false otherwise
  */
 public static function isClockedIn($usr_id)
 {
     $setup = Setup::get();
     // If clock in handling is disabled, say that we are always clocked in
     if ($setup['handle_clock_in'] == 'disabled') {
         return true;
     }
     $stmt = 'SELECT
                 usr_clocked_in
              FROM
                 {{%user}}
              WHERE
                 usr_id = ?';
     try {
         $res = DB_Helper::getInstance()->getOne($stmt, array($usr_id));
     } catch (DbException $e) {
         return -1;
     }
     if ($res == 1) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 18
0
/*
 * This file is part of the Eventum (Issue Tracking System) package.
 *
 * @copyright (c) Eventum Team
 * @license GNU General Public License, version 2 or later (GPL-2+)
 *
 * For the full copyright and license information,
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/general.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_REPORTER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
$tpl->assign('project_list', Project::getAll());
if (@$_POST['cat'] == 'update') {
    $smtp = $_POST['smtp'];
    $smtp['auth'] = (bool) $smtp['auth'];
    $setup = array('tool_caption' => $_POST['tool_caption'], 'support_email' => $_POST['support_email'], 'description_email_0' => $_POST['description_email_0'], 'spell_checker' => $_POST['spell_checker'], 'irc_notification' => $_POST['irc_notification'], 'update' => (bool) Misc::ifSet($_POST, 'update'), 'closed' => (bool) Misc::ifSet($_POST, 'closed'), 'emails' => (bool) Misc::ifSet($_POST, 'emails'), 'files' => (bool) Misc::ifSet($_POST, 'files'), 'smtp' => $smtp, 'open_signup' => $_POST['open_signup'], 'accounts_projects' => isset($_POST['accounts_projects']) ? $_POST['accounts_projects'] : null, 'accounts_role' => isset($_POST['accounts_role']) ? $_POST['accounts_role'] : null, 'subject_based_routing' => $_POST['subject_based_routing'], 'email_routing' => $_POST['email_routing'], 'note_routing' => $_POST['note_routing'], 'draft_routing' => $_POST['draft_routing'], 'email_error' => $_POST['email_error'], 'email_reminder' => $_POST['email_reminder'], 'handle_clock_in' => $_POST['handle_clock_in']);
    $res = Setup::save($setup);
    $tpl->assign('result', $res);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the setup information was saved successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to create the configuration file in the setup directory (%1\$s). " . 'Please contact your local system administrator and ask for write privileges on the provided path.', APP_CONFIG_PATH), Misc::MSG_NOTE_BOX), -2 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to update the configuration file in the setup directory (%1\$s). " . 'Please contact your local system administrator and ask for write privileges on the provided filename.', APP_SETUP_FILE), Misc::MSG_NOTE_BOX)));
}
$tpl->assign(array('setup' => Setup::get(), 'user_roles' => User::getRoles(array('Customer'))));
$tpl->displayTemplate();
Exemplo n.º 19
0
 /**
  * @param int $issue_id
  * @return array
  * @access protected
  */
 public function getEmailListing($issue_id)
 {
     $real_emails = Support::getEmailsByIssue($issue_id);
     if (is_array($real_emails)) {
         foreach ($real_emails as $i => &$email) {
             $email['id'] = $i + 1;
             unset($email['seb_body']);
         }
     }
     $setup = Setup::get();
     if (isset($setup['description_email_0']) && $setup['description_email_0'] == 'enabled') {
         $issue = Issue::getDetails($issue_id);
         $email = array('id' => 0, 'sup_date' => $issue['iss_created_date'], 'sup_from' => $issue['reporter'], 'sup_to' => '', 'sup_cc' => '', 'sup_subject' => $issue['iss_summary']);
         if ($real_emails != '') {
             $emails = array_merge(array($email), $real_emails);
         } else {
             $emails[] = $email;
         }
     } else {
         $emails = $real_emails;
     }
     return $emails;
 }
Exemplo n.º 20
0
 /**
  * Get ScmCheckin based on SCM name
  *
  * @param string $scm_name
  * @return ScmCheckin
  * @throws Exception
  */
 private static function getScmCheckinByName($scm_name)
 {
     static $instances;
     if (isset($instances[$scm_name])) {
         return $instances[$scm_name];
     }
     $setup = Setup::get();
     if (!isset($setup['scm'][$scm_name])) {
         throw new Exception("SCM '{$scm_name}' not defined");
     }
     return $instances[$scm_name] = new ScmCheckin($setup['scm'][$scm_name]);
 }
Exemplo n.º 21
0
<?php

/*
 * This file is part of the Eventum (Issue Tracking System) package.
 *
 * @copyright (c) Eventum Team
 * @license GNU General Public License, version 2 or later (GPL-2+)
 *
 * For the full copyright and license information,
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/monitor.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_REPORTER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
$tpl->assign('project_list', Project::getAll());
if (!empty($_POST['cat']) && $_POST['cat'] == 'update') {
    $setup = array('diskcheck' => $_POST['diskcheck'], 'paths' => $_POST['paths'], 'ircbot' => $_POST['ircbot']);
    $res = Setup::save(array('monitor' => $setup));
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the setup information was saved successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to create the configuration file in the setup directory (%s). " . 'Please contact your local system administrator and ask for write privileges on the provided path.', APP_CONFIG_PATH), Misc::MSG_NOTE_BOX), -2 => array(ev_gettext("ERROR: The system doesn't have the appropriate permissions to update the configuration file in the setup directory (%s). " . 'Please contact your local system administrator and ask for write privileges on the provided filename.', APP_SETUP_FILE), Misc::MSG_NOTE_BOX)));
}
$tpl->assign(array('enable_disable', array('enabled' => ev_gettext('Enabled'), 'disabled' => ev_gettext('Disabled')), 'setup' => Setup::get()));
$tpl->displayTemplate();
Exemplo n.º 22
0
 /**
  * Method used to save a copy of the given email to a configurable address.
  *
  * @param   array $email The email to save.
  * @return bool
  */
 public static function saveOutgoingEmailCopy(&$email)
 {
     // check early: do we really want to save every outgoing email?
     $setup = Setup::get();
     $save_outgoing_email = !empty($setup['smtp']['save_outgoing_email']) && $setup['smtp']['save_outgoing_email'] == 'yes';
     if (!$save_outgoing_email || empty($setup['smtp']['save_address'])) {
         return false;
     }
     static $subjects = array();
     $hdrs =& $email['headers'];
     $body =& $email['body'];
     $issue_id = $email['maq_iss_id'];
     $sender_usr_id = $email['maq_usr_id'];
     // ok, now parse the headers text and build the assoc array
     $full_email = $hdrs . "\n\n" . $body;
     $structure = Mime_Helper::decode($full_email, false, false);
     $_headers =& $structure->headers;
     $header_names = Mime_Helper::getHeaderNames($hdrs);
     $headers = array();
     foreach ($_headers as $lowercase_name => $value) {
         // need to remove the quotes to avoid a parsing problem
         // on senders that have extended characters in the first
         // or last words in their sender name
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::removeQuotes($value);
         }
         $value = Mime_Helper::encode($value);
         // add the quotes back
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::quoteSender($value);
         }
         $headers[$header_names[$lowercase_name]] = $value;
     }
     // remove any Reply-To:/Return-Path: values from outgoing messages
     unset($headers['Reply-To']);
     unset($headers['Return-Path']);
     // prevent duplicate emails from being sent out...
     $subject = @$headers['Subject'];
     if (@in_array($subject, $subjects)) {
         return false;
     }
     // replace the To: header with the requested address
     $address = $setup['smtp']['save_address'];
     $headers['To'] = $address;
     // add specialized headers if they are not already added
     if (empty($headers['X-Eventum-Type'])) {
         $headers += self::getSpecializedHeaders($issue_id, $email['maq_type'], $sender_usr_id);
     }
     $params = self::getSMTPSettings();
     $mail = Mail::factory('smtp', $params);
     $res = $mail->send($address, $headers, $body);
     if (Misc::isError($res)) {
         Logger::app()->error($res->getMessage(), array('debug' => $res->getDebugInfo()));
     }
     $subjects[] = $subject;
 }