FastX Event Triggers


API “Gateway” Triggers

This trigger is called every time an API call is made.  A JSON INPUT_OBJECT is sent to the function.  You can modify the object and return it as a result of the function.  If you want to deny a method, throw an error. The function can return a promise.

INPUT_OBJECT


{
"action": API_ACTION /* The api action that is being called */
"login": "username", /* User's login */
"token": "STRING_VALUE", /* User Token */
"data": OBJECT, /* POST data sent with the request */
}

API_ACTION

  • session/start/start
  • session/start/schedule
  • session/connect
  • session/disconnect
  • session/exec
  • session/exec-bg
  • session/log
  • session/params
  • session/purge
  • session/screenshot
  • session/terminate

Examples

Deny a method

async function guard(o) {
   throw new Error('API CALL is disabled')
}

Force a start command

async function guard(o) {
 o.data.command = 'xterm -ls'; //force the command to an xterm
 return o;
}

Log when a user connects

async function guard(o) {
  console.log ('User %s connected', o.login);
}

Update Triggers

This event is triggered every time the session updates the server.  These triggers are executed in the nodejs server and by the node user (fastx).

The update trigger is a javascript function that takes an object as a parameter. The object has the following parameters

Update Object


{
"clientChange": 0, /* number of clients that have changed since last update */
"started": false, /* Is this a new session */
"terminated": false, /* Was this session terminated */
"oldSession": SESSION_DATA, /* Session Data currently in the database */
"newSession": SESSION_DATA, /* Session Data that will be updated */
}