Пример #1
0
 function run(Model_Alert $alert, $sensors)
 {
     @($to = DevblocksPlatform::parseCsvString($alert->actions[self::EXTENSION_ID]['to']));
     @($template_subject = $alert->actions[self::EXTENSION_ID]['template_subject']);
     @($template_body = $alert->actions[self::EXTENSION_ID]['template_body']);
     $logger = DevblocksPlatform::getConsoleLog();
     // Assign template variables
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->clear_all_assign();
     $tpl->assign('alert', $alert);
     $tpl->assign('sensors', $sensors);
     $tpl->assign('num_sensors', count($sensors));
     // Build template
     $tpl_builder = DevblocksPlatform::getTemplateBuilder();
     $errors = array();
     // Subject
     if (false == ($subject = $tpl_builder->build($template_subject))) {
         $errors += $tpl_builder->getErrors();
     }
     // Body
     if (false == ($body = $tpl_builder->build($template_body))) {
         $errors += $tpl_builder->getErrors();
     }
     if (!empty($errors)) {
         $logger->err(sprintf("Errors in mail template (skipping): %s", implode("<br>\r\n", $errors)));
         return false;
     }
     if (is_array($to)) {
         foreach ($to as $address) {
             $logger->info(sprintf("Sending mail to %s about %d sensors", $address, count($sensors)));
             PortSensorMail::quickSend($address, $subject, $body);
         }
     }
 }
Пример #2
0
 function run(Model_Alert $alert, $sensors)
 {
     @($to = DevblocksPlatform::parseCsvString($alert->actions[self::EXTENSION_ID]['to']));
     @($template_msg = $alert->actions[self::EXTENSION_ID]['template_msg']);
     $result = true;
     $logger = DevblocksPlatform::getConsoleLog();
     $settings = DevblocksPlatform::getPluginSettingsService();
     // Assign template variables
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->clear_all_assign();
     $tpl->assign('alert', $alert);
     $tpl->assign('sensors', $sensors);
     $tpl->assign('num_sensors', count($sensors));
     // Build template
     $tpl_builder = DevblocksPlatform::getTemplateBuilder();
     $errors = array();
     // Body
     if (false == ($text = $tpl_builder->build($template_msg))) {
         $errors += $tpl_builder->getErrors();
     }
     if (!empty($errors)) {
         $logger->err(sprintf("Errors in SMS template (skipping): %s", implode("<br>\r\n", $errors)));
         return false;
     }
     // Truncate message to 155 chars
     if (155 <= strlen($text)) {
         $text = substr($text, 0, 152) . '...';
     }
     // Clickatell SMS gateways
     $user = $settings->get('portsensor.sms', 'clickatell_username', '');
     $password = $settings->get('portsensor.sms', 'clickatell_password', '');
     $api_id = $settings->get('portsensor.sms', 'clickatell_api_id', '');
     if (empty($user) || empty($password) || empty($api_id)) {
         return;
     }
     if (is_array($to)) {
         foreach ($to as $phone) {
             $logger->info(sprintf("Sending SMS to %s about %d sensors", $phone, count($sensors)));
             $url = sprintf("http://api.clickatell.com/http/sendmsg?user=%s&password=%s&api_id=%s&to=%s&text=%s", urlencode($user), urlencode($password), urlencode($api_id), urlencode($phone), urlencode($text));
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             $out = curl_exec($ch);
             curl_close($ch);
             $result = 0 == strcasecmp("ID:", substr($out, 0, 3));
         }
     }
     return $result;
 }
Пример #3
0
 function showTab()
 {
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('path', $tpl_path);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $tpl->assign('ticket_id', $ticket_id);
     $tpl->assign('ticket', $ticket);
     // Receate the original spam decision
     $words = DevblocksPlatform::parseCsvString($ticket->interesting_words);
     $words = DAO_Bayes::lookupWordIds($words);
     // Calculate word probabilities
     foreach ($words as $idx => $word) {
         /* @var $word CerberusBayesWord */
         $word->probability = CerberusBayes::calculateWordProbability($word);
     }
     $tpl->assign('words', $words);
     // Determine what the spam probability would be if the decision was made right now
     $analysis = CerberusBayes::calculateTicketSpamProbability($ticket_id, true);
     $tpl->assign('analysis', $analysis);
     $tpl->display('file:' . $tpl_path . 'ticket_tab/index.tpl');
 }
Пример #4
0
 function doArticlesBulkUpdateAction()
 {
     // Checked rows
     @($ids_str = DevblocksPlatform::importGPC($_REQUEST['ids'], 'string'));
     $ids = DevblocksPlatform::parseCsvString($ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     $do = array();
     // Categories
     @($category_ids = DevblocksPlatform::importGPC($_REQUEST['category_ids'], 'array', array()));
     if (is_array($category_ids)) {
         $do['category_delta'] = array();
         foreach ($category_ids as $cat_id) {
             @($cat_mode = DevblocksPlatform::importGPC($_REQUEST['category_ids_' . $cat_id], 'string', ''));
             if (!empty($cat_mode)) {
                 $do['category_delta'][] = $cat_mode . $cat_id;
             }
         }
     }
     // Feedback fields
     //		@$list_id = trim(DevblocksPlatform::importGPC($_POST['list_id'],'integer',0));
     // Do: List
     //		if(0 != strlen($list_id))
     //			$do['list_id'] = $list_id;
     // Do: Custom fields
     //		$do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $ids);
     $view->render();
     return;
 }
Пример #5
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     @set_time_limit(0);
     // no timelimit (when possible)
     $translate = DevblocksPlatform::getTranslationService();
     $stack = $request->path;
     array_shift($stack);
     // update
     $cache = DevblocksPlatform::getCacheService();
     /* @var $cache _DevblocksCacheManager */
     $settings = DevblocksPlatform::getPluginSettingsService();
     switch (array_shift($stack)) {
         case 'locked':
             if (!DevblocksPlatform::versionConsistencyCheck()) {
                 $url = DevblocksPlatform::getUrlService();
                 echo "<h1>Cerberus Helpdesk 5.x</h1>";
                 echo "The helpdesk is currently waiting for an administrator to finish upgrading. " . "Please wait a few minutes and then " . sprintf("<a href='%s'>try again</a>.<br><br>", $url->write('c=update&a=locked'));
                 echo sprintf("If you're an admin you may <a href='%s'>finish the upgrade</a>.", $url->write('c=update'));
             } else {
                 DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
             }
             break;
         default:
             $path = APP_TEMP_PATH . DIRECTORY_SEPARATOR;
             $file = $path . 'c4update_lock';
             $authorized_ips_str = $settings->get('cerberusweb.core', 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 vsprintf($translate->_('update.ip_unauthorized'), $_SERVER['REMOTE_ADDR']);
                 return;
             }
             // Check requirements
             $errors = CerberusApplication::checkRequirements();
             if (!empty($errors)) {
                 echo $translate->_('update.correct_errors');
                 echo "<ul style='color:red;'>";
                 foreach ($errors as $error) {
                     echo "<li>" . $error . "</li>";
                 }
                 echo "</ul>";
                 exit;
             }
             // If authorized, lock and attempt update
             if (!file_exists($file) || @filectime($file) + 600 < time()) {
                 // 10 min lock
                 touch($file);
                 //echo "Running plugin patches...<br>";
                 if (DevblocksPlatform::runPluginPatches('core.patches')) {
                     @unlink($file);
                     // [JAS]: Clear all caches
                     $cache->clean();
                     DevblocksPlatform::getClassLoaderService()->destroy();
                     // Clear compiled templates
                     $tpl = DevblocksPlatform::getTemplateService();
                     $tpl->clear_compiled_tpl();
                     // Reload plugin translations
                     DAO_Translation::reloadPluginStrings();
                     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
                 } else {
                     @unlink($file);
                     echo "Failure!";
                     // [TODO] Needs elaboration
                 }
                 break;
             } else {
                 echo $translate->_('update.locked_another');
             }
     }
     exit;
 }
Пример #6
0
 function doTaskBulkUpdateAction()
 {
     // Checked rows
     @($ids_str = DevblocksPlatform::importGPC($_REQUEST['ids'], 'string'));
     $ids = DevblocksPlatform::parseCsvString($ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView('', $view_id);
     // Task fields
     $due = trim(DevblocksPlatform::importGPC($_POST['due'], 'string', ''));
     $status = trim(DevblocksPlatform::importGPC($_POST['status'], 'string', ''));
     $worker_id = trim(DevblocksPlatform::importGPC($_POST['worker_id'], 'string', ''));
     $do = array();
     // Do: Due
     if (0 != strlen($due)) {
         $do['due'] = $due;
     }
     // Do: Status
     if (0 != strlen($status)) {
         $do['status'] = $status;
     }
     // Do: Worker
     if (0 != strlen($worker_id)) {
         $do['worker_id'] = $worker_id;
     }
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $ids);
     $view->render();
     return;
 }
Пример #7
0
 function doBulkUpdateAction()
 {
     // Checked rows
     @($ids_str = DevblocksPlatform::importGPC($_REQUEST['ids'], 'string'));
     $ids = DevblocksPlatform::parseCsvString($ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     // Feedback fields
     //		@$list_id = trim(DevblocksPlatform::importGPC($_POST['list_id'],'integer',0));
     $do = array();
     // Do: List
     //		if(0 != strlen($list_id))
     //			$do['list_id'] = $list_id;
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $ids);
     $view->render();
     return;
 }
Пример #8
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $umsession = UmPortalHelper::getSession();
     $stack = $response->path;
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('portal_code', UmPortalHelper::getCode());
     $page_title = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_PAGE_TITLE, 'Support Center');
     $tpl->assign('page_title', $page_title);
     $login_handler = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_LOGIN_HANDLER, '');
     $tpl->assign('login_handler', $login_handler);
     $login_extension = DevblocksPlatform::getExtension($login_handler, true);
     $tpl->assign('login_extension', $login_extension);
     @($visible_modules = unserialize(DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_VISIBLE_MODULES, '')));
     $tpl->assign('visible_modules', $visible_modules);
     @($active_user = $umsession->getProperty('sc_login', null));
     $tpl->assign('active_user', $active_user);
     // Usermeet Session
     if (null == ($fingerprint = UmPortalHelper::getFingerprint())) {
         die("A problem occurred.");
     }
     $tpl->assign('fingerprint', $fingerprint);
     $module_uri = array_shift($stack);
     switch ($module_uri) {
         case 'ajax':
             $controller = new UmScAjaxController(null);
             $controller->handleRequest(new DevblocksHttpRequest($stack));
             break;
         case 'rss':
             $controller = new UmScRssController(null);
             $controller->handleRequest(new DevblocksHttpRequest($stack));
             break;
         case 'captcha':
             @($color = DevblocksPlatform::parseCsvString(DevblocksPlatform::importGPC($_REQUEST['color'], 'string', '40,40,40')));
             @($bgcolor = DevblocksPlatform::parseCsvString(DevblocksPlatform::importGPC($_REQUEST['bgcolor'], 'string', '240,240,240')));
             // Sanitize colors
             // [TODO] Sanitize numeric range for elements 0-2
             if (3 != count($color)) {
                 $color = array(40, 40, 40);
             }
             if (3 != count($bgcolor)) {
                 $color = array(240, 240, 240);
             }
             header('Cache-control: max-age=0', true);
             // 1 wk // , must-revalidate
             header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 604800) . ' GMT');
             // 1 wk
             header('Content-type: image/jpeg');
             // Get CAPTCHA secret passphrase
             $phrase = CerberusApplication::generatePassword(4);
             $umsession->setProperty(UmScApp::SESSION_CAPTCHA, $phrase);
             $im = @imagecreate(150, 70) or die("Cannot Initialize new GD image stream");
             $background_color = imagecolorallocate($im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
             $text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
             $font = DEVBLOCKS_PATH . 'resources/font/ryanlerch_-_Tuffy_Bold(2).ttf';
             imagettftext($im, 24, mt_rand(0, 20), 5, 60 + 6, $text_color, $font, $phrase);
             imagejpeg($im, null, 85);
             imagedestroy($im);
             exit;
             break;
         case 'captcha.check':
             $entered = DevblocksPlatform::importGPC($_REQUEST['captcha'], 'string', '');
             $captcha = $umsession->getProperty(UmScApp::SESSION_CAPTCHA, '');
             if (!empty($entered) && !empty($captcha) && 0 == strcasecmp($entered, $captcha)) {
                 echo 'true';
                 exit;
             }
             echo 'false';
             exit;
             break;
         default:
             // Build the menu
             $modules = $this->_getModules();
             $menu_modules = array();
             if (is_array($modules)) {
                 foreach ($modules as $uri => $module) {
                     // Must be menu renderable
                     if (!empty($module->manifest->params['menu_title']) && !empty($uri)) {
                         $menu_modules[$uri] = $module;
                     }
                 }
             }
             $tpl->assign('menu', $menu_modules);
             // Modules
             if (isset($modules[$module_uri])) {
                 $controller = $modules[$module_uri];
             } else {
                 // First menu item
                 $controller = reset($menu_modules);
             }
             array_unshift($stack, $module_uri);
             $tpl->assign('module', $controller);
             $tpl->assign('module_response', new DevblocksHttpResponse($stack));
             $tpl->display('devblocks:usermeet.core:support_center/index.tpl:portal_' . UmPortalHelper::getCode());
             break;
     }
 }
Пример #9
0
 /**
  * @param $instance Model_CommunityTool 
  */
 public function configure(Model_CommunityTool $instance)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('config_path', $tpl_path);
     $logo_url = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_LOGO_URL, '');
     $tpl->assign('logo_url', $logo_url);
     $page_title = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_PAGE_TITLE, 'Support Center');
     $tpl->assign('page_title', $page_title);
     $style_css = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_STYLE_CSS, '');
     $tpl->assign('style_css', $style_css);
     $footer_html = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_FOOTER_HTML, '');
     $tpl->assign('footer_html', $footer_html);
     $allow_logins = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ALLOW_LOGINS, 0);
     $tpl->assign('allow_logins', $allow_logins);
     $enabled_modules = DevblocksPlatform::parseCsvString(DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ENABLED_MODULES, array()));
     $tpl->assign('enabled_modules', $enabled_modules);
     $all_modules = DevblocksPlatform::getExtensions('usermeet.sc.controller', true, true);
     $modules = array();
     // Sort the enabled modules first, in order.
     if (is_array($enabled_modules)) {
         foreach ($enabled_modules as $module_id) {
             if (!isset($all_modules[$module_id])) {
                 continue;
             }
             $module = $all_modules[$module_id];
             $modules[$module_id] = $module;
             unset($all_modules[$module_id]);
         }
     }
     // Append the unused modules
     if (is_array($all_modules)) {
         foreach ($all_modules as $module_id => $module) {
             $modules[$module_id] = $module;
             $modules = array_merge($modules, $all_modules);
         }
     }
     $tpl->assign('modules', $modules);
     $tpl->display("file:{$tpl_path}portal/sc/config/index.tpl");
 }
Пример #10
0
 /**
  * @return _DevblocksCacheManager
  */
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new _DevblocksCacheManager();
         $options = array('key_prefix' => defined('DEVBLOCKS_CACHE_PREFIX') && DEVBLOCKS_CACHE_PREFIX ? DEVBLOCKS_CACHE_PREFIX : null);
         // Shared-memory cache
         if ((extension_loaded('memcache') || extension_loaded('memcached')) && defined('DEVBLOCKS_MEMCACHED_SERVERS') && DEVBLOCKS_MEMCACHED_SERVERS) {
             $pairs = DevblocksPlatform::parseCsvString(DEVBLOCKS_MEMCACHED_SERVERS);
             $servers = array();
             if (is_array($pairs) && !empty($pairs)) {
                 foreach ($pairs as $server) {
                     list($host, $port) = explode(':', $server);
                     if (empty($host) || empty($port)) {
                         continue;
                     }
                     $servers[] = array('host' => $host, 'port' => $port);
                 }
             }
             $options['servers'] = $servers;
             self::$_cacher = new _DevblocksCacheManagerMemcached($options);
         }
         // Disk-based cache (default)
         if (null == self::$_cacher) {
             $options['cache_dir'] = APP_TEMP_PATH;
             self::$_cacher = new _DevblocksCacheManagerDisk($options);
         }
     }
     return self::$instance;
 }
Пример #11
0
 function doWatcherBulkPanelAction()
 {
     // Checked rows
     @($ids_str = DevblocksPlatform::importGPC($_REQUEST['ids'], 'string'));
     $ids = DevblocksPlatform::parseCsvString($ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     // Watcher fields
     @($status = trim(DevblocksPlatform::importGPC($_POST['do_status'], 'string', '')));
     $do = array();
     // Do: ...
     if (0 != strlen($status)) {
         $do['status'] = intval($status);
     }
     // Do: Custom fields
     //$do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $ids);
     $view->render();
     return;
 }
Пример #12
0
 static function sendMailProperties($properties)
 {
     $status = true;
     @($toStr = $properties['to']);
     @($cc = $properties['cc']);
     @($bcc = $properties['bcc']);
     @($subject = $properties['subject']);
     @($content = $properties['content']);
     @($files = $properties['files']);
     $mail_settings = self::getMailerDefaults();
     if (empty($properties['from_addy'])) {
         @($from_addy = $settings->get('feg.core', FegSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
     }
     if (empty($properties['from_personal'])) {
         @($from_personal = $settings->get('feg.core', FegSettings::DEFAULT_REPLY_PERSONAL, ''));
     }
     if (empty($subject)) {
         $subject = '(no subject)';
     }
     // [JAS]: Replace any semi-colons with commas (people like using either)
     $toList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $toStr));
     $mail_headers = array();
     $mail_headers['X-FegCompose'] = '1';
     // Headers needed for the ticket message
     $log_headers = new Swift_Message_Headers();
     $log_headers->setCharset(LANG_CHARSET_CODE);
     $log_headers->set('To', $toList);
     $log_headers->set('From', !empty($from_personal) ? sprintf("%s <%s>", $from_personal, $from_addy) : sprintf('%s', $from_addy));
     $log_headers->set('Subject', $subject);
     $log_headers->set('Date', date('r'));
     foreach ($log_headers->getList() as $hdr => $v) {
         if (null != ($hdr_val = $log_headers->getEncoded($hdr))) {
             if (!empty($hdr_val)) {
                 $mail_headers[$hdr] = $hdr_val;
             }
         }
     }
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(FegMail::getMailerDefaults());
         $email = $mail_service->createMessage();
         $email->setTo($toList);
         // cc
         $ccs = array();
         if (!empty($cc) && null != ($ccList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $cc)))) {
             $email->setCc($ccList);
         }
         // bcc
         if (!empty($bcc) && null != ($bccList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $bcc)))) {
             $email->setBcc($bccList);
         }
         $email->setFrom(array($from => $personal));
         $email->setSubject($subject);
         $email->generateId();
         $headers = $email->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Fax Email Gateway (FEG) ' . APP_VERSION . ' (Build ' . APP_BUILD . ')');
         $email->setBody($content);
         // Mime Attachments
         if (is_array($files) && !empty($files)) {
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx])) {
                     continue;
                 }
                 $email->attach(Swift_Attachment::fromPath($file)->setFilename($files['name'][$idx]));
             }
         }
         // Headers
         foreach ($email->getHeaders()->getAll() as $hdr) {
             if (null != ($hdr_val = $hdr->getFieldBody())) {
                 if (!empty($hdr_val)) {
                     $mail_headers[$hdr->getFieldName()] = $hdr_val;
                 }
             }
         }
         // [TODO] Allow separated addresses (parseRfcAddress)
         //		$mailer->log->enable();
         if (!@$mailer->send($email)) {
             throw new Exception('Mail failed to send: unknown reason');
         }
         //		$mailer->log->dump();
     } catch (Exception $e) {
         // Do Something
         $status = false;
     }
     // Give plugins a chance to note a message is imported.
     $eventMgr = DevblocksPlatform::getEventService();
     $eventMgr->trigger(new Model_DevblocksEvent('email.send', array('properties' => $properties, 'send_status' => $status ? 2 : 1)));
     return $status;
 }
Пример #13
0
 function doOppBulkUpdateAction()
 {
     // Checked rows
     @($opp_ids_str = DevblocksPlatform::importGPC($_REQUEST['opp_ids'], 'string'));
     $opp_ids = DevblocksPlatform::parseCsvString($opp_ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView('', $view_id);
     // Opp fields
     @($status = trim(DevblocksPlatform::importGPC($_POST['status'], 'string', '')));
     @($closed_date = trim(DevblocksPlatform::importGPC($_POST['closed_date'], 'string', '')));
     @($worker_id = trim(DevblocksPlatform::importGPC($_POST['worker_id'], 'string', '')));
     $do = array();
     // Do: Status
     if (0 != strlen($status)) {
         $do['status'] = $status;
     }
     // Do: Closed Date
     if (0 != strlen($closed_date)) {
         @($do['closed_date'] = intval(strtotime($closed_date)));
     }
     // Do: Worker
     if (0 != strlen($worker_id)) {
         $do['worker_id'] = $worker_id;
     }
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $opp_ids);
     $view->render();
     return;
 }
Пример #14
0
// ,'mysql'
$tables = $datadict->MetaTables();
$tables = array_flip($tables);
// ===========================================================================
// Convert the module format
$sql = "SELECT tool_code, property_value FROM community_tool_property WHERE property_key = 'common.enabled_modules'";
$rs = $db->Execute($sql);
while (!$rs->EOF) {
    $tool_code = $rs->Fields('tool_code');
    $property_value = $rs->Fields('property_value');
    // Check the deprecated login bits
    $login_contact = $db->GetOne(sprintf("SELECT property_value FROM community_tool_property WHERE property_key = 'contact.require_login' AND tool_code = %s AND property_value='1'", $db->qstr($tool_code)));
    $login_kb = $db->GetOne(sprintf("SELECT property_value FROM community_tool_property WHERE property_key = 'contact.require_kb' AND tool_code = %s AND property_value='1'", $db->qstr($tool_code)));
    // Change the format
    $modules = array();
    $mods = DevblocksPlatform::parseCsvString($property_value);
    if (is_array($mods)) {
        foreach ($mods as $mod) {
            switch ($mod) {
                case 'sc.controller.contact':
                    $modules[$mod] = !empty($login_contact) ? 1 : 0;
                    break;
                case 'sc.controller.kb':
                    $modules[$mod] = !empty($login_kb) ? 1 : 0;
                    break;
                case 'sc.controller.history':
                case 'sc.controller.account':
                    $modules[$mod] = '1';
                    // default to require login
                    break;
                default:
Пример #15
0
 function doBatchUpdateAction()
 {
     @($ticket_id_str = DevblocksPlatform::importGPC($_REQUEST['ticket_ids'], 'string'));
     @($shortcut_name = DevblocksPlatform::importGPC($_REQUEST['shortcut_name'], 'string', ''));
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     @($senders = DevblocksPlatform::importGPC($_REQUEST['senders'], 'string', ''));
     @($subjects = DevblocksPlatform::importGPC($_REQUEST['subjects'], 'string', ''));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     $subjects = DevblocksPlatform::parseCrlfString($subjects);
     $senders = DevblocksPlatform::parseCrlfString($senders);
     $do = array();
     // [TODO] This logic is repeated in several places -- try to condense (like custom field form handlers)
     // Move to Group/Bucket
     @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null));
     if (0 != strlen($move_code)) {
         list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code);
         $do['move'] = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id));
     }
     // Assign to worker
     @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null));
     if (0 != strlen($worker_id)) {
         $do['assign'] = array('worker_id' => intval($worker_id));
     }
     // Spam training
     @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null));
     if (0 != strlen($is_spam)) {
         $do['spam'] = array('is_spam' => !$is_spam ? 0 : 1);
     }
     // Set status
     @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null));
     if (0 != strlen($status)) {
         $do['status'] = array('is_waiting' => 3 == $status ? 1 : 0, 'is_closed' => 0 == $status || 3 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0);
     }
     $data = array();
     $ticket_ids = array();
     if ($filter == 'sender') {
         $data = $senders;
     } elseif ($filter == 'subject') {
         $data = $subjects;
     } elseif ($filter == 'checks') {
         $filter = '';
         // bulk update just looks for $ticket_ids == !null
         $ticket_ids = DevblocksPlatform::parseCsvString($ticket_id_str);
     }
     // Restrict to current worker groups
     $active_worker = CerberusApplication::getActiveWorker();
     $memberships = $active_worker->getMemberships();
     $view->params['tmp'] = new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, 'in', array_keys($memberships));
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, '', $data, $do, $ticket_ids);
     // Clear our temporary group restriction before re-rendering
     unset($view->params['tmp']);
     $view->render();
     return;
 }
