public function testsugarEncode()
 {
     //execute the method and test if it returns expected values
     //key param does nothing currently.
     //blank key and data
     $expected = '';
     $actual = sugarEncode('', '');
     $this->assertSame($expected, $actual);
     //blank key and valid data
     $expected = 'RGF0YQ==';
     $actual = sugarEncode('', 'Data');
     $this->assertSame($expected, $actual);
     //valid key and data
     $expected = 'RGF0YQ==';
     $actual = sugarEncode('key', 'Data');
     $this->assertSame($expected, $actual);
 }
Example #2
0
function check_now($send_usage_info = true, $get_request_data = false, $response_data = false, $from_install = false)
{
    global $sugar_config, $timedate;
    global $db, $license;
    $return_array = array();
    if (!$from_install && empty($license)) {
        loadLicense(true);
    }
    if (!$response_data) {
        if ($from_install) {
            $info = getBaseSystemInfo(false);
        } else {
            $info = getSystemInfo($send_usage_info);
        }
        require_once 'include/nusoap/nusoap.php';
        $GLOBALS['log']->debug('USING HTTPS TO CONNECT TO HEARTBEAT');
        $sclient = new nusoapclient('https://updates.sugarcrm.com/heartbeat/soap.php', false, false, false, false, false, 15, 15);
        $ping = $sclient->call('sugarPing', array());
        if (empty($ping) || $sclient->getError()) {
            $sclient = '';
        }
        if (empty($sclient)) {
            $GLOBALS['log']->debug('USING HTTP TO CONNECT TO HEARTBEAT');
            $sclient = new nusoapclient('http://updates.sugarcrm.com/heartbeat/soap.php', false, false, false, false, false, 15, 15);
        }
        $key = '4829482749329';
        $encoded = sugarEncode($key, serialize($info));
        if ($get_request_data) {
            $request_data = array('key' => $key, 'data' => $encoded);
            return serialize($request_data);
        }
        $encodedResult = $sclient->call('sugarHome', array('key' => $key, 'data' => $encoded));
    } else {
        $encodedResult = $response_data['data'];
        $key = $response_data['key'];
    }
    if ($response_data || !$sclient->getError()) {
        $serializedResultData = sugarDecode($key, $encodedResult);
        $resultData = unserialize($serializedResultData);
        if ($response_data && empty($resultData)) {
            $resultData = array();
            $resultData['validation'] = 'invalid validation key';
        }
    } else {
        $resultData = array();
        $resultData['versions'] = array();
    }
    if ($response_data || !$sclient->getError()) {
        if (!empty($resultData['msg'])) {
            if (!empty($resultData['msg']['admin'])) {
                $license->saveSetting('license', 'msg_admin', base64_encode($resultData['msg']['admin']));
            } else {
                $license->saveSetting('license', 'msg_admin', '');
            }
            if (!empty($resultData['msg']['all'])) {
                $license->saveSetting('license', 'msg_all', base64_encode($resultData['msg']['all']));
            } else {
                $license->saveSetting('license', 'msg_all', '');
            }
        } else {
            $license->saveSetting('license', 'msg_admin', '');
            $license->saveSetting('license', 'msg_all', '');
        }
        $license->saveSetting('license', 'last_validation', 'success');
        unset($_SESSION['COULD_NOT_CONNECT']);
    } else {
        $resultData = array();
        $resultData['versions'] = array();
        $license->saveSetting('license', 'last_connection_fail', TimeDate::getInstance()->nowDb());
        $license->saveSetting('license', 'last_validation', 'no_connection');
        if (empty($license->settings['license_last_validation_success']) && empty($license->settings['license_last_validation_fail']) && empty($license->settings['license_vk_end_date'])) {
            $license->saveSetting('license', 'vk_end_date', TimeDate::getInstance()->nowDb());
            $license->saveSetting('license', 'validation_key', base64_encode(serialize(array('verified' => false))));
        }
        $_SESSION['COULD_NOT_CONNECT'] = TimeDate::getInstance()->nowDb();
    }
    if (!empty($resultData['versions'])) {
        $license->saveSetting('license', 'latest_versions', base64_encode(serialize($resultData['versions'])));
    } else {
        $resultData['versions'] = array();
        $license->saveSetting('license', 'latest_versions', '');
    }
    include 'sugar_version.php';
    if (sizeof($resultData) == 1 && !empty($resultData['versions'][0]['version']) && $resultData['versions'][0]['version'] < $sugar_version) {
        $resultData['versions'][0]['version'] = $sugar_version;
        $resultData['versions'][0]['description'] = "You have the latest version.";
    }
    return $resultData['versions'];
}
 /**
  * Login to the depot
  * 
  * @return true if successful, false otherwise
  */
 function login($terms_checked = true)
 {
     if (empty($_SESSION['SugarDepotSessionID'])) {
         global $license;
         $GLOBALS['log']->debug("Begin SugarDepot Login");
         PackageManagerComm::initialize(false);
         require 'sugar_version.php';
         require 'config.php';
         $credentials = PackageManager::getCredentials();
         if (empty($license)) {
             loadLicense();
         }
         $info = sugarEncode('2813', serialize(getSystemInfo(true)));
         $pm = new PackageManager();
         $installed = $pm->buildInstalledReleases();
         $installed = base64_encode(serialize($installed));
         $params = array('installed_modules' => $installed, 'terms_checked' => $terms_checked, 'system_name' => $credentials['system_name']);
         $terms_version = !empty($_SESSION['SugarDepot_TermsVersion']) ? $_SESSION['SugarDepot_TermsVersion'] : '';
         if (!empty($terms_version)) {
             $params['terms_version'] = $terms_version;
         }
         $result = $GLOBALS['SugarDepot']->call('depotLogin', array(array('user_name' => $credentials['username'], 'password' => $credentials['password']), 'info' => $info, 'params' => $params));
         PackageManagerComm::errorCheck();
         if (!is_array($result)) {
             $_SESSION['SugarDepotSessionID'] = $result;
         }
         $GLOBALS['log']->debug("End SugarDepot Login");
         return $result;
     } else {
         return $_SESSION['SugarDepotSessionID'];
     }
 }
Example #4
0
function check_now($send_usage_info = true, $get_request_data = false, $response_data = false, $from_install = false)
{
    global $sugar_config, $timedate;
    global $db, $license;
    // This section of code is a portion of the code referred
    // to as Critical Control Software under the End User
    // License Agreement.  Neither the Company nor the Users
    // may modify any portion of the Critical Control Software.
    if (ocLicense()) {
        return array();
    }
    // END REQUIRED CODE
    $return_array = array();
    if (!$from_install && empty($license)) {
        loadLicense(true);
    }
    if (!$response_data) {
        $systemInfo = SugarSystemInfo::getInstance();
        SugarAutoLoader::requireWithCustom('include/SugarHeartbeat/SugarHeartbeatClient.php', true);
        $sclientClass = SugarAutoLoader::customClass('SugarHeartbeatClient');
        $sclient = new $sclientClass();
        if ($from_install) {
            $info = $systemInfo->getBaseInfo();
        } else {
            $info = $systemInfo->getInfo();
        }
        // This section of code is a portion of the code referred
        // to as Critical Control Software under the End User
        // License Agreement.  Neither the Company nor the Users
        // may modify any portion of the Critical Control Software.
        if (!empty($license->settings['license_key'])) {
            $key = $license->settings['license_key'];
        } else {
            //END REQUIRED CODE
            $key = '4829482749329';
        }
        $encoded = sugarEncode($key, serialize($info));
        if ($get_request_data) {
            $request_data = array('key' => $key, 'data' => $encoded);
            return serialize($request_data);
        }
        $encodedResult = $sclient->sugarHome($key, $info);
    } else {
        $encodedResult = $response_data['data'];
        $key = $response_data['key'];
    }
    if ($response_data || !$sclient->getError()) {
        $serializedResultData = sugarDecode($key, $encodedResult);
        $resultData = unserialize($serializedResultData);
        if ($response_data && empty($resultData)) {
            $resultData = array();
            $resultData['validation'] = 'invalid validation key';
        }
    } else {
        $resultData = array();
        $resultData['versions'] = array();
    }
    if (!isset($resultData['validation'])) {
        $resultData['validation'] = 'invalid';
    }
    if ($response_data || !$sclient->getError()) {
        // This section of code is a portion of the code referred
        // to as Critical Control Software under the End User
        // License Agreement.  Neither the Company nor the Users
        // may modify any portion of the Critical Control Software.
        checkDownloadKey($resultData['validation']);
        //END REQUIRED CODE
        if (!empty($resultData['msg'])) {
            if (!empty($resultData['msg']['admin'])) {
                $license->saveSetting('license', 'msg_admin', base64_encode($resultData['msg']['admin']));
            } else {
                $license->saveSetting('license', 'msg_admin', '');
            }
            if (!empty($resultData['msg']['all'])) {
                $license->saveSetting('license', 'msg_all', base64_encode($resultData['msg']['all']));
            } else {
                $license->saveSetting('license', 'msg_all', '');
            }
        } else {
            $license->saveSetting('license', 'msg_admin', '');
            $license->saveSetting('license', 'msg_all', '');
        }
        $license->saveSetting('license', 'last_validation', 'success');
        unset($_SESSION['COULD_NOT_CONNECT']);
    } else {
        $resultData = array();
        $resultData['versions'] = array();
        $license->saveSetting('license', 'last_connection_fail', TimeDate::getInstance()->nowDb());
        $license->saveSetting('license', 'last_validation', 'no_connection');
        if (empty($license->settings['license_last_validation_success']) && empty($license->settings['license_last_validation_fail']) && empty($license->settings['license_vk_end_date'])) {
            $license->saveSetting('license', 'vk_end_date', TimeDate::getInstance()->nowDb());
            $license->saveSetting('license', 'validation_key', base64_encode(serialize(array('verified' => false))));
        }
        $_SESSION['COULD_NOT_CONNECT'] = TimeDate::getInstance()->nowDb();
    }
    if (!empty($resultData['versions'])) {
        $license->saveSetting('license', 'latest_versions', base64_encode(serialize($resultData['versions'])));
    } else {
        $resultData['versions'] = array();
        $license->saveSetting('license', 'latest_versions', '');
    }
    include 'sugar_version.php';
    if (sizeof($resultData) == 1 && !empty($resultData['versions'][0]['version']) && compareVersions($sugar_version, $resultData['versions'][0]['version'])) {
        $resultData['versions'][0]['version'] = $sugar_version;
        $resultData['versions'][0]['description'] = "You have the latest version.";
    }
    return $resultData['versions'];
}