# AxEvent type

AdaptixClient generates events for various situations. To register a handler for a specific event, there are functions from the `event` namespace. Several handlers can be connected to one event.

To assign a `handler` to a specific event use the function

```javascript
void event.on_EVENT_TYPE(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

* `handler` - a handler that will be triggered when the event occurs.
* `agents` - an array of strings containing the names of agents for which the event will be triggered. Available options are "beacon", "gopher", etc.&#x20;
* `os` - an array of strings with the names of the operating systems for which the event will be triggered. The following options are available: "windows", "linux", "macos". If an empty array `[]` is specified, the command group will be registered for all operating systems.
* `listeners` - An array of strings with the names of registered listeners for which the event will be triggered. The following options are available: "BeaconHTTP", "BeaconSMB", etc. If an empty array \[] is specified, the command group will be registered for all listeners.
* `event_id` - id for `handler`

You can remove a handler that has an id set.

```javascript
void event.remove(string event_id);
```

***

## on\_new\_agent

This event occurs every time a new agent registers.

```javascript
void event.on_new_agent(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_ag = function(id) {
    ax.show_message("New agent", id);
}
event.on_new_agent(event_ag, ["beacon", "gopher"]);
```

***

## on\_filebrowser\_disks

This event occurs when the user clicks the Disks button in the File Browser.

```javascript
void event.on_filebrowser_disks(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_disks_action = function(id) {
    ax.execute_browser(id, "disks");
}
event.on_filebrowser_disks(event_disks_action, ["beacon"]);
```

***

## on\_filebrowser\_list

This event occurs whenever the user requests a list of files in the File Browser.

```javascript
void event.on_filebrowser_list(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id, string path);
```

* `id` - agent ID
* `path` - current path in File Browser

```javascript
var event_files_action = function(id, path) {
    ax.execute_browser(id, "ls " + path);
}
event.on_filebrowser_list(event_files_action, ["beacon"]);
```

***

## on\_filebrowser\_upload

This event occurs whenever the user requests a list of processes in the Process Browser.

```javascript
void event.on_processbrowser_list(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id, string path, string filepath );
```

* `id` - agent ID
* `path` - current path in File Browser
* `filepath` - path to the local file to upload

**Example**

```javascript
var event_upload_action = function(id, path, filepath) {
    let filename = ax.file_basename(filepath);
    ax.execute_browser(id, "upload " + filepath + " " + path + filename);
}
event.on_filebrowser_upload(event_upload_action, ["beacon"]);
```

***

## on\_processbrowser\_list

This event occurs when a user uploads a file in a File Browser.

```javascript
void event.on_filebrowser_upload(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_process_action = function(id) {
    ax.execute_browser(id, "ps list");
}
event.on_processbrowser_list(event_process_action, ["beacon"]);
```

***

## on\_disconnect

This event occurs when a client disconnects from the server.

```javascript
void event.on_disconnect(handler(){}, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_disc = function() {
    ax.show_message("Event", "Client disconnected!");
}
event.on_disconnect(event_disc);
```

***

## on\_ready

This event occurs when the client has finished synchronizing with the server.

```javascript
void event.on_ready(handler(){}, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_ready = function() {
    ax.show_message("Event", "Client connected!");
}
event.on_ready(event_ready);
```

***

## on\_interval

The `handler` will be executed every `n` seconds. The method returns the ID with which the event was registered.

```javascript
string on_interval(handler(){}, int n, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_timer = function() {
    ax.show_message("Timeout", "5 seconds out");
}
event.on_interval(event_timer, 5);
```

***

## on\_timeout

The `handler` will be executed once in `n` seconds. The method returns the ID with which the event was registered.

```javascript
string on_timeout(handler(){}, int n, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_timer = function() {
    ax.show_message("Timeout", "5 seconds out");
}
event.on_timeout(event_timer, 5);
```

***

## list

The method returns a list of IDs of all registered handlers.

```javascript
string list();
```

**Example**

<div align="left"><figure><img src="https://2104178602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS8p8XLFtLmf0NkofQvoa%2Fuploads%2Fl86X7ThcW0tO2nwBySWs%2FScreenshot_20250828_124408.png?alt=media&#x26;token=aed9d9a6-6615-4482-9234-5b45eab6b439" alt=""><figcaption></figcaption></figure></div>

***

## remove

The method removes handler for the event whose ID is provided.

```javascript
string remove(string event_id);
```

**Example**

<div align="left"><figure><img src="https://2104178602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS8p8XLFtLmf0NkofQvoa%2Fuploads%2FAESRlMWxykJZ6RSpSVz0%2FScreenshot_20250828_125336.png?alt=media&#x26;token=4c4285b1-2da4-41aa-954c-97f581eedf7c" alt=""><figcaption></figcaption></figure></div>

***
