Guest User

Untitled

a guest
Sep 19th, 2013
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. <?php
  2.  
  3. function xAbort($message = "")
  4. {
  5. throw new Exception($message);
  6. }
  7.  
  8. function xSysInfo($message, $type = 0)
  9. {
  10. $_GS['info'][$type][] = $message;
  11. if ($type < 2) {
  12. } else {
  13. xAddToLog($message, "system");
  14. if ($type == 2) {
  15. xabort($message);
  16. }
  17. xStop($message);
  18. }
  19. }
  20.  
  21. function xSysWarning($message)
  22. {
  23. xsysinfo($message, 1);
  24. }
  25.  
  26. function xSysError($message)
  27. {
  28. xsysinfo($message, 2);
  29. }
  30.  
  31. function xSysStop($message, $and_refresh = false)
  32. {
  33. if ($and_refresh && !headers_sent()) {
  34. refreshToURL(5);
  35. }
  36. xsysinfo($message, 3);
  37. }
  38.  
  39. function xTerminal($is_debug = false)
  40. {
  41. global $_GS;
  42. if ($is_debug) {
  43. error_reporting(E_ALL);
  44. }
  45. ob_implicit_flush();
  46. header("Content-Type: text/plain; charset=\"utf-8\"");
  47. header("Pragma: no-cache");
  48. $_GS['as_term'] = true;
  49. }
  50.  
  51. function xEcho()
  52. {
  53. global $_GS;
  54. foreach (func_num_args() ? func_get_args() : array(
  55. "- - - - -"
  56. ) as $message) {
  57. if (is_array($message) || is_object($message)) {
  58. $message = print_r($message, true);
  59. }
  60. $message .= HS2_NL;
  61. if (!$_GS['as_term']) {
  62. $message = nl2br($message);
  63. }
  64. echo $message;
  65. }
  66. }
  67.  
  68. function xStop()
  69. {
  70. foreach (func_get_args() as $message) {
  71. xecho($message);
  72. }
  73. exit();
  74. }
  75.  
  76. function xAddToLog($message, $topic = "", $clear_before = false)
  77. {
  78. global $_GS;
  79. $fname = "logs/log_" . $topic . ".txt";
  80. if ($clear_before) {
  81. @unlink(@$fname);
  82. }
  83. clearstatcache();
  84. $t = file_exists($fname) ? filemtime(@$fname) : 0;
  85. if ($f = @fopen(@$fname, "a")) {
  86. $d = abs(time() - $t);
  87. if (10 <= $d) {
  88. @fwrite(@$f, @"- - - - - [" . @gmdate("d.m.y H:i:s") . (@@$d <= 120 ? " +{$d}" : "") . "] - - - - -" . @HS2_NL);
  89. }
  90. if (is_array($message) || is_object($message)) {
  91. $message = print_r($message, true);
  92. }
  93. @fwrite(@$f, @"<" . @$_GS['module'] . "> " . @$message . @HS2_NL);
  94. @fclose(@$f);
  95. }
  96. }
  97.  
  98. function getRootURL($as_HTTPS = false)
  99. {
  100. global $_GS;
  101. return ($as_HTTPS ? "https" : "http") . "://" . $_GS['domain'] . "/" . $_GS['root_dir'];
  102. }
  103.  
  104. function ss1Elem(&$s)
  105. {
  106. if (!is_array($s)) {
  107. $s = stripslashes($s);
  108. } else {
  109. foreach ($s as $i => $v) {
  110. ss1Elem($s[$i]);
  111. }
  112. }
  113. }
  114.  
  115. function fromGPC($s)
  116. {
  117. if (!is_null($s)) {
  118. if (get_magic_quotes_gpc()) {
  119. ss1elem(&$s);
  120. }
  121. mTrim($s);
  122. }
  123. return $s;
  124. }
  125.  
  126. function filterInput($s, $mask = "")
  127. {
  128. if (is_null($s) || !$mask) {
  129. return $s;
  130. }
  131. if ($mask == "*") {
  132. return strip_tags($s);
  133. }
  134. preg_match("/^" . $mask . "$/", $s, $a);
  135. return $a[0];
  136. }
  137.  
  138. function _arr_val(&$arr, $p)
  139. {
  140. if (!isset($arr)) {
  141. return NULL;
  142. }
  143. if (preg_match("/(.+)\\[(.*)\\]/", $p, $a)) {
  144. return _arr_val($arr[$a[1]], $a[2]);
  145. }
  146. return $arr[$p];
  147. }
  148.  
  149. function isset_IN($p = "btn")
  150. {
  151. global $_IN;
  152. return !is_null(_arr_val(&$_IN, $p));
  153. }
  154.  
  155. function _IN($p, $mask = "")
  156. {
  157. global $_IN;
  158. return filterinput(_arr_val(&$_IN, $p), $mask);
  159. }
  160.  
  161. function _COOKIE($p, $mask = "")
  162. {
  163. return isset($_COOKIE[$p]) ? filterinput(fromgpc($_COOKIE[$p]), $mask) : NULL;
  164. }
  165.  
  166. function _GET($p, $mask = "")
  167. {
  168. return isset($_GET[$p]) ? filterinput(fromgpc($_GET[$p]), $mask) : NULL;
  169. }
  170.  
  171. function _POST($p, $mask = "")
  172. {
  173. return isset($_POST[$p]) ? filterinput(fromgpc($_POST[$p]), $mask) : NULL;
  174. }
  175.  
  176. function isset_RQ($p)
  177. {
  178. $_RQ = $_GET + $_POST;
  179. return !is_null(_arr_val(&$_RQ, $p));
  180. }
  181.  
  182. function _RQ($p, $mask = "")
  183. {
  184. $_RQ = $_GET + $_POST;
  185. return filterinput(fromgpc(_arr_val(&$_RQ, $p)), $mask);
  186. }
  187.  
  188. function _SESSION($p)
  189. {
  190. return isset($_SESSION[$p]) ? $_SESSION[$p] : NULL;
  191. }
  192.  
  193. function _INN($p)
  194. {
  195. return intval(_in($p));
  196. }
  197.  
  198. function _COOKIEN($p)
  199. {
  200. return intval(@$_COOKIE[$p]);
  201. }
  202.  
  203. function _GETN($p)
  204. {
  205. return intval(@$_GET[$p]);
  206. }
  207.  
  208. function _POSTN($p)
  209. {
  210. return intval(@$_POST[$p]);
  211. }
  212.  
  213. function _RQN($p)
  214. {
  215. return intval(_rq($p));
  216. }
  217.  
  218. function validMail($s)
  219. {
  220. $mask = "|^.+@.+\\..+$|";
  221. return preg_match($mask, textLow($s));
  222. }
  223.  
  224. function validURL($s)
  225. {
  226. $mask = "|^https?:\\/\\/.+\\..+$|i";
  227. return preg_match($mask, textLow($s));
  228. }
  229.  
  230. function getDomain($s)
  231. {
  232. $mask = "|^(?:https?:\\/\\/)?(?:www\\.)?([^\\/]+)|i";
  233. preg_match($mask, textLow($s), $a);
  234. return $a[1];
  235. }
  236.  
  237. function validDomain($s)
  238. {
  239. return preg_match("|.+\\..+$|", $s);
  240. }
  241.  
  242. function valid_filename($f)
  243. {
  244. return !sEmpty($f) && $f != "." && $f != ".." && textPos("/", $f) < 0 && textPos(chr(0), $f) < 0;
  245. }
  246.  
  247. function compare_ip($ip1, $ip2, $level = 4)
  248. {
  249. $ip1 = explode(".", $ip1);
  250. $ip2 = explode(".", $ip2);
  251. $i = 0;
  252. while ($i <= $level - 1) {
  253. if ($ip1[$i] != $ip2[$i]) {
  254. return false;
  255. }
  256. ++$i;
  257. }
  258. return true;
  259. }
  260.  
  261. function numInRange($z, $a, $b)
  262. {
  263. return $a <= $z && $z <= $b;
  264. }
  265.  
  266. function numRange($z, $a, $b)
  267. {
  268. if ($z < $a) {
  269. $z = $a;
  270. } else if ($b < $z) {
  271. $z = $b;
  272. }
  273. return $z;
  274. }
  275.  
  276. function calcPerc($sum, $perc, $r = 2)
  277. {
  278. return round($sum * $perc / 100, $r);
  279. }
  280.  
  281. function idArrayCreate($arr, $fld = 0)
  282. {
  283. $res = array();
  284. foreach ($arr as $r) {
  285. $res[$r[$fld]] = $r;
  286. }
  287. return $res;
  288. }
  289.  
  290. function idArrayFind($arr, $fld, $value)
  291. {
  292. foreach ($arr as $i => $r) {
  293. if ($r[$fld] == $value) {
  294. return $i;
  295. break;
  296. }
  297. }
  298. return NULL;
  299. }
  300.  
  301. function idArraySum($arr, $fld)
  302. {
  303. $z = 0;
  304. foreach ($arr as $r) {
  305. $z += $r[$fld];
  306. }
  307. return $z;
  308. }
  309.  
  310. function asArray($a, $dlm = ",", $skip_empty = true)
  311. {
  312. if (is_array($a)) {
  313. return $a;
  314. }
  315. $r = array();
  316. foreach (explode($dlm, $a) as $v) {
  317. $v = trim($v);
  318. if (!$skip_empty || !sEmpty($v)) {
  319. $r[] = $v;
  320. }
  321. }
  322. return $r;
  323. }
  324.  
  325. function asStr($s, $dlm = ",")
  326. {
  327. if (!is_array($s)) {
  328. return $s;
  329. }
  330. return strval(@implode(@$dlm, @$s));
  331. }
  332.  
  333. function arrayToStr($a)
  334. {
  335. if (is_array($a)) {
  336. return serialize($a);
  337. }
  338. return $a;
  339. }
  340.  
  341. function strToArray($s)
  342. {
  343. if (is_array($a = @unserialize(@$s))) {
  344. return $a;
  345. }
  346. return array();
  347. }
  348.  
  349. function encodeArrayToStr($arr, $key)
  350. {
  351. return encode1(arraytostr($arr), $key, true, ord($key) % 8);
  352. }
  353.  
  354. function decodeArrayFromStr($s, $key)
  355. {
  356. return strtoarray(decode1($s, $key, true, ord($key) % 8));
  357. }
  358.  
  359. function fullURL($url = "*", $as_HTTPS = -1)
  360. {
  361. global $_GS;
  362. $url = trim($url);
  363. if ($url == "*") {
  364. $url = $_GS['uri'];
  365. } else {
  366. $url = get1ElemL($url, "\n");
  367. }
  368. if (!validurl($url)) {
  369. if ($as_HTTPS === 0 - 1) {
  370. $as_HTTPS = $_GS['https'];
  371. }
  372. $url = getrooturl($as_HTTPS) . $url;
  373. }
  374. return $url;
  375. }
  376.  
  377. function goToURL($url = "*", $work_after = 0)
  378. {
  379. if (1 < abs(chklic() - time())) {
  380. exit();
  381. }
  382. $url = fullurl($url);
  383. session_commit();
  384. session_start();
  385. session_regenerate_id();
  386. header("Location: {$url}");
  387. $work_after = intval($work_after);
  388. if ($work_after < 1) {
  389. exit();
  390. }
  391. @ignore_user_abort(1);
  392. @set_time_limit(@$work_after);
  393. header("Connection: close");
  394. header("Content-Length: 0");
  395. ob_end_clean();
  396. ob_end_flush();
  397. flush();
  398. }
  399.  
  400. function refreshToURL($t = 0, $url = "*")
  401. {
  402. if ($t < 1) {
  403. $t = 1;
  404. }
  405. $url = fullurl($url);
  406. session_commit();
  407. session_start();
  408. session_regenerate_id();
  409. header("Refresh: {$t}; URL={$url}");
  410. }
  411.  
  412. function timeToStamp($t = "*")
  413. {
  414. if ("" === $t) {
  415. return "";
  416. }
  417. if ("*" === $t) {
  418. $t = time();
  419. }
  420. return gmdate("YmdHis", $t);
  421. }
  422.  
  423. function stampToTime($p)
  424. {
  425. if (empty($p)) {
  426. return NULL;
  427. }
  428. $p = str_pad($p, 14, "0", STR_PAD_LEFT);
  429. return gmmktime(@substr(@$p, 8, 2), @substr(@$p, 10, 2), @substr(@$p, 12, 2), @substr(@$p, 4, 2), @substr(@$p, 6, 2), @substr(@$p, 0, 4));
  430. }
  431.  
  432. function subStamps($p1, $p2 = -1)
  433. {
  434. $t1 = stamptotime($p1);
  435. if ($p2 < 0) {
  436. $t2 = $t1;
  437. $t1 = time();
  438. } else {
  439. $t2 = stamptotime($p2);
  440. }
  441. return $t1 - $t2;
  442. }
  443.  
  444. function encode1($text, $pass, $as_hex = true, $dl = 0)
  445. {
  446. $text = strval(base64_encode($text));
  447. $pass = mb_strtoupper(md5($pass . mb_strlen($text)));
  448. $code = "";
  449. $n = $dl;
  450. $i = 0;
  451. while ($i < mb_strlen($text)) {
  452. if (mb_strlen($pass) - $dl <= $n) {
  453. $n = 0;
  454. }
  455. $c = ord($text[$i]) ^ ord($pass[$n]);
  456. $code .= $as_hex ? sprintf("%02x", $c) : chr($c);
  457. ++$n;
  458. ++$i;
  459. }
  460. if (!$as_hex) {
  461. $code = base64_encode($code);
  462. }
  463. return $code;
  464. }
  465.  
  466. function decode1($code, $pass, $as_hex = true, $dl = 0)
  467. {
  468. if (!$as_hex) {
  469. $code = base64_decode($code);
  470. }
  471. $pass = mb_strtoupper(md5($pass . (mb_strlen($code) >> $as_hex)));
  472. $text = "";
  473. $n = $dl;
  474. $i = 0;
  475. while ($i < mb_strlen($code)) {
  476. if (mb_strlen($pass) - $dl <= $n) {
  477. $n = 0;
  478. }
  479. if ($as_hex) {
  480. $c = hexdec(mb_substr($code, $i, 2));
  481. } else {
  482. $c = ord($code[$i]);
  483. }
  484. $text .= chr($c ^ ord($pass[$n]));
  485. ++$n;
  486. $i += 1 + $as_hex;
  487. }
  488. return base64_decode($text);
  489. }
  490.  
  491. function chkLic($n = 1)
  492. {
  493. global $_GS;
  494. if (rand(1, $n) == 1) {
  495. $l = trim(@file_get_contents(@$_GS['domain'] . ".lic"));
  496. if ($l !== md5("AGLSoft(C)h-script3|" . $_GS['domain'])) {
  497. xstop("No license");
  498. }
  499. }
  500. return time();
  501. }
  502.  
  503. error_reporting(7);
  504. define("HS2_BR", "<br />");
  505. define("HS2_NL", "\r\n");
  506. define("HS2_UNIX_SECOND", 1);
  507. define("HS2_UNIX_MINUTE", 60);
  508. define("HS2_UNIX_HOUR", 60 * HS2_UNIX_MINUTE);
  509. define("HS2_UNIX_DAY", 24 * HS2_UNIX_HOUR);
  510. global $_GS;
  511. $_GS = array();
  512. $_GS['info'] = array();
  513. require_once("lib/sutils.php");
  514. require_once("lib/mail.php");
  515. $_GS['domain'] = preg_replace("|^(www\\.)|i", "", $_SERVER['SERVER_NAME']);
  516. $s = $_GS['domain'];
  517. cutElemR($s, ".");
  518. cutElemR($s, ".");
  519. $_GS['subdomain'] = $s;
  520. $s = $_SERVER['SCRIPT_NAME'];
  521. $_GS['script'] = cutElemR($s, "/");
  522. $_GS['root_dir'] = $s ? substr($s, 1) . "/" : "";
  523. $s = $_GS['script'];
  524. cutElemR($s, ".");
  525. $_GS['module'] = strtolower($s);
  526. $_GS['https'] = $_SERVER['SERVER_PORT'] == 443;
  527. $_GS['root_url'] = getrooturl($_GS['https']);
  528. $s = $_SERVER['REQUEST_URI'];
  529. cutElemL($s, "/" . $_GS['root_dir']);
  530. $_GS['uri'] = $s;
  531. $_GS['server_ip'] = $_SERVER['SERVER_ADDR'];
  532. $_GS['client_ip'] = $_SERVER['REMOTE_ADDR'];
  533. $_GS['is_local'] = substr($_GS['server_ip'], 0, 0 - 1) == "127.0.0.";
  534. $_GS['is_self'] = $_GS['client_ip'] == $_GS['server_ip'];
  535. $_GS['lang'] = "";
  536. $_GS['mode'] = "";
  537. $_GS['theme'] = "";
  538. $_GS['default_lang'] = "en";
  539. $_GS['TZ'] = 0;
  540. $_GS['site_name'] = "";
  541. global $_IN;
  542. $_IN = fromGPC($_POST);
  543. if (1 < abs(chklic() - time())) {
  544. exit();
  545. }
  546. ?>
Add Comment
Please, Sign In to add comment