<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
    
require __DIR__."/../../server/api.php";
require __DIR__."/api.php";

class XtermApi extends FileApi {

    static $xterm_context;

    function _pathFromUrl($url) {
        $url = explode('/',$url,4);
        $url = @$url[3] ? "/".$url[3] : "";
        
        $base = substr($_SERVER['REQUEST_URI'],0,strlen($_SERVER['REQUEST_URI'])-strlen($_SERVER['QUERY_STRING']));
        $base = preg_replace('/(\/)?('.basename($_SERVER["PHP_SELF"]).')?\??$/i','',$base);
        $base = implode('/',explode('/',$base,-3));
        
        if ($base=="" || strpos($url,$base)===0) {
            $rel = substr($url,strlen($base));
            $path = realpath(__DIR__."/../../..").$rel;
            return $path;
        }
        return false;
    }    
}

XtermApi::$xterm_context = [
    'ssl' => [
        'local_cert'  => __DIR__.'/cache/fullchain.pem',
        'local_pk'    => __DIR__.'/cache/privkey.pem',
        'verify_peer' => false,
    ]
];

$api = new XtermApi;