1
|
|
|
<?php |
2
|
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
3
|
|
|
/********************************************************************************* |
4
|
|
|
* SugarCRM Community Edition is a customer relationship management program developed by |
5
|
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
6
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
20
|
|
|
* details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25
|
|
|
* 02110-1301 USA. |
26
|
|
|
* |
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
29
|
|
|
* |
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
33
|
|
|
* |
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
39
|
|
|
********************************************************************************/ |
40
|
|
|
|
41
|
|
|
/********************************************************************************* |
42
|
|
|
|
43
|
|
|
********************************************************************************/ |
44
|
|
|
require_once('include/utils/encryption_utils.php'); |
45
|
|
|
|
46
|
|
|
function getSystemInfo($send_usage_info=true){ |
47
|
|
|
global $sugar_config; |
48
|
|
|
global $db, $administration, $timedate; |
49
|
|
|
$info=array(); |
50
|
|
|
$info = getBaseSystemInfo($send_usage_info); |
51
|
|
|
if($send_usage_info){ |
52
|
|
|
$info['application_key']=$sugar_config['unique_key']; |
53
|
|
|
$info['php_version']=phpversion(); |
54
|
|
|
if(isset($_SERVER['SERVER_SOFTWARE'])) { |
55
|
|
|
$info['server_software'] = $_SERVER['SERVER_SOFTWARE']; |
56
|
|
|
} // if |
57
|
|
|
|
58
|
|
|
//get user count. |
59
|
|
|
|
60
|
|
|
$query = "SELECT count(*) as total from users WHERE " . User::getLicensedUsersWhere(); |
61
|
|
|
$result = $db->getOne($query, false, 'fetching active users count'); |
62
|
|
|
if ($result !== false) { |
63
|
|
|
$info['users'] = $result; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if(empty($administration)){ |
67
|
|
|
|
68
|
|
|
$administration = new Administration(); |
69
|
|
|
} |
70
|
|
|
$administration->retrieveSettings('system'); |
71
|
|
|
$info['system_name'] = (!empty($administration->settings['system_name']))?substr($administration->settings['system_name'], 0 ,255):''; |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
$result=$db->getOne("select count(*) count from users where status='Active' and deleted=0 and is_admin='1'", false, 'fetching admin count'); |
75
|
|
|
if($result !== false) { |
76
|
|
|
$info['admin_users'] = $result; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
$result=$db->getOne("select count(*) count from users", false, 'fetching all users count'); |
81
|
|
|
if($result !== false) { |
82
|
|
|
$info['registered_users'] = $result; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$lastMonth = $db->convert("'". $timedate->getNow()->modify("-30 days")->asDb(false) . "'", 'datetime'); |
86
|
|
|
if( !$send_usage_info) { |
87
|
|
|
$info['users_active_30_days'] = -1; |
88
|
|
|
} else { |
89
|
|
|
$info['users_active_30_days'] = $db->getOne("SELECT count( DISTINCT users.id ) user_count FROM tracker, users WHERE users.id = tracker.user_id AND tracker.date_modified >= $lastMonth", false, 'fetching last 30 users count'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
if(!$send_usage_info){ |
96
|
|
|
$info['latest_tracker_id'] = -1; |
97
|
|
|
}else{ |
98
|
|
|
$id=$db->getOne("select id from tracker order by date_modified desc", false, 'fetching most recent tracker entry'); |
99
|
|
|
if ( $id !== false ) |
100
|
|
|
$info['latest_tracker_id'] = $id; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$info['db_type']=$sugar_config['dbconfig']['db_type']; |
104
|
|
|
$info['db_version']=$db->version(); |
105
|
|
|
} |
106
|
|
|
if(file_exists('distro.php')){ |
107
|
|
|
include('distro.php'); |
108
|
|
|
if(!empty($distro_name))$info['distro_name'] = $distro_name; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
$info['os'] = php_uname('s'); |
111
|
|
|
$info['os_version'] = php_uname('r'); |
112
|
|
|
$info['timezone_u'] = $GLOBALS['current_user']->getPreference('timezone'); |
113
|
|
|
$info['timezone'] = date('e'); |
114
|
|
|
if($info['timezone'] == 'e'){ |
115
|
|
|
$info['timezone'] = date('T'); |
116
|
|
|
} |
117
|
|
|
return $info; |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
function getBaseSystemInfo($send_usage_info=true){ |
122
|
|
|
include('sugar_version.php'); |
123
|
|
|
$info=array(); |
124
|
|
|
|
125
|
|
|
if($send_usage_info){ |
126
|
|
|
$info['sugar_db_version']=$sugar_db_version; |
127
|
|
|
} |
128
|
|
|
$info['sugar_version']=$sugar_version; |
129
|
|
|
$info['sugar_flavor']=$sugar_flavor; |
130
|
|
|
$info['auth_level'] = 0; |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
|
134
|
|
|
return $info; |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function check_now($send_usage_info=true, $get_request_data=false, $response_data = false, $from_install=false ) { |
140
|
|
|
global $sugar_config, $timedate; |
141
|
|
|
global $db, $license; |
142
|
|
|
include('sugar_version.php'); |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
$return_array=array(); |
146
|
|
|
if(!$from_install && empty($license))loadLicense(true); |
147
|
|
|
|
148
|
|
|
if(!$response_data){ |
149
|
|
|
|
150
|
|
|
if($from_install){ |
151
|
|
|
$info = getBaseSystemInfo(false); |
152
|
|
|
|
153
|
|
|
}else{ |
154
|
|
|
$info = getSystemInfo($send_usage_info); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
require_once('include/nusoap/nusoap.php'); |
158
|
|
|
|
159
|
|
|
$GLOBALS['log']->debug('USING HTTPS TO CONNECT TO HEARTBEAT'); |
160
|
|
|
$sclient = new nusoapclient('https://updates.sugarcrm.com/heartbeat/soap.php', false, false, false, false, false, 15, 15); |
|
|
|
|
161
|
|
|
$ping = $sclient->call('sugarPing', array()); |
162
|
|
|
if (empty($ping) || $sclient->getError()) { |
163
|
|
|
if (!$get_request_data) { |
164
|
|
|
return array( |
165
|
|
|
array( |
166
|
|
|
'version' => $sugar_version, |
167
|
|
|
'description' => "You have the latest version." |
168
|
|
|
) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
$key = '4829482749329'; |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
|
178
|
|
|
$encoded = sugarEncode($key, serialize($info)); |
179
|
|
|
|
180
|
|
|
if($get_request_data){ |
181
|
|
|
$request_data = array('key'=>$key, 'data'=>$encoded); |
182
|
|
|
return serialize($request_data); |
183
|
|
|
} |
184
|
|
|
$encodedResult = $sclient->call('sugarHome', array('key'=>$key, 'data'=>$encoded)); |
185
|
|
|
|
186
|
|
|
}else{ |
187
|
|
|
$encodedResult = $response_data['data']; |
188
|
|
|
$key = $response_data['key']; |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if($response_data || !$sclient->getError()){ |
193
|
|
|
$serializedResultData = sugarDecode($key,$encodedResult); |
194
|
|
|
$resultData = unserialize($serializedResultData); |
195
|
|
|
if($response_data && empty($resultData)) |
196
|
|
|
{ |
197
|
|
|
$resultData = array(); |
198
|
|
|
$resultData['validation'] = 'invalid validation key'; |
199
|
|
|
} |
200
|
|
|
}else |
201
|
|
|
{ |
202
|
|
|
$resultData = array(); |
203
|
|
|
$resultData['versions'] = array(); |
204
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
if($response_data || !$sclient->getError() ) |
208
|
|
|
{ |
209
|
|
|
if(!empty($resultData['msg'])){ |
210
|
|
|
if(!empty($resultData['msg']['admin'])){ |
211
|
|
|
$license->saveSetting('license', 'msg_admin', base64_encode($resultData['msg']['admin'])); |
212
|
|
|
}else{ |
213
|
|
|
$license->saveSetting('license', 'msg_admin',''); |
214
|
|
|
} |
215
|
|
|
if(!empty($resultData['msg']['all'])){ |
216
|
|
|
$license->saveSetting('license', 'msg_all', base64_encode($resultData['msg']['all'])); |
217
|
|
|
}else{ |
218
|
|
|
$license->saveSetting('license', 'msg_all',''); |
219
|
|
|
} |
220
|
|
|
}else{ |
221
|
|
|
$license->saveSetting('license', 'msg_admin',''); |
222
|
|
|
$license->saveSetting('license', 'msg_all',''); |
223
|
|
|
} |
224
|
|
|
$license->saveSetting('license', 'last_validation', 'success'); |
225
|
|
|
unset($_SESSION['COULD_NOT_CONNECT']); |
226
|
|
|
} |
227
|
|
|
else |
228
|
|
|
{ |
229
|
|
|
$resultData = array(); |
230
|
|
|
$resultData['versions'] = array(); |
231
|
|
|
|
232
|
|
|
$license->saveSetting('license', 'last_connection_fail', TimeDate::getInstance()->nowDb()); |
233
|
|
|
$license->saveSetting('license', 'last_validation', 'no_connection'); |
234
|
|
|
|
235
|
|
|
if( empty($license->settings['license_last_validation_success']) && empty($license->settings['license_last_validation_fail']) && empty($license->settings['license_vk_end_date'])){ |
236
|
|
|
$license->saveSetting('license', 'vk_end_date', TimeDate::getInstance()->nowDb()); |
237
|
|
|
|
238
|
|
|
$license->saveSetting('license', 'validation_key', base64_encode(serialize(array('verified'=>false)))); |
239
|
|
|
} |
240
|
|
|
$_SESSION['COULD_NOT_CONNECT'] =TimeDate::getInstance()->nowDb(); |
241
|
|
|
|
242
|
|
|
} |
243
|
|
|
if(!empty($resultData['versions'])){ |
244
|
|
|
|
245
|
|
|
$license->saveSetting('license', 'latest_versions',base64_encode(serialize($resultData['versions']))); |
246
|
|
|
}else{ |
247
|
|
|
$resultData['versions'] = array(); |
248
|
|
|
$license->saveSetting('license', 'latest_versions','') ; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
if(sizeof($resultData) == 1 && !empty($resultData['versions'][0]['version']) |
252
|
|
|
&& compareVersions($sugar_version, $resultData['versions'][0]['version'])) |
253
|
|
|
{ |
254
|
|
|
$resultData['versions'][0]['version'] = $sugar_version; |
255
|
|
|
$resultData['versions'][0]['description'] = "You have the latest version."; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
return $resultData['versions']; |
260
|
|
|
} |
261
|
|
|
/* |
262
|
|
|
* returns true if $ver1 > $ver2 |
263
|
|
|
*/ |
264
|
|
|
function compareVersions($ver1, $ver2) |
265
|
|
|
{ |
266
|
|
|
return (version_compare($ver1, $ver2) === 1); |
267
|
|
|
} |
268
|
|
|
function set_CheckUpdates_config_setting($value) { |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
$admin=new Administration(); |
272
|
|
|
$admin->saveSetting('Update','CheckUpdates',$value); |
273
|
|
|
} |
274
|
|
|
/* return's value for the 'CheckUpdates' config setting |
275
|
|
|
* if the setting does not exist one gets created with a default value of automatic. |
276
|
|
|
*/ |
277
|
|
|
function get_CheckUpdates_config_setting() { |
278
|
|
|
|
279
|
|
|
$checkupdates='automatic'; |
280
|
|
|
|
281
|
|
|
|
282
|
|
|
$admin=new Administration(); |
283
|
|
|
$admin=$admin->retrieveSettings('Update',true); |
284
|
|
|
if (empty($admin->settings) or empty($admin->settings['Update_CheckUpdates'])) { |
285
|
|
|
$admin->saveSetting('Update','CheckUpdates','automatic'); |
286
|
|
|
} else { |
287
|
|
|
$checkupdates=$admin->settings['Update_CheckUpdates']; |
288
|
|
|
} |
289
|
|
|
return $checkupdates; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
function set_last_check_version_config_setting($value) { |
293
|
|
|
|
294
|
|
|
|
295
|
|
|
$admin=new Administration(); |
296
|
|
|
$admin->saveSetting('Update','last_check_version',$value); |
297
|
|
|
} |
298
|
|
|
function get_last_check_version_config_setting() { |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
$admin=new Administration(); |
303
|
|
|
$admin=$admin->retrieveSettings('Update'); |
304
|
|
|
if (empty($admin->settings) or empty($admin->settings['Update_last_check_version'])) { |
305
|
|
|
return null; |
306
|
|
|
} else { |
307
|
|
|
return $admin->settings['Update_last_check_version']; |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
|
312
|
|
|
function set_last_check_date_config_setting($value) { |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
$admin=new Administration(); |
316
|
|
|
$admin->saveSetting('Update','last_check_date',$value); |
317
|
|
|
} |
318
|
|
|
function get_last_check_date_config_setting() { |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
|
322
|
|
|
$admin=new Administration(); |
323
|
|
|
$admin=$admin->retrieveSettings('Update'); |
324
|
|
|
if (empty($admin->settings) or empty($admin->settings['Update_last_check_date'])) { |
325
|
|
|
return 0; |
326
|
|
|
} else { |
327
|
|
|
return $admin->settings['Update_last_check_date']; |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
function set_sugarbeat($value) { |
332
|
|
|
global $sugar_config; |
333
|
|
|
$_SUGARBEAT="sugarbeet"; |
334
|
|
|
$sugar_config[$_SUGARBEAT] = $value; |
335
|
|
|
write_array_to_file( "sugar_config", $sugar_config, "config.php" ); |
336
|
|
|
} |
337
|
|
|
function get_sugarbeat() { |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
global $sugar_config; |
341
|
|
|
$_SUGARBEAT="sugarbeet"; |
342
|
|
|
|
343
|
|
|
if (isset($sugar_config[$_SUGARBEAT]) && $sugar_config[$_SUGARBEAT] == false) { |
344
|
|
|
return false; |
345
|
|
|
} |
346
|
|
|
return true; |
347
|
|
|
|
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
|
352
|
|
|
function shouldCheckSugar(){ |
353
|
|
|
global $license, $timedate; |
354
|
|
|
if( |
355
|
|
|
|
356
|
|
|
get_CheckUpdates_config_setting() == 'automatic' ){ |
357
|
|
|
return true; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
return false; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
|
365
|
|
|
function loadLicense($firstLogin=false){ |
366
|
|
|
|
367
|
1 |
|
$GLOBALS['license']=new Administration(); |
368
|
1 |
|
$GLOBALS['license']=$GLOBALS['license']->retrieveSettings('license', $firstLogin); |
369
|
|
|
|
370
|
1 |
|
} |
371
|
|
|
|
372
|
|
|
function loginLicense(){ |
373
|
|
|
global $current_user, $license; |
374
|
|
|
loadLicense(true); |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
if (shouldCheckSugar()) { |
378
|
|
|
|
379
|
|
|
|
380
|
|
|
$last_check_date=get_last_check_date_config_setting(); |
381
|
|
|
$current_date_time=time(); |
382
|
|
|
$time_period=3*23*3600 ; |
383
|
|
|
if (($current_date_time - $last_check_date) > $time_period |
384
|
|
|
) { |
385
|
|
|
$version = check_now(get_sugarbeat()); |
386
|
|
|
|
387
|
|
|
unset($_SESSION['license_seats_needed']); |
388
|
|
|
loadLicense(); |
389
|
|
|
set_last_check_date_config_setting("$current_date_time"); |
390
|
|
|
include('sugar_version.php'); |
391
|
|
|
|
392
|
|
|
$newVersion = ''; |
393
|
|
|
if (!empty($version) && count($version) == 1) |
394
|
|
|
{ |
395
|
|
|
$newVersion = $version[0]['version']; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
if (version_compare($newVersion, $sugar_version, '>') && is_admin($current_user)) |
|
|
|
|
399
|
|
|
{ |
400
|
|
|
//set session variables. |
401
|
|
|
$_SESSION['available_version']=$version[0]['version']; |
402
|
|
|
$_SESSION['available_version_description']=$version[0]['description']; |
403
|
|
|
set_last_check_version_config_setting($version[0]['version']); |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.