Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 3.0.8.0
- * @ Author : DeZender
- * @ Release on : 25.09.2017
- * @ Official site : http://DeZender.Net
- *
- */
- namespace Stalker\Lib\Core;
- class Stb
- {
- public $id = 0;
- public $mac = '';
- public $ip = null;
- public $hd = 0;
- private $user_agent = '';
- private $access_token = null;
- private $is_moderator = null;
- private $params = array( );
- private $db = null;
- public $lang = null;
- private $locale = null;
- private $country_id = null;
- private $openweathermap_country_id = null;
- public $city_id = null;
- public $openweathermap_city_id = null;
- public $timezone = null;
- public static $server_timezone = null;
- public $timezone_diff = 0;
- private $stb_lang = null;
- public $additional_services_on = 0;
- private static $just_created = false;
- private $valid_hash_version = false;
- private static $allowed_languages = null;
- private static $clock_formats = array(
- '12h',
- '24h'
- );
- private static $instance = null;
- /**
- * @static
- * @return Stb
- */
- public static function getInstance()
- {
- if (self::$instance == NULL) {
- self::$instance = new Stb( );
- }
- return self::$instance;
- }
- private function __construct()
- {
- $debug_key = $this->getDebugKey( );
- $this->user_agent = ((empty( $_SERVER['HTTP_USER_AGENT'] ) ? '' : $_SERVER['HTTP_USER_AGENT']));
- if (!(empty( $_SERVER['HTTP_X_USER_AGENT'] ))) {
- $this->user_agent .= '; ' . $_SERVER['HTTP_X_USER_AGENT'];
- }
- $this->parseAuthorizationHeader( );
- if (!(empty( $debug_key )) && $this->checkDebugKey( $debug_key )) {
- if (!(empty( $_REQUEST['mac'] ))) {
- $this->mac = @htmlspecialchars( trim( urldecode( $_REQUEST['mac'] ) ) );
- }
- else if (!(empty( $_COOKIE['mac'] ))) {
- $this->mac = @htmlspecialchars( trim( urldecode( $_COOKIE['mac'] ) ) );
- }
- else {
- echo 'Identification failed';
- exit( );
- }
- if (!(empty( $_COOKIE['debug'] )) || !(empty( $_REQUEST['debug'] ))) {
- Mysql::$debug = true;
- }
- }
- else if (!(empty( $_COOKIE['mac'] )) && empty( $_COOKIE['mac_emu'] )) {
- $this->mac = @htmlspecialchars( trim( urldecode( $_COOKIE['mac'] ) ) );
- if (!(empty( $_REQUEST['action'] )) && ($_REQUEST['action'] != 'handshake') && ($_REQUEST['action'] != 'get_profile') && ($_REQUEST['action'] != 'get_localization') && ($_REQUEST['action'] != 'do_auth') && !($this->isValidAccessToken( $this->access_token ))) {
- error_log( 'STB authorization failed. MAC: ' . $this->mac . ', token: ' . $this->access_token );
- echo 'Authorization failed.';
- exit( );
- }
- }
- else {
- if ((!(empty( $_SERVER['TARGET'] )) && (($_SERVER['TARGET'] == 'API') || ($_SERVER['TARGET'] == 'ADM'))) || (!(empty( $_REQUEST['type'] )) && ($_REQUEST['type'] == 'stb'))) {
- }
- else {
- $this->mac = '';
- echo 'Unauthorized request.';
- exit( );
- }
- }
- $this->mac = strtoupper( $this->mac );
- if (!(empty( $_COOKIE['stb_lang'] ))) {
- $this->stb_lang = @trim( urldecode( $_COOKIE['stb_lang'] ) );
- }
- if (!(empty( $_COOKIE['timezone'] )) && ($_COOKIE['timezone'] != 'undefined')) {
- $this->timezone = @trim( $_COOKIE['timezone'] );
- }
- if (@$_SERVER['HTTP_X_REAL_IP']) {
- $this->ip = @$_SERVER['HTTP_X_REAL_IP'];
- }
- else {
- $this->ip = @$_SERVER['REMOTE_ADDR'];
- }
- $this->db = Mysql::getInstance( );
- try {
- $this->getStbParams( );
- }
- catch (MysqlException $e) {
- echo $e->getMessage( ) . PHP_EOL;
- return;
- }
- if (!(empty( $_COOKIE['mac'] )) && (empty( $this->id ) || ($this->params['status'] == 1) || ($this->params['blocked'] == 1)) && !(empty( $_REQUEST['action'] )) && ($_REQUEST['action'] != 'handshake') && ($_REQUEST['action'] != 'get_profile') && ($_REQUEST['action'] != 'get_localization') && ($_REQUEST['action'] != 'do_auth') && ($_REQUEST['action'] != 'get_events') && ($_REQUEST['action'] != 'get_modules') && ($_REQUEST['action'] != 'get_main_info') && ($_REQUEST['action'] != 'get_payment_info') && ($_REQUEST['action'] != 'get_agreement_info') && ($_REQUEST['action'] != 'get_terms_info')) {
- error_log( 'Access denied to ' . $_REQUEST['type'] . ':' . $_REQUEST['action'] . ' for MAC: ' . $this->mac );
- echo 'Access denied.';
- exit( );
- }
- if (empty( $this->id )) {
- $this->initLocale( $this->stb_lang );
- if (!(empty( $_COOKIE['mac'] )) && !(empty( $_REQUEST['action'] )) && ($_REQUEST['action'] != 'handshake') && ($_REQUEST['action'] != 'get_profile') && ($_REQUEST['action'] != 'get_localization') && ($_REQUEST['action'] != 'do_auth') && ($_REQUEST['action'] != 'get_events') && ($_REQUEST['action'] != 'get_main_info') && ($_REQUEST['action'] != 'get_payment_info') && ($_REQUEST['action'] != 'get_agreement_info') && ($_REQUEST['action'] != 'get_terms_info')) {
- error_log( 'STB not found in the database, authorization failed. MAC: ' . $this->mac . ', token: ' . $this->access_token );
- echo 'Authorization failed.';
- exit( );
- }
- }
- }
- private function checkDebugKey($key)
- {
- return (bool) Mysql::getInstance( )->from( 'administrators' )->where( array(
- 'debug_key' => $key,
- 'login' => 'admin'
- ) )->get( )->first( );
- }
- private function getDebugKey()
- {
- if (!(empty( $_REQUEST['debug_key'] ))) {
- return $_REQUEST['debug_key'];
- }
- if (!(empty( $_COOKIE['debug_key'] ))) {
- return $_COOKIE['debug_key'];
- }
- return null;
- }
- public function setId($id)
- {
- $this->id = (int) $id;
- $this->params['id'] = (int) $id;
- }
- public function getTimezone()
- {
- return $this->timezone;
- }
- public function getParam($name)
- {
- return $this->params[$name];
- }
- public function getUserAgent()
- {
- return $this->user_agent;
- }
- public function getStbLanguage()
- {
- return $this->stb_lang;
- }
- public function setParam($key, $value)
- {
- if (!(array_key_exists( $key, $this->params ))) {
- return false;
- }
- if ($this->params[$key] == $value) {
- return true;
- }
- $this->params[$key] = $value;
- if (property_exists( $this, $key )) {
- $this->$key = $value;
- }
- return Mysql::getInstance( )->update( 'users', array( $key => $value ), array( 'id' => $this->id ) );
- }
- public function getStbParams()
- {
- if (!(empty( $this->mac ))) {
- $user = $this->db->from( 'users' )->where( array( 'mac' => $this->mac ) )->get( )->first( );
- }
- else {
- if (User::isInitialized( ) && User::getInstance( )->getId( )) {
- $user = $this->db->from( 'users' )->where( array( 'id' => (int) User::getInstance( )->getId( ) ) )->get( )->first( );
- }
- }
- if (!(empty( $user ))) {
- $this->params = $user;
- $this->id = $user['id'];
- $this->hd = $user['hd'];
- if (($this->params['hw_version_2'] && (($this->params['hw_version_2'] % 2) == 0)) || ($this->params['hw_version_2'] == '')) {
- $this->valid_hash_version = true;
- }
- $this->locale = ((empty( $user['locale'] ) && Config::exist( 'default_locale' ) ? Config::get( 'default_locale' ) : $user['locale']));
- if ((Config::getSafe( 'default_city_id', 0 ) == 0) && ($user['city_id'] == 0)) {
- $this->city_id = 0;
- }
- else {
- $this->city_id = ((empty( $user['city_id'] ) && Config::exist( 'default_city_id' ) ? Config::get( 'default_city_id' ) : intval( $user['city_id'] )));
- }
- if ((Config::getSafe( 'default_openweathermap_city_id', 0 ) == 0) && ($user['openweathermap_city_id'] == 0)) {
- $this->openweathermap_city_id = 0;
- }
- else {
- $this->openweathermap_city_id = ((empty( $user['openweathermap_city_id'] ) && Config::exist( 'default_openweathermap_city_id' ) ? Config::get( 'default_openweathermap_city_id' ) : intval( $user['openweathermap_city_id'] )));
- }
- $this->timezone = ((empty( $this->timezone ) && Config::exist( 'default_timezone' ) ? Config::get( 'default_timezone' ) : $this->timezone));
- self::$server_timezone = date_default_timezone_get( );
- date_default_timezone_set( $this->timezone );
- ............................................................................
- ...........................................
- ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement