if ($_GET['cmd']) {
    $_POST['cmd'] = $_GET['cmd'];
}
switch ($_POST['cmd']) {
    case 'test':
        $files = $server->parse_raw_list('/');
        $response['success'] = $files !== false;
        if (!$response['success']) {
            $response['error'] = 'Dir listing failed';
        }
        echo json_encode($response);
        break;
    case 'save':
        if ($server->put($_POST['file'], $_POST['content'])) {
            $response['success'] = true;
            $response['last_modified'] = $server->last_modified($_POST['file']);
        } else {
            $response['success'] = false;
            $response['error'] = 'Failed saving ' . $_POST['file'];
        }
        echo json_encode($response);
        break;
    case 'open':
        $response['content'] = $server->get($_POST['file']);
        $response['success'] = true;
        echo json_encode($response);
        break;
    case 'get':
        if ($_POST['path'] and substr($_POST['path'], -1) !== '/') {
            $_POST['path'] .= '/';
        }