Пример #16
0
 static function sendTicketMessage($properties = array())
 {
     $settings = DevblocksPlatform::getPluginSettingsService();
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     @($from_addy = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
     @($from_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''));
     // [TODO] If we still don't have a $from_addy we need a graceful failure.
     /*
     	     * [TODO] Move these into constants?
     	    'message_id'
     	    -----'ticket_id'
     'subject'
     	    'to'
     	    'cc'
     	    'bcc'
     	    'content'
     	    'files'
     	    'closed'
     	    'ticket_reopen'
     	    'unlock_date'
     	    'bucket_id'
     	    'agent_id',
     'is_autoreply',
     'dont_send',
     'dont_save_copy'
     */
     $mail_succeeded = true;
     try {
         // objects
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         // properties
         @($reply_message_id = $properties['message_id']);
         @($content = $properties['content']);
         @($files = $properties['files']);
         @($forward_files = $properties['forward_files']);
         @($worker_id = $properties['agent_id']);
         @($subject = $properties['subject']);
         $message = DAO_Ticket::getMessage($reply_message_id);
         $message_headers = DAO_MessageHeader::getAll($reply_message_id);
         $ticket_id = $message->ticket_id;
         $ticket = DAO_Ticket::getTicket($ticket_id);
         // [TODO] Check that message|ticket isn't NULL
         // If this ticket isn't spam trained and our outgoing message isn't an autoreply
         if ($ticket->spam_training == CerberusTicketSpamTraining::BLANK && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
             CerberusBayes::markTicketAsNotSpam($ticket_id);
         }
         // Allow teams to override the default from/personal
         @($group_reply = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
         @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL, ''));
         @($group_personal_with_worker = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL_WITH_WORKER, 0));
         if (!empty($group_reply)) {
             $from_addy = $group_reply;
         }
         if (!empty($group_personal)) {
             $from_personal = $group_personal;
         }
         // Prefix the worker name on the personal line?
         if (!empty($group_personal_with_worker) && null != ($reply_worker = DAO_Worker::getAgent($worker_id))) {
             $from_personal = $reply_worker->getName() . (!empty($from_personal) ? ', ' . $from_personal : "");
         }
         // Headers
         $mail->setFrom(array($from_addy => $from_personal));
         $mail->generateId();
         $headers = $mail->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         // Subject
         if (empty($subject)) {
             $subject = $ticket->subject;
         }
         if (!empty($properties['to'])) {
             // forward
             $mail->setSubject($subject);
         } else {
             // reply
             @($group_has_subject = intval(DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_HAS_MASK, 0)));
             @($group_subject_prefix = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_PREFIX, ''));
             $prefix = sprintf("[%s#%s] ", !empty($group_subject_prefix) ? $group_subject_prefix . ' ' : '', $ticket->mask);
             $mail->setSubject(sprintf('Re: %s%s', $group_has_subject ? $prefix : '', $subject));
         }
         // References
         if (!empty($message) && false !== @($in_reply_to = $message_headers['message-id'])) {
             $headers->addTextHeader('References', $in_reply_to);
             $headers->addTextHeader('In-Reply-To', $in_reply_to);
         }
         // Auto-reply handling (RFC-3834 compliant)
         if (isset($properties['is_autoreply']) && $properties['is_autoreply']) {
             $headers->addTextHeader('Auto-Submitted', 'auto-replied');
             if (null == ($first_address = DAO_Address::get($ticket->first_wrote_address_id))) {
                 return;
             }
             // Don't send e-mail to ourselves
             if (isset($helpdesk_senders[$first_address->email])) {
                 return;
             }
             // Make sure we haven't mailed this address an autoreply within 5 minutes
             if ($first_address->last_autoreply > 0 && $first_address->last_autoreply > time() - 300) {
                 return;
             }
             $first_email = strtolower($first_address->email);
             $first_split = explode('@', $first_email);
             if (!is_array($first_split) || count($first_split) != 2) {
                 return;
             }
             // If return-path is blank
             if (isset($message_headers['return-path']) && $message_headers['return-path'] == '<>') {
                 return;
             }
             // Ignore bounces
             if ($first_split[0] == "postmaster" || $first_split[0] == "mailer-daemon") {
                 return;
             }
             // Ignore autoresponses to autoresponses
             if (isset($message_headers['auto-submitted']) && $message_headers['auto-submitted'] != 'no') {
                 return;
             }
             if (isset($message_headers['precedence']) && ($message_headers['precedence'] == 'list' || $message_headers['precedence'] == 'junk' || ($message_headers['precedence'] = 'bulk'))) {
                 return;
             }
             // Set the auto-reply date for this address to right now
             DAO_Address::update($ticket->first_wrote_address_id, array(DAO_Address::LAST_AUTOREPLY => time()));
             // Auto-reply just to the initial requester
             $mail->addTo($first_address->email);
             // Not an auto-reply
         } else {
             // Forwards
             if (!empty($properties['to'])) {
                 $aTo = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['to']));
                 if (is_array($aTo)) {
                     foreach ($aTo as $to_addy) {
                         $mail->addTo($to_addy);
                     }
                 }
                 // Replies
             } else {
                 // Recipients
                 $requesters = DAO_Ticket::getRequestersByTicket($ticket_id);
                 if (is_array($requesters)) {
                     foreach ($requesters as $requester) {
                         /* @var $requester Model_Address */
                         $mail->addTo($requester->email);
                     }
                 }
             }
             // Ccs
             if (!empty($properties['cc'])) {
                 $aCc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['cc']));
                 $mail->setCc($aCc);
             }
             // Bccs
             if (!empty($properties['bcc'])) {
                 $aBcc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['bcc']));
                 $mail->setBcc($aBcc);
             }
         }
         /*
          * [IMPORTANT -- Yes, this is simply a line in the sand.]
          * You're welcome to modify the code to meet your needs, but please respect 
          * our licensing.  Buy a legitimate copy to help support the project!
          * http://www.cerberusweb.com/
          */
         $license = CerberusLicense::getInstance();
         if (empty($license) || @empty($license['serial'])) {
             $content .= base64_decode("DQoNCi0tLQ0KQ29tYmF0IHNwYW0gYW5kIGltcHJvdmUgcmVzc" . "G9uc2UgdGltZXMgd2l0aCBDZXJiZXJ1cyBIZWxwZGVzayA0LjAhDQpodHRwOi8vd3d3LmNlc" . "mJlcnVzd2ViLmNvbS8NCg");
         }
         // Body
         $mail->setBody($content);
         // Mime Attachments
         if (is_array($files) && !empty($files)) {
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx])) {
                     continue;
                 }
                 $mail->attach(Swift_Attachment::fromPath($file)->setFilename($files['name'][$idx]));
             }
         }
         // Forward Attachments
         if (!empty($forward_files) && is_array($forward_files)) {
             $attachments_path = APP_STORAGE_PATH . '/attachments/';
             foreach ($forward_files as $file_id) {
                 $attachment = DAO_Attachment::get($file_id);
                 $attachment_path = $attachments_path . $attachment->filepath;
                 $mail->attach(Swift_Attachment::fromPath($attachment_path)->setFilename($attachment->display_name));
             }
         }
         if (!DEMO_MODE) {
             // If we're not supposed to send
             if (isset($properties['dont_send']) && $properties['dont_send']) {
                 // ...do nothing
             } else {
                 // otherwise send
                 if (!$mailer->send($mail)) {
                     $mail_succeeded = false;
                     throw new Exception('Mail not sent.');
                 }
             }
         }
     } catch (Exception $e) {
         // tag failure, so we can add a note to the message later
         $mail_succeeded = false;
     }
     // Handle post-mail actions
     $change_fields = array();
     $fromAddressInst = CerberusApplication::hashLookupAddress($from_addy, true);
     $fromAddressId = $fromAddressInst->id;
     if ((!isset($properties['dont_keep_copy']) || !$properties['dont_keep_copy']) && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
         $change_fields[DAO_Ticket::LAST_WROTE_ID] = $fromAddressId;
         $change_fields[DAO_Ticket::UPDATED_DATE] = time();
         if (!empty($worker_id)) {
             $change_fields[DAO_Ticket::LAST_WORKER_ID] = $worker_id;
             $change_fields[DAO_Ticket::LAST_ACTION_CODE] = CerberusTicketActionCode::TICKET_WORKER_REPLY;
         }
         // Only change the subject if not forwarding
         if (!empty($subject) && empty($properties['to'])) {
             $change_fields[DAO_Ticket::SUBJECT] = $subject;
         }
         $fields = array(DAO_Message::TICKET_ID => $ticket_id, DAO_Message::CREATED_DATE => time(), DAO_Message::ADDRESS_ID => $fromAddressId, DAO_Message::IS_OUTGOING => 1, DAO_Message::WORKER_ID => !empty($worker_id) ? $worker_id : 0);
         $message_id = DAO_Message::create($fields);
         // Content
         DAO_MessageContent::create($message_id, $content);
         $headers = $mail->getHeaders();
         // Headers
         foreach ($headers->getAll() as $hdr) {
             if (null != ($hdr_val = $hdr->getFieldBody())) {
                 if (!empty($hdr_val)) {
                     DAO_MessageHeader::create($message_id, $hdr->getFieldName(), CerberusParser::fixQuotePrintableString($hdr_val));
                 }
             }
         }
         // Attachments
         if (is_array($files) && !empty($files)) {
             $attachment_path = APP_STORAGE_PATH . '/attachments/';
             reset($files);
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx]) || !file_exists($file)) {
                     continue;
                 }
                 $fields = array(DAO_Attachment::MESSAGE_ID => $message_id, DAO_Attachment::DISPLAY_NAME => $files['name'][$idx], DAO_Attachment::MIME_TYPE => $files['type'][$idx], DAO_Attachment::FILE_SIZE => filesize($file));
                 $file_id = DAO_Attachment::create($fields);
                 $attachment_bucket = sprintf("%03d/", mt_rand(1, 100));
                 $attachment_file = $file_id;
                 if (!file_exists($attachment_path . $attachment_bucket)) {
                     mkdir($attachment_path . $attachment_bucket, 0775, true);
                 }
                 if (!is_writeable($attachment_path . $attachment_bucket)) {
                     echo "Can't write to bucket " . $attachment_path . $attachment_bucket . "<BR>";
                 }
                 copy($file, $attachment_path . $attachment_bucket . $attachment_file);
                 @unlink($file);
                 DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file));
             }
         }
         // add note to message if email failed
         if ($mail_succeeded === false) {
             $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
             DAO_MessageNote::create($fields);
         }
     }
     // Post-Reply Change Properties
     if (isset($properties['closed'])) {
         switch ($properties['closed']) {
             case 0:
                 // open
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 $change_fields[DAO_Ticket::DUE_DATE] = 0;
                 break;
             case 1:
                 // closed
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 1;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
             case 2:
                 // waiting
                 $change_fields[DAO_Ticket::IS_WAITING] = 1;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
         }
     }
     // Who should handle the followup?
     if (isset($properties['next_worker_id'])) {
         $change_fields[DAO_Ticket::NEXT_WORKER_ID] = $properties['next_worker_id'];
     }
     // Allow anybody to reply after
     if (isset($properties['unlock_date']) && !empty($properties['unlock_date'])) {
         $unlock = strtotime($properties['unlock_date']);
         if (intval($unlock) > 0) {
             $change_fields[DAO_Ticket::UNLOCK_DATE] = $unlock;
         }
     }
     // Move
     if (!empty($properties['bucket_id'])) {
         // [TODO] Use API to move, or fire event
         // [TODO] Ensure team/bucket exist
         list($team_id, $bucket_id) = CerberusApplication::translateTeamCategoryCode($properties['bucket_id']);
         $change_fields[DAO_Ticket::TEAM_ID] = $team_id;
         $change_fields[DAO_Ticket::CATEGORY_ID] = $bucket_id;
     }
     if (!empty($ticket_id) && !empty($change_fields)) {
         DAO_Ticket::updateTicket($ticket_id, $change_fields);
     }
     // Outbound Reply Event (not automated reply, etc.)
     if (!empty($worker_id)) {
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.outbound', array('ticket_id' => $ticket_id, 'worker_id' => $worker_id)));
     }
 }
