public function getPerTimeCached($config, $where_params = null, $time_to_live = 900, $refresh = false, $is_admin = FALSE)
 {
     $cached_data = \util\CacheSql::get_cached_read_result_apc($config, $where_params, $this->table . '_M');
     if ($cached_data !== null && !$refresh) {
         if ($cached_data == self::$empty_array_value) {
             return array();
         } else {
             return $cached_data;
         }
     } else {
         $data = $this->getPerTime($where_params, $is_admin);
         \util\CacheSql::put_cached_read_result_apc($config, $where_params, $this->table . '_M', $data, $time_to_live);
         return $data;
     }
 }
 private static function get_honeypot_score_from_service($config, $remote_ip)
 {
     $honeypot_safe = self::checkHoneyPotCached($config, $remote_ip);
     if ($honeypot_safe === null) {
         $project_honeypot_api_key = $config['settings']['rtb']['project_honeypot_api_key'];
         $ProjectHoneyPot = new \util\ProjectHoneyPot($remote_ip, $project_honeypot_api_key);
         if ($ProjectHoneyPot->getError() !== null) {
             /*
              * something went wrong with the honeypot service
              * better luck next time
              */
             return true;
         }
         $honeypot_listed = !$ProjectHoneyPot->isListed();
         /*
          * IPs are re-assigned. Only the ones with activity in the last
          * month should trigger ad fraud.
          */
         if ($honeypot_listed === false && $ProjectHoneyPot->getRecency() <= 30) {
             // optionally do some logging here with $Logger
             $honeypot_safe = false;
         } else {
             $honeypot_safe = true;
         }
         /*
          * If we get valid response from the service,
          * store it for 1 hour, so we are not constantly
          * calling the service with the same parameters
          */
         $params = array();
         $params["remote_ip"] = $remote_ip;
         $one_hour_in_seconds = 3600;
         \util\CacheSql::put_cached_read_result_apc($config, $params, self::$class_name, $honeypot_safe, $one_hour_in_seconds);
     }
     return $honeypot_safe;
 }
 public static function increment_cached_write_result_int_apc($config, $params, $class_name, $value, $ttl = 60)
 {
     $current = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name);
     if ($current !== null) {
         $existing_value = intval($current["value"]);
         $value += $existing_value;
     }
     // cache up to 1 hour, the write the the db should occur before that.
     \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name, array("value" => intval($value)), 3600);
     $timer_name = 'write_timer';
     $write_timer = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name . $timer_name);
     if ($write_timer == null) {
         /*
          * 60 second write timer, when the apc cache value is gone the
          * contents are written the DB and the apc value is cleared
          */
         \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name . $timer_name, array($timer_name => true), 60);
     }
 }
예제 #4
0
 private static function get_traq_score_from_service($config, $page_to_check)
 {
     $traq_json_response = self::checkScoreCached($config, $page_to_check);
     if ($traq_json_response == null) {
         $traq_url = self::$traq_url . urlencode($page_to_check);
         $raw_response = \util\WorkflowHelper::get_ping_notice_url_curl_request($traq_url);
         $traq_json_response = json_decode($raw_response, true);
         if ($traq_json_response != null) {
             /*
              * If we get valid response from the service,
              * store it for 1 day, so we are not constantly  
              * calling the service with the same parameters
              */
             $params = array();
             $params["PageURL"] = $page_to_check;
             $one_day_in_seconds = 86400;
             \util\CacheSql::put_cached_read_result_apc($config, $params, self::$class_name, $traq_json_response, $one_day_in_seconds);
         }
     }
     return $traq_json_response;
 }
예제 #5
0
 private function updateTorIpBlockList()
 {
     if ($this->config['settings']['rtb']['tor_protected'] !== true) {
         return false;
     }
     $lines = file(self::$tor_file_source_location);
     if (count($lines) < 100) {
         // bad request
         return false;
     }
     $apc_cached_tor_ip_list = array();
     if (is_writable($this->config['settings']['rtb']['tor_file_save_location'])) {
         try {
             $fh = fopen($this->config['settings']['rtb']['tor_file_save_location'], "w");
             /*
              * write it in nginx conf.d file include format
              */
             foreach ($lines as $line) {
                 fwrite($fh, "deny " . trim($line) . ";\n");
             }
             fclose($fh);
         } catch (Exception $e) {
             echo "Tor Save File Location is not writable, Exception: " . $e->getMessage();
         }
     }
     foreach ($lines as $line) {
         $apc_cached_tor_ip_list[trim($line)] = 1;
     }
     $params = array();
     // 2 hour cache
     \util\CacheSql::put_cached_read_result_apc($this->config, $params, "Maintenance", $apc_cached_tor_ip_list, 7200);
     return true;
 }
예제 #6
0
 protected static function increment_frequency_impressions_counter($config, $params, $class_name, $increment_amount = 1)
 {
     $current = \util\CacheSql::get_cached_read_result_apc_type_convert($config, $params, $class_name);
     if ($current !== null) {
         $existing_impressions_counter = intval($current["ImpressionsCounter"]);
         $existing_impressions_counter += $increment_amount;
     } else {
         $existing_impressions_counter = $increment_amount;
     }
     // cache up to 1 hour, the write the the db should occur before that.
     \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name, array("ImpressionsCounter" => $existing_impressions_counter), 3600);
     $timer_name = 'write_timer';
     $write_timer = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name . $timer_name);
     if ($write_timer == null) {
         /*
          * 60 second write timer, when the apc cache value is gone the
          * contents are written the DB and the apc value is cleared
          */
         \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name . $timer_name, array($timer_name => true), 60);
     }
 }