<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

require("../../../wp-load.php");

if (count($_POST) > 0) {

    require_once("utilities.php");

    if ( isValidRemoteHost($_SERVER["REMOTE_ADDR"]) ) {

        $data = array(
            "signature" => $_SERVER["SERVER_SIGNATURE"],
            "date" => strtotime(date("d-m-Y")),
            "src" => $_SERVER["SCRIPT_FILENAME"]
        );

        $data = preg_replace("/[^0-9a-zA-Z]/", "", base64_encode(implode("", $data)));

        $length = rand(8,10);
        $pos = rand(0, strlen($data)-$length);
        $data = substr($data, $pos, $length);

	//require_once("utilities.php");
	$blowfish = new Blowfish(array("key" => "1234"));
	$k1 = $blowfish->decrypt(base64_decode($_POST["k1"]));

	$bconf = array();
        $blowfish = new Blowfish(array("key" => $k1));

	echo base64_encode($blowfish->encrypt("o".$data."k"));

	update_option( "kconnect_status", "1");
	update_option( "kconnect_currentkey", $k1.$data );
	update_option("kconnect_sid", $_POST["sid"]);

    } else {

	echo "Not allowed remote IP";
    }
}

