/**
  * @param \SS_HTTPRequest $request
  * @return \Heystack\Ecommerce\Locale\Interfaces\CountryInterface|null
  */
 public function getCountryForRequest(\SS_HTTPRequest $request)
 {
     $location = false;
     if ($this->isAllowedUserAgent($request->getHeader('User-Agent'))) {
         $ip = static::parseIP($request->getIP());
         if (!$ip) {
             return null;
         }
         $fp = fopen(sprintf('https://geoip.maxmind.com/a?l=%s&i=%s', $this->key, $ip), 'r', null, stream_context_create(['https' => ['timeout' => $this->timeout]]));
         if (is_resource($fp)) {
             $location = stream_get_contents($fp);
             fclose($fp);
         }
     }
     return $location ? $this->localeService->getCountry(new Identifier($location)) : null;
 }
 /**
  * Creates a failed spam attempt object witht the user's info
  *
  * @param SS_HTTPRequest
  * @return ContactFormSpamAttempt
  */
 public function createSpamAttempt(SS_HTTPRequest $r)
 {
     $spam = ContactFormSpamAttempt::create(array('IPAddress' => $r->getIP(), 'URL' => $r->getURL(), 'Notes' => $this->class));
     return $spam;
 }
 /**
  * Fetch one or all remote dump files and writes to local filesystem.
  *
  * If filename is supplied as getVar then only that file will be retrieved, otherwise all files which don't exist locally will be retrieved up to number getVar.
  *
  * If filename is supplied as getVar then file will overwrite existing file.
  *
  * SideEffects:
  *  Reads files from remote system.
  *  Writes files to local filesystem.
  *  Outputs results
  *
  * @param SS_HTTPRequest $request
  * @return int number of files fetched
  * @throws PermissionFailureException
  */
 public function fetch(SS_HTTPRequest $request)
 {
     $options = CollectionTools::options_from_array($request->getVars(), array('RemoteHost' => $request->getIP(), 'Path' => Replicant::asset_path(), 'FileName' => '', 'UserName' => null, 'Password' => null));
     $action = ReplicantActionFetch::create();
     $action->checkPerm()->update($options)->execute();
     return $action->format();
 }
 /**
  * sends a message to user
  * @param POST 'Message'
  * @param POST 'To'
  * @param SS_HTTPRequest $request
  */
 public function set_message(SS_HTTPRequest $request)
 {
     if (!Permission::checkMember(Member::currentUser(), "CMS_ACCESS_LiveChatAdmin")) {
         header("HTTP/1.0 403 Forbidden");
         die('You do not have permission to use the live chat module');
     }
     if (!$request->postVar('Message')) {
         header("HTTP/1.0 400 Bad Request");
         die('No Message found');
     }
     if (!$request->postVar('To')) {
         header("HTTP/1.0 400 Bad Request");
         die('No target user ID found');
     }
     // redirecting one user to another
     if (substr($request->postVar('Message'), 0, 9) == '/redirect') {
         $this->redirectChatToUser($request->postVar('To'), substr($request->postVar('Message'), 10));
         die;
     }
     LiveChatMessage::create(array('Message' => htmlentities($request->postVar('Message')), 'ToID' => is_numeric($request->postVar('To')) ? $request->postVar('To') : 0, 'Read' => false, 'FromID' => Member::currentUserID(), 'FromIP' => $request->getIP(), 'FromName' => is_numeric($request->postVar('To')) ? "" : $request->postVar('To')))->write();
     die;
     // success
 }