<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
header("Content-type: application/json");
if(isset($_POST['ikdata'])){
if (!isset($_SESSION)) session_start();
$db=pDatabase::getInstance();
$datafungsi=[
	"login"=>"login"
];

if(!$db->ceckmodule($cl)) exit;
	$data=$_POST['ikdata'];
	$ex=false;
	if(isset($datafungsi[$data[0]])) $ex=$datafungsi[$data[0]]($data);
	echo $ex;
}else{
	echo false;
}
function login($data){
	$db=pDatabase::getInstance();
	
	$hasil=array("status"=>0,"url"=>"","pesan"=>"Terjadi Kesalahan");
	if(!isset($data['username'])){
		$hasil['pesan']="Username salah";
		return json_encode($hasil,true);
	}
	if(!isset($data['password'])){
		$hasil['pesan']="Password salah";
		return json_encode($hasil,true);
	}
	$method = "AES-128-CBC";
	$iv = '1244327671011121'; 
	$options=1;
	
	$keypass=substr(PRIVATE_KEY, 0,13);
	$datapost=array("username"=>$data['username'],"password"=>sha1($data['password']));
	$dataus=openssl_encrypt(json_encode($datapost,true),$method, $keypass,
                        $options, $iv);
    
	
	
	$hasil['url']=API_URL."loginkey?token=".PUBLIK_KEY."&data=".urlencode($dataus);
	$hasil['status']=2;
	return json_encode($hasil,true);
}


?>