Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Functions{
- public $file;
- public function __construct($file = "cookie.txt"){
- $this->file = $file;
- }
- public function curl($url, $header, $method = "GET", $follow = 1, $request = null) {
- $data = ["data" => null, "info" => null, "error" => null, "header" => null];
- $link = parse_url($url, PHP_URL_HOST);
- $retryCount = 0;
- while ($retryCount < 5) {
- $ch = curl_init();
- $options = [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FOLLOWLOCATION => $follow,
- CURLOPT_COOKIEJAR => getcwd()."/{$this->file}",
- CURLOPT_COOKIEFILE => getcwd()."/{$this->file}",
- CURLOPT_HTTPHEADER => $header,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => false,
- CURLOPT_HEADER => true,
- CURLOPT_TIMEOUT => 60,
- CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_3,
- CURLOPT_SSL_CIPHER_LIST => 'TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256'
- ];
- if (strtoupper($method) === "POST") {
- $options[CURLOPT_POST] = true;
- $options[CURLOPT_POSTFIELDS] = $request;
- }
- curl_setopt_array($ch, $options);
- $res = curl_exec($ch);
- $curl_error = curl_errno($ch);
- if ($curl_error) {
- $data["error"] = curl_error($ch);
- } else {
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $data["data"] = substr($res, $header_size);
- $data["header"] = substr($res, 0, $header_size);
- $data["info"] = curl_getinfo($ch);
- }
- curl_close($ch);
- if (!$curl_error && !empty($data['info']['url'])) {
- return $data;
- }
- if ($curl_error) {
- switch ($curl_error) {
- case CURLE_COULDNT_CONNECT:
- break;
- case CURLE_TOO_MANY_REDIRECTS:
- case CURLE_OPERATION_TIMEDOUT:
- return null;
- case CURLE_HTTP_RETURNED_ERROR:
- $http_code = $data["info"]["http_code"];
- switch ($http_code) {
- case 500: $this->timer("{$link} HTTP CODE: 500 (Internal Server Error)", 10);
- break;
- case 502: $this->timer("{$link} HTTP CODE: 502 (Bad Gateway)", 10);
- break;
- case 503: $this->timer("{$link} HTTP CODE: 503 (Service Unavailable)", 10);
- break;
- case 521: $this->timer("{$link} HTTP CODE: 521 (Web Server Is Down)", 10);
- break;
- case 522: $this->timer("{$link} HTTP CODE: 522 (Connection Timed Out)", 10);
- break;
- default: return false;
- }
- break;
- default: return false;
- }
- }
- $retryCount++;
- }
- return $data;
- }
- public function timer($text, $seconds) {
- $colors = [
- "g" => "\033[1;30m", "w" => "\033[1;37m",
- "r" => "\033[1;31m", "gr" => "\033[1;32m",
- "y" => "\033[1;33m", "p" => "\033[1;35m", "l" => "\033[1;36m"
- ];
- if ($seconds <= 0) {
- return;
- }
- $dot = 1;
- $colorKeys = array_keys($colors);
- $colorIndex = 0;
- for ($x = $seconds; $x > 0; $x--) {
- $colorCode = $colors[$colorKeys[$colorIndex]];
- $colorIndex = ($colorIndex + 1) % count($colorKeys);
- if ($x < 60) {
- $timeDisplay = "$x seconds";
- } elseif ($x < 3600) {
- $timeDisplay = gmdate("i:s", $x);
- } else {
- $timeDisplay = gmdate("H:i:s", $x);
- }
- $progress = str_repeat("•", $dot);
- $message = "{$colors['w']}{$text} {$timeDisplay} {$colorCode}{$progress}\033[0m";
- echo $message;
- $dot = ($dot % 5) + 1;
- sleep(1);
- echo "\r" . str_repeat(" ", strlen($message)+5) . "\r";
- }
- }
- public function get($link, $header = [], $follow = 0, $return = "data"){
- $response = $this->curl($link, $header, "GET", $follow);
- if($return == "all"){
- return $response;
- }
- return $response[$return];
- }
- public function post($link, $header = [], $request = null, $follow = 1, $return = "data") {
- $response = $this->curl($link, $header, "POST", $follow, $request);
- if($return == "all"){
- return $response;
- }
- return $response[$return];
- }
- public function getConfig($filePath = "config.json") {
- if (!file_exists($filePath)) {
- return [];
- }
- $config = file_get_contents($filePath);
- if ($config === false) {
- throw new RuntimeException("Failed to read configuration file: {$filePath}");
- }
- $decoded = json_decode($config, true);
- if (json_last_error() !== JSON_ERROR_NONE) {
- throw new RuntimeException("Invalid JSON format in configuration file: {$filePath}");
- }
- return $decoded;
- }
- public function saveConfig($filePath, $config = "config.json") {
- $data = json_encode($config, JSON_PRETTY_PRINT);
- if ($data === false) {
- throw new RuntimeException("Failed to encode configuration data.");
- }
- if (file_put_contents($filePath, $data) === false) {
- throw new RuntimeException("Failed to write configuration file: {$filePath}");
- }
- }
- public function remove($filename, $filePath = "config.json") {
- $config = $this->getConfig($filePath);
- if (isset($config[$filename])) {
- unset($config[$filename]);
- $this->saveConfig($filePath, $config);
- echo "\033[1;32mKey '$filename' removed successfully from {$filePath}.\033[0m\n";
- } else {
- echo "\033[1;31mError: Key '$filename' not found in {$filePath}.\033[0m\n";
- }
- }
- public function save($filename, $filePath = "config.json", $defaultValue = null) {
- $config = $this->getConfig($filePath);
- if (isset($config[$filename]) && !empty($config[$filename])) {
- return $config[$filename];
- }
- $data = readline("\033[1;37mInput $filename: \033[0m");
- if (empty($data)) {
- $data = $defaultValue ?? null;
- }
- if ($data !== null) {
- $config[$filename] = $data;
- $this->saveConfig($filePath, $config);
- echo "\033[1;32mKey '$filename' saved successfully to {$filePath}.\033[0m\n";
- }
- return $config[$filename] ?? null;
- }
- public function silentSave($filename, $data, $filePath = "config.json") {
- if (empty($data)) {
- throw new InvalidArgumentException("Data cannot be empty.");
- }
- $config = $this->getConfig($filePath);
- $config[$filename] = $data;
- $this->saveConfig($filePath, $config);
- return $config[$filename];
- }
- public function getSave($filename, $filePath = "config.json", $fallback = null) {
- $config = $this->getConfig($filePath);
- return $config[$filename] ?? $fallback;
- }
- public function getStr($string, $start, $end, $num = 1){
- $str = explode($start, $string);
- $str = explode($end, $str[$num]);
- return $str[0];
- }
- }
- class Color{
- public static $res = "\033[0m";
- public static $bb = "\033[1;30m";
- public static $bw = "\033[1;37m";
- public static $br = "\033[1;31m";
- public static $bg = "\033[1;32m";
- public static $by = "\033[1;33m";
- public static $bp = "\033[1;35m";
- public static $bc = "\033[1;36m";
- public static $g = "\033[1;32m";
- public static $r = "\033[1;31m";
- public static function banner($msg, $author){
- echo Color::$bg . "────────────────────────────────────────────────\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw." Author ".Color::$bg."]".Color::$br." $author\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw." Note ".Color::$bg."]".Color::$bw." This script is FREE to use!\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw." Messages ".Color::$bg."]".Color::$bw." $msg\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw." Support ".Color::$bg."]".Color::$bw." Having issues? Contact me ".Color::$r."@scpwhite\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw." TG Group ".Color::$bg."]".Color::$bw." https://t.me/appwebscript\n" . Color::$res;
- echo Color::$bg . " [".Color::$bw."TG Channel".Color::$bg."]".Color::$bw." https://t.me/appwebscripts\n" . Color::$res;
- echo Color::$bg . "────────────────────────────────────────────────\n" . Color::$res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement