Пример #1
0
 public function getProfile()
 {
     $debug_key = $this->getDebugKey();
     if (Config::getSafe('disable_portal', false) && (empty($debug_key) || !$this->checkDebugKey($debug_key))) {
         try {
             Mysql::getInstance()->update('users', array('access_token' => $this->access_token), array('id' => $this->id));
             if (\Config::getSafe('bind_stb_auth_and_oauth', true)) {
                 $this->resetOauthToken();
             }
         } catch (MysqlException $e) {
             echo $e->getMessage() . PHP_EOL;
         }
         return array('status' => 1, 'block_msg' => _('The portal is temporarily unavailable.<br>Please try again later.<br>Sorry for the inconvenience.'), 'portal_disabled' => true);
     }
     if (function_exists('geoip_country_code_by_name')) {
         $country = @geoip_country_code_by_name($this->ip);
         if (!$country) {
             error_log('geoip_country_code_by_name(): Host ' . $this->ip . ' not found');
         }
     } else {
         $country = '';
     }
     $model = isset($_REQUEST['stb_type']) ? $_REQUEST['stb_type'] : '';
     $serial_number = isset($_REQUEST['sn']) ? $_REQUEST['sn'] : '';
     $version = isset($_REQUEST['ver']) ? $_REQUEST['ver'] : '';
     $device_id = isset($_REQUEST['device_id']) ? $_REQUEST['device_id'] : '';
     $device_id2 = isset($_REQUEST['device_id2']) ? $_REQUEST['device_id2'] : '';
     $signature = isset($_REQUEST['signature']) ? $_REQUEST['signature'] : '';
     $force_auth = null;
     $filter_response = $this->passAccessFilter($country, $model, $this->mac, $serial_number, $version, $device_id2, $signature, $force_auth);
     $this->params['stb_type'] = $model;
     if (is_array($filter_response)) {
         $filter_result = $filter_response['result'];
     } else {
         $filter_result = $filter_response;
     }
     if (!$filter_result) {
         $this->logDeniedByFilter($country, $model, $this->mac, $version);
         $profile = array('status' => 1, 'msg' => 'access denied');
         if (!empty($filter_response['message'])) {
             $profile['block_msg'] = _($filter_response['message']);
         }
         return $profile;
     }
     if ((empty($_SERVER['TARGET']) || $_SERVER['TARGET'] != 'API' && $_SERVER['TARGET'] != 'ADM') && Config::getSafe('enable_mac_format_validation', true) && !Middleware::isValidMAC($this->mac)) {
         $this->logNotValidMAC(isset($_REQUEST['sn']) ? $_REQUEST['sn'] : '', isset($_REQUEST['stb_type']) ? $_REQUEST['stb_type'] : '');
         return array('status' => 1);
     }
     $debug_key = $this->getDebugKey();
     if (!empty($debug_key) && $this->checkDebugKey($debug_key)) {
         // emulation
     } elseif (Config::getSafe('enable_device_id_validation', true)) {
         if ($device_id2) {
             $device = Mysql::getInstance()->from('users')->where(array('device_id2' => $device_id2))->get()->first();
             if (!empty($device) && strtoupper($device['mac']) != $this->mac) {
                 $this->logDeviceConflict($device_id2, $this->mac, $serial_number, $model, 'MAC address mismatch, reason - device_id2');
                 return array('status' => 1, 'msg' => 'device conflict - MAC address mismatch');
             }
         }
         if ($this->id) {
             $update = array();
             if (!$this->getParam('device_id') && $device_id) {
                 $update['device_id'] = $device_id;
             }
             if (!$this->getParam('device_id2') && $device_id2) {
                 $update['device_id2'] = $device_id2;
             }
             if (!empty($update)) {
                 Mysql::getInstance()->update('users', $update, array('id' => $this->id));
             }
             if ($this->getParam('device_id') && $this->getParam('device_id') != $device_id) {
                 $this->logDeviceConflict($device_id, $this->mac, $serial_number, $model, 'device_id mismatch');
                 return array('status' => 1, 'msg' => 'device conflict - device_id mismatch', 'block_msg' => _('Your STB is damaged.<br/> Call the provider.'));
             }
             if ($this->getParam('device_id2') && $this->getParam('device_id2') != $device_id2) {
                 $this->logDeviceConflict($device_id2, $this->mac, $serial_number, $model, 'device_id2 mismatch');
                 return array('status' => 1, 'msg' => 'device conflict - device_id mismatch', 'block_msg' => _('Your STB is damaged.<br/> Call the provider.'));
             }
         }
     }
     if ($model != 'MAG200' && $model != 'MAG260' && (empty($debug_key) || !$this->checkDebugKey($debug_key))) {
         preg_match("/Player Engine version: (\\S+)/", $version, $match);
         if (!empty($match[1])) {
             $player_version = hexdec($match[1]);
         }
         if (empty($player_version) || empty($match) || $player_version < 1382) {
             $auto_update_setting = ImageAutoUpdate::getSettingByStbType($this->params['stb_type']);
             return array('status' => 1, 'msg' => 'old firmware', 'block_msg' => _('Firmware of your STB is outdated.<br>Please update it.'), 'autoupdate' => empty($auto_update_setting) ? false : $auto_update_setting, 'update_url' => self::getImageUpdateUrl($this->params['stb_type']));
         }
     }
     $valid_saved_auth = $this->getParam('access_token') && $this->access_token == $this->getParam('access_token') && !intval($_REQUEST['not_valid_token']);
     if (!$this->id) {
         $disable_auth_for_models = Config::exist('disable_auth_for_models') ? preg_split("/\\s*,\\s*/", trim(Config::get('disable_auth_for_models'))) : array();
         if (!$valid_saved_auth && Config::exist('auth_url') && (!in_array($model, $disable_auth_for_models) || $force_auth === true)) {
             if (Config::getSafe('init_device_before_auth', false)) {
                 $this->initProfile(null, null, $device_id, $device_id2);
                 $this->getInfoFromOss(!$force_auth);
             }
             return array('status' => 2, 'template' => $this->getUserPortalTheme(), 'info' => Config::exist('registration_url') ? sprintf(_('Use your username and password to login or register on %s'), Config::get('registration_url')) : '');
         } else {
             if (!Config::getSafe('auto_add_stb', true)) {
                 return array('status' => 1, 'block_msg' => str_replace('.', '!', _('Please contact your provider<br>to register this device.')));
             } else {
                 $this->initProfile(null, null, $device_id, $device_id2);
                 $this->params['stb_type'] = $model;
             }
         }
     } else {
         Mysql::getInstance()->update('users', array('access_token' => $this->access_token), array('id' => $this->id));
         if (\Config::getSafe('bind_stb_auth_and_oauth', true)) {
             $this->resetOauthToken();
         }
         if (!$valid_saved_auth && intval($_REQUEST['auth_second_step']) === 0 && Config::exist('auth_url') && (strpos(Config::get('auth_url'), 'auth_every_load') || $force_auth === true)) {
             $this->getInfoFromOss(!$force_auth);
             return array('status' => 2, 'template' => $this->getUserPortalTheme(), 'info' => Config::exist('registration_url') ? sprintf(_('Use your username and password to login or register on %s'), Config::get('registration_url')) : '');
         }
     }
     $this->db->update('users', array('last_start' => 'NOW()', 'keep_alive' => 'NOW()', 'version' => @$_REQUEST['ver'], 'hd' => @$_REQUEST['hd'], 'stb_type' => $model, 'video_out' => isset($_REQUEST['video_out']) ? $_REQUEST['video_out'] : '', 'serial_number' => isset($_REQUEST['sn']) ? $_REQUEST['sn'] : '', 'num_banks' => isset($_REQUEST['num_banks']) ? (int) $_REQUEST['num_banks'] : 0, 'image_version' => isset($_REQUEST['image_version']) ? $_REQUEST['image_version'] : '', 'locale' => $this->locale, 'country' => $country, 'verified' => (int) ($force_auth === false), 'hw_version' => isset($_REQUEST['hw_version']) ? $_REQUEST['hw_version'] : ''), array('id' => $this->id));
     $info = $this->getInfoFromOss(!$force_auth);
     if (self::$just_created == true && Config::getSafe('enable_welcome_message', false)) {
         $event = new SysEvent();
         $event->setUserListById($this->id);
         $event->sendMsg(sprintf(_('Welcome %s<br>We are glad to see you on the Stalker portal!'), $this->getParam('fname')));
     }
     $master = new VideoMaster();
     $profile = $this->params;
     if ($info && array_key_exists('error_msg', $info)) {
         $profile['block_msg'] = $info['error_msg'];
     }
     $profile['storages'] = $master->getStoragesForStb();
     $itv = Itv::getInstance();
     $profile['last_itv_id'] = $itv->getLastId();
     $profile['updated'] = $this->getUpdatedPlaces();
     $profile['rtsp_type'] = Config::get('rtsp_type');
     $profile['rtsp_flags'] = Config::get('rtsp_flags');
     $profile['locale'] = $this->locale;
     $profile['stb_lang'] = $this->stb_lang;
     $profile['display_menu_after_loading'] = empty($this->params['show_after_loading']) ? Config::getSafe('display_menu_after_loading', false) : $this->params['show_after_loading'] == 'main_menu';
     $profile['record_max_length'] = intval(Config::get('record_max_length'));
     $profile['web_proxy_host'] = Config::exist('stb_http_proxy_host') ? Config::get('stb_http_proxy_host') : '';
     $profile['web_proxy_port'] = Config::exist('stb_http_proxy_port') ? Config::get('stb_http_proxy_port') : '';
     $profile['web_proxy_user'] = Config::exist('stb_http_proxy_user') ? Config::get('stb_http_proxy_user') : '';
     $profile['web_proxy_pass'] = Config::exist('stb_http_proxy_pass') ? Config::get('stb_http_proxy_pass') : '';
     $profile['web_proxy_exclude_list'] = Config::exist('stb_http_proxy_exclude_list') ? Config::get('stb_http_proxy_exclude_list') : '';
     $profile['update_url'] = self::getImageUpdateUrl(empty($_REQUEST['stb_type']) ? 'mag250' : $_REQUEST['stb_type']);
     if (!in_array($this->mac, Config::getSafe('playback_limit_whitelist', array()))) {
         $profile['playback_limit'] = (int) Config::get('enable_playback_limit', 0);
     } else {
         $profile['playback_limit'] = 0;
     }
     $profile['demo_video_url'] = Config::getSafe('demo_video_url', '');
     $profile['tv_quality_filter'] = Config::get('enable_tv_quality_filter');
     $profile['use_embedded_settings'] = Config::getSafe('use_embedded_settings', false);
     $profile['test_download_url'] = Config::getSafe('test_download_url', '');
     $profile['is_moderator'] = $this->isModerator();
     $profile['watchdog_timeout'] = Config::getSafe('watchdog_timeout', 30000);
     $max_id = Mysql::getInstance()->select('max(id) as max_id')->from('users')->get()->first('max_id');
     $profile['timeslot_ratio'] = $this->id / $max_id;
     $profile['timeslot'] = $profile['timeslot_ratio'] * $profile['watchdog_timeout'];
     $profile['kinopoisk_rating'] = Config::getSafe('kinopoisk_rating', true);
     $profile['enable_tariff_plans'] = Config::getSafe('enable_tariff_plans', false);
     $profile['enable_buffering_indication'] = Config::getSafe('enable_buffering_indication', false);
     $profile['default_timezone'] = Config::getSafe('default_timezone', '');
     $profile['default_locale'] = Config::getSafe('default_locale', '');
     $profile['allowed_stb_types'] = array_map(function ($item) {
         return strtolower(trim($item));
     }, explode(',', Config::getSafe('allowed_stb_types', 'MAG200,MAG245,MAG245D,MAG250,MAG254,MAG255,MAG260,MAG270,MAG275,AuraHD,WR320,IP_STB_HD')));
     $profile['allowed_stb_types_for_local_recording'] = array_map(function ($item) {
         return strtolower(trim($item));
     }, explode(',', Config::getSafe('allowed_stb_types_for_local_recording', 'MAG245,MAG245D,MAG250,MAG254,MAG255,MAG260,MAG270,MAG275,AuraHD,WR320,IP_STB_HD')));
     $auto_update_setting = ImageAutoUpdate::getSettingByStbType($this->params['stb_type']);
     if ($auto_update_setting) {
         $profile['autoupdate'] = $auto_update_setting;
     }
     $profile['strict_stb_type_check'] = Config::getSafe('strict_stb_type_check', false);
     $profile['cas_type'] = Config::getSafe('cas_type', 0);
     $profile['cas_params'] = Config::getSafe('cas_params', null);
     $profile['cas_web_params'] = Config::getSafe('cas_web_params', null);
     $profile['cas_additional_params'] = Config::getSafe('cas_additional_params', array());
     $profile['cas_hw_descrambling'] = Config::getSafe('cas_hw_descrambling', 0);
     $profile['cas_ini_file'] = Config::getSafe('cas_ini_file', "");
     $profile['logarithm_volume_control'] = Config::getSafe('logarithm_volume_control', false);
     $profile['allow_subscription_from_stb'] = Config::getSafe('allow_subscription_from_stb', true);
     $profile['deny_720p_gmode_on_mag200'] = Config::getSafe('deny_720p_gmode_on_mag200', false);
     $profile['enable_arrow_keys_setpos'] = Config::getSafe('enable_arrow_keys_setpos', false);
     $profile['show_purchased_filter'] = Config::getSafe('show_purchased_filter', false);
     $profile['timezone_diff'] = $this->timezone_diff;
     $profile['enable_connection_problem_indication'] = Config::getSafe('enable_connection_problem_indication', true);
     $profile['invert_channel_switch_direction'] = Config::getSafe('invert_channel_switch_direction', false);
     $profile['play_in_preview_only_by_ok'] = $this->params['play_in_preview_by_ok'] === null ? (bool) Config::getSafe('play_in_preview_only_by_ok', false) : (bool) $this->params['play_in_preview_by_ok'];
     $profile['enable_stream_error_logging'] = Config::getSafe('enable_stream_error_logging', false);
     $profile['always_enabled_subtitles'] = Config::getSafe('always_enabled_subtitles', false);
     $profile['enable_service_button'] = Config::getSafe('enable_service_button', false);
     $profile['enable_setting_access_by_pass'] = Config::getSafe('enable_setting_access_by_pass', false);
     $profile['show_tv_channel_logo'] = Config::getSafe('show_tv_channel_logo', true);
     $profile['tv_archive_continued'] = Config::getSafe('tv_archive_continued', false);
     $profile['plasma_saving_timeout'] = Config::getSafe('plasma_saving_timeout', false);
     $profile['show_tv_only_hd_filter_option'] = Config::getSafe('show_tv_only_hd_filter_option', false);
     $profile['tv_playback_retry_limit'] = Config::getSafe('tv_playback_retry_limit', 0);
     $profile['fading_tv_retry_timeout'] = Config::getSafe('fading_tv_retry_timeout', true);
     $profile['epg_update_time_range'] = floatval(Config::getSafe('epg_update_delay_per_user', 0.2)) * $max_id;
     $profile['store_auth_data_on_stb'] = Config::getSafe('store_auth_data_on_stb', true) && Config::exist('auth_url') && $force_auth !== false;
     if (Config::getSafe('enable_tariff_plans', false)) {
         $profile['additional_services_on'] = '1';
     }
     $profile['hdmi_event_reaction'] = $profile['hdmi_event_reaction'] === null ? (int) Config::getSafe('enable_hdmi_events_handler', true) : (int) $profile['hdmi_event_reaction'];
     $profile['account_page_by_password'] = Config::getSafe('account_page_by_password', false);
     $profile['tester'] = Mysql::getInstance()->from('testers')->where(array('mac' => $this->mac, 'status' => 1))->get()->first() != null;
     $profile['show_channel_logo_in_preview'] = Config::getSafe('show_channel_logo_in_preview', false);
     $profile['enable_stream_losses_logging'] = Config::getSafe('enable_stream_losses_logging', false);
     $profile['external_payment_page_url'] = sprintf(Config::getSafe('external_payment_page_url', ''), $this->getParam('ls'), $this->mac);
     $profile['max_local_recordings'] = Config::getSafe('max_local_recordings', 10);
     $profile['tv_channel_default_aspect'] = Config::getSafe('tv_channel_default_aspect', 'fit');
     $profile['default_led_level'] = Config::getSafe('default_led_level', 10);
     $profile['standby_led_level'] = Config::getSafe('standby_led_level', 90);
     if (Config::exist('portal_logo_url')) {
         $profile['portal_logo_url'] = Config::get('portal_logo_url');
     }
     $profile['show_version_in_main_menu'] = Config::getSafe('show_version_in_main_menu', true);
     $profile['check_ssl_certificate'] = (int) Config::getSafe('check_ssl_certificate', false);
     $profile['disable_youtube_for_mag200'] = Config::getSafe('disable_youtube_for_mag200', true);
     $profile['hls_fast_start'] = Config::getSafe('hls_fast_start', true);
     $profile['auth_access'] = Config::exist('auth_url');
     $profile['epg_data_block_period_for_stb'] = Config::getSafe('epg_data_block_period_for_stb', 5);
     $profile['standby_on_hdmi_off'] = Config::getSafe('standby_on_hdmi_off', false);
     $profile['force_ch_link_check'] = Config::getSafe('force_ch_link_check', false);
     unset($profile['device_id']);
     unset($profile['device_id2']);
     unset($profile['access_token']);
     unset($profile['serial_number']);
     return $profile;
 }