public static function setUpBeforeClass()
 {
     CRM_Core_Config::singleton(1, 1);
     CRM_Utils_System::loadBootStrap(array('name' => $GLOBALS['_CV']['ADMIN_USER'], 'pass' => $GLOBALS['_CV']['ADMIN_PASS']));
     CRM_Utils_System::synchronizeUsers();
     parent::setUpBeforeClass();
 }
Ejemplo n.º 2
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config =& CRM_Core_Config::singleton();
    // this does not return on failure
    CRM_Utils_System::authenticateScript(true);
    //log the execution of script
    CRM_Core_Error::debug_log_message('civimail.cronjob.php');
    // load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    // we now use DB locks on a per job basis
    processQueue($config->mailerJobSize);
}
 /**
  * Given a permission string, check for access requirements
  *
  * @param string $str
  *   The permission to check.
  *
  * @return bool
  *   true if yes, else false
  */
 public function check($str)
 {
     // Generic cms 'administer users' role tranlates to 'administrator' WordPress role
     $str = $this->translatePermission($str, 'WordPress', array('administer users' => 'edit_users'));
     if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
         return FALSE;
     }
     if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
         return TRUE;
     }
     // CRM-15629
     // During some extern/* calls we don't bootstrap CMS hence
     // below constants are not set. In such cases, we don't need to
     // check permission, hence directly return TRUE
     if (!defined('ABSPATH') || !defined('WPINC')) {
         require_once 'CRM/Utils/System.php';
         CRM_Utils_System::loadBootStrap();
     }
     require_once ABSPATH . WPINC . '/pluggable.php';
     // for administrators give them all permissions
     if (!function_exists('current_user_can')) {
         return TRUE;
     }
     if (current_user_can('super admin') || current_user_can('administrator')) {
         return TRUE;
     }
     // Make string lowercase and convert spaces into underscore
     $str = CRM_Utils_String::munge(strtolower($str));
     if (is_user_logged_in()) {
         // Check whether the logged in user has the capabilitity
         if (current_user_can($str)) {
             return TRUE;
         }
     } else {
         //check the capabilities of Anonymous user)
         $roleObj = new WP_Roles();
         if ($roleObj->get_role('anonymous_user') != NULL && array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Ejemplo n.º 4
0
 protected function boot(InputInterface $input, OutputInterface $output)
 {
     if ($input->hasOption('test') && $input->getOption('test')) {
         putenv('CIVICRM_UF=UnitTests');
         $_ENV['CIVICRM_UF'] = 'UnitTests';
     }
     if ($input->hasOption('level') && $input->getOption('level') !== 'full') {
         \Civi\Cv\Bootstrap::singleton()->boot(array('prefetch' => FALSE));
     } else {
         \Civi\Cv\Bootstrap::singleton()->boot();
         \CRM_Core_Config::singleton();
         \CRM_Utils_System::loadBootStrap(array(), FALSE);
         if ($input->getOption('user')) {
             if (is_callable(array(\CRM_Core_Config::singleton()->userSystem, 'loadUser'))) {
                 \CRM_Utils_System::loadUser($input->getOption('user'));
             } else {
                 $output->writeln("<error>Failed to set user. Feature not supported by UF (" . CIVICRM_UF . ")</error>");
             }
         }
     }
 }
function run($argc, $argv)
{
    global $debug;
    session_start();
    require_once '../civicrm.config.php';
    require_once 'api/v2/Domain.php';
    require_once 'api/v2/Group.php';
    require_once 'api/v2/GroupNesting.php';
    require_once 'api/v2/GroupOrganization.php';
    require_once 'api/v2/Contact.php';
    if ($argc < 3 || $argc > 4) {
        #var_dump($argv);
        print_usage($argv[0]);
        exit(-1);
    }
    $org_name = $argv[1];
    $org_desc = $argv[2];
    $config = CRM_Core_Config::singleton();
    //load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    # create the domain
    $existing_domain = civicrm_domain_get();
    $domain_params = array('name' => $org_name, 'description' => $org_desc, 'version' => $existing_domain['version']);
    $domain = civicrm_domain_create($domain_params);
    if ($debug) {
        print "Create domain result: " . var_export($domain) . "\n";
    }
    $domain_id = $domain['id'];
    # find the parent group, if necessary
    if (!is_null($argv[3])) {
        $parent_group_name = $argv[3];
        $parent_group_params = array('title' => $parent_group_name);
        $parent_groups = civicrm_group_get($parent_group_params);
        if ($debug) {
            print "Find parent group result: " . var_export($parent_groups) . "\n";
        }
        $parent_group_keys = array_keys($parent_groups);
        $parent_group_id = $parent_group_keys[0];
    }
    # create the group
    $group_params = array('title' => $org_name, 'description' => $org_desc, 'is_active' => 1);
    $group = civicrm_group_add($group_params);
    if ($debug) {
        print "Create group result: " . var_export($group) . "\n";
    }
    $group_id = $group['result'];
    # create the org nesting if necessary
    if (!is_null($parent_group_id)) {
        $group_nesting_params = array('parent_group_id' => $parent_group_id, 'child_group_id' => $group_id);
        $group_nesting = civicrm_group_nesting_create($group_nesting_params);
        if ($debug) {
            print "Create group nesting result: " . var_export($group_nesting) . "\n";
        }
    }
    # create the org contact
    $org_params = array('organization_name' => $org_name, 'contact_type' => 'Organization');
    $org = civicrm_contact_create($org_params);
    if ($debug) {
        print "Create org contact result: " . var_export($org) . "\n";
    }
    $org_id = $org['contact_id'];
    # associate the two
    $group_org_params = array('group_id' => $group_id, 'organization_id' => $org_id);
    $group_org_id = civicrm_group_organization_create($group_org_params);
    if ($debug) {
        print "Create group-org association result: " . var_export($group_org_id) . "\n";
    }
    print "\n";
    print "Add or modify the following lines in the appropriate ";
    print "civicrm.settings.php file for {$org_name}:\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ID', {$domain_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_GROUP_ID', {$group_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ORG_ID', {$org_id} );\n";
    print "\n";
}
Ejemplo n.º 6
0
 /**
  * @inheritDoc
  */
 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
 {
     require_once 'DB.php';
     $config = CRM_Core_Config::singleton();
     $user = NULL;
     if ($loadCMSBootstrap) {
         $bootStrapParams = array();
         if ($name && $password) {
             $bootStrapParams = array('name' => $name, 'pass' => $password);
         }
         CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, FALSE);
     }
     jimport('joomla.application.component.helper');
     jimport('joomla.database.table');
     jimport('joomla.user.helper');
     $JUserTable = JTable::getInstance('User', 'JTable');
     $db = $JUserTable->getDbo();
     $query = $db->getQuery(TRUE);
     $query->select('id, name, username, email, password');
     $query->from($JUserTable->getTableName());
     $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)');
     $db->setQuery($query, 0, 0);
     $users = $db->loadObjectList();
     $row = array();
     if (count($users)) {
         $row = $users[0];
     }
     $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
     if (!defined('JVERSION')) {
         require $joomlaBase . '/libraries/cms/version/version.php';
         $jversion = new JVersion();
         define('JVERSION', $jversion->getShortVersion());
     }
     if (!empty($row)) {
         $dbPassword = $row->password;
         $dbId = $row->id;
         $dbEmail = $row->email;
         if (version_compare(JVERSION, '2.5.18', 'lt') || version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt')) {
             // now check password
             list($hash, $salt) = explode(':', $dbPassword);
             $cryptpass = md5($password . $salt);
             if ($hash != $cryptpass) {
                 return FALSE;
             }
         } else {
             if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) {
                 return FALSE;
             }
             //include additional files required by Joomla 3.2.1+
             if (version_compare(JVERSION, '3.2.1', 'ge')) {
                 require_once $joomlaBase . '/libraries/cms/application/helper.php';
                 require_once $joomlaBase . '/libraries/cms/application/cms.php';
                 require_once $joomlaBase . '/libraries/cms/application/administrator.php';
             }
         }
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($row, $dbId, $dbEmail, 'Joomla');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId);
         if (!$contactID) {
             return FALSE;
         }
         return array($contactID, $dbId, mt_rand());
     }
     return FALSE;
 }
Ejemplo n.º 7
0
 function authenticate($user, $pass)
 {
     session_start();
     require_once 'CRM/Core/Config.php';
     $config =& CRM_Core_Config::singleton();
     // this does not return on failure
     // require_once 'CRM/Utils/System.php';
     CRM_Utils_System::authenticateScript(true, $user, $pass);
     // bootstrap CMS environment
     global $civicrm_root;
     $_SERVER['SCRIPT_FILENAME'] = "{$civicrm_root}/bin/cli.php";
     require_once 'CRM/Utils/System.php';
     CRM_Utils_System::loadBootStrap($user, $pass);
 }
 function CRM_ProcessAuthorizeReport()
 {
     _civicrm_initialize();
     $config = CRM_Core_Config::singleton();
     //load bootstrap to call hooks
     require_once 'CRM/Utils/System.php';
     CRM_Utils_System::loadBootStrap();
     $config->userFramework = 'Soap';
     $config->userFrameworkClass = 'CRM_Utils_System_Soap';
     $config->userHookClass = 'CRM_Utils_Hook_Soap';
     if (!function_exists('imap_headers')) {
         die('PHP IMAP extension required to use this script');
     }
     if (defined('_CRM_PROCESS_AUTHORIZE_REPORT_DEBUG')) {
         $this->_debug = _CRM_PROCESS_AUTHORIZE_REPORT_DEBUG;
         error_reporting(E_ALL);
         ini_set('display_errors', true);
     } else {
         $this->_debug = false;
         ini_set('display_errors', false);
     }
 }
Ejemplo n.º 9
0
 /**
  * Authenticate the user against the drupal db
  *
  * @param string $name     the user name
  * @param string $password the password for the above user name
  * @param boolean $loadCMSBootstrap load cms bootstrap?
  * @param NULL|string $realPath filename of script
  *
  * @return mixed false if no auth
  *               array(
  *  contactID, ufID, unique string ) if success
  * @access public
  */
 static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
 {
     require_once 'DB.php';
     $config = CRM_Core_Config::singleton();
     $dbDrupal = DB::connect($config->userFrameworkDSN);
     if (DB::isError($dbDrupal)) {
         CRM_Core_Error::fatal("Cannot connect to drupal db via {$config->userFrameworkDSN}, " . $dbDrupal->getMessage());
     }
     $account = $userUid = $userMail = NULL;
     if ($loadCMSBootstrap) {
         $bootStrapParams = array();
         if ($name && $password) {
             $bootStrapParams = array('name' => $name, 'pass' => $password);
         }
         CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
         global $user;
         if ($user) {
             $userUid = $user->uid;
             $userMail = $user->mail;
         }
     } else {
         // CRM-8638
         // SOAP cannot load drupal bootstrap and hence we do it the old way
         // Contact CiviSMTP folks if we run into issues with this :)
         $cmsPath = $config->userSystem->cmsRootPath($realPath);
         require_once "{$cmsPath}/includes/bootstrap.inc";
         require_once "{$cmsPath}/includes/password.inc";
         $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
         $name = $dbDrupal->escapeSimple($strtolower($name));
         $sql = "\nSELECT u.*\nFROM   {$config->userFrameworkUsersTableName} u\nWHERE  LOWER(u.name) = '{$name}'\nAND    u.status = 1\n";
         $query = $dbDrupal->query($sql);
         $row = $query->fetchRow(DB_FETCHMODE_ASSOC);
         if ($row) {
             $fakeDrupalAccount = drupal_anonymous_user();
             $fakeDrupalAccount->name = $name;
             $fakeDrupalAccount->pass = $row['pass'];
             $passwordCheck = user_check_password($password, $fakeDrupalAccount);
             if ($passwordCheck) {
                 $userUid = $row['uid'];
                 $userMail = $row['mail'];
             }
         }
     }
     if ($userUid && $userMail) {
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $userUid, $userMail, 'Drupal');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($userUid);
         if (!$contactID) {
             return FALSE;
         }
         return array($contactID, $userUid, mt_rand());
     }
     return FALSE;
 }
Ejemplo n.º 10
0
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7                                                |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015                                |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM.                                    |
|                                                                    |
| CiviCRM is free software; you can copy, modify, and distribute it  |
| under the terms of the GNU Affero General Public License           |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
|                                                                    |
| CiviCRM is distributed in the hope that it will be useful, but     |
| WITHOUT ANY WARRANTY; without even the implied warranty of         |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
| See the GNU Affero General Public License for more details.        |
|                                                                    |
| You should have received a copy of the GNU Affero General Public   |
| License and the CiviCRM Licensing Exception along                  |
| with this program; if not, contact CiviCRM LLC                     |
| at info[AT]civicrm[DOT]org. If you have questions about the        |
| GNU Affero General Public License or the licensing of CiviCRM,     |
| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+--------------------------------------------------------------------+
*/
require_once '../civicrm.config.php';
$config = CRM_Core_Config::singleton();
CRM_Utils_System::loadBootStrap(array(), FALSE);
CRM_Cxn_BAO_Cxn::createApiServer()->handle(file_get_contents('php://input'))->send();
Ejemplo n.º 11
0
function run($supportedArgs, $context)
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    // this does not return on failure
    CRM_Utils_System::authenticateScript(true);
    //log the execution of script
    CRM_Core_Error::debug_log_message('Email2Activity.php');
    // load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    $mailDir = MAIL_DIR_DEFAULT;
    if (isset($_GET['mailDir'])) {
        $mailDir = $_GET['mailDir'];
    }
    if ($mailDir == 'PUT YOUR MAIL DIR HERE') {
        require_once 'CRM/Core/Error.php';
        CRM_Core_Error::fatal();
    }
    if (array_key_exists('context', $_GET) && isset($supportedArgs[strtolower($_GET['context'])])) {
        $context = $supportedArgs[strtolower($_GET['context'])];
    }
    $email = new bin_Email2Activity($mailDir, $context);
    $email->run();
}
Ejemplo n.º 12
0
function authenticate_wordpress($config)
{
    // make sure user has access to civicrm
    CRM_Utils_System::loadBootStrap();
    require_once "CRM/Core/Permission.php";
    if (CRM_Core_Permission::check('access CiviCRM')) {
        return true;
    }
    return false;
}
Ejemplo n.º 13
0
 /**
 * Authenticate the user against the joomla db
 *
 * @param string $name     the user name
 * @param string $password the password for the above user name
 * @param $loadCMSBootstrap boolean load cms bootstrap?
 *
 * @return mixed false if no auth
 *               array(
 contactID, ufID, unique string ) if success
 * @access public
 */
 function authenticate($name, $password, $loadCMSBootstrap = FALSE)
 {
     require_once 'DB.php';
     $config = CRM_Core_Config::singleton();
     if ($loadCMSBootstrap) {
         $bootStrapParams = array();
         if ($name && $password) {
             $bootStrapParams = array('name' => $name, 'pass' => $password);
         }
         CRM_Utils_System::loadBootStrap($bootStrapParams);
     }
     jimport('joomla.application.component.helper');
     jimport('joomla.database.table');
     $JUserTable =& JTable::getInstance('User', 'JTable');
     $db = $JUserTable->getDbo();
     $query = $db->getQuery(TRUE);
     $query->select('id, username, email, password');
     $query->from($JUserTable->getTableName());
     $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)');
     $db->setQuery($query, 0, 0);
     $users = $db->loadAssocList();
     $row = array();
     if (count($users)) {
         $row = $users[0];
     }
     $user = NULL;
     if (!empty($row)) {
         $dbPassword = CRM_Utils_Array::value('password', $row);
         $dbId = CRM_Utils_Array::value('id', $row);
         $dbEmail = CRM_Utils_Array::value('email', $row);
         // now check password
         if (strpos($dbPassword, ':') === FALSE) {
             if ($dbPassword != md5($password)) {
                 return FALSE;
             }
         } else {
             list($hash, $salt) = explode(':', $dbPassword);
             $cryptpass = md5($password . $salt);
             if ($hash != $cryptpass) {
                 return FALSE;
             }
         }
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $dbId, $dbEmail, 'Joomla');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId);
         if (!$contactID) {
             return FALSE;
         }
         return array($contactID, $dbId, mt_rand());
     }
     return FALSE;
 }
Ejemplo n.º 14
0
 /**
 * Authenticate the user against the drupal db
 *
 * @param string $name     the user name
 * @param string $password the password for the above user name
 *
 * @return mixed false if no auth
 *               array(
    contactID, ufID, unique string ) if success
 * @access public
 */
 function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
 {
     require_once 'DB.php';
     $config = CRM_Core_Config::singleton();
     $dbDrupal = DB::connect($config->userFrameworkDSN);
     if (DB::isError($dbDrupal)) {
         CRM_Core_Error::fatal("Cannot connect to drupal db via {$config->userFrameworkDSN}, " . $dbDrupal->getMessage());
     }
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $dbpassword = md5($password);
     $name = $dbDrupal->escapeSimple($strtolower($name));
     $sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '{$name}' AND u.pass = '******' AND u.status = 1";
     $query = $dbDrupal->query($sql);
     $user = NULL;
     // need to change this to make sure we matched only one row
     while ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) {
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row['uid'], $row['mail'], 'Drupal');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($row['uid']);
         if (!$contactID) {
             return FALSE;
         } else {
             //success
             if ($loadCMSBootstrap) {
                 $bootStrapParams = array();
                 if ($name && $password) {
                     $bootStrapParams = array('name' => $name, 'pass' => $password);
                 }
                 CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
             }
             return array($contactID, $row['uid'], mt_rand());
         }
     }
     return FALSE;
 }
Ejemplo n.º 15
0
 /**
  * @inheritDoc
  */
 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
 {
     //@todo this 'PEAR-y' stuff is only required when bookstrap is not being loaded which is rare
     // if ever now.
     // probably if bootstrap is loaded this call
     // CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath); would be
     // sufficient to do what this fn does. It does exist as opposed to return which might need some hanky-panky to make
     // safe in the unknown situation where authenticate might be called & it is important that
     // false is returned
     require_once 'DB.php';
     $config = CRM_Core_Config::singleton();
     $dbDrupal = DB::connect($config->userFrameworkDSN);
     if (DB::isError($dbDrupal)) {
         CRM_Core_Error::fatal("Cannot connect to drupal db via {$config->userFrameworkDSN}, " . $dbDrupal->getMessage());
     }
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $dbpassword = md5($password);
     $name = $dbDrupal->escapeSimple($strtolower($name));
     $userFrameworkUsersTableName = $this->getUsersTableName();
     $sql = 'SELECT u.* FROM ' . $userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '{$name}' AND u.pass = '******' AND u.status = 1";
     $query = $dbDrupal->query($sql);
     $user = NULL;
     // need to change this to make sure we matched only one row
     while ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) {
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row['uid'], $row['mail'], 'Drupal');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($row['uid']);
         if (!$contactID) {
             return FALSE;
         } else {
             //success
             if ($loadCMSBootstrap) {
                 $bootStrapParams = array();
                 if ($name && $password) {
                     $bootStrapParams = array('name' => $name, 'pass' => $password);
                 }
                 CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
             }
             return array($contactID, $row['uid'], mt_rand());
         }
     }
     return FALSE;
 }
Ejemplo n.º 16
0
Archivo: REST.php Proyecto: kidaa30/yes
 /**
  * @return array|NULL
  *   NULL if execution should proceed; array if the response is already known
  */
 public function loadCMSBootstrap()
 {
     $requestParams = CRM_Utils_Request::exportValues();
     $q = CRM_Utils_array::value('q', $requestParams);
     $args = explode('/', $q);
     // Proceed with bootstrap for "?entity=X&action=Y"
     // Proceed with bootstrap for "?q=civicrm/X/Y" but not "?q=civicrm/ping"
     if (!empty($q)) {
         if (count($args) == 2 && $args[1] == 'ping') {
             return NULL;
             // this is pretty wonky but maybe there's some reason I can't see
         }
         if (count($args) != 3) {
             return self::error('ERROR: Malformed REST path');
         }
         if ($args[0] != 'civicrm') {
             return self::error('ERROR: Malformed REST path');
         }
         // Therefore we have reasonably well-formed "?q=civicrm/X/Y"
     }
     if (!CRM_Utils_System::authenticateKey(FALSE)) {
         // FIXME: At time of writing, this doesn't actually do anything because
         // authenticateKey abends, but that's a bad behavior which sends a
         // malformed response.
         return self::error('Failed to authenticate key');
     }
     $uid = NULL;
     if (!$uid) {
         $store = NULL;
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
         if (empty($api_key)) {
             return self::error("FATAL: mandatory param 'api_key' (user key) missing");
         }
         $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
         if ($contact_id) {
             $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
         }
     }
     if ($uid) {
         CRM_Utils_System::loadBootStrap(array('uid' => $uid), TRUE, FALSE);
         return NULL;
     } else {
         return self::error('ERROR: No CMS user associated with given api-key');
     }
 }
