Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 3.0.8.0
  8. * @ Author : DeZender
  9. * @ Release on : 25.09.2017
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace Stalker\Lib\Core;
  15.  
  16. class Stb
  17. {
  18. public $id = 0;
  19. public $mac = '';
  20. public $ip = null;
  21. public $hd = 0;
  22. private $user_agent = '';
  23. private $access_token = null;
  24. private $is_moderator = null;
  25. private $params = array( );
  26. private $db = null;
  27. public $lang = null;
  28. private $locale = null;
  29. private $country_id = null;
  30. private $openweathermap_country_id = null;
  31. public $city_id = null;
  32. public $openweathermap_city_id = null;
  33. public $timezone = null;
  34. public static $server_timezone = null;
  35. public $timezone_diff = 0;
  36. private $stb_lang = null;
  37. public $additional_services_on = 0;
  38. private static $just_created = false;
  39. private $valid_hash_version = false;
  40. private static $allowed_languages = null;
  41. private static $clock_formats = array(
  42. '12h',
  43. '24h'
  44. );
  45. private static $instance = null;
  46.  
  47. /**
  48. * @static
  49. * @return Stb
  50. */
  51. public static function getInstance()
  52. {
  53. if (self::$instance == NULL) {
  54. self::$instance = new Stb( );
  55. }
  56.  
  57. return self::$instance;
  58. }
  59.  
  60. private function __construct()
  61. {
  62. $debug_key = $this->getDebugKey( );
  63. $this->user_agent = ((empty( $_SERVER['HTTP_USER_AGENT'] ) ? '' : $_SERVER['HTTP_USER_AGENT']));
  64.  
  65. if (!(empty( $_SERVER['HTTP_X_USER_AGENT'] ))) {
  66. $this->user_agent .= '; ' . $_SERVER['HTTP_X_USER_AGENT'];
  67. }
  68.  
  69. $this->parseAuthorizationHeader( );
  70.  
  71. if (!(empty( $debug_key )) && $this->checkDebugKey( $debug_key )) {
  72. if (!(empty( $_REQUEST['mac'] ))) {
  73. $this->mac = @htmlspecialchars( trim( urldecode( $_REQUEST['mac'] ) ) );
  74. }
  75. else if (!(empty( $_COOKIE['mac'] ))) {
  76. $this->mac = @htmlspecialchars( trim( urldecode( $_COOKIE['mac'] ) ) );
  77. }
  78. else {
  79. echo 'Identification failed';
  80. exit( );
  81. }
  82.  
  83. if (!(empty( $_COOKIE['debug'] )) || !(empty( $_REQUEST['debug'] ))) {
  84. Mysql::$debug = true;
  85. }
  86. }
  87. else if (!(empty( $_COOKIE['mac'] )) && empty( $_COOKIE['mac_emu'] )) {
  88. $this->mac = @htmlspecialchars( trim( urldecode( $_COOKIE['mac'] ) ) );
  89.  
  90. if (!(empty( $_REQUEST['action'] )) && ($_REQUEST['action'] != 'handshake') && ($_REQUEST['action'] != 'get_profile') && ($_REQUEST['action'] != 'get_localization') && ($_REQUEST['action'] != 'do_auth') && !($this->isValidAccessToken( $this->access_token ))) {
  91. error_log( 'STB authorization failed. MAC: ' . $this->mac . ', token: ' . $this->access_token );
  92. echo 'Authorization failed.';
  93. exit( );
  94. }
  95. }
  96. else {
  97. if ((!(empty( $_SERVER['TARGET'] )) && (($_SERVER['TARGET'] == 'API') || ($_SERVER['TARGET'] == 'ADM'))) || (!(empty( $_REQUEST['type'] )) && ($_REQUEST['type'] == 'stb'))) {
  98. }
  99. else {
  100. $this->mac = '';
  101. echo 'Unauthorized request.';
  102. exit( );
  103. }
  104. }
  105.  
  106. $this->mac = strtoupper( $this->mac );
  107.  
  108. if (!(empty( $_COOKIE['stb_lang'] ))) {
  109. $this->stb_lang = @trim( urldecode( $_COOKIE['stb_lang'] ) );
  110. }
  111.  
  112. if (!(empty( $_COOKIE['timezone'] )) && ($_COOKIE['timezone'] != 'undefined')) {
  113. $this->timezone = @trim( $_COOKIE['timezone'] );
  114. }
  115.  
  116. if (@$_SERVER['HTTP_X_REAL_IP']) {
  117. $this->ip = @$_SERVER['HTTP_X_REAL_IP'];
  118. }
  119. else {
  120. $this->ip = @$_SERVER['REMOTE_ADDR'];
  121. }
  122.  
  123. $this->db = Mysql::getInstance( );
  124.  
  125. try {
  126. $this->getStbParams( );
  127. }
  128. catch (MysqlException $e) {
  129. echo $e->getMessage( ) . PHP_EOL;
  130. return;
  131. }
  132.  
  133. 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')) {
  134. error_log( 'Access denied to ' . $_REQUEST['type'] . ':' . $_REQUEST['action'] . ' for MAC: ' . $this->mac );
  135. echo 'Access denied.';
  136. exit( );
  137. }
  138.  
  139. if (empty( $this->id )) {
  140. $this->initLocale( $this->stb_lang );
  141.  
  142. 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')) {
  143. error_log( 'STB not found in the database, authorization failed. MAC: ' . $this->mac . ', token: ' . $this->access_token );
  144. echo 'Authorization failed.';
  145. exit( );
  146. }
  147. }
  148. }
  149.  
  150. private function checkDebugKey($key)
  151. {
  152. return (bool) Mysql::getInstance( )->from( 'administrators' )->where( array(
  153. 'debug_key' => $key,
  154. 'login' => 'admin'
  155. ) )->get( )->first( );
  156. }
  157.  
  158. private function getDebugKey()
  159. {
  160. if (!(empty( $_REQUEST['debug_key'] ))) {
  161. return $_REQUEST['debug_key'];
  162. }
  163.  
  164. if (!(empty( $_COOKIE['debug_key'] ))) {
  165. return $_COOKIE['debug_key'];
  166. }
  167.  
  168. return null;
  169. }
  170.  
  171. public function setId($id)
  172. {
  173. $this->id = (int) $id;
  174. $this->params['id'] = (int) $id;
  175. }
  176.  
  177. public function getTimezone()
  178. {
  179. return $this->timezone;
  180. }
  181.  
  182. public function getParam($name)
  183. {
  184. return $this->params[$name];
  185. }
  186.  
  187. public function getUserAgent()
  188. {
  189. return $this->user_agent;
  190. }
  191.  
  192. public function getStbLanguage()
  193. {
  194. return $this->stb_lang;
  195. }
  196.  
  197. public function setParam($key, $value)
  198. {
  199. if (!(array_key_exists( $key, $this->params ))) {
  200. return false;
  201. }
  202.  
  203. if ($this->params[$key] == $value) {
  204. return true;
  205. }
  206.  
  207. $this->params[$key] = $value;
  208.  
  209. if (property_exists( $this, $key )) {
  210. $this->$key = $value;
  211. }
  212.  
  213. return Mysql::getInstance( )->update( 'users', array( $key => $value ), array( 'id' => $this->id ) );
  214. }
  215.  
  216. public function getStbParams()
  217. {
  218. if (!(empty( $this->mac ))) {
  219. $user = $this->db->from( 'users' )->where( array( 'mac' => $this->mac ) )->get( )->first( );
  220. }
  221. else {
  222. if (User::isInitialized( ) && User::getInstance( )->getId( )) {
  223. $user = $this->db->from( 'users' )->where( array( 'id' => (int) User::getInstance( )->getId( ) ) )->get( )->first( );
  224. }
  225. }
  226.  
  227. if (!(empty( $user ))) {
  228. $this->params = $user;
  229. $this->id = $user['id'];
  230. $this->hd = $user['hd'];
  231. if (($this->params['hw_version_2'] && (($this->params['hw_version_2'] % 2) == 0)) || ($this->params['hw_version_2'] == '')) {
  232. $this->valid_hash_version = true;
  233. }
  234.  
  235. $this->locale = ((empty( $user['locale'] ) && Config::exist( 'default_locale' ) ? Config::get( 'default_locale' ) : $user['locale']));
  236.  
  237. if ((Config::getSafe( 'default_city_id', 0 ) == 0) && ($user['city_id'] == 0)) {
  238. $this->city_id = 0;
  239. }
  240. else {
  241. $this->city_id = ((empty( $user['city_id'] ) && Config::exist( 'default_city_id' ) ? Config::get( 'default_city_id' ) : intval( $user['city_id'] )));
  242. }
  243.  
  244. if ((Config::getSafe( 'default_openweathermap_city_id', 0 ) == 0) && ($user['openweathermap_city_id'] == 0)) {
  245. $this->openweathermap_city_id = 0;
  246. }
  247. else {
  248. $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'] )));
  249. }
  250.  
  251. $this->timezone = ((empty( $this->timezone ) && Config::exist( 'default_timezone' ) ? Config::get( 'default_timezone' ) : $this->timezone));
  252. self::$server_timezone = date_default_timezone_get( );
  253. date_default_timezone_set( $this->timezone );
  254. ............................................................................
  255. ...........................................
  256. ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement