Exemplo n.º 1
0
 function showTab()
 {
     $settings = CerberusSettings::getInstance();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $core_tplpath = dirname(dirname(dirname(__FILE__))) . '/cerberusweb.core/templates/';
     $tpl->assign('core_tplpath', $core_tplpath);
     $tpl->cache_lifetime = "0";
     $tpl->assign('response_uri', 'config/translations');
     $view = C4_AbstractViewLoader::getView('C4_TranslationView', C4_TranslationView::DEFAULT_ID);
     $tpl->assign('view', $view);
     $tpl->assign('view_fields', C4_TranslationView::getFields());
     $tpl->assign('view_searchable_fields', C4_TranslationView::getSearchFields());
     $tpl->display('file:' . $tpl_path . 'config/translations/index.tpl');
 }
Exemplo n.º 2
0
 function showTab()
 {
     $settings = CerberusSettings::getInstance();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $core_tplpath = dirname(dirname(dirname(__FILE__))) . '/cerberusweb.core/templates/';
     $tpl->assign('core_tplpath', $core_tplpath);
     $tpl->cache_lifetime = "0";
     $tpl->assign('response_uri', 'config/watchers2');
     $defaults = new C4_AbstractViewModel();
     $defaults->class_name = 'C4_Watcher2View';
     $defaults->id = C4_Watcher2View::DEFAULT_ID;
     $defaults->renderSortBy = SearchFields_Watcher2MailFilter::POS;
     $defaults->renderSortAsc = 0;
     $view = C4_AbstractViewLoader::getView(C4_Watcher2View::DEFAULT_ID, $defaults);
     $tpl->assign('view', $view);
     $tpl->assign('view_fields', C4_Watcher2View::getFields());
     $tpl->assign('view_searchable_fields', C4_Watcher2View::getSearchFields());
     $tpl->display('file:' . $tpl_path . 'config/watchers2/index.tpl');
 }
Exemplo n.º 3
0
 function doRegisterAction()
 {
     @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $settings = CerberusSettings::getInstance();
     $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, null);
     $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, "Support Dept.");
     $url = DevblocksPlatform::getUrlService();
     $mail_service = DevblocksPlatform::getMailService();
     $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
     $code = CerberusApplication::generatePassword(8);
     if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, true))) {
         // Already registered?
         if ($addy->is_registered) {
             $tpl->assign('register_error', sprintf("'%s' is already registered.", $email));
             DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register')));
             return;
         }
         $fields = array(DAO_Address::IS_REGISTERED => 0, DAO_Address::PASS => $code);
         DAO_Address::update($addy->id, $fields);
     } else {
         $tpl->assign('register_error', sprintf("'%s' is an invalid e-mail address.", $email));
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register')));
         return;
     }
     $message = $mail_service->createMessage();
     $message->setTo($email);
     $message->setFrom(array($from => $from_personal));
     $message->setSubject("Confirming your support e-mail address");
     $message->setBody(sprintf("This is a message to confirm your recent registration request at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "If you've closed the browser window, you can continue by visiting:\r\n" . "%s\r\n" . "\r\n" . "Thanks!\r\n" . "%s\r\n", $url->write('', true), $code, $url->write('c=register&a=confirm', true), $from_personal));
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
     $result = $mailer->send($message);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm')));
 }
Exemplo n.º 4
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $path = $response->path;
     // [JAS]: Ajax? // [TODO] Explore outputting whitespace here for Safari
     //	    if(empty($path))
     //			return;
     $tpl = DevblocksPlatform::getTemplateService();
     $session = DevblocksPlatform::getSessionService();
     $settings = CerberusSettings::getInstance();
     $translate = DevblocksPlatform::getTranslationService();
     $active_worker = CerberusApplication::getActiveWorker();
     $visit = $session->getVisit();
     $page_manifests = $this->_getAllowedPages();
     $controller = array_shift($path);
     // Default page [TODO] This is supposed to come from framework.config.php
     if (empty($controller)) {
         $controller = 'home';
     }
     // [JAS]: Require us to always be logged in for Cerberus pages
     if (empty($visit) && 0 != strcasecmp($controller, 'login')) {
         $query = array();
         if (!empty($response->path)) {
             $query = array('url' => urlencode(implode('/', $response->path)));
         }
         DevblocksPlatform::redirect(new DevblocksHttpRequest(array('login'), $query));
     }
     $page_id = $this->_getPageIdByUri($controller);
     @($page = DevblocksPlatform::getExtension($page_id, true));
     /* @var $page CerberusPageExtension */
     if (empty($page)) {
         header("Status: 404");
         return;
         // [TODO] 404
     }
     // [JAS]: Listeners (Step-by-step guided tour, etc.)
     $listenerManifests = DevblocksPlatform::getExtensions('devblocks.listener.http');
     foreach ($listenerManifests as $listenerManifest) {
         /* @var $listenerManifest DevblocksExtensionManifest */
         $inst = $listenerManifest->createInstance();
         /* @var $inst DevblocksHttpRequestListenerExtension */
         $inst->run($response, $tpl);
     }
     $tpl->assign('active_worker', $active_worker);
     $tour_enabled = false;
     if (!empty($visit) && !is_null($active_worker)) {
         $tour_enabled = intval(DAO_WorkerPref::get($active_worker->id, 'assist_mode', 1));
         if (DEMO_MODE) {
             $tour_enabled = 1;
         }
         // override for DEMO
         $keyboard_shortcuts = intval(DAO_WorkerPref::get($active_worker->id, 'keyboard_shortcuts', 1));
         $tpl->assign('pref_keyboard_shortcuts', $keyboard_shortcuts);
         $active_worker_memberships = $active_worker->getMemberships();
         $tpl->assign('active_worker_memberships', $active_worker_memberships);
         $unread_notifications = DAO_WorkerEvent::getUnreadCountByWorker($active_worker->id);
         $tpl->assign('active_worker_notify_count', $unread_notifications);
         DAO_Worker::logActivity($active_worker->id, $page->getActivity());
     }
     $tpl->assign('tour_enabled', $tour_enabled);
     // [JAS]: Variables provided to all page templates
     $tpl->assign('settings', $settings);
     $tpl->assign('session', $_SESSION);
     $tpl->assign('translate', $translate);
     $tpl->assign('visit', $visit);
     $tpl->assign('license', CerberusLicense::getInstance());
     $tpl->assign('page_manifests', $page_manifests);
     $tpl->assign('page', $page);
     $tpl->assign('response_uri', implode('/', $response->path));
     $core_tpl = DEVBLOCKS_PLUGIN_PATH . 'cerberusweb.core/templates/';
     $tpl->assign('core_tpl', $core_tpl);
     // Prebody Renderers
     $preBodyRenderers = DevblocksPlatform::getExtensions('cerberusweb.renderer.prebody', true);
     if (!empty($preBodyRenderers)) {
         $tpl->assign('prebody_renderers', $preBodyRenderers);
     }
     // Postbody Renderers
     $postBodyRenderers = DevblocksPlatform::getExtensions('cerberusweb.renderer.postbody', true);
     if (!empty($postBodyRenderers)) {
         $tpl->assign('postbody_renderers', $postBodyRenderers);
     }
     // Timings
     $tpl->assign('render_time', microtime(true) - DevblocksPlatform::getStartTime());
     if (function_exists('memory_get_usage') && function_exists('memory_get_peak_usage')) {
         $tpl->assign('render_memory', memory_get_usage() - DevblocksPlatform::getStartMemory());
         $tpl->assign('render_peak_memory', memory_get_peak_usage() - DevblocksPlatform::getStartPeakMemory());
     }
     $tpl->display($core_tpl . 'border.tpl');
     //		$cache = DevblocksPlatform::getCacheService();
     //		$cache->printStatistics();
 }
Exemplo n.º 5
0
 function saveOutgoingMailSettingsAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $worker = CerberusApplication::getActiveWorker();
     if (!$worker || !$worker->is_superuser) {
         echo $translate->_('common.access_denied');
         return;
     }
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'mail')));
         return;
     }
     @($default_reply_address = DevblocksPlatform::importGPC($_REQUEST['sender_address'], 'string'));
     @($default_reply_personal = DevblocksPlatform::importGPC($_REQUEST['sender_personal'], 'string'));
     @($default_signature = DevblocksPlatform::importGPC($_POST['default_signature'], 'string'));
     @($default_signature_pos = DevblocksPlatform::importGPC($_POST['default_signature_pos'], 'integer', 0));
     @($smtp_host = DevblocksPlatform::importGPC($_REQUEST['smtp_host'], 'string', 'localhost'));
     @($smtp_port = DevblocksPlatform::importGPC($_REQUEST['smtp_port'], 'integer', 25));
     @($smtp_enc = DevblocksPlatform::importGPC($_REQUEST['smtp_enc'], 'string', 'None'));
     @($smtp_timeout = DevblocksPlatform::importGPC($_REQUEST['smtp_timeout'], 'integer', 30));
     @($smtp_max_sends = DevblocksPlatform::importGPC($_REQUEST['smtp_max_sends'], 'integer', 20));
     @($smtp_auth_enabled = DevblocksPlatform::importGPC($_REQUEST['smtp_auth_enabled'], 'integer', 0));
     if ($smtp_auth_enabled) {
         @($smtp_auth_user = DevblocksPlatform::importGPC($_REQUEST['smtp_auth_user'], 'string'));
         @($smtp_auth_pass = DevblocksPlatform::importGPC($_REQUEST['smtp_auth_pass'], 'string'));
     } else {
         // need to clear auth info when smtp auth is disabled
         @($smtp_auth_user = '');
         @($smtp_auth_pass = '');
     }
     $settings = CerberusSettings::getInstance();
     $settings->set(CerberusSettings::DEFAULT_REPLY_FROM, $default_reply_address);
     $settings->set(CerberusSettings::DEFAULT_REPLY_PERSONAL, $default_reply_personal);
     $settings->set(CerberusSettings::DEFAULT_SIGNATURE, $default_signature);
     $settings->set(CerberusSettings::DEFAULT_SIGNATURE_POS, $default_signature_pos);
     $settings->set(CerberusSettings::SMTP_HOST, $smtp_host);
     $settings->set(CerberusSettings::SMTP_PORT, $smtp_port);
     $settings->set(CerberusSettings::SMTP_AUTH_ENABLED, $smtp_auth_enabled);
     $settings->set(CerberusSettings::SMTP_AUTH_USER, $smtp_auth_user);
     $settings->set(CerberusSettings::SMTP_AUTH_PASS, $smtp_auth_pass);
     $settings->set(CerberusSettings::SMTP_ENCRYPTION_TYPE, $smtp_enc);
     $settings->set(CerberusSettings::SMTP_TIMEOUT, !empty($smtp_timeout) ? $smtp_timeout : 30);
     $settings->set(CerberusSettings::SMTP_MAX_SENDS, !empty($smtp_max_sends) ? $smtp_max_sends : 20);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'mail', 'outgoing', 'test')));
 }
Exemplo n.º 6
0
 function writeResponse(DevblocksHttpResponse $response)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $theme = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_THEME, UmScApp::DEFAULT_THEME);
     if (!is_dir($tpl_path . 'portal/sc/themes/' . $theme)) {
         $theme = UmScApp::DEFAULT_THEME;
     }
     $umsession = $this->getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     $stack = $response->path;
     @($module = array_shift($stack));
     switch ($module) {
         default:
         case 'home':
             $sHomeRss = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_HOME_RSS, '');
             $aHomeRss = !empty($sHomeRss) ? unserialize($sHomeRss) : array();
             $feeds = array();
             // [TODO] Implement a feed cache so we aren't bombing out
             foreach ($aHomeRss as $title => $url) {
                 $feed = null;
                 try {
                     $feed = Zend_Feed::import($url);
                 } catch (Exception $e) {
                 }
                 if (!empty($feed) && $feed->count()) {
                     $feeds[] = array('name' => $title, 'feed' => $feed);
                 }
             }
             $tpl->assign('feeds', $feeds);
             $tpl->display("file:{$tpl_path}portal/sc/internal/home/index.tpl");
             break;
         case 'account':
             if (!$this->allow_logins || empty($active_user)) {
                 break;
             }
             $address = DAO_Address::get($active_user->id);
             $tpl->assign('address', $address);
             $tpl->display("file:{$tpl_path}portal/sc/internal/account/index.tpl");
             break;
         case 'kb':
             // KB Roots
             $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, '');
             $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
             $kb_roots_str = '0';
             if (!empty($kb_roots)) {
                 $kb_roots_str = implode(',', array_keys($kb_roots));
             }
             switch (array_shift($stack)) {
                 case 'article':
                     if (empty($kb_roots)) {
                         return;
                     }
                     $id = intval(array_shift($stack));
                     list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::ID, '=', $id), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
                     if (!isset($articles[$id])) {
                         break;
                     }
                     $article = DAO_KbArticle::get($id);
                     $tpl->assign('article', $article);
                     @($article_list = $umsession->getProperty(UmScApp::SESSION_ARTICLE_LIST, array()));
                     if (!empty($article) && !isset($article_list[$id])) {
                         DAO_KbArticle::update($article->id, array(DAO_KbArticle::VIEWS => ++$article->views));
                         $article_list[$id] = $id;
                         $umsession->setProperty(UmScApp::SESSION_ARTICLE_LIST, $article_list);
                     }
                     $categories = DAO_KbCategory::getWhere();
                     $tpl->assign('categories', $categories);
                     $cats = DAO_KbArticle::getCategoriesByArticleId($id);
                     $breadcrumbs = array();
                     foreach ($cats as $cat_id) {
                         if (!isset($breadcrumbs[$cat_id])) {
                             $breadcrumbs[$cat_id] = array();
                         }
                         $pid = $cat_id;
                         while ($pid) {
                             $breadcrumbs[$cat_id][] = $pid;
                             $pid = $categories[$pid]->parent_id;
                         }
                         $breadcrumbs[$cat_id] = array_reverse($breadcrumbs[$cat_id]);
                         // Remove any breadcrumbs not in this SC profile
                         $pid = reset($breadcrumbs[$cat_id]);
                         if (!isset($kb_roots[$pid])) {
                             unset($breadcrumbs[$cat_id]);
                         }
                     }
                     $tpl->assign('breadcrumbs', $breadcrumbs);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/kb/article.tpl");
                     break;
                 default:
                 case 'browse':
                     @($root = intval(array_shift($stack)));
                     $tpl->assign('root_id', $root);
                     $categories = DAO_KbCategory::getWhere();
                     $tpl->assign('categories', $categories);
                     $tree_map = DAO_KbCategory::getTreeMap(0);
                     // Remove other top-level categories
                     if (is_array($tree_map[0])) {
                         foreach ($tree_map[0] as $child_id => $count) {
                             if (!isset($kb_roots[$child_id])) {
                                 unset($tree_map[0][$child_id]);
                             }
                         }
                     }
                     // Remove empty categories
                     if (is_array($tree_map[0])) {
                         foreach ($tree_map as $node_id => $children) {
                             foreach ($children as $child_id => $count) {
                                 if (empty($count)) {
                                     @($pid = $categories[$child_id]->parent_id);
                                     unset($tree_map[$pid][$child_id]);
                                     unset($tree_map[$child_id]);
                                 }
                             }
                         }
                     }
                     $tpl->assign('tree', $tree_map);
                     // Breadcrumb // [TODO] API-ize inside Model_KbTree ?
                     $breadcrumb = array();
                     $pid = $root;
                     while (0 != $pid) {
                         $breadcrumb[] = $pid;
                         $pid = $categories[$pid]->parent_id;
                     }
                     $tpl->assign('breadcrumb', array_reverse($breadcrumb));
                     $tpl->assign('mid', @intval(ceil(count($tree_map[$root]) / 2)));
                     // Articles
                     if (!empty($root)) {
                         list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::CATEGORY_ID, '=', $root), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
                     }
                     $tpl->assign('articles', $articles);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/kb/index.tpl");
                     break;
             }
             break;
         case 'answers':
             $query = rawurldecode(array_shift($stack));
             $tpl->assign('query', $query);
             $sFnrSources = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_FNR_SOURCES, '');
             $aFnrSources = !empty($sFnrSources) ? unserialize($sFnrSources) : array();
             if (!empty($query)) {
                 // [JAS]: If we've been customized with specific sources, use them
                 $where = !empty($aFnrSources) ? sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, implode(',', array_keys($aFnrSources))) : sprintf("%s IN (-1)", DAO_FnrExternalResource::ID);
                 $resources = DAO_FnrExternalResource::getWhere($where);
                 $feeds = Model_FnrExternalResource::searchResources($resources, $query);
                 $tpl->assign('feeds', $feeds);
                 $fields = array(DAO_FnrQuery::QUERY => $query, DAO_FnrQuery::CREATED => time(), DAO_FnrQuery::SOURCE => $this->getPortal(), DAO_FnrQuery::NO_MATCH => empty($feeds) ? 1 : 0);
                 DAO_FnrQuery::create($fields);
             }
             // KB
             $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, '');
             $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
             list($articles, $count) = DAO_KbArticle::search(array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, 'fulltext', $query), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, 'fulltext', $query)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 100, 0, null, null, true);
             $tpl->assign('articles', $articles);
             $tpl->display("file:{$tpl_path}portal/sc/internal/answers/index.tpl");
             break;
         case 'contact':
             $response = array_shift($stack);
             $settings = CerberusSettings::getInstance();
             $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
             $tpl->assign('default_from', $default_from);
             switch ($response) {
                 case 'confirm':
                     $tpl->assign('last_opened', $umsession->getProperty('support.write.last_opened', ''));
                     $tpl->display("file:{$tpl_path}portal/sc/internal/contact/confirm.tpl");
                     break;
                 default:
                 case 'step1':
                     $umsession->setProperty('support.write.last_error', null);
                 case 'step2':
                     $sFrom = $umsession->getProperty('support.write.last_from', '');
                     $sSubject = $umsession->getProperty('support.write.last_subject', '');
                     $sNature = $umsession->getProperty('support.write.last_nature', '');
                     $sContent = $umsession->getProperty('support.write.last_content', '');
                     //		    			$aLastFollowupQ = $umsession->getProperty('support.write.last_followup_q','');
                     $aLastFollowupA = $umsession->getProperty('support.write.last_followup_a', '');
                     $sError = $umsession->getProperty('support.write.last_error', '');
                     $tpl->assign('last_from', $sFrom);
                     $tpl->assign('last_subject', $sSubject);
                     $tpl->assign('last_nature', $sNature);
                     $tpl->assign('last_content', $sContent);
                     //						$tpl->assign('last_followup_q', $aLastFollowupQ);
                     $tpl->assign('last_followup_a', $aLastFollowupA);
                     $tpl->assign('last_error', $sError);
                     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_DISPATCH, '');
                     //		    			$dispatch = !empty($sDispatch) ? (is_array($sDispatch) ? unserialize($sDispatch): array($sDispatch)) : array();
                     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
                     $tpl->assign('dispatch', $dispatch);
                     switch ($response) {
                         default:
                             // If there's only one situation, skip to step2
                             if (1 == count($dispatch)) {
                                 @($sNature = md5(key($dispatch)));
                                 $umsession->setProperty('support.write.last_nature', $sNature);
                                 reset($dispatch);
                             } else {
                                 $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step1.tpl");
                                 break;
                             }
                         case 'step2':
                             // Cache along with answers?
                             if (is_array($dispatch)) {
                                 foreach ($dispatch as $k => $v) {
                                     if (md5($k) == $sNature) {
                                         $umsession->setProperty('support.write.last_nature_string', $k);
                                         $tpl->assign('situation', $k);
                                         $tpl->assign('situation_params', $v);
                                         break;
                                     }
                                 }
                             }
                             $ticket_fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
                             $tpl->assign('ticket_fields', $ticket_fields);
                             $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step2.tpl");
                             break;
                     }
                     break;
             }
             break;
             //				$tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl");
             //				break;
         //				$tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl");
         //				break;
         case 'history':
             if (!$this->allow_logins || empty($active_user)) {
                 break;
             }
             $mask = array_shift($stack);
             if (empty($mask)) {
                 list($open_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 0)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false);
                 $tpl->assign('open_tickets', $open_tickets);
                 list($closed_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 1)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false);
                 $tpl->assign('closed_tickets', $closed_tickets);
                 $tpl->display("file:{$tpl_path}portal/sc/internal/history/index.tpl");
             } else {
                 // Secure retrieval (address + mask)
                 list($tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MASK, '=', $mask), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id)), 1, 0, null, null, false);
                 $ticket = array_shift($tickets);
                 // Security check (mask compare)
                 if (0 == strcasecmp($ticket[SearchFields_Ticket::TICKET_MASK], $mask)) {
                     $messages = DAO_Ticket::getMessagesByTicket($ticket[SearchFields_Ticket::TICKET_ID]);
                     $messages = array_reverse($messages, true);
                     $tpl->assign('ticket', $ticket);
                     $tpl->assign('messages', $messages);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/history/display.tpl");
                 }
             }
             break;
         case 'register':
             if (!$this->allow_logins) {
                 break;
             }
             @($step = array_shift($stack));
             switch ($step) {
                 case 'forgot':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot.tpl");
                     break;
                 case 'forgot2':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot_confirm.tpl");
                     break;
                 case 'confirm':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/confirm.tpl");
                     break;
                 default:
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/index.tpl");
                     break;
             }
             break;
     }
     //		print_r($response);
 }
Exemplo n.º 7
0
}
if (isset($columns['MESSAGE_ID'])) {
    $sql = $datadict->DropColumnSQL('message', 'message_id');
    $datadict->ExecuteSQLArray($sql);
}
if (isset($columns['IS_ADMIN'])) {
    $sql = $datadict->DropColumnSQL('message', 'is_admin');
    $datadict->ExecuteSQLArray($sql);
}
if (!isset($columns['IS_OUTGOING'])) {
    $sql = $datadict->AddColumnSQL('message', 'is_outgoing I1 DEFAULT 0 NOTNULL');
    $datadict->ExecuteSQLArray($sql);
    // Gather Helpdesk/Group addresses
    try {
        $froms = array();
        $settings = CerberusSettings::getInstance();
        if (null != ($default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, null))) {
            $froms[$default_from] = 1;
        }
        if (null != ($group_settings = DAO_GroupSettings::getSettings()) && is_array($group_settings)) {
            foreach ($group_settings as $group_id => $gs) {
                if (is_array($gs) && isset($gs[DAO_GroupSettings::SETTING_REPLY_FROM])) {
                    $group_from = $gs[DAO_GroupSettings::SETTING_REPLY_FROM];
                    if (!empty($group_from)) {
                        $froms[$group_from] = 1;
                    }
                }
            }
        }
        if (is_array($froms) && !empty($froms)) {
            $froms = array_keys($froms);
Exemplo n.º 8
0
 private function _sendConfirmation($email, $link)
 {
     $settings = CerberusSettings::getInstance();
     $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL);
     $url = DevblocksPlatform::getUrlService();
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $code = CerberusApplication::generatePassword(8);
         if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, false))) {
             $fields = array(DAO_AddressAuth::CONFIRM => $code);
             DAO_AddressAuth::update($addy->id, $fields);
         } else {
             return;
         }
         $message = $mail_service->createMessage();
         $message->setTo($email);
         $send_from = new Swift_Address($from, $from_personal);
         $message->setFrom($send_from);
         $message->setSubject("Account Confirmation Code");
         $message->setBody(sprintf("Below is your confirmation code.  Please copy and paste it into the confirmation form at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "Thanks!\r\n", $link, $code));
         $message->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $mailer->send($message, $email, $send_from);
     } catch (Exception $e) {
         return;
     }
 }
Exemplo n.º 9
0
 /**
  * Enter description here...
  *
  * @param array $headers
  * @return array (group_id,address)
  */
 private static function findDestination($headers)
 {
     static $routing = null;
     $settings = CerberusSettings::getInstance();
     // [TODO] Should this cache be at the class level?
     if (is_null($routing)) {
         $routing = DAO_Mail::getMailboxRouting();
     }
     $destinations = self::getDestinations($headers);
     if (is_array($destinations)) {
         foreach ($destinations as $address) {
             // Test each pattern successively
             foreach ($routing as $route) {
                 /* @var $route Model_MailRoute */
                 $pattern = sprintf("/^%s\$/i", str_replace(array('*', '+'), array('.*?', '\\+'), $route->pattern));
                 if (preg_match($pattern, $address)) {
                     return array($route->team_id, $address);
                 }
             }
         }
     }
     // Check if we have a default mailbox configured before returning NULL.
     if (null != ($default_team = DAO_Group::getDefaultGroup())) {
         return array($default_team->id, '');
     }
     return null;
     // bounce
 }
Exemplo n.º 10
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     @set_time_limit(0);
     // no timelimit (when possible)
     $stack = $request->path;
     array_shift($stack);
     // update
     //	    $cache = DevblocksPlatform::getCacheService(); /* @var $cache _DevblocksCacheManager */
     $settings = CerberusSettings::getInstance();
     $authorized_ips_str = $settings->get(CerberusSettings::AUTHORIZED_IPS);
     $authorized_ips = DevblocksPlatform::parseCrlfString($authorized_ips_str);
     $authorized_ip_defaults = DevblocksPlatform::parseCsvString(AUTHORIZED_IPS_DEFAULTS);
     $authorized_ips = array_merge($authorized_ips, $authorized_ip_defaults);
     // Is this IP authorized?
     $pass = false;
     foreach ($authorized_ips as $ip) {
         if (substr($ip, 0, strlen($ip)) == substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip))) {
             $pass = true;
             break;
         }
     }
     if (!$pass) {
         echo 'Your IP address (' . $_SERVER['REMOTE_ADDR'] . ') is not authorized to debug this helpdesk.  Your administrator needs to authorize your IP in Helpdesk Setup or in the framework.config.php file under AUTHORIZED_IPS_DEFAULTS.';
         return;
     }
     switch (array_shift($stack)) {
         case 'phpinfo':
             phpinfo();
             break;
         case 'check':
             echo sprintf("<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title></title>\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\tBODY {font-family: Arial, Helvetica, sans-serif; font-size: 12px;}\n\t\t\t\t\t\t\tFORM {margin:0px; } \n\t\t\t\t\t\t\tH1 { margin:0px; }\n\t\t\t\t\t\t\t.fail {color:red;font-weight:bold;}\n\t\t\t\t\t\t\t.pass {color:green;font-weight:bold;}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t\t<h1>Cerberus Helpdesk - Requirements Checker:</h1>\n\t\t\t\t\t");
             $errors = CerberusApplication::checkRequirements();
             if (!empty($errors)) {
                 echo "<ul class='fail'>";
                 foreach ($errors as $error) {
                     echo sprintf("<li>%s</li>", $error);
                 }
                 echo "</ul>";
             } else {
                 echo '<span class="pass">Your server is compatible with Cerberus Helpdesk 4.x!</span>';
             }
             echo sprintf("\n\t\t\t\t\t</body>\n\t\t\t\t\t</html>\n\t\t\t\t");
             break;
         case 'report':
             @($db = DevblocksPlatform::getDatabaseService());
             @($settings = CerberusSettings::getInstance());
             @($tables = $db->MetaTables('TABLE', false));
             $report_output = sprintf("[Cerberus Helpdesk] App Build: %s\n" . "[Cerberus Helpdesk] Devblocks Build: %s\n" . "[Cerberus Helpdesk] URL-Rewrite: %s\n" . "\n" . "[Privs] storage/attachments: %s\n" . "[Privs] storage/mail/new: %s\n" . "[Privs] storage/mail/fail: %s\n" . "[Privs] storage/tmp: %s\n" . "[Privs] storage/tmp/templates_c: %s\n" . "[Privs] storage/tmp/cache: %s\n" . "\n" . "[PHP] Version: %s\n" . "[PHP] OS: %s\n" . "[PHP] SAPI: %s\n" . "\n" . "[php.ini] safe_mode: %s\n" . "[php.ini] max_execution_time: %s\n" . "[php.ini] memory_limit: %s\n" . "[php.ini] file_uploads: %s\n" . "[php.ini] upload_max_filesize: %s\n" . "[php.ini] post_max_size: %s\n" . "\n" . "[PHP:Extension] MySQL: %s\n" . "[PHP:Extension] PostgreSQL: %s\n" . "[PHP:Extension] MailParse: %s\n" . "[PHP:Extension] IMAP: %s\n" . "[PHP:Extension] Session: %s\n" . "[PHP:Extension] PCRE: %s\n" . "[PHP:Extension] GD: %s\n" . "[PHP:Extension] mbstring: %s\n" . "[PHP:Extension] XML: %s\n" . "[PHP:Extension] SimpleXML: %s\n" . "[PHP:Extension] DOM: %s\n" . "[PHP:Extension] SPL: %s\n" . "\n" . '%s', APP_BUILD, PLATFORM_BUILD, file_exists(APP_PATH . '/.htaccess') ? 'YES' : 'NO', substr(sprintf('%o', fileperms(APP_STORAGE_PATH . '/attachments')), -4), substr(sprintf('%o', fileperms(APP_STORAGE_PATH . '/mail/new')), -4), substr(sprintf('%o', fileperms(APP_STORAGE_PATH . '/mail/fail')), -4), substr(sprintf('%o', fileperms(APP_TEMP_PATH)), -4), substr(sprintf('%o', fileperms(APP_TEMP_PATH . '/templates_c')), -4), substr(sprintf('%o', fileperms(APP_TEMP_PATH . '/cache')), -4), PHP_VERSION, PHP_OS . ' (' . php_uname() . ')', php_sapi_name(), ini_get('safe_mode'), ini_get('max_execution_time'), ini_get('memory_limit'), ini_get('file_uploads'), ini_get('upload_max_filesize'), ini_get('post_max_size'), extension_loaded("mysql") ? 'YES' : 'NO', extension_loaded("pgsql") ? 'YES' : 'NO', extension_loaded("mailparse") ? 'YES' : 'NO', extension_loaded("imap") ? 'YES' : 'NO', extension_loaded("session") ? 'YES' : 'NO', extension_loaded("pcre") ? 'YES' : 'NO', extension_loaded("gd") ? 'YES' : 'NO', extension_loaded("mbstring") ? 'YES' : 'NO', extension_loaded("xml") ? 'YES' : 'NO', extension_loaded("simplexml") ? 'YES' : 'NO', extension_loaded("dom") ? 'YES' : 'NO', extension_loaded("spl") ? 'YES' : 'NO', '');
             if (!empty($settings)) {
                 $report_output .= sprintf("[Setting] HELPDESK_TITLE: %s\n" . "[Setting] DEFAULT_REPLY_FROM: %s\n" . "[Setting] DEFAULT_REPLY_PERSONAL: %s\n" . "[Setting] SMTP_HOST: %s\n" . "[Setting] SMTP_PORT: %s\n" . "[Setting] SMTP_ENCRYPTION_TYPE: %s\n" . "\n" . '%s', $settings->get(CerberusSettings::HELPDESK_TITLE, ''), str_replace(array('@', '.'), array(' at ', ' dot '), $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, '')), $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, ''), $settings->get(CerberusSettings::SMTP_HOST, ''), $settings->get(CerberusSettings::SMTP_PORT, ''), $settings->get(CerberusSettings::SMTP_ENCRYPTION_TYPE, ''), '');
             }
             if (is_array($tables) && !empty($tables)) {
                 $report_output .= sprintf("[Stats] # Workers: %s\n" . "[Stats] # Groups: %s\n" . "[Stats] # Tickets: %s\n" . "[Stats] # Messages: %s\n" . "\n" . "[Database] Tables:\n * %s\n" . "\n" . '%s', intval($db->getOne('SELECT count(id) FROM worker')), intval($db->getOne('SELECT count(id) FROM team')), intval($db->getOne('SELECT count(id) FROM ticket')), intval($db->getOne('SELECT count(id) FROM message')), implode("\n * ", array_values($tables)), '');
             }
             echo sprintf("<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title></title>\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\tBODY {font-family: Arial, Helvetica, sans-serif; font-size: 12px;}\n\t\t\t\t\t\t\tFORM {margin:0px; } \n\t\t\t\t\t\t\tH1 { margin:0px; }\n\t\t\t\t\t\t\t.fail {color:red;font-weight:bold;}\n\t\t\t\t\t\t\t.pass {color:green;font-weight:bold;}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t\t<form>\n\t\t\t\t\t\t\t<h1>Cerberus Helpdesk - Debug Report:</h1>\n\t\t\t\t\t\t\t<textarea rows='25' cols='100'>%s</textarea>\n\t\t\t\t\t\t</form>\t\n\t\t\t\t\t</body>\n\t\t\t\t\t</html>\n\t\t\t\t\t", $report_output);
             break;
         default:
             $url_service = DevblocksPlatform::getUrlService();
             echo sprintf("<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title></title>\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\tBODY {font-family: Arial, Helvetica, sans-serif; font-size: 12px;}\n\t\t\t\t\t\t\tFORM {margin:0px; } \n\t\t\t\t\t\t\tH1 { margin:0px; }\n\t\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t\t<form>\n\t\t\t\t\t\t\t<h1>Cerberus Helpdesk - Debug Menu:</h1>\n\t\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t\t<li><a href='%s'>Requirements Checker</a></li>\n\t\t\t\t\t\t\t\t<li><a href='%s'>Debug Report (for technical support)</a></li>\n\t\t\t\t\t\t\t\t<li><a href='%s'>phpinfo()</a></li>\n\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t</form>\t\n\t\t\t\t\t</body>\n\t\t\t\t\t</html>\n\t\t\t\t\t", $url_service->write('c=debug&a=check'), $url_service->write('c=debug&a=report'), $url_service->write('c=debug&a=phpinfo'));
             break;
     }
     exit;
 }
