Example #1
0
 /**
  * @inheritDoc
  */
 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
 {
     $config = CRM_Core_Config::singleton();
     $dbBackdrop = DB::connect($config->userFrameworkDSN);
     if (DB::isError($dbBackdrop)) {
         CRM_Core_Error::fatal("Cannot connect to Backdrop database via {$config->userFrameworkDSN}, " . $dbBackdrop->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 = $this->cmsRootPath();
         require_once "{$cmsPath}/core/includes/bootstrap.inc";
         require_once "{$cmsPath}/core/includes/password.inc";
         $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
         $name = $dbBackdrop->escapeSimple($strtolower($name));
         $userFrameworkUsersTableName = $this->getUsersTableName();
         $sql = "\nSELECT u.*\nFROM   {$userFrameworkUsersTableName} u\nWHERE  LOWER(u.name) = '{$name}'\nAND    u.status = 1\n";
         $query = $dbBackdrop->query($sql);
         $row = $query->fetchRow(DB_FETCHMODE_ASSOC);
         if ($row) {
             $fakeAccount = backdrop_anonymous_user();
             $fakeAccount->name = $name;
             $fakeAccount->pass = $row['pass'];
             $passwordCheck = user_check_password($password, $fakeAccount);
             if ($passwordCheck) {
                 $userUid = $row['uid'];
                 $userMail = $row['mail'];
             }
         }
     }
     if ($userUid && $userMail) {
         CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $userUid, $userMail, 'Backdrop');
         $contactID = CRM_Core_BAO_UFMatch::getContactId($userUid);
         if (!$contactID) {
             return FALSE;
         }
         return array($contactID, $userUid, mt_rand());
     }
     return FALSE;
 }
Example #2
0
 /**
  * @param $config
  *
  * @return mixed
  */
 public function install($config)
 {
     global $installDirPath;
     // create database if does not exists
     $this->createDatabaseIfNotExists($config['mysql']['server'], $config['mysql']['username'], $config['mysql']['password'], $config['mysql']['database']);
     global $installDirPath;
     // Build database
     require_once $installDirPath . 'civicrm.php';
     civicrm_main($config);
     if (!$this->errors) {
         global $installType, $installURLPath;
         $registerSiteURL = "https://civicrm.org/register-site";
         $commonOutputMessage = "<li>" . ts("Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to <a %1>fill out the site registration form</a>. The information collected will help us prioritize improvements, target our communications and build the community. If you have a technical role for this site, be sure to check Keep in Touch to receive technical updates (a low volume mailing list).", array(1 => "href='{$registerSiteURL}' target='_blank'")) . "</li>" . "<li>" . ts("We have integrated KCFinder with CKEditor and TinyMCE. This allows a user to upload images. All uploaded images are public.") . "</li>";
         $output = NULL;
         if ($installType == 'drupal' && version_compare(VERSION, '7.0-rc1') >= 0) {
             // clean output
             @ob_clean();
             $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
             $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
             $output .= '<head>';
             $output .= '<title>' . ts('CiviCRM Installed') . '</title>';
             $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
             $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
             $output .= '</head>';
             $output .= '<body>';
             $output .= '<div style="padding: 1em;"><p class="good">' . ts('CiviCRM has been successfully installed') . '</p>';
             $output .= '<ul>';
             $drupalURL = civicrm_cms_base();
             $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/people/permissions";
             $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
             $output .= "<li>" . ts("Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a %1>review these permissions</a> to ensure that they are appropriate for your requirements (<a %2>learn more...</a>)", array(1 => "target='_blank' href='{$drupalPermissionsURL}'", 2 => "target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'")) . "</li>";
             $output .= "<li>" . ts("Use the <a %1>Configuration Checklist</a> to review and configure settings for your new site", array(1 => "target='_blank' href='{$drupalURL}'")) . "</li>";
             $output .= $commonOutputMessage;
             // automatically enable CiviCRM module once it is installed successfully.
             // so we need to Bootstrap Drupal, so that we can call drupal hooks.
             global $cmsPath, $crmPath;
             // relative / abosolute paths are not working for drupal, hence using chdir()
             chdir($cmsPath);
             // Force the re-initialisation of the config singleton on the next call
             // since so far, we had used the Config object without loading the DB.
             $c = CRM_Core_Config::singleton(FALSE);
             $c->free();
             include_once "./includes/bootstrap.inc";
             include_once "./includes/unicode.inc";
             drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
             // prevent session information from being saved.
             drupal_save_session(FALSE);
             // Force the current user to anonymous.
             $original_user = $GLOBALS['user'];
             $GLOBALS['user'] = drupal_anonymous_user();
             // explicitly setting error reporting, since we cannot handle drupal related notices
             error_reporting(1);
             // rebuild modules, so that civicrm is added
             system_rebuild_module_data();
             // now enable civicrm module.
             module_enable(array('civicrm', 'civicrmtheme'));
             // clear block, page, theme, and hook caches
             drupal_flush_all_caches();
             //add basic drupal permissions
             civicrm_install_set_drupal_perms();
             // restore the user.
             $GLOBALS['user'] = $original_user;
             drupal_save_session(TRUE);
             //change the default language to one chosen
             if (isset($config['seedLanguage']) && $config['seedLanguage'] != 'en_US') {
                 civicrm_api3('Setting', 'create', array('domain_id' => 'current_domain', 'lcMessages' => $config['seedLanguage']));
             }
             $output .= '</ul>';
             $output .= '</div>';
             $output .= '</body>';
             $output .= '</html>';
             echo $output;
         } elseif ($installType == 'backdrop') {
             // clean output
             @ob_clean();
             $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
             $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
             $output .= '<head>';
             $output .= '<title>' . ts('CiviCRM Installed') . '</title>';
             $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
             $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
             $output .= '</head>';
             $output .= '<body>';
             $output .= '<div style="padding: 1em;"><p class="good">' . ts('CiviCRM has been successfully installed') . '</p>';
             $output .= '<ul>';
             $backdropURL = civicrm_cms_base();
             $backdropPermissionsURL = "{$backdropURL}index.php?q=admin/config/people/permissions";
             $backdropURL .= "index.php?q=civicrm/admin/configtask&reset=1";
             $output .= "<li>" . ts("Backdrop user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a %1>review these permissions</a> to ensure that they are appropriate for your requirements (<a %2>learn more...</a>)", array(1 => "target='_blank' href='{$backdropPermissionsURL}'", 2 => "target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'")) . "</li>";
             $output .= "<li>" . ts("Use the <a %1>Configuration Checklist</a> to review and configure settings for your new site", array(1 => "target='_blank' href='{$backdropURL}'")) . "</li>";
             $output .= $commonOutputMessage;
             // automatically enable CiviCRM module once it is installed successfully.
             // so we need to Bootstrap Drupal, so that we can call drupal hooks.
             global $cmsPath, $crmPath;
             // relative / abosolute paths are not working for drupal, hence using chdir()
             chdir($cmsPath);
             // Force the re-initialisation of the config singleton on the next call
             // since so far, we had used the Config object without loading the DB.
             $c = CRM_Core_Config::singleton(FALSE);
             $c->free();
             include_once "./core/includes/bootstrap.inc";
             include_once "./core/includes/unicode.inc";
             backdrop_bootstrap(BACKDROP_BOOTSTRAP_FULL);
             // prevent session information from being saved.
             backdrop_save_session(FALSE);
             // Force the current user to anonymous.
             $original_user = $GLOBALS['user'];
             $GLOBALS['user'] = backdrop_anonymous_user();
             // explicitly setting error reporting, since we cannot handle drupal related notices
             error_reporting(1);
             // rebuild modules, so that civicrm is added
             system_rebuild_module_data();
             // now enable civicrm module.
             module_enable(array('civicrm', 'civicrmtheme'));
             // clear block, page, theme, and hook caches
             backdrop_flush_all_caches();
             //add basic backdrop permissions
             civicrm_install_set_backdrop_perms();
             // restore the user.
             $GLOBALS['user'] = $original_user;
             backdrop_save_session(TRUE);
             //change the default language to one chosen
             if (isset($config['seedLanguage']) && $config['seedLanguage'] != 'en_US') {
                 civicrm_api3('Setting', 'create', array('domain_id' => 'current_domain', 'lcMessages' => $config['seedLanguage']));
             }
             $output .= '</ul>';
             $output .= '</div>';
             $output .= '</body>';
             $output .= '</html>';
             echo $output;
         } elseif ($installType == 'drupal' && version_compare(VERSION, '6.0') >= 0) {
             // clean output
             @ob_clean();
             $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
             $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
             $output .= '<head>';
             $output .= '<title>' . ts('CiviCRM Installed') . '</title>';
             $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
             $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
             $output .= '</head>';
             $output .= '<body>';
             $output .= '<div style="padding: 1em;"><p class="good">' . ts("CiviCRM has been successfully installed") . '</p>';
             $output .= '<ul>';
             $drupalURL = civicrm_cms_base();
             $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/user/permissions";
             $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
             $output .= "<li>" . ts("Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a %1>review these permissions</a> to ensure that they are appropriate for your requirements (<a %2>learn more...</a>)", array(1 => "target='_blank' href='{$drupalPermissionsURL}'", 2 => "target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'")) . "</li>";
             $output .= "<li>" . ts("Use the <a %1>Configuration Checklist</a> to review and configure settings for your new site", array(1 => "target='_blank' href='{$drupalURL}'")) . "</li>";
             $output .= $commonOutputMessage;
             // explicitly setting error reporting, since we cannot handle drupal related notices
             error_reporting(1);
             // automatically enable CiviCRM module once it is installed successfully.
             // so we need to Bootstrap Drupal, so that we can call drupal hooks.
             global $cmsPath, $crmPath;
             // relative / abosolute paths are not working for drupal, hence using chdir()
             chdir($cmsPath);
             // Force the re-initialisation of the config singleton on the next call
             // since so far, we had used the Config object without loading the DB.
             $c = CRM_Core_Config::singleton(FALSE);
             $c->free();
             include_once "./includes/bootstrap.inc";
             drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
             // rebuild modules, so that civicrm is added
             module_rebuild_cache();
             // now enable civicrm module.
             module_enable(array('civicrm'));
             // clear block, page, theme, and hook caches
             drupal_flush_all_caches();
             //add basic drupal permissions
             db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile create, profile edit, profile view, register for events, view event info\') WHERE rid IN (1, 2)');
             echo $output;
         } elseif ($installType == 'wordpress') {
             echo '<h1>' . ts('CiviCRM Installed') . '</h1>';
             echo '<div style="padding: 1em;"><p style="background-color: #0C0; border: 1px #070 solid; color: white;">' . ts("CiviCRM has been successfully installed") . '</p>';
             echo '<ul>';
             $cmsURL = civicrm_cms_base();
             $cmsURL .= "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/configtask&reset=1";
             $wpPermissionsURL = "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/access/wp-permissions&reset=1";
             $output .= "<li>" . ts("WordPress user permissions have been automatically set - giving Anonymous and Subscribers access to public CiviCRM forms and features. We recommend that you <a %1>review these permissions</a> to ensure that they are appropriate for your requirements (<a %2>learn more...</a>)", array(1 => "target='_blank' href='{$wpPermissionsURL}'", 2 => "target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'")) . "</li>";
             $output .= "<li>" . ts("Use the <a %1>Configuration Checklist</a> to review and configure settings for your new site", array(1 => "target='_blank' href='{$cmsURL}'")) . "</li>";
             $output .= $commonOutputMessage;
             echo '</ul>';
             echo '</div>';
             $c = CRM_Core_Config::singleton(FALSE);
             $c->free();
             $wpInstallRedirect = admin_url("?page=CiviCRM&q=civicrm&reset=1");
             echo "<script>\n         window.location = '{$wpInstallRedirect}';\n        </script>";
         }
     }
     return $this->errors;
 }