===== PART 11/12 ===== ctivity = Time::now(); $link->setDirty('modified', true); $this->Links->save($link); return null; } /** * @return bool */ protected function isProxy() { if (!empty($_SERVER["HTTP_CF_IPCOUNTRY"])) { if ($_SERVER["HTTP_CF_IPCOUNTRY"] === 'T1') { return true; } } $ip = get_ip(); $proxy_service = get_option('proxy_service', 'disabled'); if ($proxy_service === 'disabled') { return false; } if ($proxy_service === 'free') { $url = 'https://blackbox.ipinfo.app/lookup/' . urlencode($ip); $options = [ CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 2, CURLOPT_ENCODING => 'gzip,deflate', ]; $proxy_check = curlRequest($url, 'GET', [], [], $options)->body; if (strcasecmp($proxy_check, "Y") === 0) { return true; } } if ($proxy_service === 'isproxyip') { if (empty(get_option('isproxyip_key'))) { return false; } $url = 'https://api.isproxyip.com/v1/check.php?key=' . urlencode(get_option('isproxyip_key')) . '&ip=' . urlencode($ip); $options = [ CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 2, CURLOPT_ENCODING => 'gzip,deflate', ]; $proxy_check = curlRequest($url, 'GET', [], [], $options)->body; if (strcasecmp($proxy_check, "Y") === 0) { return true; } } return false; } /** * @return bool */ protected function verifyOnetimeCaptcha() { if (!isset($_SESSION['onetime_captcha'])) { return false; } $salt = \Cake\Utility\Security::getSalt(); $onetime_captcha = sha1($salt . get_ip() . $_SERVER['HTTP_USER_AGENT']); if ($onetime_captcha === $_SESSION['onetime_captcha']) { return true; } return false; } protected function displayCaptchaShortlink($plan_disable_captcha, $plan_onetime_captcha) { if (!isset_captcha()) { return false; } if (get_option('enable_captcha_shortlink') !== 'yes') { return false; } if ($plan_disable_captcha) { return false; } if ($plan_onetime_captcha && $this->verifyOnetimeCaptcha()) { return false; } return true; } public function shorten() { $this->autoRender = false; $this->setResponse($this->getResponse()->withType('json')); if (!$this->getRequest()->is('ajax')) { $content = [ 'status' => 'error', 'message' => __('Bad Request.'), 'url' => '', ]; $this->getResponse()->body(json_encode($content)); return $this->response; } $user_id = 1; if (null !== $this->Auth->user('id')) { $user_id = $this->Auth->user('id'); } if ($user_id === 1 && (bool)get_option('enable_captcha_shortlink_anonymous', false) && isset_captcha() && !$this->Captcha->verify($this->getRequest()->getData()) ) { $content = [ 'status' => 'error', 'message' => __('The CAPTCHA was incorrect. Try again'), 'url' => '', ]; $this->setResponse($this->getResponse()->withStringBody(json_encode($content))); return $this->response; } if ($user_id == 1 && get_option('home_shortening_register') === 'yes') { $content = [ 'status' => 'error', 'message' => __('Bad Request.'), 'url' => '', ]; $this->setResponse($this->getResponse()->withStringBody(json_encode($content))); return $this->response; } $user = $this->Links->Users->find()->where(['status' => 1, 'id' => $user_id])->first(); if (!$user) { $content = [ 'status' => 'error', 'message' => __('Invalid user'), 'url' => '', ]; $this->setResponse($this->getResponse()->withStringBody(json_encode($content))); return $this->response; } $url = trim($this->getRequest()->getData('url')); $url = str_replace(" ", "%20", $url); $url = parse_url($url, PHP_URL_SCHEME) === null ? 'http://' . $url : $url; $this->setRequest($this->getRequest()->withData('url', $url)); $domain = ''; if ($this->getRequest()->getData('domain')) { $domain = $this->getRequest()->getData('domain'); } if (!in_array($domain, get_multi_domains_list())) { $domain = ''; } $linkWhere = [ 'url_hash' => sha1($this->getRequest()->getData('url')), 'user_id' => $user->id, 'status' => 1, 'ad_type' => $this->getRequest()->getData('ad_type'), 'url' => $this->getRequest()->getData('url'), ]; if ($this->getRequest()->getData('alias') && strlen($this->getRequest()->getData('alias')) > 0) { $linkWhere['alias'] = $this->getRequest()->getData('alias'); } $link = $this->Links->find()->where($linkWhere)->first(); if ($link) { $content = [ 'status' => 'success', 'message' => '', 'url' => get_short_url($link->alias, $domain), ]; $this->setResponse($this->getResponse()->withStringBody(json_encode($content))); return $this->response; } $user_plan = get_user_plan($user->id); if ($user_plan->url_daily_li