public function post()
 {
     $ip = ipDecode(get_client_ip());
     $name = I('post.')['name'];
     $note = I('post.')['note'];
     if ($name == "" || $note == "") {
         return;
     } else {
         $data = array("name" => $name, "note" => $note, "cdate" => date("Y-m-d H:i:s", time()), "done" => 0, "ip" => $ip);
         $Messagers = D('Messagers');
         $Messagers->add($data);
     }
 }
Example #2
0
 /**
  * Retrieve IP addresses associated with a user.
  *
  * @param int $userID Unique ID for a user.
  * @return array IP addresses for the user.
  */
 public function getIPs($userID)
 {
     $IPs = [];
     try {
         $packedIPs = Gdn::sql()->getWhere('UserIP', ['UserID' => $userID])->resultArray();
     } catch (\Exception $e) {
         return $IPs;
     }
     foreach ($packedIPs as $UserIP) {
         if ($unpackedIP = ipDecode($UserIP['IPAddress'])) {
             $IPs[] = $unpackedIP;
         }
     }
     return $IPs;
 }
Example #3
0
 /**
  * Returns an IP address with a link to the user search.
  *
  * @param string $IP
  * @param string $CssClass
  * @return string
  */
 function ipAnchor($IP, $CssClass = '')
 {
     if ($IP) {
         return anchor(formatIP($IP), '/user/browse?keywords=' . urlencode(ipDecode($IP)), $CssClass);
     } else {
         return $IP;
     }
 }
Example #4
0
 /**
  * Recursively walk through all array elements or object properties and decode IP fields.
  *
  * @param array|object $input
  * @return array|object
  */
 function ipDecodeRecursive($input)
 {
     walkAllRecursive($input, function (&$val, $key = null, $parent = null) {
         if (is_string($val)) {
             if (stringEndsWith($key, 'IPAddress', true) || stringEndsWith($parent, 'IPAddresses', true)) {
                 $val = ipDecode($val);
             }
         }
     });
     return $input;
 }
Example #5
0
 /**
  * Add ban data to all Get requests.
  *
  * @since 2.0.18
  * @access public
  *
  * @param mixed User data (array or object).
  * @param Gdn_Validation $Validation
  * @param bool $UpdateBlocks
  * @return bool Whether user is banned.
  */
 public static function checkUser($User, $Validation = null, $UpdateBlocks = false, &$BansFound = null)
 {
     $Bans = self::AllBans();
     $Fields = array('Name' => 'Name', 'Email' => 'Email', 'IPAddress' => 'LastIPAddress');
     $Banned = array();
     if (!$BansFound) {
         $BansFound = array();
     }
     foreach ($Bans as $Ban) {
         // Convert ban to regex.
         $Parts = explode('*', str_replace('%', '*', $Ban['BanValue']));
         $Parts = array_map('preg_quote', $Parts);
         $Regex = '`^' . implode('.*', $Parts) . '$`i';
         $value = val($Fields[$Ban['BanType']], $User);
         if ($Ban['BanType'] === 'IPAddress') {
             $value = ipDecode($value);
         }
         if (preg_match($Regex, $value)) {
             $Banned[$Ban['BanType']] = true;
             $BansFound[] = $Ban;
             if ($UpdateBlocks) {
                 Gdn::sql()->update('Ban')->set('CountBlockedRegistrations', 'CountBlockedRegistrations + 1', false, false)->where('BanID', $Ban['BanID'])->put();
             }
         }
     }
     // Add the validation results.
     if ($Validation) {
         foreach ($Banned as $BanType => $Value) {
             $Validation->addValidationResult(Gdn_Form::LabelCode($BanType), 'ValidateBanned');
         }
     }
     return count($Banned) == 0;
 }