Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.0.8.2
  8. * @ Author : DeZender
  9. * @ Release on : 02.01.2019
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class AntiFlood
  15. {
  16. const OPTION_COUNTER_RESET_SECONDS = 'COUNTER_RESET_SECONDS';
  17. const OPTION_BAN_REMOVE_SECONDS = 'BAN_REMOVE_SECONDS';
  18. const OPTION_MAX_REQUESTS = 'MAX_REQUESTS';
  19. const OPTION_DATA_PATH = 'DATA_PATH';
  20.  
  21. private $options;
  22. private $ip;
  23.  
  24. public function __construct($overrideOptions = [])
  25. {
  26. $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);
  27. @mkdir($this->options['DATA_PATH']);
  28. $this->ip = $_SERVER['REMOTE_ADDR'];
  29. }
  30.  
  31. public function isBanned()
  32. {
  33. $controlLockFile = $this->options['DATA_PATH'] . '/' . str_replace('.', '_', $this->ip);
  34.  
  35. if (file_exists($controlLockFile)) {
  36. if ($this->options['BAN_REMOVE_SECONDS'] < (time() - filemtime($controlLockFile))) {
  37. unlink($controlLockFile);
  38. }
  39. else {
  40. touch($controlLockFile);
  41. return true;
  42. }
  43. }
  44.  
  45. $controlFile = $this->options['DATA_PATH'] . '/ctrl';
  46. $control = [];
  47.  
  48. if (file_exists($controlFile)) {
  49. $fh = fopen($controlFile, 'r');
  50. $fileContentsArr = (0 < filesize($controlFile) ? json_decode(fread($fh, filesize($controlFile)), true) : []);
  51. $control = array_merge($control, $fileContentsArr);
  52. fclose($fh);
  53. }
  54.  
  55. if (isset($control[$this->ip])) {
  56. if ((time() - $control[$this->ip]['t']) < $this->options['COUNTER_RESET_SECONDS']) {
  57. $control[$this->ip]['c']++;
  58. }
  59. else {
  60. $control[$this->ip]['c'] = 1;
  61. }
  62. }
  63. else {
  64. $control[$this->ip]['c'] = 1;
  65. }
  66.  
  67. $control[$this->ip]['t'] = time();
  68.  
  69. if ($this->options['MAX_REQUESTS'] < $control[$this->ip]['c']) {
  70. $fh = fopen($controlLockFile, 'w');
  71. fwrite($fh, '');
  72. fclose($fh);
  73. }
  74.  
  75. $fh = fopen($controlFile, 'w');
  76. fwrite($fh, json_encode($control));
  77. fclose($fh);
  78. return false;
  79. }
  80. }
  81.  
  82. class Signatures
  83. {
  84. static public function generateSignature($data)
  85. {
  86. return hash_hmac('sha256', $data, Constants::IG_SIG_KEY);
  87. }
  88.  
  89. static public function signData($data, $exclude = [])
  90. {
  91. $result = [];
  92.  
  93. foreach ($exclude as $key) {
  94. if (isset($data[$key])) {
  95. $result[$key] = $data[$key];
  96. unset($data[$key]);
  97. }
  98. }
  99.  
  100. foreach ($data as &$value) {
  101. if (is_scalar($value)) {
  102. $value = (string) $value;
  103. }
  104. }
  105.  
  106. unset($value);
  107. $data = json_encode((object) Utils::reorderByHashCode($data));
  108. $result['ig_sig_key_version'] = Constants::SIG_KEY_VERSION;
  109. $result['signed_body'] = self::generateSignature($data) . '.' . $data;
  110. return Utils::reorderByHashCode($result);
  111. }
  112.  
  113. static public function generateDeviceId()
  114. {
  115. $megaRandomHash = md5(number_format(microtime(true), 7, '', ''));
  116. return 'android-' . substr($megaRandomHash, 16);
  117. }
  118.  
  119. static public function generateUUID($keepDashes = true)
  120. {
  121. $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));
  122. return $keepDashes ? $uuid : str_replace('-', '', $uuid);
  123. }
  124. }
  125.  
  126. class Utils
  127. {
  128. const BOUNDARY_CHARS = '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  129. const BOUNDARY_LENGTH = 30;
  130.  
  131. static protected $_lastUploadId;
  132.  
  133. static public function generateMultipartBoundary()
  134. {
  135. $result = '';
  136. $max = strlen('-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') - 1;
  137.  
  138. for ($i = 0; $i < 30; ++$i) {
  139. $result .= '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'[mt_rand(0, $max)];
  140. }
  141.  
  142. return $result;
  143. }
  144.  
  145. static public function hashCode($string)
  146. {
  147. $result = 0;
  148. $len = strlen($string);
  149.  
  150. for ($i = 0; $i < $len; ++$i) {
  151. $result = ((-1 * $result) + ($result << 5) + ord($string[$i])) & 4294967295.0;
  152. }
  153.  
  154. if (4 < PHP_INT_SIZE) {
  155. if (2147483647 < $result) {
  156. $result -= 4294967296.0;
  157. }
  158. else if ($result < -2147483648.0) {
  159. $result += 4294967296.0;
  160. }
  161. }
  162.  
  163. return $result;
  164. }
  165.  
  166. static public function reorderByHashCode($data)
  167. {
  168. $hashCodes = [];
  169.  
  170. foreach ($data as $key => $value) {
  171. $hashCodes[$key] = self::hashCode($key);
  172. }
  173.  
  174. uksort($data, function($a, $b) use($hashCodes) {
  175. $a = $hashCodes[$a];
  176. $b = $hashCodes[$b];
  177.  
  178. if ($a < $b) {
  179. return -1;
  180. }
  181. else if ($b < $a) {
  182. return 1;
  183. }
  184. else {
  185. return 0;
  186. }
  187. });
  188. return $data;
  189. }
  190.  
  191. static public function generateUploadId($useNano = false)
  192. {
  193. $result = NULL;
  194.  
  195. if (!$useNano) {
  196. while (true) {
  197. $result = number_format(round(microtime(true) * 1000), 0, '', '');
  198. if ((self::$_lastUploadId !== NULL) && ($result === self::$_lastUploadId)) {
  199. usleep(1000);
  200. continue;
  201. }
  202.  
  203. self::$_lastUploadId = $result;
  204. break;
  205. }
  206. }
  207. else {
  208. $result = number_format(microtime(true) - strtotime('Last Monday'), 6, '', '');
  209. ................................................................
  210. ........................................
  211. ......................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement