0

On a slow and low resource dev box I need to save terminal sessions using asciinema. I cannot afford to install the official asciinema-server. I tried to find out what is being sent to the server and save it with a small PHP script. So I created a ~/.config/asciinema/config config file and set the api url to one on localhost.

I have a very simple script that is hit when a cast is uploaded but it seems nothing is being posted. Here is my script:

<?php
session_start();
$i = [];
$i['post'] = $_POST;
$i['get'] = $_GET;
$i['request'] = $_REQUEST;
$i['server'] = $_SERVER;
$i['cookie'] = $_COOKIE;
$i['env'] = $_ENV;
$i['files'] = $_FILES;
$i['session'] = $_SESSION;
$i['body'] = file_get_contents('php://input');
$j = json_encode($i);
$n = mt_rand(100000000, 999999999);
file_put_contents(__DIR__ . "/$n.json", $j);

And here is a captured request where I did a simple ls -la in the terminal and uploaded the session:

{
    "post": [],
    "get": [],
    "request": [],
    "server": {
        "USER": "********",
        "HOME": "/home/********",
        "HTTP_CONNECTION": "close",
        "HTTP_AUTHORIZATION": "Basic dXNlcm5hbWU6cGFzc3dvcmQK",
        "HTTP_USER_AGENT": "asciinema/2.0.0 CPython/3.6.9 Linux/5.4.0-144-generic-x86_64-with-Ubuntu-18.04-bionic",
        "HTTP_HOST": "test.dev",
        "HTTP_ACCEPT_ENCODING": "identity",
        "SCRIPT_FILENAME": "/var/www/testbench/asciinema/api/asciicasts/index.php",
        "REDIRECT_STATUS": "200",
        "SERVER_NAME": "test.dev",
        "SERVER_PORT": "80",
        "SERVER_ADDR": "127.0.0.1",
        "REMOTE_PORT": "51626",
        "REMOTE_ADDR": "127.0.0.1",
        "SERVER_SOFTWARE": "nginx/1.14.0",
        "GATEWAY_INTERFACE": "CGI/1.1",
        "REQUEST_SCHEME": "http",
        "SERVER_PROTOCOL": "HTTP/1.1",
        "DOCUMENT_ROOT": "/var/www/testbench",
        "DOCUMENT_URI": "/asciinema/api/asciicasts/index.php",
        "REQUEST_URI": "/asciinema/api/asciicasts/",
        "SCRIPT_NAME": "/asciinema/api/asciicasts/index.php",
        "CONTENT_LENGTH": "",
        "CONTENT_TYPE": "",
        "REQUEST_METHOD": "GET",
        "QUERY_STRING": "",
        "FCGI_ROLE": "RESPONDER",
        "PHP_SELF": "/asciinema/api/asciicasts/index.php",
        "PHP_AUTH_USER": "********",
        "PHP_AUTH_PW": "********",
        "REQUEST_TIME_FLOAT": 1678396966.030703,
        "REQUEST_TIME": 1678396966
    },
    "cookie": [],
    "env": [],
    "files": [],
    "session": [],
    "body": ""
}

The function that uploads the cast should be this: https://github.com/asciinema/asciinema/blob/d34941cd6dc3b38fab4a48b80456722386da2725/asciinema/api.py#L40

Where else should I look for the cast data?

Majid Fouladpour
  • 29,356
  • 21
  • 76
  • 127
  • 2
    Why not just [save the cast locally, without uploading it](https://discourse.asciinema.org/t/do-i-have-to-upload-my-recordings-to-asciinema-org/26)? – MattDMo Mar 09 '23 at 22:14
  • @MattDMo Yes I can Ctrl+C to save the cast locally and rename/move it where I want it to be. At first, it was a mater of convenience as I thought it would take very little effort. Now it is a mater of curiosity (what's going on?) – Majid Fouladpour Mar 09 '23 at 22:18
  • @MattDMo and I didn't know about `asciinema rec demo.cast` method. Thanks! – Majid Fouladpour Mar 09 '23 at 22:21
  • The web app for the server is at https://github.com/asciinema/asciinema-server, and the recorder is at https://github.com/asciinema/asciinema. The docs aren't of much help, they just say to look at the source for how it all works. – MattDMo Mar 09 '23 at 22:23
  • The file format description is [here](https://github.com/asciinema/asciinema/blob/master/doc/asciicast-v1.md). – MattDMo Mar 09 '23 at 22:24
  • @MattDMo, yes, the link in the question is to the function that uploads the cast. The language is Python and I am not sure I interpreter what is being done fully/correctly. The format is also simple but without getting my hands on the cast string it is of no use. – Majid Fouladpour Mar 09 '23 at 22:29
  • Well, try recording a short cast and playing around with it. It looks like it in JSON text format, so at least you don't have to do binary decoding or anything. – MattDMo Mar 09 '23 at 22:35

0 Answers0