Ejemplo n.º 17
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:s:e:k:g:parse";
    $longOptions = array('name=', 'pass='******'key=', 'start=', 'end=', 'geocoding=', 'parse=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('start' => 's', 'end' => 'e', 'name' => 'n', 'pass' => 'p', 'key' => 'k', 'geocoding' => 'g', 'parse' => 'ap');
    foreach ($vars as $var => $short) {
        ${$var} = null;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(true, $name, $pass);
    //log the execution of script
    CRM_Core_Error::debug_log_message('UpdateAddress.php');
    // load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    // do check for geocoding.
    $processGeocode = false;
    if (empty($config->geocodeMethod)) {
        if ($geocoding == 'true') {
            echo ts('Error: You need to set a mapping provider under Global Settings');
            exit;
        }
    } else {
        $processGeocode = true;
        // user might want to over-ride.
        if ($geocoding == 'false') {
            $processGeocode = false;
        }
    }
    // do check for parse street address.
    require_once 'CRM/Core/BAO/Preferences.php';
    $parseAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'), false);
    $parseStreetAddress = false;
    if (!$parseAddress) {
        if ($parse == 'true') {
            echo ts('Error: You need to enable Street Address Parsing under Global Settings >> Address Settings.');
            exit;
        }
    } else {
        $parseStreetAddress = true;
        // user might want to over-ride.
        if ($parse == 'false') {
            $parseStreetAddress = false;
        }
    }
    // don't process.
    if (!$parseStreetAddress && !$processGeocode) {
        echo ts('Error: Both Geocode mapping as well as Street Address Parsing are disabled. You must configure one or both options to use this script.');
        exit;
    }
    // we have an exclusive lock - run the mail queue
    processContacts($config, $processGeocode, $parseStreetAddress, $start, $end);
}
Ejemplo n.º 18
0
    // check if the script is being used for civimail processing or email to
    // activity processing.
    if (isset($cli->args[0]) && $cli->args[0] == "activities") {
        CRM_Utils_Mail_EmailProcessor::processActivities();
    } else {
        CRM_Utils_Mail_EmailProcessor::processBounces();
    }
    $lock->release();
} else {
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    CRM_Utils_System::authenticateScript(TRUE);
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    //log the execution of script
    CRM_Core_Error::debug_log_message('EmailProcessor.php');
    $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
    if (!$lock->isAcquired()) {
        throw new Exception('Could not acquire lock, another EmailProcessor process is running');
    }
    // try to unset any time limits
    if (!ini_get('safe_mode')) {
        set_time_limit(0);
    }
    require_once 'CRM/Utils/Mail/EmailProcessor.php';
    // cleanup directories with old mail files (if they exist): CRM-4452
    CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.ignored');
    CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.processed');
    // check if the script is being used for civimail processing or email to
Ejemplo n.º 19
0
 function loadCMSBootstrap()
 {
     $q = CRM_Utils_array::value('q', $_REQUEST);
     $args = explode('/', $q);
     // If the function isn't in the civicrm namespace or request
     // is for login or ping
     if (empty($args) || $args[0] != 'civicrm' || count($args) != 3 && $args[1] != 'login' && $args[1] != 'ping' || $args[1] == 'login' || $args[1] == 'ping') {
         return;
     }
     $uid = null;
     $session = CRM_Core_Session::singleton();
     if (!CRM_Utils_System::authenticateKey(false)) {
         return;
     }
     if ($session->get('PHPSESSID') && $session->get('cms_user_id')) {
         $uid = $session->get('cms_user_id');
     }
     if (!$uid) {
         require_once 'CRM/Core/DAO.php';
         require_once 'CRM/Utils/Request.php';
         $store = null;
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, false, null, 'REQUEST');
         $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
         if ($contact_id) {
             require_once 'CRM/Core/BAO/UFMatch.php';
             $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
         }
     }
     if ($uid) {
         CRM_Utils_System::loadBootStrap(null, null, $uid);
     }
 }