<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ServersController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
//        $curl = curl_init();
//
//        curl_setopt_array($curl, array(
//            CURLOPT_URL => 'https://api.timeweb.cloud/api/v1/servers',
//            CURLOPT_RETURNTRANSFER => true,
//            CURLOPT_ENCODING => '',
//            CURLOPT_MAXREDIRS => 10,
//            CURLOPT_TIMEOUT => 0,
//            CURLOPT_FOLLOWLOCATION => true,
//            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//            CURLOPT_CUSTOMREQUEST => 'POST',
//            CURLOPT_POSTFIELDS =>'{
//  "is_ddos_guard": true,
//  "name": "name",
//  "bandwidth": 200,
//  "configuration": {
//    "configurator_id": 11,
//    "disk": 15360,
//    "cpu": 1,
//    "ram": 2048
//  },
//  "image_id":"1e08c363-c52b-46fe-a855-3de37ed3c117",
//  "avatar_id": "avatar",
//  "comment": "comment",
//  "is_local_network": false
//}',
//            CURLOPT_HTTPHEADER => array(
//                'Content-Type: application/json',
//                'Accept: application/json',
//                'Authorization: Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6IjFrYnhacFJNQGJSI0tSbE1xS1lqIn0.eyJ1c2VyIjoiYXJldnlhbjI0NiIsInR5cGUiOiJhcGlfa2V5IiwicG9ydGFsX3Rva2VuIjoiNjM5MGM0ZTktYjA3Ni00MzgyLTk1YTUtZGNmYjRjMWIyOWEwIiwiYXBpX2tleV9pZCI6Ijg0NTkxY2E5LTU5M2UtNDlmZi1iZTE0LTgzNmU1YTU0MGM5MCIsImlhdCI6MTY4MDUxNDE5NiwiZXhwIjoxNjg4MjkwMTk3fQ.AyzXWF0inIpC9GYZsW1xIxsnNVL7UmIbIkqVSXpsfwM5ZdWrz3x8C6QETeF14ZQiIwT8og747_NnKrg3spF8IcMsr8vcHkgSgYA50wq423h_HN3uoBZr_357yH8fTeBwmLTQO4RjomSscHmOJO0L-LXqw2xcfT87YeeQj-q4ztfTXMEh611buc15BubBrQktokv_lHEMG3VDEWZQBR757aicRQIzeSUYcng32MWlPbHzG6RY8_SPEB9oGZax9hdfVS95_r230w2b-bxxY_3A9goijU210jjiXbNRjppkErnzuqtKuZjebSChK6mprLGHRWjsqHw2S4kYqG91rt-3qAz9KQ2AgNo9CGS2YuzOnSCsTbFkIH4_OPVjCqDomqLtW-524Acthubpg5oZpqJ0xwIkz8xd_yf3awFXl1b5UEsXyTf5p8vVtbHUzzzcEoHq64DfizSDw7On3Navsyn_b5VfnRVzPnmTHEOzVWP-9bUgsYwww1DWGWYTnHvh-wao'
//            ),
//        ));
//        $response = curl_exec($curl);
//        curl_close($curl);
        $response='{"server":{"id":1378703,"name":"name","comment":"comment","os":{"id":93,"name":"ubuntu","version":null},"software":null,"preset_id":null,"configurator_id":11,"location":"ru-1","boot_mode":"std","status":"installing","start_at":null,"is_ddos_guard":true,"is_master_ssh":false,"avatar_id":"avatar","vnc_pass":"","cpu":1,"cpu_frequency":"3.3","ram":2048,"created_at":"2023-04-03T16:16:45.000Z","networks":[{"type":"public","bandwidth":200,"ips":[{"ip":"2a03:6f01:1:2::2644","is_main":true,"ptr":"1378703-arevyan246.tw1.ru","type":"ipv6"},{"ip":"85.193.87.182","is_main":true,"ptr":"1378703-arevyan246.tw1.ru","type":"ipv4"}]}],"disks":[{"size":15360,"used":0,"id":9091959,"type":"nvme","is_mounted":true,"is_system":true,"status":"done","system_name":"vda"}],"image":{"id":"1e08c363-c52b-46fe-a855-3de37ed3c117","name":"TimewebCloud_Docker_02.04.2023","is_custom":false}},"response_id":"1423250f-0729-43a4-8145-7c477d0fd784"} ';
        $php_array = json_decode($response, true);
//        print_r($php_array["server"]);
//        print_r($php_array["server"]["id"]);

        print_r($php_array);
        echo '<br>';
        echo $id =$php_array["server"]["id"];
        echo '<br>';
        echo $cpu_frequency =$php_array["server"]["cpu_frequency"];
        echo '<br>';
        echo $ram =$php_array["server"]["ram"];
        echo '<br>';
        echo $name =$php_array["server"]["name"];
        echo '<br>';
        echo $ip = $php_array["server"]["networks"][0]["ips"][1]["ip"];
        echo '<br>';
        echo $ptr = $php_array["server"]["networks"][0]["ips"][1]["ptr"];
        echo '<br>';
        echo $status =$php_array["server"]["status"];


        return view('server');
    }
}
