<?php
include(__DIR__ . '/../includes/functions.php');
$ret = $db->select('vpn', '*', 'file_name = :file_name', '', [':file_name' => hex2bin($_GET['name'])]);

$settings = $db->select('credentials', '*', 'id = :id', '', [':id' => 1]);

$type = $settings[0]['type'] ?? 'hide';
$visible = $settings[0]['visibal']?? 'onlypass';



getcredentials($ret,$type,$visible);

		

function getcredentials($dbdata, $mType ,$mVisible){
	$filename = $dbdata[0]['file_name'] ?? 'empty';
	$username = $dbdata[0]['username'] ?? 'empty';
	$password = $dbdata[0]['password'] ?? 'empty';
	
	
	if($filename == "empty"){
	    output("empty","empty","error","empty","empty");
	}else{
	    output($username,$password,"ok",$mType,$mVisible);
	}

	
}

function output($uname,$pass,$type,$gType,$gVisible) {
    $response;
    
    if($type == "error"){
        $response = [ "status" => "Not found vpn credentials","username" => $uname , "password" => $pass,"connecttype" => $gType, "visibility" => $gVisible];
    }else{
        $response = [ "status" => "ok","username" => $uname , "password" => $pass,"connecttype" => $gType, "visibility" => $gVisible];
    }
    
    
	header('Content-type: application/json; charset=UTF-8');
	echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
    
?>