/**
  * Check if a request comes from a CloudFlare IP.
  * @return bool
  */
 public function isCloudFlareIP()
 {
     // Store original remote address in $original_ip
     $this->original_ip = $this->getOriginalIP();
     if (!isset($this->original_ip)) {
         return false;
     }
     // Process original_ip if on cloudflare
     $ip_ranges = $this->cf_ipv4;
     if (IpUtils::isIpv6($this->original_ip)) {
         $ip_ranges = $this->cf_ipv6;
     }
     foreach ($ip_ranges as $range) {
         if (IpUtils::checkIp($this->original_ip, $range)) {
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function matches(Request $request)
 {
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('#' . str_replace('#', '\\#', $pattern) . '#', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path) {
         $path = str_replace('#', '\\#', $this->path);
         if (!preg_match('#' . $path . '#', rawurldecode($request->getPathInfo()))) {
             return false;
         }
     }
     if (null !== $this->host && !preg_match('#' . str_replace('#', '\\#', $this->host) . '#i', $request->getHost())) {
         return false;
     }
     if (null !== $this->ip && !IpUtils::checkIp($request->getClientIp(), $this->ip)) {
         return false;
     }
     return true;
 }
Exemple #3
0
 public function matches(Request $request)
 {
     if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
         return false;
     }
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('{' . $pattern . '}', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path && !preg_match('{' . $this->path . '}', rawurldecode($request->getPathInfo()))) {
         return false;
     }
     if (null !== $this->host && !preg_match('{' . $this->host . '}i', $request->getHost())) {
         return false;
     }
     if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
         return true;
     }
     return count($this->ips) === 0;
 }
 /**
  * {@inheritdoc}
  */
 public function matches(Request $request)
 {
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('{' . $pattern . '}', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path && !preg_match('{' . $this->path . '}', rawurldecode($request->getPathInfo()))) {
         return false;
     }
     if (null !== $this->host && !preg_match('{' . $this->host . '}i', $request->getHost())) {
         return false;
     }
     if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
         return true;
     }
     // Note to future implementors: add additional checks above the
     // foreach above or else your check might not be run!
     return count($this->ips) === 0;
 }
 function actionPlay()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     $prod_id = Yii::app()->request->getParam("prod_id");
     $prod_name = Yii::app()->request->getParam("prod_name");
     $prod_subname = Yii::app()->request->getParam("prod_subname");
     $prod_type = Yii::app()->request->getParam("prod_type");
     $play_type = Yii::app()->request->getParam("play_type");
     $playback_time = Yii::app()->request->getParam("playback_time");
     $video_url = Yii::app()->request->getParam("video_url");
     $duration = Yii::app()->request->getParam("duration");
     $sid = Yii::app()->request->getParam("sid");
     $cid = Yii::app()->request->getParam("cid");
     $vid = Yii::app()->request->getParam("vid");
     if (!isset($prod_id) || is_null($prod_id) || !isset($prod_type) || is_null($prod_type)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PARAM_IS_INVALID);
         return;
     }
     if (!isset($play_type) || is_null($play_type)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PARAM_IS_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     try {
         $userid = Yii::app()->user->id;
         $ip = IpUtils::getIp();
         $HTTP_CLIENT = isset($_SERVER['HTTP_CLIENT']) ? $_SERVER['HTTP_CLIENT'] : "";
         //remove the code, needn't the requirement.
         //			if($HTTP_CLIENT ===null || $HTTP_CLIENT ===''){
         //			  Program::model()->incPlayCount($prod_id);
         //			}
         if ($prod_type === '1') {
             if (is_numeric($duration) && intval($duration) >= 0) {
                 $durations = intval($duration);
                 if ($durations > 0) {
                     $h = intval($durations / 3600);
                     $m = intval($durations % 3600 / 60);
                     $s = intval($durations % 3600 % 60);
                     $durations = '';
                     if ($h > 0) {
                         $durations = $h . ':';
                     } else {
                         $durations = '00:';
                     }
                     if ($m < 10) {
                         $durations = $durations . '0' . $m . ':';
                     } else {
                         $durations = $durations . $m . ':';
                     }
                     if ($s < 10) {
                         $durations = $durations . '0' . $s;
                     } else {
                         $durations = $durations . $s;
                     }
                     Program::model()->updateDuraning($prod_id, $durations);
                 }
             } else {
                 try {
                     if ($duration === '' || $duration === '-1') {
                         $history = new VideoFeedback();
                         $history->author_id = $userid;
                         $history->client = $HTTP_CLIENT;
                         $history->prod_type = $prod_type;
                         $history->prod_name = $prod_name;
                         $history->prod_id = $prod_id;
                         $history->feedback_type = '9';
                         $history->create_date = new CDbExpression('NOW()');
                         $history->save();
                     }
                 } catch (Exception $e) {
                     Yii::log(CJSON::encode($e), "error");
                 }
             }
         }
         if ($prod_type === '3') {
             $history = PlayHistory::model()->getHisotryByShowProd($userid, $prod_id, $prod_subname);
         } else {
             $history = PlayHistory::model()->getHisotryByProd($userid, $prod_id);
         }
         $remarks = Program::model()->getProgram($prod_id);
         $remarks = $remarks[0]->d_remarks;
         if ($history === null) {
             $history = new PlayHistory();
         }
         $history->author_id = $userid;
         $history->prod_type = $prod_type;
         $history->prod_name = $prod_name;
         $history->prod_subname = $prod_subname;
         $history->prod_id = $prod_id;
         $history->status = Constants::OBJECT_APPROVAL;
         $history->play_type = $play_type;
         $history->playback_time = $playback_time;
         $history->video_url = $video_url;
         $history->duration = $duration;
         $history->create_date = new CDbExpression('NOW()');
         $history->sid = $sid;
         $history->cid = $cid;
         $history->vid = $vid;
         $history->save();
         $play_history = array('user_id' => $userid, 'prod_type' => $prod_type, 'prod_name' => $prod_name, 'prod_subname' => $prod_subname, 'prod_id' => $prod_id, 'play_type' => $play_type, 'playback_time' => $playback_time, 'video_url' => $video_url, 'duration' => $duration, 'sid' => $sid, 'cid' => $cid, 'vid' => $vid, 'remarks' => $remarks, 'ip' => $ip, 'create_date' => date('Y-m-d H:i:s'));
         SendBeanstalk::sendMessage(json_encode($play_history));
         IjoyPlusServiceUtils::exportServiceError(Constants::SUCC);
     } catch (Exception $e) {
         IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
     }
 }
Exemple #6
0
 private function isFromTrustedProxy()
 {
     return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
 }
 /**
  * Checks whether the IP address of the client is unknown or not
  * @return bool True if the IP address of the client is unknown, because a proxy might be used
  */
 public static function isClientIpUnknown()
 {
     return IpUtils::getClientIp() == '0.0.0.0';
 }
 /**
  * @dataProvider ips
  **/
 public function testMakeRanges($ips, $ranges)
 {
     $this->assertEquals($ranges, IpUtils::makeRanges($ips));
 }