2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 ********************************************************************************/
41 require_once('include/utils/encryption_utils.php');
43 function getSystemInfo($send_usage_info=true){
45 global $db, $authLevel, $administration;
47 $info = getBaseSystemInfo($send_usage_info);
50 if(isset($_SERVER['SERVER_ADDR']))
51 $info['ip_address'] = $_SERVER['SERVER_ADDR'];
53 $info['ip_address'] = '127.0.0.1';
55 $info['application_key']=$sugar_config['unique_key'];
56 $info['php_version']=phpversion();
57 if(isset($_SERVER['SERVER_SOFTWARE'])) {
58 $info['server_software'] = $_SERVER['SERVER_SOFTWARE'];
63 $user_list = get_user_array(false, "Active", "", false, null, " AND is_group=0 AND portal_only=0 ", false);
67 $info['users']=count($user_list);
68 if(empty($administration)){
70 $administration = new Administration();
72 $administration->retrieveSettings('system');
73 $info['system_name'] = (!empty($administration->settings['system_name']))?substr($administration->settings['system_name'], 0 ,255):'';
76 $query="select count(*) count from users where status='Active' and deleted=0 and is_admin='1'";
77 $result=$db->query($query, 'fetching admin count', false);
78 $row = $db->fetchByAssoc($result);
80 $info['admin_users'] = $row['count'];
82 if(empty($authLevel)){
85 $query="select count(*) count from users";
86 $result=$db->query($query, 'fetching all users count', false);
87 $row = $db->fetchByAssoc($result);
90 $info['registered_users'] = $row['count'];
92 $lastMonth = db_convert("'".date($GLOBALS['timedate']->get_db_date_time_format() , strtotime('-1 month')) . "'", 'datetime');
93 if( !$send_usage_info){
94 $info['users_active_30_days'] = -1;
97 $query = "SELECT count( DISTINCT users.id ) user_count FROM tracker, users WHERE users.id = tracker.user_id AND tracker.date_modified >= $lastMonth";
98 $result=$db->query($query, 'fetching last 30 users count', false);
99 $row = $db->fetchByAssoc($result);
100 $info['users_active_30_days'] = $row['user_count'];
107 if(!$send_usage_info){
108 $info['latest_tracker_id'] = -1;
110 $query="select id from tracker order by date_modified desc";
111 $id=$db->getOne($query,'fetching most recent tracker entry',false);
113 $info['latest_tracker_id'] = $id;
116 $dbManager = &DBManagerFactory::getInstance();
117 $info['db_type']=$sugar_config['dbconfig']['db_type'];
118 $info['db_version']=$dbManager->version();
120 if(file_exists('distro.php')){
121 include('distro.php');
122 if(!empty($distro_name))$info['distro_name'] = $distro_name;
124 $info['auth_level'] = $authLevel;
125 $info['os'] = php_uname('s');
126 $info['os_version'] = php_uname('r');
127 $info['timezone_u'] = $GLOBALS['current_user']->getPreference('timezone');
128 $info['timezone'] = date('e');
129 if($info['timezone'] == 'e'){
130 $info['timezone'] = date('T');
136 function getBaseSystemInfo($send_usage_info=true){
138 include('sugar_version.php');
141 if($send_usage_info){
142 $info['sugar_db_version']=$sugar_db_version;
144 $info['sugar_version']=$sugar_version;
145 $info['sugar_flavor']=$sugar_flavor;
146 $info['auth_level'] = $authLevel;
155 function check_now($send_usage_info=true, $get_request_data=false, $response_data = false, $from_install=false ) {
156 global $sugar_config, $timedate;
157 global $db, $license;
160 $return_array=array();
161 if(!$from_install && empty($license))loadLicense(true);
166 $info = getBaseSystemInfo(false);
169 $info = getSystemInfo($send_usage_info);
172 require_once('include/nusoap/nusoap.php');
174 $GLOBALS['log']->debug('USING HTTPS TO CONNECT TO HEARTBEAT');
175 $sclient = new nusoapclient('https://updates.sugarcrm.com/heartbeat/soap.php', false, false, false, false, false, 15, 15);
176 $ping = $sclient->call('sugarPing', array());
177 if(empty($ping) || $sclient->getError()){
182 $GLOBALS['log']->debug('USING HTTP TO CONNECT TO HEARTBEAT');
183 $sclient = new nusoapclient('http://updates.sugarcrm.com/heartbeat/soap.php', false, false, false, false, false, 15, 15);
191 $key = '4829482749329';
195 $encoded = sugarEncode($key, serialize($info));
197 if($get_request_data){
198 $request_data = array('key'=>$key, 'data'=>$encoded);
199 return serialize($request_data);
201 $encodedResult = $sclient->call('sugarHome', array('key'=>$key, 'data'=>$encoded));
204 $encodedResult = $response_data['data'];
205 $key = $response_data['key'];
209 if($response_data || !$sclient->getError()){
210 $serializedResultData = sugarDecode($key,$encodedResult);
211 $resultData = unserialize($serializedResultData);
212 if($response_data && empty($resultData))$resultData['validation'] = 'invalid validation key';
215 $resultData = array();
216 $resultData['versions'] = array();
220 if($response_data || !$sclient->getError() )
222 if(!empty($resultData['msg'])){
223 if(!empty($resultData['msg']['admin'])){
224 $license->saveSetting('license', 'msg_admin', base64_encode($resultData['msg']['admin']));
226 $license->saveSetting('license', 'msg_admin','');
228 if(!empty($resultData['msg']['all'])){
229 $license->saveSetting('license', 'msg_all', base64_encode($resultData['msg']['all']));
231 $license->saveSetting('license', 'msg_all','');
234 $license->saveSetting('license', 'msg_admin','');
235 $license->saveSetting('license', 'msg_all','');
237 $license->saveSetting('license', 'last_validation', 'success');
238 unset($_SESSION['COULD_NOT_CONNECT']);
242 $resultData = array();
243 $resultData['versions'] = array();
245 $license->saveSetting('license', 'last_connection_fail', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
246 $license->saveSetting('license', 'last_validation', 'no_connection');
248 if( empty($license->settings['license_last_validation_success']) && empty($license->settings['license_last_validation_fail']) && empty($license->settings['license_vk_end_date'])){
249 $license->saveSetting('license', 'vk_end_date', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
251 $license->saveSetting('license', 'validation_key', base64_encode(serialize(array('verified'=>false))));
253 $_SESSION['COULD_NOT_CONNECT'] =gmdate($GLOBALS['timedate']->get_db_date_time_format());
256 if(!empty($resultData['versions'])){
258 $license->saveSetting('license', 'latest_versions',base64_encode(serialize($resultData['versions'])));
260 $resultData['versions'] = array();
261 $license->saveSetting('license', 'latest_versions','') ;
267 include('sugar_version.php');
269 if(sizeof($resultData) == 1 && !empty($resultData['versions'][0]['version']) && $resultData['versions'][0]['version'] < $sugar_version)
271 $resultData['versions'][0]['version'] = $sugar_version;
272 $resultData['versions'][0]['description'] = "You have the latest version.";
276 return $resultData['versions'];
278 function set_CheckUpdates_config_setting($value) {
281 $admin=new Administration();
282 $admin->saveSetting('Update','CheckUpdates',$value);
284 /* return's value for the 'CheckUpdates' config setting
285 * if the setting does not exist one gets created with a default value of automatic.
287 function get_CheckUpdates_config_setting() {
289 $checkupdates='automatic';
292 $admin=new Administration();
293 $admin=$admin->retrieveSettings('Update',true);
294 if (empty($admin->settings) or empty($admin->settings['Update_CheckUpdates'])) {
295 $admin->saveSetting('Update','CheckUpdates','automatic');
297 $checkupdates=$admin->settings['Update_CheckUpdates'];
299 return $checkupdates;
302 function set_last_check_version_config_setting($value) {
305 $admin=new Administration();
306 $admin->saveSetting('Update','last_check_version',$value);
308 function get_last_check_version_config_setting() {
312 $admin=new Administration();
313 $admin=$admin->retrieveSettings('Update');
314 if (empty($admin->settings) or empty($admin->settings['Update_last_check_version'])) {
317 return $admin->settings['Update_last_check_version'];
322 function set_last_check_date_config_setting($value) {
325 $admin=new Administration();
326 $admin->saveSetting('Update','last_check_date',$value);
328 function get_last_check_date_config_setting() {
332 $admin=new Administration();
333 $admin=$admin->retrieveSettings('Update');
334 if (empty($admin->settings) or empty($admin->settings['Update_last_check_date'])) {
337 return $admin->settings['Update_last_check_date'];
341 function set_sugarbeat($value) {
342 global $sugar_config;
343 $_SUGARBEAT="sugarbeet";
344 $sugar_config[$_SUGARBEAT] = $value;
345 write_array_to_file( "sugar_config", $sugar_config, "config.php" );
347 function get_sugarbeat() {
350 global $sugar_config;
351 $_SUGARBEAT="sugarbeet";
353 if (isset($sugar_config[$_SUGARBEAT]) && $sugar_config[$_SUGARBEAT] == false) {
362 function shouldCheckSugar(){
366 get_CheckUpdates_config_setting() == 'automatic' ){
375 function loadLicense($firstLogin=false){
377 $GLOBALS['license']=new Administration();
378 $GLOBALS['license']=$GLOBALS['license']->retrieveSettings('license', $firstLogin);
382 function loginLicense(){
383 global $current_user, $license, $authLevel;
388 if (shouldCheckSugar()) {
391 $last_check_date=get_last_check_date_config_setting();
392 $current_date_time=time();
393 $time_period=3*23*3600 ;
394 if (($current_date_time - $last_check_date) > $time_period
396 $version = check_now(get_sugarbeat());
398 unset($_SESSION['license_seats_needed']);
400 set_last_check_date_config_setting("$current_date_time");
401 include('sugar_version.php');
403 if(!empty($version)&& count($version) == 1 && $version[0]['version'] > $sugar_version && is_admin($current_user))
405 //set session variables.
406 $_SESSION['available_version']=$version[0]['version'];
407 $_SESSION['available_version_description']=$version[0]['description'];
408 set_last_check_version_config_setting($version[0]['version']);