示例#1
0
 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'])));
         } elseif (!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) && !empty($_REQUEST['action']) && $_REQUEST['action'] != 'handshake' && $_REQUEST['action'] != 'get_profile' && $_REQUEST['action'] != 'get_localization' && $_REQUEST['action'] != 'do_auth') {
         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') {
             error_log("STB not found in the database, authorization failed. MAC: " . $this->mac . ", token: " . $this->access_token);
             echo 'Authorization failed.';
             exit;
         }
     }
 }
示例#2
0
 /**
  * 设置是否为调试模式
  */
 public function setDebugMode($mode = true)
 {
     return $mode == true ? self::$debug = true : (self::$debug = false);
 }