Пример #17
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 = DevblocksPlatform::getPluginSettingsService();
     $authorized_ips_str = $settings->get('cerberusweb.core', 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 5.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 = DevblocksPlatform::getPluginSettingsService());
             @($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('cerberusweb.core', CerberusSettings::HELPDESK_TITLE, ''), str_replace(array('@', '.'), array(' at ', ' dot '), $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, '')), $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''), $settings->get('cerberusweb.core', CerberusSettings::SMTP_HOST, ''), $settings->get('cerberusweb.core', CerberusSettings::SMTP_PORT, ''), $settings->get('cerberusweb.core', 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;
 }
Пример #18
0
 /**
  * @return _DevblocksCacheManager
  */
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new _DevblocksCacheManager();
         $frontendOptions = array('cache_id_prefix' => defined('DEVBLOCKS_CACHE_PREFIX') && DEVBLOCKS_CACHE_PREFIX ? DEVBLOCKS_CACHE_PREFIX : null, 'lifetime' => 21600, 'write_control' => false, 'automatic_serialization' => true);
         // Shared-memory cache
         if (extension_loaded('memcache') && defined('DEVBLOCKS_MEMCACHED_SERVERS') && DEVBLOCKS_MEMCACHED_SERVERS) {
             $pairs = DevblocksPlatform::parseCsvString(DEVBLOCKS_MEMCACHED_SERVERS);
             $servers = array();
             if (is_array($pairs) && !empty($pairs)) {
                 foreach ($pairs as $server) {
                     list($host, $port) = explode(':', $server);
                     if (empty($host) || empty($port)) {
                         continue;
                     }
                     $servers[] = array('host' => $host, 'port' => $port, 'persistent' => true);
                 }
             }
             $backendOptions = array('servers' => $servers);
             self::$_zend_cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
         }
         // Disk-based cache (default)
         if (null == self::$_zend_cache) {
             $backendOptions = array('cache_dir' => APP_TEMP_PATH);
             self::$_zend_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         }
     }
     return self::$instance;
 }
Пример #19
0
 function saveTab()
 {
     @($plugin_id = DevblocksPlatform::importGPC($_REQUEST['plugin_id'], 'string'));
     @($access_ids = DevblocksPlatform::importGPC($_REQUEST['access_ids'], 'array', array()));
     @($add_nickname = DevblocksPlatform::importGPC($_REQUEST['add_nickname'], 'string'));
     @($deletes = DevblocksPlatform::importGPC($_REQUEST['deletes'], 'array', array()));
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'webapi')));
         return;
     }
     // Deletes
     if (!empty($deletes)) {
         DAO_WebapiKey::delete($deletes);
     }
     // Edits
     if (is_array($access_ids)) {
         foreach ($access_ids as $access_id) {
             $rights = array();
             // ACL
             @($aclAddresses = DevblocksPlatform::importGPC($_REQUEST['aclAddresses' . $access_id], 'integer', 0));
             //			@$aclFnr = DevblocksPlatform::importGPC($_REQUEST['aclFnr'.$access_id],'integer',0);
             @($aclOrgs = DevblocksPlatform::importGPC($_REQUEST['aclOrgs' . $access_id], 'integer', 0));
             @($aclTasks = DevblocksPlatform::importGPC($_REQUEST['aclTasks' . $access_id], 'integer', 0));
             @($aclParser = DevblocksPlatform::importGPC($_REQUEST['aclParser' . $access_id], 'integer', 0));
             @($aclTickets = DevblocksPlatform::importGPC($_REQUEST['aclTickets' . $access_id], 'integer', 0));
             @($aclKB = DevblocksPlatform::importGPC($_REQUEST['aclKB' . $access_id], 'array'));
             $aclKBTopics = array();
             foreach ($aclKB as $k => $v) {
                 $aclKBTopics[$v] = 1;
             }
             $rights['acl_addresses'] = $aclAddresses;
             //			$rights['acl_fnr'] = $aclFnr;
             $rights['acl_orgs'] = $aclOrgs;
             $rights['acl_tasks'] = $aclTasks;
             $rights['acl_parser'] = $aclParser;
             $rights['acl_tickets'] = $aclTickets;
             $rights['acl_kb_topics'] = $aclKBTopics;
             // IPs
             @($ipList = DevblocksPlatform::importGPC($_REQUEST['ips' . $access_id], 'string', ''));
             if (!empty($ipList)) {
                 $ips = array_unique(DevblocksPlatform::parseCsvString($ipList));
                 $rights['ips'] = $ips;
             }
             $fields = array(DAO_WebapiKey::RIGHTS => serialize($rights));
             DAO_WebapiKey::update($access_id, $fields);
         }
     }
     // Add Access Key
     if (!empty($add_nickname)) {
         $gen_access_key = CerberusApplication::generatePassword(20);
         $gen_secret_key = CerberusApplication::generatePassword(30);
         $fields = array(DAO_WebapiKey::NICKNAME => $add_nickname, DAO_WebapiKey::ACCESS_KEY => $gen_access_key, DAO_WebapiKey::SECRET_KEY => $gen_secret_key);
         $key_id = DAO_WebapiKey::create($fields);
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('config', 'webapi')));
     exit;
 }
Пример #20
0
 static function getMatches(Model_Address $fromAddress, CerberusParserMessage $message)
 {
     //		print_r($fromAddress);
     //		print_r($message);
     $matches = array();
     $rules = DAO_MailToGroupRule::getWhere();
     $message_headers = $message->headers;
     $custom_fields = DAO_CustomField::getAll();
     // Lazy load when needed on criteria basis
     $address_field_values = null;
     $org_field_values = null;
     // Check filters
     if (is_array($rules)) {
         foreach ($rules as $rule) {
             /* @var $rule Model_MailToGroupRule */
             $passed = 0;
             // check criteria
             foreach ($rule->criteria as $crit_key => $crit) {
                 @($value = $crit['value']);
                 switch ($crit_key) {
                     case 'dayofweek':
                         $current_day = strftime('%w');
                         //						$current_day = 1;
                         // Forced to English abbrevs as indexes
                         $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
                         // Is the current day enabled?
                         if (isset($crit[$days[$current_day]])) {
                             $passed++;
                         }
                         break;
                     case 'timeofday':
                         $current_hour = strftime('%H');
                         $current_min = strftime('%M');
                         //						$current_hour = 17;
                         //						$current_min = 5;
                         if (null != ($from_time = @$crit['from'])) {
                             list($from_hour, $from_min) = explode(':', $from_time);
                         }
                         if (null != ($to_time = @$crit['to'])) {
                             if (list($to_hour, $to_min) = explode(':', $to_time)) {
                             }
                         }
                         // Do we need to wrap around to the next day's hours?
                         if ($from_hour > $to_hour) {
                             // yes
                             $to_hour += 24;
                             // add 24 hrs to the destination (1am = 25th hour)
                         }
                         // Are we in the right 24 hourly range?
                         if ((int) $current_hour >= $from_hour && (int) $current_hour <= $to_hour) {
                             // If we're in the first hour, are we minutes early?
                             if ($current_hour == $from_hour && (int) $current_min < $from_min) {
                                 break;
                             }
                             // If we're in the last hour, are we minutes late?
                             if ($current_hour == $to_hour && (int) $current_min > $to_min) {
                                 break;
                             }
                             $passed++;
                         }
                         break;
                     case 'tocc':
                         $tocc = array();
                         $destinations = DevblocksPlatform::parseCsvString($value);
                         // Build a list of To/Cc addresses on this message
                         @($to_list = imap_rfc822_parse_adrlist($message_headers['to'], 'localhost'));
                         @($cc_list = imap_rfc822_parse_adrlist($message_headers['cc'], 'localhost'));
                         if (is_array($to_list)) {
                             foreach ($to_list as $addy) {
                                 $tocc[] = $addy->mailbox . '@' . $addy->host;
                             }
                         }
                         if (is_array($cc_list)) {
                             foreach ($cc_list as $addy) {
                                 $tocc[] = $addy->mailbox . '@' . $addy->host;
                             }
                         }
                         $dest_flag = false;
                         // bail out when true
                         if (is_array($destinations) && is_array($tocc)) {
                             foreach ($destinations as $dest) {
                                 if ($dest_flag) {
                                     break;
                                 }
                                 $regexp_dest = DevblocksPlatform::strToRegExp($dest);
                                 foreach ($tocc as $addy) {
                                     if (@preg_match($regexp_dest, $addy)) {
                                         $passed++;
                                         $dest_flag = false;
                                         break;
                                     }
                                 }
                             }
                         }
                         break;
                     case 'from':
                         $regexp_from = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_from, $fromAddress->email)) {
                             $passed++;
                         }
                         break;
                     case 'subject':
                         // [TODO] Decode if necessary
                         @($subject = $message_headers['subject']);
                         $regexp_subject = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_subject, $subject)) {
                             $passed++;
                         }
                         break;
                     case 'body':
                         // Line-by-line body scanning (sed-like)
                         $lines = preg_split("/[\r\n]/", $message->body);
                         if (is_array($lines)) {
                             foreach ($lines as $line) {
                                 if (@preg_match($value, $line)) {
                                     $passed++;
                                     break;
                                 }
                             }
                         }
                         break;
                     case 'header1':
                     case 'header2':
                     case 'header3':
                     case 'header4':
                     case 'header5':
                         @($header = strtolower($crit['header']));
                         if (empty($header)) {
                             $passed++;
                             break;
                         }
                         if (empty($value)) {
                             // we're checking for null/blanks
                             if (!isset($message_headers[$header]) || empty($message_headers[$header])) {
                                 $passed++;
                             }
                         } elseif (isset($message_headers[$header]) && !empty($message_headers[$header])) {
                             $regexp_header = DevblocksPlatform::strToRegExp($value);
                             // Flatten CRLF
                             if (@preg_match($regexp_header, str_replace(array("\r", "\n"), ' ', $message_headers[$header]))) {
                                 $passed++;
                             }
                         }
                         break;
                     default:
                         // ignore invalids
                         // Custom Fields
                         if (0 == strcasecmp('cf_', substr($crit_key, 0, 3))) {
                             $field_id = substr($crit_key, 3);
                             // Make sure it exists
                             if (null == @($field = $custom_fields[$field_id])) {
                                 continue;
                             }
                             // Lazy values loader
                             $field_values = array();
                             switch ($field->source_extension) {
                                 case ChCustomFieldSource_Address::ID:
                                     if (null == $address_field_values) {
                                         $address_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Address::ID, $fromAddress->id));
                                     }
                                     $field_values =& $address_field_values;
                                     break;
                                 case ChCustomFieldSource_Org::ID:
                                     if (null == $org_field_values) {
                                         $org_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Org::ID, $fromAddress->contact_org_id));
                                     }
                                     $field_values =& $org_field_values;
                                     break;
                             }
                             // No values, default.
                             if (!isset($field_values[$field_id])) {
                                 continue;
                             }
                             // Type sensitive value comparisons
                             switch ($field->type) {
                                 case 'S':
                                     // string
                                 // string
                                 case 'T':
                                     // clob
                                 // clob
                                 case 'U':
                                     // URL
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : '';
                                     $oper = isset($crit['oper']) ? $crit['oper'] : "=";
                                     if ($oper == "=" && @preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && @(!preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val))) {
                                         $passed++;
                                     }
                                     break;
                                 case 'N':
                                     // number
                                     if (!isset($field_values[$field_id])) {
                                         break;
                                     }
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     $oper = isset($crit['oper']) ? $crit['oper'] : "=";
                                     if ($oper == "=" && intval($field_val) == intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && intval($field_val) != intval($value)) {
                                         $passed++;
                                     } elseif ($oper == ">" && intval($field_val) > intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "<" && intval($field_val) < intval($value)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'E':
                                     // date
                                     $field_val = isset($field_values[$field_id]) ? intval($field_values[$field_id]) : 0;
                                     $from = isset($crit['from']) ? $crit['from'] : "0";
                                     $to = isset($crit['to']) ? $crit['to'] : "now";
                                     if (intval(@strtotime($from)) <= $field_val && intval(@strtotime($to)) >= $field_val) {
                                         $passed++;
                                     }
                                     break;
                                 case 'C':
                                     // checkbox
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     if (intval($value) == intval($field_val)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'D':
                                     // dropdown
                                 // dropdown
                                 case 'X':
                                     // multi-checkbox
                                 // multi-checkbox
                                 case 'M':
                                     // multi-picklist
                                 // multi-picklist
                                 case 'W':
                                     // worker
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : array();
                                     if (!is_array($value)) {
                                         $value = array($value);
                                     }
                                     if (is_array($field_val)) {
                                         // if multiple things set
                                         foreach ($field_val as $v) {
                                             // loop through possible
                                             if (isset($value[$v])) {
                                                 // is any possible set?
                                                 $passed++;
                                                 break;
                                             }
                                         }
                                     } else {
                                         // single
                                         if (isset($value[$field_val])) {
                                             // is our set field in possibles?
                                             $passed++;
                                             break;
                                         }
                                     }
                                     break;
                             }
                         }
                         break;
                 }
             }
             // If our rule matched every criteria, stop and return the filter
             if ($passed == count($rule->criteria)) {
                 DAO_MailToGroupRule::increment($rule->id);
                 // ++ the times we've matched
                 $matches[$rule->id] = $rule;
                 // Bail out if this rule had a move action
                 if (isset($rule->actions['move'])) {
                     return $matches;
                 }
             }
         }
     }
     // If we're at the end of rules and didn't bail out yet
     if (!empty($matches)) {
         return $matches;
     }
     // No matches
     return NULL;
 }
