123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <?php
- use Chamilo\CoreBundle\Entity\BranchSync;
- use Chamilo\CoreBundle\Entity\Repository\BranchSyncRepository;
- use GuzzleHttp\Client;
- require_once __DIR__.'/../global.inc.php';
- api_protect_admin_script();
- $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
- switch ($action) {
- case 'update_changeable_setting':
- $url_id = api_get_current_access_url_id();
- if (api_is_global_platform_admin() && $url_id == 1) {
- if (isset($_GET['id']) && !empty($_GET['id'])) {
- $params = ['variable = ? ' => [$_GET['id']]];
- $data = api_get_settings_params($params);
- if (!empty($data)) {
- foreach ($data as $item) {
- $params = ['id' => $item['id'], 'access_url_changeable' => $_GET['changeable']];
- api_set_setting_simple($params);
- }
- }
- echo '1';
- }
- }
- break;
- case 'version':
-
- session_write_close();
- echo version_check();
- break;
- case 'get_extra_content':
- $blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
- if (empty($blockName)) {
- die;
- }
- if (api_is_multiple_url_enabled()) {
- $accessUrlId = api_get_current_access_url_id();
- if ($accessUrlId == -1) {
- die;
- }
- $urlInfo = api_get_access_url($accessUrlId);
- $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
- $cleanUrl = str_replace('/', '-', $url);
- $newUrlDir = api_get_path(SYS_APP_PATH)."home/$cleanUrl/admin/";
- } else {
- $newUrlDir = api_get_path(SYS_APP_PATH)."home/admin/";
- }
- if (!file_exists($newUrlDir)) {
- die;
- }
- if (!Security::check_abs_path("{$newUrlDir}{$blockName}_extra.html", $newUrlDir)) {
- die;
- }
- if (!file_exists("{$newUrlDir}{$blockName}_extra.html")) {
- die;
- }
- echo file_get_contents("{$newUrlDir}{$blockName}_extra.html");
- break;
- case 'get_latest_news':
- if (api_get_configuration_value('admin_chamilo_announcements_disable') === true) {
- break;
- }
- try {
- $latestNews = getLatestNews();
- $latestNews = json_decode($latestNews, true);
- echo Security::remove_XSS($latestNews['text'], COURSEMANAGER);
- break;
- } catch (Exception $e) {
- break;
- }
- }
- function version_check()
- {
- $tbl_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable = "registered" ';
- $result = Database::query($sql);
- $row = Database::fetch_array($result, 'ASSOC');
-
- $return = '';
- if ($row['selected_value'] == 'false') {
- $return .= get_lang('VersionCheckExplanation');
- $return .= '<form class="version-checking" action="'.api_get_path(WEB_CODE_PATH).'admin/index.php" id="VersionCheck" name="VersionCheck" method="post">';
- $return .= '<label class="checkbox"><input type="checkbox" name="donotlistcampus" value="1" id="checkbox" />'.get_lang('HideCampusFromPublicPlatformsList');
- $return .= '</label><button type="submit" class="btn btn-primary btn-block" name="Register" value="'.get_lang('EnableVersionCheck').'" id="register" >'.get_lang('EnableVersionCheck').'</button>';
- $return .= '</form>';
- check_system_version();
- } else {
-
- $return .= check_system_version();
- }
- return $return;
- }
- function check_system_version()
- {
-
- if (!in_array('curl', get_loaded_extensions())) {
- return '<span style="color:red">'.get_lang('ImpossibleToContactVersionServerPleaseTryAgain').'</span>';
- }
- $url = 'https://version.chamilo.org';
- $options = [
- 'verify' => false,
- ];
- $urlValidated = false;
- try {
- $client = new GuzzleHttp\Client();
- $res = $client->request('GET', $url, $options);
- if ($res->getStatusCode() == '200' || $res->getStatusCode() == '301') {
- $urlValidated = true;
- }
- } catch (Exception $e) {
- }
-
- $system_version = trim(api_get_configuration_value('system_version'));
- if ($urlValidated) {
-
- $number_of_courses = Statistics::countCourses();
-
- $number_of_users = Statistics::countUsers();
- $number_of_active_users = Statistics::countUsers(
- null,
- null,
- null,
- true
- );
-
- $number_of_sessions = SessionManager::count_sessions(api_get_current_access_url_id());
- $packager = api_get_configuration_value('packager');
- if (empty($packager)) {
- $packager = 'chamilo';
- }
- $uniqueId = '';
- $entityManager = Database::getManager();
-
- $repository = $entityManager->getRepository('ChamiloCoreBundle:BranchSync');
-
- $branch = $repository->getTopBranch();
- if (is_a($branch, '\Chamilo\CoreBundle\Entity\BranchSync')) {
- $uniqueId = $branch->getUniqueId();
- }
- $data = [
- 'url' => api_get_path(WEB_PATH),
- 'campus' => api_get_setting('siteName'),
- 'contact' => api_get_setting('emailAdministrator'),
- 'version' => $system_version,
- 'numberofcourses' => $number_of_courses,
- 'numberofusers' => $number_of_users,
- 'numberofactiveusers' => $number_of_active_users,
- 'numberofsessions' => $number_of_sessions,
-
-
- 'donotlistcampus' => api_get_setting('donotlistcampus'),
- 'organisation' => api_get_setting('Institution'),
- 'language' => api_get_setting('platformLanguage'),
- 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'),
- 'ip' => $_SERVER['REMOTE_ADDR'],
-
-
-
-
- 'packager' => $packager,
- 'unique_id' => $uniqueId,
- ];
- $version = null;
- $client = new GuzzleHttp\Client();
- $url .= '?';
- foreach ($data as $k => $v) {
- $url .= urlencode($k).'='.urlencode($v).'&';
- }
- $res = $client->request('GET', $url, $options);
- if ($res->getStatusCode() == '200') {
- $versionData = $res->getHeader('X-Chamilo-Version');
- if (isset($versionData[0])) {
- $version = trim($versionData[0]);
- }
- }
- if (version_compare($system_version, $version, '<')) {
- $output = '<span style="color:red">'.get_lang('YourVersionNotUpToDate').'<br />
- '.get_lang('LatestVersionIs').' <b>Chamilo '.$version.'</b>. <br />
- '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version.'</b>. <br />'.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>';
- } else {
- $output = '<span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version.'</span>';
- }
- return $output;
- }
- return '<span style="color:red">'.get_lang('ImpossibleToContactVersionServerPleaseTryAgain').'</span>';
- }
- function getLatestNews()
- {
- $url = 'https://version.chamilo.org/news/latest.php';
- $client = new Client();
- $response = $client->request(
- 'GET',
- $url,
- [
- 'query' => [
- 'language' => api_get_interface_language(),
- ],
- ]
- );
- if ($response->getStatusCode() !== 200) {
- throw new Exception(get_lang('DenyEntry'));
- }
- return $response->getBody()->getContents();
- }
|