<?php
error_reporting(0);

$db = new SQLite3('./.db.db');
$res = $db->query('SELECT * FROM dns'); 
$rows = array();
$rowsn = array();
$json_response = array(); 

function fancryEncrypt($input) {
    $main = bin2hex($input);
    $output = strrev($main);
    return $output;
} 

function generateRandomText($length) {
    $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $randomText = '';

    for ($i = 0; $i < $length; $i++) {
        $randomText .= $characters[rand(0, strlen($characters) - 1)];
    }

    return $randomText;
}

$default_record['name'] = 'Select server';
$default_record['url'] = '';
array_push($json_response, $default_record);

while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
    $row_array['name'] = $row['title']; 
    $row_array['url'] = $row['url']; 
    array_push($json_response, $row_array);  
}

header('Content-type: application/json; charset=UTF-8');

$final = json_encode($json_response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

$json = [
    "peterparker" => fancryEncrypt($final)
]; 

echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?>
