Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.0.8.2
- * @ Author : DeZender
- * @ Release on : 02.01.2019
- * @ Official site : http://DeZender.Net
- *
- */
- class AntiFlood
- {
- const OPTION_COUNTER_RESET_SECONDS = 'COUNTER_RESET_SECONDS';
- const OPTION_BAN_REMOVE_SECONDS = 'BAN_REMOVE_SECONDS';
- const OPTION_MAX_REQUESTS = 'MAX_REQUESTS';
- const OPTION_DATA_PATH = 'DATA_PATH';
- private $options;
- private $ip;
- public function __construct($overrideOptions = [])
- {
- $this->options = array_merge(['COUNTER_RESET_SECONDS' => 2, 'MAX_REQUESTS' => 5, 'BAN_REMOVE_SECONDS' => 60, 'DATA_PATH' => '/tmp/antiflood_' . str_replace(['www.', '.'], ['', '_'], $_SERVER['SERVER_NAME'])], $overrideOptions);
- @mkdir($this->options['DATA_PATH']);
- $this->ip = $_SERVER['REMOTE_ADDR'];
- }
- public function isBanned()
- {
- $controlLockFile = $this->options['DATA_PATH'] . '/' . str_replace('.', '_', $this->ip);
- if (file_exists($controlLockFile)) {
- if ($this->options['BAN_REMOVE_SECONDS'] < (time() - filemtime($controlLockFile))) {
- unlink($controlLockFile);
- }
- else {
- touch($controlLockFile);
- return true;
- }
- }
- $controlFile = $this->options['DATA_PATH'] . '/ctrl';
- $control = [];
- if (file_exists($controlFile)) {
- $fh = fopen($controlFile, 'r');
- $fileContentsArr = (0 < filesize($controlFile) ? json_decode(fread($fh, filesize($controlFile)), true) : []);
- $control = array_merge($control, $fileContentsArr);
- fclose($fh);
- }
- if (isset($control[$this->ip])) {
- if ((time() - $control[$this->ip]['t']) < $this->options['COUNTER_RESET_SECONDS']) {
- $control[$this->ip]['c']++;
- }
- else {
- $control[$this->ip]['c'] = 1;
- }
- }
- else {
- $control[$this->ip]['c'] = 1;
- }
- $control[$this->ip]['t'] = time();
- if ($this->options['MAX_REQUESTS'] < $control[$this->ip]['c']) {
- $fh = fopen($controlLockFile, 'w');
- fwrite($fh, '');
- fclose($fh);
- }
- $fh = fopen($controlFile, 'w');
- fwrite($fh, json_encode($control));
- fclose($fh);
- return false;
- }
- }
- class Signatures
- {
- static public function generateSignature($data)
- {
- return hash_hmac('sha256', $data, Constants::IG_SIG_KEY);
- }
- static public function signData($data, $exclude = [])
- {
- $result = [];
- foreach ($exclude as $key) {
- if (isset($data[$key])) {
- $result[$key] = $data[$key];
- unset($data[$key]);
- }
- }
- foreach ($data as &$value) {
- if (is_scalar($value)) {
- $value = (string) $value;
- }
- }
- unset($value);
- $data = json_encode((object) Utils::reorderByHashCode($data));
- $result['ig_sig_key_version'] = Constants::SIG_KEY_VERSION;
- $result['signed_body'] = self::generateSignature($data) . '.' . $data;
- return Utils::reorderByHashCode($result);
- }
- static public function generateDeviceId()
- {
- $megaRandomHash = md5(number_format(microtime(true), 7, '', ''));
- return 'android-' . substr($megaRandomHash, 16);
- }
- static public function generateUUID($keepDashes = true)
- {
- $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 4095) | 16384, mt_rand(0, 16383) | 32768, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
- return $keepDashes ? $uuid : str_replace('-', '', $uuid);
- }
- }
- class Utils
- {
- const BOUNDARY_CHARS = '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- const BOUNDARY_LENGTH = 30;
- static protected $_lastUploadId;
- static public function generateMultipartBoundary()
- {
- $result = '';
- $max = strlen('-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') - 1;
- for ($i = 0; $i < 30; ++$i) {
- $result .= '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'[mt_rand(0, $max)];
- }
- return $result;
- }
- static public function hashCode($string)
- {
- $result = 0;
- $len = strlen($string);
- for ($i = 0; $i < $len; ++$i) {
- $result = ((-1 * $result) + ($result << 5) + ord($string[$i])) & 4294967295.0;
- }
- if (4 < PHP_INT_SIZE) {
- if (2147483647 < $result) {
- $result -= 4294967296.0;
- }
- else if ($result < -2147483648.0) {
- $result += 4294967296.0;
- }
- }
- return $result;
- }
- static public function reorderByHashCode($data)
- {
- $hashCodes = [];
- foreach ($data as $key => $value) {
- $hashCodes[$key] = self::hashCode($key);
- }
- uksort($data, function($a, $b) use($hashCodes) {
- $a = $hashCodes[$a];
- $b = $hashCodes[$b];
- if ($a < $b) {
- return -1;
- }
- else if ($b < $a) {
- return 1;
- }
- else {
- return 0;
- }
- });
- return $data;
- }
- static public function generateUploadId($useNano = false)
- {
- $result = NULL;
- if (!$useNano) {
- while (true) {
- $result = number_format(round(microtime(true) * 1000), 0, '', '');
- if ((self::$_lastUploadId !== NULL) && ($result === self::$_lastUploadId)) {
- usleep(1000);
- continue;
- }
- self::$_lastUploadId = $result;
- break;
- }
- }
- else {
- $result = number_format(microtime(true) - strtotime('Last Monday'), 6, '', '');
- ................................................................
- ........................................
- ......................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement