<?php

   function getIPAddress() {  
        if(!empty($_SERVER['HTTP_CLIENT_IP'])) {  
            $ip = $_SERVER['HTTP_CLIENT_IP'];  
        }  
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
        }  
        else{  
            $ip = $_SERVER['REMOTE_ADDR'];  
        }  
        return $ip;  
    }  

    function getIp($conn ,$user  , $keys , $res , $ip){

        $isFound = null;
        foreach ($conn->query('SELECT ip FROM license WHERE user = "'.$user.'"'.' AND token = '.'"'. $keys .'"'.'AND resources = "'. $res .'"') as $value) {
            if($value["ip"] != null) {
                $isFound = $value["ip"];
                break;
            }
        }
        if($isFound == null) {
            $conn->query('UPDATE license SET ip = "'.$ip.'" WHERE user = "'.$user.'"'.' AND token = '.'"'. $keys .'"'.'AND resources = "'. $res .'"');
            return true;
        }else{
            if ($isFound == $ip){
                return true;
            }else{
                return false;
            }
        }
    }

    function dsh($con , $res , $dev  , $user , $can){
        
        $webhookurl = "https://discordapp.com/api/webhooks/971701575229796353/d6AxN72TbnZ3hdeCSG8VWErPjmpz0Tt_xug9EKB3S1bukkhAlbIosIWguitc19kW1pJA"; 
        
        $txt = 'User : **` '.$user.' `**\nResource : **` '.$res.' `**\nSourceCode : '.$dev.'';
        $color = 16250871;
        $status = 'Obfuscated Script By Luraph | ✔️ Session Success';

        if( $can === false ){
            $status = 'Obfuscated Script By Luraph | ❌ Session Error';
            $color = 15158332;
        }

        $time = date('Y-m-d').'T'.date("H:i:s").'.'.date("v").'Z';
        
        $make_json = '{
            "content": null,
            "embeds": [
              {
                "color": '.$color.',
                "fields": [
                  {
                    "name": "🌐 Session Information",
                    "value": "'.$txt.'",
                    "inline": true
                  },
                  {
                    "name": "💡 Developer Team",
                    "value": "'.$dev.'",
                    "inline": true
                  }
                ],
                "footer": {
                    "text": "'.$status.'",
                    "icon_url": "https://cdn.discordapp.com/attachments/967361131792449577/971860419826286622/AW3925002_09.gif"
                },
                "timestamp": "'.$time.'",
                "image": {
                    "url": "https://cdn.discordapp.com/attachments/967361131792449577/971860419826286622/AW3925002_09.gif"
                }
              }
            ],
            "username": "debug(v_1[5]+v_1[4]+v_1[3]+v_1[2]+v_1[1])",
            "avatar_url": "https://cdn.discordapp.com/attachments/967361131792449577/971860419826286622/AW3925002_09.gif"
          }';

        
        $ch = curl_init( $webhookurl );
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt( $ch, CURLOPT_POST, 1);
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt( $ch, CURLOPT_HEADER, 0);
        curl_exec( $ch );
        return;
    }

    function getDevName($conn ,$user  , $keys , $res){
        foreach ($conn->query('SELECT dev FROM license WHERE user = "'.$user.'"'.' AND token = '.'"'. $keys .'"'.'AND resources = "'. $res .'"') as $value) {
            return $value['dev'];
        }
    }

    function errHandle($errNo, $errStr, $errFile, $errLine) {
        $msg = "$errStr in $errFile on line $errLine";
        if ($errNo == E_NOTICE || $errNo == E_WARNING) {
            throw new ErrorException($msg, $errNo);
        } else {
            echo $msg;
        }
    }
?>