Exemplo n.º 11
0
 private function _sendForwards($event, $is_inbound)
 {
     @($ticket_id = $event->params['ticket_id']);
     @($send_worker_id = $event->params['worker_id']);
     $url_writer = DevblocksPlatform::getUrlService();
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // (Action) Forward Email To:
     // Sanitize and combine all the destination addresses
     $next_worker = DAO_Worker::getAgent($ticket->next_worker_id);
     $notify_emails = $next_worker->email;
     if (empty($notify_emails)) {
         return;
     }
     // [TODO] This could be more efficient
     $messages = DAO_Ticket::getMessagesByTicket($ticket_id);
     $message = end($messages);
     // last message
     unset($messages);
     $headers = $message->getHeaders();
     // The whole flipping Swift section needs wrapped to catch exceptions
     try {
         $settings = CerberusSettings::getInstance();
         $reply_to = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, '');
         // See if we need a group-specific reply-to
         if (!empty($ticket->team_id)) {
             @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
             if (!empty($group_from)) {
                 $reply_to = $group_from;
             }
         }
         $sender = DAO_Address::get($message->address_id);
         $sender_email = strtolower($sender->email);
         $sender_split = explode('@', $sender_email);
         if (!is_array($sender_split) || count($sender_split) != 2) {
             return;
         }
         // If return-path is blank
         if (isset($headers['return-path']) && $headers['return-path'] == '<>') {
             return;
         }
         // Ignore bounces
         if ($sender_split[0] == "postmaster" || $sender_split[0] == "mailer-daemon") {
             return;
         }
         // Ignore autoresponses autoresponses
         if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') {
             return;
         }
         // Attachments
         $attachments = $message->getAttachments();
         $mime_attachments = array();
         if (is_array($attachments)) {
             foreach ($attachments as $attachment) {
                 if (0 == strcasecmp($attachment->display_name, 'original_message.html')) {
                     continue;
                 }
                 $attachment_path = APP_STORAGE_PATH . '/attachments/';
                 // [TODO] This is highly redundant in the codebase
                 if (!file_exists($attachment_path . $attachment->filepath)) {
                     continue;
                 }
                 $attach = Swift_Attachment::fromPath($attachment_path . $attachment->filepath);
                 if (!empty($attachment->display_name)) {
                     $attach->setFilename($attachment->display_name);
                 }
                 $mime_attachments[] = $attach;
             }
         }
         // Send copies
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         /* @var $mail Swift_Message */
         $mail->setTo(array($notify_emails));
         $mail->setFrom(array($sender->email));
         $mail->setReplyTo($reply_to);
         $mail->setReturnPath($reply_to);
         $mail->setSubject(sprintf("[RW: %s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject));
         $hdrs = $mail->getHeaders();
         if (null !== @($msgid = $headers['message-id'])) {
             $hdrs->addTextHeader('Message-Id', $msgid);
         }
         if (null !== @($in_reply_to = $headers['in-reply-to'])) {
             $hdrs->addTextHeader('References', $in_reply_to);
             $hdrs->addTextHeader('In-Reply-To', $in_reply_to);
         }
         $hdrs->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $hdrs->addTextHeader('Precedence', 'List');
         $hdrs->addTextHeader('Auto-Submitted', 'auto-generated');
         $mail->setBody($message->getContent());
         // Send message attachments with watcher
         if (is_array($mime_attachments)) {
             foreach ($mime_attachments as $mime_attachment) {
                 $mail->attach($mime_attachment);
             }
         }
         $result = $mailer->send($mail);
     } catch (Exception $e) {
         if (!empty($message_id)) {
             $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
             DAO_MessageNote::create($fields);
         }
     }
 }
Exemplo n.º 12
0
 public function saveConfiguration()
 {
     @($sLogoUrl = DevblocksPlatform::importGPC($_POST['logo_url'], 'string', ''));
     @($sPageTitle = DevblocksPlatform::importGPC($_POST['page_title'], 'string', 'Contact Us'));
     @($iCaptcha = DevblocksPlatform::importGPC($_POST['captcha_enabled'], 'integer', 1));
     //        @$sThemeUrl = DevblocksPlatform::importGPC($_POST['theme_url'],'string','');
     DAO_CommunityToolProperty::set($this->getPortal(), self::PARAM_LOGO_URL, $sLogoUrl);
     DAO_CommunityToolProperty::set($this->getPortal(), self::PARAM_PAGE_TITLE, $sPageTitle);
     DAO_CommunityToolProperty::set($this->getPortal(), self::PARAM_CAPTCHA_ENABLED, $iCaptcha);
     //        DAO_CommunityToolProperty::set($this->getPortal(), self::PARAM_THEME_URL, $sThemeUrl);
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     @($arDeleteSituations = DevblocksPlatform::importGPC($_POST['delete_situations'], 'array', array()));
     @($sEditReason = DevblocksPlatform::importGPC($_POST['edit_reason'], 'string', ''));
     @($sReason = DevblocksPlatform::importGPC($_POST['reason'], 'string', ''));
     @($sTo = DevblocksPlatform::importGPC($_POST['to'], 'string', ''));
     @($aFollowup = DevblocksPlatform::importGPC($_POST['followup'], 'array', array()));
     @($aFollowupLong = DevblocksPlatform::importGPC($_POST['followup_long'], 'array', array()));
     if (empty($sTo)) {
         $sTo = $default_from;
     }
     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_DISPATCH, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     // [JAS]: [TODO] Only needed temporarily to clean up imports
     // [TODO] Move to patch
     if (is_array($dispatch)) {
         foreach ($dispatch as $d_reason => $d_params) {
             if (!is_array($d_params)) {
                 $dispatch[$d_reason] = array('to' => $d_params, 'followups' => array());
             } else {
                 unset($d_params['']);
             }
         }
     }
     // Nuke a record we're replacing or any checked boxes
     foreach ($dispatch as $d_reason => $d_params) {
         if (!empty($sEditReason) && md5($d_reason) == $sEditReason) {
             unset($dispatch[$d_reason]);
         } elseif (!empty($arDeleteSituations) && false !== array_search(md5($d_reason), $arDeleteSituations)) {
             unset($dispatch[$d_reason]);
         }
     }
     // If we have new data, add it
     if (!empty($sReason) && !empty($sTo) && false === array_search(md5($sReason), $arDeleteSituations)) {
         $dispatch[$sReason] = array('to' => $sTo, 'followups' => array());
         $followups =& $dispatch[$sReason]['followups'];
         if (!empty($aFollowup)) {
             foreach ($aFollowup as $idx => $followup) {
                 if (empty($followup)) {
                     continue;
                 }
                 $followups[$followup] = false !== array_search($idx, $aFollowupLong) ? 1 : 0;
             }
         }
     }
     ksort($dispatch);
     DAO_CommunityToolProperty::set($this->getPortal(), self::PARAM_DISPATCH, serialize($dispatch));
 }
Exemplo n.º 13
0
 private function _sendConfirmationEmail($to, $worker)
 {
     $translate = DevblocksPlatform::getTranslationService();
     $settings = CerberusSettings::getInstance();
     $url_writer = DevblocksPlatform::getUrlService();
     $tpl = DevblocksPlatform::getTemplateService();
     // Tentatively assign the e-mail address to this worker
     DAO_AddressToWorker::assign($to, $worker->id);
     // Create a confirmation code and save it
     $code = CerberusApplication::generatePassword(20);
     DAO_AddressToWorker::update($to, array(DAO_AddressToWorker::CODE => $code, DAO_AddressToWorker::CODE_EXPIRE => time() + 24 * 60 * 60));
     // Email the confirmation code to the address
     // [TODO] This function can return false, and we need to do something different if it does.
     CerberusMail::quickSend($to, vsprintf($translate->_('prefs.address.confirm.mail.subject'), $settings->get(CerberusSettings::HELPDESK_TITLE)), vsprintf($translate->_('prefs.address.confirm.mail.body'), array($worker->getName(), $url_writer->write('c=preferences&a=confirm_email&code=' . $code, true))));
     $output = array(vsprintf($translate->_('prefs.address.confirm.mail.subject'), $to));
     $tpl->assign('pref_success', $output);
 }
Exemplo n.º 14
0
 function doContactSendAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sSubject = DevblocksPlatform::importGPC($_POST['subject'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     @($aFieldIds = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
     @($aFollowUpQ = DevblocksPlatform::importGPC($_POST['followup_q'], 'array', array()));
     // Load the answers to any situational questions
     $aFollowUpA = array();
     if (is_array($aFollowUpQ)) {
         foreach ($aFollowUpQ as $idx => $q) {
             @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'string', ''));
             $aFollowUpA[$idx] = $answer;
         }
     }
     $umsession = UmPortalHelper::getSession();
     $fingerprint = UmPortalHelper::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_subject', $sSubject);
     $umsession->setProperty('support.write.last_content', $sContent);
     //		$umsession->setProperty('support.write.last_followup_q',$aFollowUpQ);
     $umsession->setProperty('support.write.last_followup_a', $aFollowUpA);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_CAPTCHA_ENABLED, 1);
     // Subject is required if the field  is on the form
     if (isset($_POST['subject']) && empty($sSubject)) {
         $umsession->setProperty('support.write.last_error', 'A subject is required.');
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Sender and CAPTCHA required
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, @$umsession->getProperty(UmScApp::SESSION_CAPTCHA, '***'))) {
         if (empty($sFrom)) {
             $umsession->setProperty('support.write.last_error', 'Invalid e-mail address.');
         } else {
             $umsession->setProperty('support.write.last_error', 'What you typed did not match the image.');
         }
         // Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_SITUATIONS, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     foreach ($dispatch as $k => $v) {
         if (md5($k) == $sNature) {
             $to = $v['to'];
             $subject = 'Contact me: ' . strip_tags($k);
             break;
         }
     }
     if (!empty($sSubject)) {
         $subject = $sSubject;
     }
     $fieldContent = '';
     if (!empty($aFollowUpQ)) {
         $fieldContent = "\r\n\r\n";
         $fieldContent .= "--------------------------------------------\r\n";
         if (!empty($sNature)) {
             $fieldContent .= $subject . "\r\n";
             $fieldContent .= "--------------------------------------------\r\n";
         }
         foreach ($aFollowUpQ as $idx => $q) {
             $answer = isset($aFollowUpA[$idx]) ? $aFollowUpA[$idx] : '';
             $fieldContent .= "Q) " . $q . "\r\n" . "A) " . $answer . "\r\n";
             if ($idx + 1 < count($aFollowUpQ)) {
                 $fieldContent .= "\r\n";
             }
         }
         $fieldContent .= "--------------------------------------------\r\n";
         "\r\n";
     }
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     $message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist($sFrom, '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $message->headers['from'] = $from->mailbox . '@' . $from->host;
     $message->body = 'IP: ' . $fingerprint['ip'] . "\r\n\r\n" . $sContent . $fieldContent;
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // Auto-save any custom fields
     $fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
     if (!empty($aFieldIds)) {
         foreach ($aFieldIds as $iIdx => $iFieldId) {
             if (!empty($iFieldId)) {
                 $field =& $fields[$iFieldId];
                 /* @var $field Model_CustomField */
                 $value = "";
                 switch ($field->type) {
                     case Model_CustomField::TYPE_SINGLE_LINE:
                     case Model_CustomField::TYPE_MULTI_LINE:
                         @($value = trim($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_NUMBER:
                         @($value = intval($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_DATE:
                         if (false !== ($time = strtotime($aFollowUpA[$iIdx]))) {
                             @($value = intval($time));
                         }
                         break;
                     case Model_CustomField::TYPE_DROPDOWN:
                         @($value = $aFollowUpA[$iIdx]);
                         break;
                     case Model_CustomField::TYPE_CHECKBOX:
                         @($value = isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx]) ? 1 : 0);
                         break;
                 }
                 if (!empty($value)) {
                     DAO_CustomFieldValue::setFieldValue('cerberusweb.fields.source.ticket', $ticket_id, $iFieldId, $value);
                 }
             }
         }
     }
     // Clear any errors
     $umsession->setProperty('support.write.last_nature', null);
     $umsession->setProperty('support.write.last_nature_string', null);
     $umsession->setProperty('support.write.last_content', null);
     $umsession->setProperty('support.write.last_error', null);
     $umsession->setProperty('support.write.last_opened', $ticket->mask);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'confirm')));
 }
Exemplo n.º 15
0
 function saveTab()
 {
     $settings = CerberusSettings::getInstance();
     @($plugin_id = DevblocksPlatform::importGPC($_REQUEST['plugin_id'], 'string'));
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($name = DevblocksPlatform::importGPC($_REQUEST['name'], 'string', ''));
     @($rate = floatval(DevblocksPlatform::importGPC($_REQUEST['rate'], 'string', '')));
     @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0));
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'timetracking.activities')));
         return;
     }
     if (empty($id)) {
         // Add
         $fields = array(DAO_TimeTrackingActivity::NAME => $name, DAO_TimeTrackingActivity::RATE => $rate);
         $activity_id = DAO_TimeTrackingActivity::create($fields);
     } else {
         // Edit
         if ($do_delete) {
             // Delete
             DAO_TimeTrackingActivity::delete($id);
         } else {
             // Modify
             $fields = array(DAO_TimeTrackingActivity::NAME => $name, DAO_TimeTrackingActivity::RATE => $rate);
             DAO_TimeTrackingActivity::update($id, $fields);
         }
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('config', 'timetracking.activities')));
     exit;
 }
Exemplo n.º 16
0
 function hasPriv($priv_id)
 {
     // We don't need to do much work if we're a superuser
     if ($this->is_superuser) {
         return true;
     }
     $settings = CerberusSettings::getInstance();
     $acl_enabled = $settings->get(CerberusSettings::ACL_ENABLED);
     // ACL is a paid feature (please respect the licensing and support the project!)
     $license = CerberusLicense::getInstance();
     if (!$acl_enabled || !isset($license['serial']) || isset($license['a'])) {
         return "core.config" == substr($priv_id, 0, 11) ? false : true;
     }
     // Check the aggregated worker privs from roles
     $acl = DAO_WorkerRole::getACL();
     $privs_by_worker = $acl[DAO_WorkerRole::CACHE_KEY_PRIVS_BY_WORKER];
     if (!empty($priv_id) && isset($privs_by_worker[$this->id][$priv_id])) {
         return true;
     }
     return false;
 }
Exemplo n.º 17
0
 /**
  * @return CerberusSettings
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new CerberusSettings();
     }
     return self::$instance;
 }
Exemplo n.º 18
0
 function getComposeSignatureAction()
 {
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer', 0));
     $settings = CerberusSettings::getInstance();
     $group = DAO_Group::getTeam($group_id);
     $active_worker = CerberusApplication::getActiveWorker();
     $worker = DAO_Worker::getAgent($active_worker->id);
     // Use the most recent info (not session)
     $sig = $settings->get(CerberusSettings::DEFAULT_SIGNATURE, '');
     if (!empty($group->signature)) {
         $sig = $group->signature;
     }
     /*
      * [TODO] This is the 3rd place this replace happens, we really need 
      * to move the signature translation into something like CerberusApplication
      */
     echo sprintf("\r\n%s\r\n", str_replace(array('#first_name#', '#last_name#', '#title#'), array($worker->first_name, $worker->last_name, $worker->title), $sig));
 }
Exemplo n.º 19
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     /* @var $response DevblocksHttpResponse */
     $path = $response->path;
     $uri_prefix = array_shift($path);
     // should be mobile
     // [JAS]: Ajax? // [TODO] Explore outputting whitespace here for Safari
     //	    if(empty($path))
     //			return;
     $tpl = DevblocksPlatform::getTemplateService();
     $session = DevblocksPlatform::getSessionService();
     $settings = CerberusSettings::getInstance();
     $translate = DevblocksPlatform::getTranslationService();
     $visit = $session->getVisit();
     $controller = array_shift($path);
     $pages = DevblocksPlatform::getExtensions('cerberusweb.mobile.page', true);
     // Default page [TODO] This is supposed to come from framework.config.php
     if (empty($controller)) {
         $controller = 'tickets';
     }
     // [JAS]: Require us to always be logged in for Cerberus pages
     // [TODO] This should probably consult with the page itself for ::authenticated()
     if (empty($visit)) {
         $controller = 'login';
     }
     $page_id = $this->_getPageIdByUri($controller);
     /* @var $page CerberusPageExtension */
     @($page = $pages[$page_id]);
     if (empty($page)) {
         return;
     }
     // 404
     // [TODO] Reimplement
     if (!empty($visit) && !is_null($visit->getWorker())) {
         DAO_Worker::logActivity($visit->getWorker()->id, $page->getActivity());
     }
     // [JAS]: Listeners (Step-by-step guided tour, etc.)
     $listenerManifests = DevblocksPlatform::getExtensions('devblocks.listener.http');
     foreach ($listenerManifests as $listenerManifest) {
         /* @var $listenerManifest DevblocksExtensionManifest */
         $inst = $listenerManifest->createInstance();
         /* @var $inst DevblocksHttpRequestListenerExtension */
         $inst->run($response, $tpl);
     }
     // [JAS]: Pre-translate any dynamic strings
     $common_translated = array();
     if (!empty($visit) && !is_null($visit->getWorker())) {
         $common_translated['header_signed_in'] = vsprintf($translate->_('header.signed_in'), array('<b>' . $visit->getWorker()->getName() . '</b>'));
     }
     $tpl->assign('common_translated', $common_translated);
     //        $tour_enabled = false;
     //		if(!empty($visit) && !is_null($visit->getWorker())) {
     //        	$worker = $visit->getWorker();
     //			$tour_enabled = DAO_WorkerPref::get($worker->id, 'assist_mode');
     //			$tour_enabled = ($tour_enabled===false) ? 1 : $tour_enabled;
     //			if(DEMO_MODE) $tour_enabled = 1; // override for DEMO
     //		}
     //		$tpl->assign('tour_enabled', $tour_enabled);
     // [JAS]: Variables provided to all page templates
     $tpl->assign('settings', $settings);
     $tpl->assign('session', $_SESSION);
     $tpl->assign('translate', $translate);
     $tpl->assign('visit', $visit);
     $tpl->assign('license', CerberusLicense::getInstance());
     $active_worker = CerberusApplication::getActiveWorker();
     $tpl->assign('active_worker', $active_worker);
     if (!empty($active_worker)) {
         $active_worker_memberships = $active_worker->getMemberships();
         $tpl->assign('active_worker_memberships', $active_worker_memberships);
     }
     $tpl->assign('pages', $pages);
     $tpl->assign('page', $page);
     $tpl->assign('response_uri', implode('/', $response->path));
     $tpl_path = DEVBLOCKS_PLUGIN_PATH . 'cerberusweb.mobile/templates/';
     $tpl->assign('core_tpl', DEVBLOCKS_PLUGIN_PATH . 'cerberusweb.core/templates/');
     // Timings
     $tpl->assign('render_time', microtime(true) - DevblocksPlatform::getStartTime());
     if (function_exists('memory_get_usage') && function_exists('memory_get_peak_usage')) {
         $tpl->assign('render_memory', memory_get_usage() - DevblocksPlatform::getStartMemory());
         $tpl->assign('render_peak_memory', memory_get_peak_usage() - DevblocksPlatform::getStartPeakMemory());
     }
     $tpl->display($tpl_path . 'border.tpl');
 }
Exemplo n.º 20
0
 function doReplyAction()
 {
     @($mask = DevblocksPlatform::importGPC($_REQUEST['mask'], 'string', ''));
     @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', ''));
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     // Secure retrieval (address + mask)
     list($tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MASK, '=', $mask), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id)), 1, 0, null, null, false);
     $ticket = array_shift($tickets);
     $messages = DAO_Ticket::getMessagesByTicket($ticket[SearchFields_Ticket::TICKET_ID]);
     $last_message = array_pop($messages);
     /* @var $last_message CerberusMessage */
     $last_message_headers = $last_message->getHeaders();
     unset($messages);
     // Helpdesk settings
     $settings = CerberusSettings::getInstance();
     $global_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, null);
     // Ticket group settings
     $group_id = $ticket[SearchFields_Ticket::TICKET_TEAM_ID];
     @($group_from = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
     // Headers
     $to = !empty($group_from) ? $group_from : $global_from;
     @($in_reply_to = $last_message_headers['message-id']);
     @($message_id = CerberusApplication::generateMessageId());
     $message = new CerberusParserMessage();
     $message->headers['from'] = $active_user->email;
     $message->headers['to'] = $to;
     $message->headers['date'] = gmdate('r');
     $message->headers['subject'] = 'Re: ' . $ticket[SearchFields_Ticket::TICKET_SUBJECT];
     $message->headers['message-id'] = $message_id;
     $message->headers['in-reply-to'] = $in_reply_to;
     $message->body = sprintf("%s", $content);
     CerberusParser::parseMessage($message, array('no_autoreply' => true));
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'history', $ticket[SearchFields_Ticket::TICKET_MASK])));
 }
Exemplo n.º 21
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     $worker = CerberusApplication::getActiveWorker();
     if (empty($worker)) {
         return;
     }
     $stack = $request->path;
     array_shift($stack);
     // print
     @($object = strtolower(array_shift($stack)));
     // ticket|message|etc
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $settings = CerberusSettings::getInstance();
     $tpl->assign('settings', $settings);
     $translate = DevblocksPlatform::getTranslationService();
     $tpl->assign('translate', $translate);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     $buckets = DAO_Bucket::getAll();
     $tpl->assign('buckets', $buckets);
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     // Security
     $active_worker = CerberusApplication::getActiveWorker();
     $active_worker_memberships = $active_worker->getMemberships();
     // [TODO] Make this pluggable
     // Subcontroller
     switch ($object) {
         case 'ticket':
             @($id = array_shift($stack));
             @($ticket = is_numeric($id) ? DAO_Ticket::getTicket($id) : DAO_Ticket::getTicketByMask($id));
             $convo_timeline = array();
             $messages = $ticket->getMessages();
             foreach ($messages as $message_id => $message) {
                 /* @var $message CerberusMessage */
                 $key = $message->created_date . '_m' . $message_id;
                 // build a chrono index of messages
                 $convo_timeline[$key] = array('m', $message_id);
             }
             @($mail_inline_comments = DAO_WorkerPref::get($active_worker->id, 'mail_inline_comments', 1));
             if ($mail_inline_comments) {
                 // if inline comments are enabled
                 $comments = DAO_TicketComment::getByTicketId($ticket->id);
                 arsort($comments);
                 $tpl->assign('comments', $comments);
                 // build a chrono index of comments
                 foreach ($comments as $comment_id => $comment) {
                     /* @var $comment Model_TicketComment */
                     $key = $comment->created . '_c' . $comment_id;
                     $convo_timeline[$key] = array('c', $comment_id);
                 }
             }
             ksort($convo_timeline);
             $tpl->assign('convo_timeline', $convo_timeline);
             // Comment parent addresses
             $comment_addresses = array();
             foreach ($comments as $comment) {
                 /* @var $comment Model_TicketComment */
                 $address_id = intval($comment->address_id);
                 if (!isset($comment_addresses[$address_id])) {
                     $address = DAO_Address::get($address_id);
                     $comment_addresses[$address_id] = $address;
                 }
             }
             $tpl->assign('comment_addresses', $comment_addresses);
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/ticket.tpl');
             break;
         case 'message':
             @($id = array_shift($stack));
             @($message = DAO_Ticket::getMessage($id));
             @($ticket = DAO_Ticket::getTicket($message->ticket_id));
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             $tpl->assign('message', $message);
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/message.tpl');
             break;
     }
 }
Exemplo n.º 22
0
 static function reflect(CerberusParserMessage $message, $to)
 {
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         $settings = CerberusSettings::getInstance();
         @($from_addy = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
         @($from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, ''));
         $mail->setTo(array($to));
         $headers = $mail->getHeaders();
         if (isset($message->headers['subject'])) {
             if (is_array($message->headers['subject'])) {
                 $subject = array_shift($message->headers['subject']);
             } else {
                 $subject = $message->headers['subject'];
             }
             $mail->setSubject($subject);
         }
         if (isset($message->headers['message-id'])) {
             $headers->addTextHeader('Message-Id', $message->headers['message-id']);
         }
         if (isset($message->headers['in-reply-to'])) {
             $headers->addTextHeader('In-Reply-To', $message->headers['in-reply-to']);
         }
         if (isset($message->headers['references'])) {
             $headers->addTextHeader('References', $message->headers['references']);
         }
         if (isset($message->headers['from'])) {
             $mail->setFrom($message->headers['from']);
         }
         if (isset($message->headers['return-path'])) {
             $mail->setReturnPath($message->headers['return-path']);
         }
         if (isset($message->headers['reply-to'])) {
             $mail->setReplyTo($message->headers['reply-to']);
         }
         $headers->addTextHeader('X-CerberusRedirect', '1');
         $mail->setBody($message->body);
         // Files
         if (is_array($message->files)) {
             foreach ($message->files as $file_name => $file) {
                 /* @var $file ParserFile */
                 $mail->attach(Swift_Attachment::fromPath($file->tmpname)->setFilename($file_name));
             }
         }
         $result = $mailer->send($mail);
         if (!$result) {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
 }
Exemplo n.º 23
0
 function replyAction()
 {
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($is_forward = DevblocksPlatform::importGPC($_REQUEST['forward'], 'integer', 0));
     $settings = CerberusSettings::getInstance();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('id', $id);
     $tpl->assign('is_forward', $is_forward);
     $message = DAO_Ticket::getMessage($id);
     $tpl->assign('message', $message);
     $ticket = DAO_Ticket::getTicket($message->ticket_id);
     $tpl->assign('ticket', $ticket);
     // ReplyToolbarItem Extensions
     $replyToolbarItems = DevblocksPlatform::getExtensions('cerberusweb.reply.toolbaritem', true);
     if (!empty($replyToolbarItems)) {
         $tpl->assign('reply_toolbaritems', $replyToolbarItems);
     }
     // Show attachments for forwarded messages
     if ($is_forward) {
         $forward_attachments = $message->getAttachments();
         $tpl->assign('forward_attachments', $forward_attachments);
     }
     $workers = DAO_Worker::getAllActive();
     $tpl->assign('workers', $workers);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     $team_categories = DAO_Bucket::getTeams();
     $tpl->assign('team_categories', $team_categories);
     @($ticket_team = $teams[$ticket->team_id]);
     if (null != ($worker = CerberusApplication::getActiveWorker())) {
         /* @var $worker CerberusWorker */
         /* [JAS]:
          * If the worker is replying to an unassigned ticket, assign it to them to warn
          * other workers.  By default the 'next worker' followup propery will revert back 
          * to 'anybody' when desired.
          * 
          * We're intentionally not telling the template about the new owner.
          */
         if (0 == $ticket->next_worker_id) {
             DAO_Ticket::updateTicket($ticket->id, array(DAO_Ticket::NEXT_WORKER_ID => $worker->id));
         }
         // Signatures
         if (!empty($ticket_team) && !empty($ticket_team->signature)) {
             $signature = $ticket_team->signature;
         } else {
             // [TODO] Default signature
             $signature = $settings->get(CerberusSettings::DEFAULT_SIGNATURE);
         }
         $tpl->assign('signature', str_replace(array('#first_name#', '#last_name#', '#title#'), array($worker->first_name, $worker->last_name, $worker->title), $signature));
         $signature_pos = $settings->get(CerberusSettings::DEFAULT_SIGNATURE_POS, 0);
         $tpl->assign('signature_pos', $signature_pos);
     }
     $tpl->assign('upload_max_filesize', ini_get('upload_max_filesize'));
     $kb_topics = DAO_KbCategory::getWhere(sprintf("%s = %d", DAO_KbCategory::PARENT_ID, 0));
     $tpl->assign('kb_topics', $kb_topics);
     $tpl->cache_lifetime = "0";
     $tpl->display('file:' . $this->_TPL_PATH . 'display/rpc/reply.tpl');
 }
Exemplo n.º 24
0
 private function _sendForwards($event, $is_inbound)
 {
     @($ticket_id = $event->params['ticket_id']);
     @($message_id = $event->params['message_id']);
     @($send_worker_id = $event->params['worker_id']);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     $workers = DAO_Worker::getAllActive();
     // [JAS]: Don't send obvious spam to watchers.
     if ($ticket->spam_score >= 0.9) {
         return true;
     }
     @($notifications = DAO_WorkerMailForward::getWhere(sprintf("%s = %d", DAO_WorkerMailForward::GROUP_ID, $ticket->team_id)));
     // Bail out early if we have no forwards for this group
     if (empty($notifications)) {
         return;
     }
     $message = DAO_Ticket::getMessage($message_id);
     $headers = $message->getHeaders();
     // The whole flipping Swift section needs wrapped to catch exceptions
     try {
         $settings = CerberusSettings::getInstance();
         $reply_to = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, '');
         // See if we need a group-specific reply-to
         if (!empty($ticket->team_id)) {
             @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
             if (!empty($group_from)) {
                 $reply_to = $group_from;
             }
         }
         $sender = DAO_Address::get($message->address_id);
         $sender_email = strtolower($sender->email);
         $sender_split = explode('@', $sender_email);
         if (!is_array($sender_split) || count($sender_split) != 2) {
             return;
         }
         // If return-path is blank
         if (isset($headers['return-path']) && $headers['return-path'] == '<>') {
             return;
         }
         // Ignore bounces
         if ($sender_split[1] == "postmaster" || $sender_split[1] == "mailer-daemon") {
             return;
         }
         // Ignore autoresponses autoresponses
         if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') {
             return;
         }
         // Headers
         //==========
         // Build mailing list
         $send_to = array();
         foreach ($notifications as $n) {
             /* @var $n Model_WorkerMailForward */
             if (!isset($n->group_id) || !isset($n->bucket_id)) {
                 continue;
             }
             // if worker no longer exists or is disabled
             if (!isset($workers[$n->worker_id])) {
                 continue;
             }
             // Don't allow a worker to usurp a helpdesk address
             if (isset($helpdesk_senders[$n->email])) {
                 continue;
             }
             if ($n->group_id == $ticket->team_id && ($n->bucket_id == -1 || $n->bucket_id == $ticket->category_id)) {
                 // Event checking
                 if ($is_inbound && ($n->event == 'i' || $n->event == 'io') || !$is_inbound && ($n->event == 'o' || $n->event == 'io') || $is_inbound && $n->event == 'r' && $ticket->next_worker_id == $n->worker_id) {
                     $send_to[$n->email] = true;
                 }
             }
         }
         // Attachments
         $attachments = $message->getAttachments();
         $mime_attachments = array();
         if (is_array($attachments)) {
             foreach ($attachments as $attachment) {
                 if (0 == strcasecmp($attachment->display_name, 'original_message.html')) {
                     continue;
                 }
                 $attachment_path = APP_STORAGE_PATH . '/attachments/';
                 // [TODO] This is highly redundant in the codebase
                 if (!file_exists($attachment_path . $attachment->filepath)) {
                     continue;
                 }
                 $file =& new Swift_File($attachment_path . $attachment->filepath);
                 $mime_attachments[] =& new Swift_Message_Attachment($file, $attachment->display_name, $attachment->mime_type);
             }
         }
         // Send copies
         if (is_array($send_to) && !empty($send_to)) {
             $mail_service = DevblocksPlatform::getMailService();
             $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
             foreach ($send_to as $to => $bool) {
                 // Proxy the message
                 $rcpt_to = new Swift_RecipientList();
                 $a_rcpt_to = array();
                 $mail_from = new Swift_Address($sender->email);
                 $rcpt_to->addTo($to);
                 $a_rcpt_to = new Swift_Address($to);
                 $mail = $mail_service->createMessage();
                 /* @var $mail Swift_Message */
                 $mail->setTo($a_rcpt_to);
                 $mail->setFrom($mail_from);
                 $mail->setReplyTo($reply_to);
                 $mail->setReturnPath($reply_to);
                 $mail->setSubject(sprintf("[%s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject));
                 if (false !== @($msgid = $headers['message-id'])) {
                     $mail->headers->set('Message-Id', $msgid);
                 }
                 if (false !== @($in_reply_to = $headers['in-reply-to'])) {
                     $mail->headers->set('References', $in_reply_to);
                     $mail->headers->set('In-Reply-To', $in_reply_to);
                 }
                 $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
                 $mail->headers->set('Precedence', 'List');
                 $mail->headers->set('Auto-Submitted', 'auto-generated');
                 $mail->attach(new Swift_Message_Part($message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE));
                 // Send message attachments with watcher
                 if (is_array($mime_attachments)) {
                     foreach ($mime_attachments as $mime_attachment) {
                         $mail->attach($mime_attachment);
                     }
                 }
                 $mailer->send($mail, $rcpt_to, $mail_from);
             }
         }
     } catch (Exception $e) {
         $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
         DAO_MessageNote::create($fields);
     }
 }
Exemplo n.º 25
0
 function doRecoverStep1Action()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string'));
     $worker = DAO_Worker::lookupAgentEmail($email);
     if (empty($email) || empty($worker)) {
         return;
     }
     $_SESSION[self::KEY_FORGOT_EMAIL] = $email;
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         $code = CerberusApplication::generatePassword(10);
         $_SESSION[self::KEY_FORGOT_SENTCODE] = $code;
         $settings = CerberusSettings::getInstance();
         $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
         $personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL);
         // Headers
         $mail->setTo(array($email));
         $mail->setFrom(array($from => $personal));
         $mail->setSubject($translate->_('signin.forgot.mail.subject'));
         $mail->generateId();
         $headers = $mail->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $mail->setBody(vsprintf($translate->_('signin.forgot.mail.body'), $code));
         if (!$mailer->send($mail)) {
             throw new Exception('Password Forgot confirmation email failed to send.');
         }
     } catch (Exception $e) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step1', 'failed')));
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step2')));
 }
Exemplo n.º 26
0
 /**
  * Enter description here...
  *
  * @param CerberusParserMessage $message
  * @return integer
  */
 public static function parseMessage(CerberusParserMessage $message, $options = array())
 {
     //		print_r($rfcMessage);
     /*
      * options:
      * 'no_autoreply'
      */
     $logger = DevblocksPlatform::getConsoleLog();
     $settings = CerberusSettings::getInstance();
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     $headers =& $message->headers;
     // To/From/Cc/Bcc
     $sReturnPath = @$headers['return-path'];
     $sReplyTo = @$headers['reply-to'];
     $sFrom = @$headers['from'];
     $sTo = @$headers['to'];
     $bIsNew = true;
     // Overloadable
     $enumSpamTraining = '';
     $from = array();
     $to = array();
     if (!empty($sReplyTo)) {
         $from = CerberusParser::parseRfcAddress($sReplyTo);
     } elseif (!empty($sFrom)) {
         $from = CerberusParser::parseRfcAddress($sFrom);
     } elseif (!empty($sReturnPath)) {
         $from = CerberusParser::parseRfcAddress($sReturnPath);
     }
     if (!empty($sTo)) {
         // [TODO] Do we still need this RFC address parser?
         $to = CerberusParser::parseRfcAddress($sTo);
     }
     // Subject
     // Fix quote printable subject (quoted blocks can appear anywhere in subject)
     $sSubject = "";
     if (isset($headers['subject']) && !empty($headers['subject'])) {
         $sSubject = self::fixQuotePrintableString($headers['subject']);
     }
     // The subject can still end up empty after QP decode
     if (empty($sSubject)) {
         $sSubject = "(no subject)";
     }
     // Date
     $iDate = @strtotime($headers['date']);
     // If blank, or in the future, set to the current date
     if (empty($iDate) || $iDate > time()) {
         $iDate = time();
     }
     if (empty($from) || !is_array($from)) {
         $logger->warn("[Parser] Invalid 'From' address: " . $from);
         return NULL;
     }
     @($fromAddress = $from[0]->mailbox . '@' . $from[0]->host);
     @($fromPersonal = $from[0]->personal);
     if (null == ($fromAddressInst = CerberusApplication::hashLookupAddress($fromAddress, true))) {
         $logger->err("[Parser] 'From' address could not be created: " . $fromAddress);
         return NULL;
     }
     // Is banned?
     if (1 == $fromAddressInst->is_banned) {
         $logger->info("[Parser] Ignoring ticket from banned address: " . $fromAddressInst->email);
         return NULL;
     }
     // Message Id / References / In-Reply-To
     @($sMessageId = $headers['message-id']);
     $body_append_text = array();
     $body_append_html = array();
     // [mdf]Check attached files before creating the ticket because we may need to overwrite the message-id
     // also store any contents of rfc822 files so we can include them after the body
     foreach ($message->files as $filename => $file) {
         /* @var $file ParserFile */
         switch ($file->mime_type) {
             case 'message/rfc822':
                 $full_filename = $file->tmpname;
                 $mail = mailparse_msg_parse_file($full_filename);
                 $struct = mailparse_msg_get_structure($mail);
                 $msginfo = mailparse_msg_get_part_data($mail);
                 $inline_headers = $msginfo['headers'];
                 if (isset($headers['from']) && (strtolower(substr($headers['from'], 0, 11)) == 'postmaster@' || strtolower(substr($headers['from'], 0, 14)) == 'mailer-daemon@')) {
                     $headers['in-reply-to'] = $inline_headers['message-id'];
                 }
                 break;
         }
     }
     // [JAS] [TODO] References header may contain multiple message-ids to find
     if (null != ($ids = self::findParentMessage($headers))) {
         $bIsNew = false;
         $id = $ids['ticket_id'];
         $msgid = $ids['message_id'];
         // Is it a worker reply from an external client?  If so, proxy
         if (null != ($worker_address = DAO_AddressToWorker::getByAddress($fromAddressInst->email))) {
             $logger->info("[Parser] Handling an external worker response from " . $fromAddressInst->email);
             if (!DAO_Ticket::isTicketRequester($worker_address->address, $id)) {
                 // Watcher Commands [TODO] Document on wiki/etc
                 if (0 != ($matches = preg_match_all("/\\[(.*?)\\]/i", $message->headers['subject'], $commands))) {
                     @($command = strtolower(array_pop($commands[1])));
                     $logger->info("[Parser] Worker command: " . $command);
                     switch ($command) {
                         case 'close':
                             DAO_Ticket::updateTicket($id, array(DAO_Ticket::IS_CLOSED => CerberusTicketStatus::CLOSED));
                             break;
                         case 'take':
                             DAO_Ticket::updateTicket($id, array(DAO_Ticket::NEXT_WORKER_ID => $worker_address->worker_id));
                             break;
                         case 'comment':
                             $comment_id = DAO_TicketComment::create(array(DAO_TicketComment::ADDRESS_ID => $fromAddressInst->id, DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => $id, DAO_TicketComment::COMMENT => $message->body));
                             return $id;
                             break;
                         default:
                             // Typo?
                             break;
                     }
                 }
                 $attachment_files = array();
                 $attachment_files['name'] = array();
                 $attachment_files['type'] = array();
                 $attachment_files['tmp_name'] = array();
                 $attachment_files['size'] = array();
                 $i = 0;
                 foreach ($message->files as $filename => $file) {
                     $attachment_files['name'][$i] = $filename;
                     $attachment_files['type'][$i] = $file->mime_type;
                     $attachment_files['tmp_name'][$i] = $file->tmpname;
                     $attachment_files['size'][$i] = $file->file_size;
                     $i++;
                 }
                 CerberusMail::sendTicketMessage(array('message_id' => $msgid, 'content' => $message->body, 'files' => $attachment_files, 'agent_id' => $worker_address->worker_id));
                 return $id;
             } else {
                 // ... worker is a requester, treat as normal
                 $logger->info("[Parser] The external worker was a ticket requester, so we're not treating them as a watcher.");
             }
         } else {
             // Reply: Not sent by a worker
             /*
              * [TODO] check that this sender is a requester on the matched ticket
              * Otherwise blank out the $id
              */
         }
     }
     // Pre-parse mail rules
     if (null != ($pre_filter = Model_PreParseRule::getMatches(empty($id) ? 1 : 0, $fromAddressInst, $message))) {
         // Do something with matching filter's actions
         foreach ($pre_filter->actions as $action_key => $action) {
             switch ($action_key) {
                 case 'blackhole':
                     return NULL;
                     break;
                 case 'redirect':
                     @($to = $action['to']);
                     CerberusMail::reflect($message, $to);
                     return NULL;
                     break;
                 case 'bounce':
                     @($msg = $action['message']);
                     // [TODO] Follow the RFC spec on a true bounce
                     CerberusMail::quickSend($fromAddress, "Delivery failed: " . $sSubject, $msg);
                     return NULL;
                     break;
             }
         }
     }
     $group_id = 0;
     if (empty($id)) {
         // New Ticket
         // Routing new tickets
         if (null != ($routing_rules = Model_MailToGroupRule::getMatches($fromAddressInst, $message))) {
             if (is_array($routing_rules)) {
                 foreach ($routing_rules as $rule) {
                     // Only end up with the last 'move' action (ignore the previous)
                     if (isset($rule->actions['move'])) {
                         $group_id = intval($rule->actions['move']['group_id']);
                         // We don't need to move again when running rule actions
                         unset($rule->actions['move']);
                     }
                 }
             }
         }
         // Last ditch effort to check for a default group to deliver to
         if (empty($group_id)) {
             if (null != ($default_team = DAO_Group::getDefaultGroup())) {
                 $group_id = $default_team->id;
             } else {
                 // Bounce
                 return null;
             }
         }
         // [JAS] It's important to not set the group_id on the ticket until the messages exist
         // or inbox filters will just abort.
         $fields = array(DAO_Ticket::MASK => CerberusApplication::generateTicketMask(), DAO_Ticket::SUBJECT => $sSubject, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::FIRST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::LAST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::CREATED_DATE => $iDate, DAO_Ticket::UPDATED_DATE => $iDate, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_OPENED);
         $id = DAO_Ticket::createTicket($fields);
         // Apply routing actions to our new ticket ID
         if (isset($routing_rules) && is_array($routing_rules)) {
             foreach ($routing_rules as $rule) {
                 $rule->run($id);
             }
         }
     }
     // [JAS]: Add requesters to the ticket
     if (!empty($fromAddressInst->id) && !empty($id)) {
         // Don't add a requester if the sender is a helpdesk address
         if (isset($helpdesk_senders[$fromAddressInst->email])) {
             $logger->info("[Parser] Not adding ourselves as a requester: " . $fromAddressInst->email);
         } else {
             DAO_Ticket::createRequester($fromAddressInst->id, $id);
         }
     }
     // Add the other TO/CC addresses to the ticket
     // [TODO] This should be cleaned up and optimized
     if ($settings->get(CerberusSettings::PARSER_AUTO_REQ, 0)) {
         @($autoreq_exclude_list = $settings->get(CerberusSettings::PARSER_AUTO_REQ_EXCLUDE, ''));
         $destinations = self::getDestinations($headers);
         if (is_array($destinations) && !empty($destinations)) {
             // Filter out any excluded requesters
             if (!empty($autoreq_exclude_list)) {
                 @($autoreq_exclude = DevblocksPlatform::parseCrlfString($autoreq_exclude_list));
                 if (is_array($autoreq_exclude) && !empty($autoreq_exclude)) {
                     foreach ($autoreq_exclude as $excl_pattern) {
                         $excl_regexp = DevblocksPlatform::parseStringAsRegExp($excl_pattern);
                         // Check all destinations for this pattern
                         foreach ($destinations as $idx => $dest) {
                             if (@preg_match($excl_regexp, $dest)) {
                                 unset($destinations[$idx]);
                             }
                         }
                     }
                 }
             }
             foreach ($destinations as $dest) {
                 if (null != ($destInst = CerberusApplication::hashLookupAddress($dest, true))) {
                     // Skip if the destination is one of our senders or the matching TO
                     if (isset($helpdesk_senders[$destInst->email])) {
                         continue;
                     }
                     DAO_Ticket::createRequester($destInst->id, $id);
                 }
             }
         }
     }
     $attachment_path = APP_STORAGE_PATH . '/attachments/';
     // [TODO] This should allow external attachments (S3)
     $fields = array(DAO_Message::TICKET_ID => $id, DAO_Message::CREATED_DATE => $iDate, DAO_Message::ADDRESS_ID => $fromAddressInst->id);
     $email_id = DAO_Message::create($fields);
     // Content
     DAO_MessageContent::create($email_id, $message->body);
     // Headers
     foreach ($headers as $hk => $hv) {
         DAO_MessageHeader::create($email_id, $id, $hk, $hv);
     }
     // [mdf] Loop through files to insert attachment records in the db, and move temporary files
     if (!empty($email_id)) {
         foreach ($message->files as $filename => $file) {
             /* @var $file ParserFile */
             //[mdf] skip rfc822 messages since we extracted their content above
             if ($file->mime_type == 'message/rfc822') {
                 continue;
             }
             $fields = array(DAO_Attachment::MESSAGE_ID => $email_id, DAO_Attachment::DISPLAY_NAME => $filename, DAO_Attachment::MIME_TYPE => $file->mime_type, DAO_Attachment::FILE_SIZE => intval($file->file_size));
             $file_id = DAO_Attachment::create($fields);
             if (empty($file_id)) {
                 @unlink($file->tmpname);
                 // remove our temp file
                 continue;
             }
             // Make file attachments use buckets so we have a max per directory
             $attachment_bucket = sprintf("%03d/", mt_rand(1, 100));
             $attachment_file = $file_id;
             if (!file_exists($attachment_path . $attachment_bucket)) {
                 @mkdir($attachment_path . $attachment_bucket, 0770, true);
                 // [TODO] Needs error checking
             }
             rename($file->getTempFile(), $attachment_path . $attachment_bucket . $attachment_file);
             // [TODO] Split off attachments into its own DAO
             DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file));
         }
     }
     // Finalize our new ticket details (post-message creation)
     if ($bIsNew && !empty($id) && !empty($email_id)) {
         // First thread (needed for anti-spam)
         DAO_Ticket::updateTicket($id, array(DAO_Ticket::FIRST_MESSAGE_ID => $email_id));
         // Prime the change fields (which a few things like anti-spam might change before we commit)
         $change_fields = array(DAO_Ticket::TEAM_ID => $group_id);
         $out = CerberusBayes::calculateTicketSpamProbability($id);
         if (!empty($group_id)) {
             @($spam_threshold = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_THRESHOLD, 80));
             @($spam_action = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION, ''));
             @($spam_action_param = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION_PARAM, ''));
             if ($out['probability'] * 100 >= $spam_threshold) {
                 $enumSpamTraining = CerberusTicketSpamTraining::SPAM;
                 switch ($spam_action) {
                     default:
                     case 0:
                         // do nothing
                         break;
                     case 1:
                         // delete
                         $change_fields[DAO_Ticket::IS_CLOSED] = 1;
                         $change_fields[DAO_Ticket::IS_DELETED] = 1;
                         break;
                     case 2:
                         // move
                         $buckets = DAO_Bucket::getAll();
                         // Verify bucket exists
                         if (!empty($spam_action_param) && isset($buckets[$spam_action_param])) {
                             $change_fields[DAO_Ticket::TEAM_ID] = $group_id;
                             $change_fields[DAO_Ticket::CATEGORY_ID] = $spam_action_param;
                         }
                         break;
                 }
             }
         }
         // end spam training
         // Save properties
         if (!empty($change_fields)) {
             DAO_Ticket::updateTicket($id, $change_fields);
         }
     }
     // Reply notifications (new messages are handled by 'move' listener)
     if (!$bIsNew) {
         // Inbound Reply Event
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.inbound', array('ticket_id' => $id)));
     }
     // New ticket processing
     if ($bIsNew) {
         // Auto reply
         @($autoreply_enabled = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY_ENABLED, 0));
         @($autoreply = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY, ''));
         /*
          * Send the group's autoreply if one exists, as long as this ticket isn't spam
          */
         if (!isset($options['no_autoreply']) && $autoreply_enabled && !empty($autoreply) && $enumSpamTraining != CerberusTicketSpamTraining::SPAM) {
             CerberusMail::sendTicketMessage(array('ticket_id' => $id, 'message_id' => $email_id, 'content' => str_replace(array('#ticket_id#', '#mask#', '#subject#', '#timestamp#', '#sender#', '#sender_first#', '#orig_body#'), array($id, $sMask, $sSubject, date('r'), $fromAddress, $fromAddressInst->first_name, ltrim($message->body)), $autoreply), 'is_autoreply' => true, 'dont_keep_copy' => true));
         }
     }
     // end bIsNew
     unset($message);
     // Re-open and update our date on new replies
     if (!$bIsNew) {
         DAO_Ticket::updateTicket($id, array(DAO_Ticket::UPDATED_DATE => time(), DAO_Ticket::IS_WAITING => 0, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::IS_DELETED => 0, DAO_Ticket::LAST_WROTE_ID => $fromAddressInst->id, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_CUSTOMER_REPLY));
         // [TODO] The TICKET_CUSTOMER_REPLY should be sure of this message address not being a worker
     }
     @imap_errors();
     // Prevent errors from spilling out into STDOUT
     return $id;
 }