Пример #21
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     @set_time_limit(0);
     // no timelimit (when possible)
     $translate = DevblocksPlatform::getTranslationService();
     $stack = $request->path;
     array_shift($stack);
     // update
     $cache = DevblocksPlatform::getCacheService();
     /* @var $cache _DevblocksCacheManager */
     switch (array_shift($stack)) {
         case 'locked':
             if (!DevblocksPlatform::versionConsistencyCheck()) {
                 $url = DevblocksPlatform::getUrlService();
                 echo "<h1>Feg - Fax Email Gateway 1.x</h1>";
                 echo "The application is currently waiting for an administrator to finish upgrading. " . "Please wait a few minutes and then " . sprintf("<a href='%s'>try again</a>.<br><br>", $url->write('c=update&a=locked'));
                 echo sprintf("If you're an admin you may <a href='%s'>finish the upgrade</a>.", $url->write('c=update'));
             } else {
                 DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
             }
             break;
         default:
             $path = APP_TEMP_PATH . DIRECTORY_SEPARATOR;
             $file = $path . 'feg_update_lock';
             $settings = DevblocksPlatform::getPluginSettingsService();
             $authorized_ips_str = $settings->get('feg.core', FegSettings::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 vsprintf($translate->_('update.ip_unauthorized'), $_SERVER['REMOTE_ADDR']);
                 return;
             }
             // Check requirements
             $errors = FegApplication::checkRequirements();
             if (!empty($errors)) {
                 echo $translate->_('update.correct_errors');
                 echo "<ul style='color:red;'>";
                 foreach ($errors as $error) {
                     echo "<li>" . $error . "</li>";
                 }
                 echo "</ul>";
                 exit;
             }
             try {
                 // If authorized, lock and attempt update
                 if (!file_exists($file) || @filectime($file) + 600 < time()) {
                     // 10 min lock
                     // Log everybody out since we're touching the database
                     $session = DevblocksPlatform::getSessionService();
                     $session->clearAll();
                     // Lock file
                     touch($file);
                     // Recursive patch
                     FegApplication::update();
                     // Clean up
                     @unlink($file);
                     $cache = DevblocksPlatform::getCacheService();
                     $cache->save(APP_BUILD, "devblocks_app_build");
                     // Clear all caches
                     $cache->clean();
                     DevblocksPlatform::getClassLoaderService()->destroy();
                     // Clear compiled templates
                     $tpl = DevblocksPlatform::getTemplateService();
                     $tpl->utility->clearCompiledTemplate();
                     $tpl->cache->clearAll();
                     // Reload plugin translations
                     DAO_Translation::reloadPluginStrings();
                     // Redirect
                     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
                 } else {
                     echo $translate->_('update.locked_another');
                 }
             } catch (Exception $e) {
                 unlink($file);
                 die($e->getMessage());
             }
     }
     exit;
 }
Пример #22
0
 private function _getSearchAction($path)
 {
     @($p_query = DevblocksPlatform::importGPC($_REQUEST['query'], 'string', ''));
     @($p_resources = DevblocksPlatform::importGPC($_REQUEST['resources'], 'string', ''));
     $resource_where = null;
     // Specific topics only?
     if (!empty($p_resources)) {
         $db = DevblocksPlatform::getDatabaseService();
         $resource_ids = DevblocksPlatform::parseCsvString($p_resources);
         if (!empty($resource_ids)) {
             $resource_where = sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, $db->qstr(implode(',', $resource_ids)));
         }
     }
     $resources = DAO_FnrExternalResource::getWhere($resource_where);
     $feeds = Model_FnrExternalResource::searchResources($resources, $p_query);
     $xml_out = new SimpleXMLElement("<resources></resources>");
     foreach ($feeds as $matches) {
         $eMatch = $xml_out->addChild("resource");
         $eMatch->addChild('name', $matches['name']);
         $eMatch->addChild('topic', $matches['topic_name']);
         $eMatch->addChild('link', $matches['feed']->link);
         $eResults = $eMatch->addChild("results");
         foreach ($matches['feed'] as $item) {
             $eResult = $eResults->addChild("result");
             if ($item instanceof Zend_Feed_Entry_Rss) {
                 $eResult->addChild('title', (string) $item->title());
                 $eResult->addChild('link', (string) $item->link());
                 $eResult->addChild('date', (string) $item->pubDate());
                 $eResult->addChild('description', (string) $item->description());
             } elseif ($item instanceof Zend_Feed_Atom) {
                 $eResult->addChild('title', (string) $item->title());
                 $eResult->addChild('link', (string) $item->link['href']);
                 $eResult->addChild('date', (string) $item->published());
                 $eResult->addChild('description', (string) $item->summary());
             }
         }
     }
     $this->_render($xml_out->asXML());
 }
Пример #23
0
 function doWorkersBulkUpdateAction()
 {
     // Checked rows
     @($ids_str = DevblocksPlatform::importGPC($_REQUEST['ids'], 'string'));
     $ids = DevblocksPlatform::parseCsvString($ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     // Worker fields
     @($is_disabled = trim(DevblocksPlatform::importGPC($_POST['is_disabled'], 'string', '')));
     $do = array();
     // Do: Disabled
     if (0 != strlen($is_disabled)) {
         $do['is_disabled'] = $is_disabled;
     }
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $ids);
     $view->render();
     return;
 }
Пример #24
0
 function doOrgBulkUpdateAction()
 {
     // Checked rows
     @($org_ids_str = DevblocksPlatform::importGPC($_REQUEST['org_ids'], 'string'));
     $org_ids = DevblocksPlatform::parseCsvString($org_ids_str);
     // Filter: whole list or check
     @($filter = DevblocksPlatform::importGPC($_REQUEST['filter'], 'string', ''));
     // View
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     // Org fields
     @($country = trim(DevblocksPlatform::importGPC($_POST['country'], 'string', '')));
     $do = array();
     // Do: Country
     if (0 != strlen($country)) {
         $do['country'] = $country;
     }
     // Do: Custom fields
     $do = DAO_CustomFieldValue::handleBulkPost($do);
     $view->doBulkUpdate($filter, $do, $org_ids);
     $view->render();
     return;
 }
Пример #25
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;
 }
Пример #26
0
 /**
  * @return Model_GroupInboxFilter|false
  */
 static function getMatches($group_id, $ticket_id, $only_rule_id = 0)
 {
     $matches = array();
     if (empty($group_id)) {
         return false;
     }
     if (!empty($only_rule_id)) {
         $filters = array(DAO_GroupInboxFilter::get($only_rule_id));
     } else {
         $filters = DAO_GroupInboxFilter::getByGroupId($group_id);
     }
     // Check the ticket
     if (null === ($ticket = DAO_Ticket::getTicket($ticket_id))) {
         return false;
     }
     // Build our objects
     $ticket_from = DAO_Address::get($ticket->last_wrote_address_id);
     $ticket_group_id = $ticket->team_id;
     // [TODO] These expensive checks should only populate when needed
     $messages = DAO_Ticket::getMessagesByTicket($ticket_id);
     if (empty($messages)) {
         return false;
     }
     if (null == @($message = array_pop($messages))) {
         /* @var $message CerberusMessage */
         return false;
     }
     $message_headers = $message->getHeaders();
     $custom_fields = DAO_CustomField::getAll();
     // Lazy load when needed on criteria basis
     $ticket_field_values = null;
     $address_field_values = null;
     $org_field_values = null;
     // Check filters
     if (is_array($filters)) {
         foreach ($filters as $filter) {
             /* @var $filter Model_GroupInboxFilter */
             $passed = 0;
             // check criteria
             foreach ($filter->criteria as $rule_key => $rule) {
                 @($value = $rule['value']);
                 switch ($rule_key) {
                     case 'tocc':
                         $destinations = DevblocksPlatform::parseCsvString($value);
                         // Build a list of To/Cc addresses on this message
                         @($to_list = imap_rfc822_parse_adrlist($message_headers['to'], 'localhost'));
                         @($cc_list = imap_rfc822_parse_adrlist($message_headers['cc'], 'localhost'));
                         if (is_array($to_list)) {
                             foreach ($to_list as $addy) {
                                 $tocc[] = $addy->mailbox . '@' . $addy->host;
                             }
                         }
                         if (is_array($cc_list)) {
                             foreach ($cc_list as $addy) {
                                 $tocc[] = $addy->mailbox . '@' . $addy->host;
                             }
                         }
                         $dest_flag = false;
                         // bail out when true
                         if (is_array($destinations) && is_array($tocc)) {
                             foreach ($destinations as $dest) {
                                 if ($dest_flag) {
                                     break;
                                 }
                                 $regexp_dest = DevblocksPlatform::strToRegExp($dest);
                                 foreach ($tocc as $addy) {
                                     if (@preg_match($regexp_dest, $addy)) {
                                         $passed++;
                                         $dest_flag = false;
                                         break;
                                     }
                                 }
                             }
                         }
                         break;
                     case 'from':
                         $regexp_from = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_from, $ticket_from->email)) {
                             $passed++;
                         }
                         break;
                     case 'subject':
                         $regexp_subject = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_subject, $ticket->subject)) {
                             $passed++;
                         }
                         break;
                     case 'header1':
                     case 'header2':
                     case 'header3':
                     case 'header4':
                     case 'header5':
                         @($header = strtolower($rule['header']));
                         if (empty($header)) {
                             $passed++;
                             break;
                         }
                         if (empty($value)) {
                             // we're checking for null/blanks
                             if (!isset($message_headers[$header]) || empty($message_headers[$header])) {
                                 $passed++;
                             }
                         } elseif (isset($message_headers[$header]) && !empty($message_headers[$header])) {
                             $regexp_header = DevblocksPlatform::strToRegExp($value);
                             // Flatten CRLF
                             if (@preg_match($regexp_header, str_replace(array("\r", "\n"), ' ', $message_headers[$header]))) {
                                 $passed++;
                             }
                         }
                         break;
                     default:
                         // ignore invalids
                         // Custom Fields
                         if (0 == strcasecmp('cf_', substr($rule_key, 0, 3))) {
                             $field_id = substr($rule_key, 3);
                             // Make sure it exists
                             if (null == @($field = $custom_fields[$field_id])) {
                                 continue;
                             }
                             // Lazy values loader
                             $field_values = array();
                             switch ($field->source_extension) {
                                 case ChCustomFieldSource_Address::ID:
                                     if (null == $address_field_values) {
                                         $address_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Address::ID, $ticket_from->id));
                                     }
                                     $field_values =& $address_field_values;
                                     break;
                                 case ChCustomFieldSource_Org::ID:
                                     if (null == $org_field_values) {
                                         $org_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Org::ID, $ticket_from->contact_org_id));
                                     }
                                     $field_values =& $org_field_values;
                                     break;
                                 case ChCustomFieldSource_Ticket::ID:
                                     if (null == $ticket_field_values) {
                                         $ticket_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $ticket->id));
                                     }
                                     $field_values =& $ticket_field_values;
                                     break;
                             }
                             // No values, default.
                             //							if(!isset($field_values[$field_id]))
                             //								continue;
                             // Type sensitive value comparisons
                             // [TODO] Operators
                             switch ($field->type) {
                                 case 'S':
                                     // string
                                 // string
                                 case 'T':
                                     // clob
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : '';
                                     $oper = isset($rule['oper']) ? $rule['oper'] : "=";
                                     if ($oper == "=" && @preg_match(DevblocksPlatform::strToRegExp($value), $field_val)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && @(!preg_match(DevblocksPlatform::strToRegExp($value), $field_val))) {
                                         $passed++;
                                     }
                                     break;
                                 case 'N':
                                     // number
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     $oper = isset($rule['oper']) ? $rule['oper'] : "=";
                                     if ($oper == "=" && intval($field_val) == intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && intval($field_val) != intval($value)) {
                                         $passed++;
                                     } elseif ($oper == ">" && $intval($field_val) > intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "<" && $intval($field_val) < intval($value)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'E':
                                     // date
                                     $field_val = isset($field_values[$field_id]) ? intval($field_values[$field_id]) : 0;
                                     $from = isset($rule['from']) ? $rule['from'] : "0";
                                     $to = isset($rule['to']) ? $rule['to'] : "now";
                                     if (intval(@strtotime($from)) <= $field_val && intval(@strtotime($to)) >= $field_val) {
                                         $passed++;
                                     }
                                     break;
                                 case 'C':
                                     // checkbox
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     if (intval($value) == intval($field_val)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'D':
                                     // dropdown
                                 // dropdown
                                 case 'X':
                                     // multi-checkbox
                                 // multi-checkbox
                                 case 'M':
                                     // multi-picklist
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : array();
                                     if (!is_array($value)) {
                                         $value = array($value);
                                     }
                                     foreach ($value as $v) {
                                         if (isset($field_val[$v])) {
                                             $passed++;
                                         }
                                     }
                                     break;
                             }
                         }
                         break;
                 }
             }
             // If our rule matched every criteria, stop and return the filter
             if ($passed == count($filter->criteria)) {
                 DAO_GroupInboxFilter::increment($filter->id);
                 // ++ the times we've matched
                 $matches[$filter->id] = $filter;
                 // If we're not stackable anymore, bail out.
                 if (!$filter->is_stackable) {
                     return $matches;
                 }
             }
         }
     }
     // If last rule was still stackable...
     if (!empty($matches)) {
         return $matches;
     }
     // No matches
     return false;
 }