Exemplo n.º 27
0
 private function _handleImportContact($xml)
 {
     $settings = CerberusSettings::getInstance();
     $logger = DevblocksPlatform::getConsoleLog();
     $sFirstName = (string) $xml->first_name;
     $sLastName = (string) $xml->last_name;
     $sEmail = (string) $xml->email;
     $sPassword = (string) $xml->password;
     $sOrganization = (string) $xml->organization;
     // Dupe check org
     if (null != ($address = DAO_Address::lookupAddress($sEmail))) {
         $logger->info('[Importer] Avoiding creating duplicate contact #' . $address->id . ' (' . $sEmail . ')');
         // [TODO] Still associate with org if local blank?
         // [TODO] Still associate password if local blank?
         return true;
     }
     $fields = array(DAO_Address::FIRST_NAME => $sFirstName, DAO_Address::LAST_NAME => $sLastName, DAO_Address::EMAIL => $sEmail);
     // Associate SC password
     if (!empty($sPassword) && $sPassword != md5('')) {
         $fields[DAO_Address::IS_REGISTERED] = 1;
         $fields[DAO_Address::PASS] = $sPassword;
     }
     $address_id = DAO_Address::create($fields);
     // Associate with organization
     if (!empty($sOrganization)) {
         if (null != ($org_id = DAO_ContactOrg::lookup($sOrganization, true))) {
             DAO_Address::update($address_id, array(DAO_Address::CONTACT_ORG_ID => $org_id));
         }
     }
     $logger->info('[Importer] Imported contact #' . $address_id . ' (' . $sEmail . ')');
     return true;
 }
Exemplo n.º 28
0
 /**
  * @return Swift
  */
 function getMailer($smtp_host = null, $smtp_user = null, $smtp_pass = null, $smtp_port = null, $smtp_enc = null)
 {
     $settings = CerberusSettings::getInstance();
     // [TODO] This shouldn't have Cerberus-specific settings in it.
     if (!isset($smtp_host)) {
         $smtp_host = $settings->get(CerberusSettings::SMTP_HOST, 'localhost');
     }
     if (!isset($smtp_user)) {
         $smtp_user = $settings->get(CerberusSettings::SMTP_AUTH_USER, null);
     }
     if (!isset($smtp_pass)) {
         $smtp_pass = $settings->get(CerberusSettings::SMTP_AUTH_PASS, null);
     }
     if (!isset($smtp_port)) {
         $smtp_port = $settings->get(CerberusSettings::SMTP_PORT, '25');
     }
     if (!isset($smtp_enc)) {
         $smtp_enc = $settings->get(CerberusSettings::SMTP_ENCRYPTION_TYPE, 'None');
     }
     if ($smtp_enc == 'TLS') {
         $smtp_enc = Swift_Connection_SMTP::ENC_TLS;
     } else {
         if ($smtp_enc == 'SSL') {
             $smtp_enc = Swift_Connection_SMTP::ENC_SSL;
         } else {
             $smtp_enc = Swift_Connection_SMTP::ENC_OFF;
         }
     }
     $smtp = new Swift_Connection_SMTP($smtp_host, $smtp_port, $smtp_enc);
     if (!empty($smtp_user) && !empty($smtp_pass)) {
         $smtp->setUsername($smtp_user);
         $smtp->setPassword($smtp_pass);
     }
     $swift =& new Swift($smtp);
     return $swift;
 }
Exemplo n.º 29
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     @($reload = DevblocksPlatform::importGPC($_REQUEST['reload'], 'integer', 0));
     @($loglevel = DevblocksPlatform::importGPC($_REQUEST['loglevel'], 'integer', 0));
     $logger = DevblocksPlatform::getConsoleLog();
     $translate = DevblocksPlatform::getTranslationService();
     $settings = CerberusSettings::getInstance();
     $authorized_ips_str = $settings->get(CerberusSettings::AUTHORIZED_IPS);
     $authorized_ips = DevblocksPlatform::parseCrlfString($authorized_ips_str);
     $authorized_ip_defaults = DevblocksPlatform::parseCsvString(AUTHORIZED_IPS_DEFAULTS);
     $authorized_ips = array_merge($authorized_ips, $authorized_ip_defaults);
     @($is_ignoring_wait = DevblocksPlatform::importGPC($_REQUEST['ignore_wait'], 'integer', 0));
     $pass = false;
     foreach ($authorized_ips as $ip) {
         if (substr($ip, 0, strlen($ip)) == substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip))) {
             $pass = true;
             break;
         }
     }
     if (!$pass) {
         echo vsprintf($translate->_('cron.ip_unauthorized'), $_SERVER['REMOTE_ADDR']);
         return;
     }
     $stack = $request->path;
     array_shift($stack);
     // cron
     $job_id = array_shift($stack);
     @set_time_limit(0);
     // Unlimited (if possible)
     $url = DevblocksPlatform::getUrlService();
     $timelimit = intval(ini_get('max_execution_time'));
     if ($reload) {
         $reload_url = sprintf("%s?reload=%d&loglevel=%d&ignore_wait=%d", $url->write('c=cron' . ($job_id ? "&a=" . $job_id : "")), intval($reload), intval($loglevel), intval($is_ignoring_wait));
         echo "<HTML>" . "<HEAD>" . "<TITLE></TITLE>" . "<meta http-equiv='Refresh' content='" . intval($reload) . ";" . $reload_url . "'>" . "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>" . "</HEAD>" . "<BODY>";
         // onload=\"setTimeout(\\\"window.location.replace('".$url->write('c=cron')."')\\\",30);\"
     }
     // [TODO] Determine if we're on a time limit under 60 seconds
     $cron_manifests = DevblocksPlatform::getExtensions('cerberusweb.cron', true, true);
     $jobs = array();
     if (empty($job_id)) {
         // do everything
         // Determine who wants to go first by next time and longest waiting
         $nexttime = time() + 86400;
         if (is_array($cron_manifests)) {
             foreach ($cron_manifests as $idx => $instance) {
                 /* @var $instance CerberusCronPageExtension */
                 $lastrun = $instance->getParam(CerberusCronPageExtension::PARAM_LASTRUN, 0);
                 if ($instance->isReadyToRun($is_ignoring_wait)) {
                     if ($timelimit) {
                         if ($lastrun < $nexttime) {
                             $jobs[0] = $cron_manifests[$idx];
                             $nexttime = $lastrun;
                         }
                     } else {
                         $jobs[] =& $cron_manifests[$idx];
                     }
                 }
             }
         }
     } else {
         // single job
         $manifest = DevblocksPlatform::getExtension($job_id, false, true);
         if (empty($manifest)) {
             exit;
         }
         $instance = $manifest->createInstance();
         if ($instance) {
             if ($instance->isReadyToRun($is_ignoring_wait)) {
                 $jobs[0] =& $instance;
             }
         }
     }
     if (!empty($jobs)) {
         foreach ($jobs as $nextjob) {
             $nextjob->setParam(CerberusCronPageExtension::PARAM_LOCKED, time());
             $nextjob->_run();
         }
     } elseif ($reload) {
         $logger->info(vsprintf($translate->_('cron.nothing_to_do'), intval($reload)));
     }
     if ($reload) {
         echo "</BODY>" . "</HTML>";
     }
     exit;
 }
Exemplo n.º 30
0
 function import()
 {
     $sources = DAO_ForumsSource::getWhere();
     $settings = CerberusSettings::getInstance();
     // Track posters that are also workers
     $poster_workers = array();
     if (null != ($poster_workers_str = $settings->get(ChForumsPlugin::SETTING_POSTER_WORKERS, null))) {
         $poster_workers = DevblocksPlatform::parseCrlfString($poster_workers_str);
     }
     foreach ($sources as $source) {
         /* @var $source Model_ForumsSource */
         // [TODO] Convert to REST client (move into Devblocks)
         $source_url = sprintf("%s?lastpostid=%d&limit=100", $source->url, $source->last_postid);
         $xml_in = file_get_contents($source_url);
         $xml = new SimpleXMLElement($xml_in);
         $last_postid = 0;
         foreach ($xml->thread as $thread) {
             @($thread_id = (string) $thread->id);
             @($thread_title = (string) $thread->title);
             @($thread_last_updated = (string) $thread->last_updated);
             @($thread_last_postid = (string) $thread->last_postid);
             @($thread_last_poster = (string) $thread->last_poster);
             @($thread_link = (string) $thread->link);
             if (null == ($th = DAO_ForumsThread::getBySourceThreadId($source->id, $thread_id))) {
                 $fields = array(DAO_ForumsThread::FORUM_ID => $source->id, DAO_ForumsThread::THREAD_ID => $thread_id, DAO_ForumsThread::TITLE => $thread_title, DAO_ForumsThread::LAST_UPDATED => intval($thread_last_updated), DAO_ForumsThread::LAST_POSTER => $thread_last_poster, DAO_ForumsThread::LINK => $thread_link);
                 DAO_ForumsThread::create($fields);
             } else {
                 // If the last post was a worker, leave the thread at the current closed state
                 $closed = false === array_search(strtolower($thread_last_poster), $poster_workers) ? 0 : $th->is_closed;
                 $fields = array(DAO_ForumsThread::LAST_UPDATED => intval($thread_last_updated), DAO_ForumsThread::LAST_POSTER => $thread_last_poster, DAO_ForumsThread::LINK => $thread_link, DAO_ForumsThread::IS_CLOSED => $closed);
                 DAO_ForumsThread::update($th->id, $fields);
             }
             $last_postid = $thread_last_postid;
         }
         // foreach($xml->thread)
         // Save our progress to the database
         if (!empty($last_postid)) {
             DAO_ForumsSource::update($source->id, array(DAO_ForumsSource::LAST_POSTID => $last_postid));
         }
     }
     // foreach($sources)
 }