Logging in Virtualizor is enabled by default. The time period for the retention of the Login logs can be set in the Master Settings of the Admin panel or using the master configurations API.
Use the Login Logs API to retrieve data about the login activities of all of your account's users. The API response contains the list of the login activity details. The details provide information about the login activity such as IP address of the login location and time of login. To filter or limit the size of the list you can pass in one or more query parameters.
HTTP Request
https://hostname:4085/index.php?act=loginlogs&username=USERNAME&ip=IP&page=PAGE&reslen=RESLEN
Parameters
Name | Method | Value | Description | Required |
---|---|---|---|---|
act | GET | loginlogs | The action will return the loginlogs | Yes |
username | GET | text | The logs returned on the basis of username | No |
ip | GET | text | The logs returned on the basis of IP address | No |
reslen | GET | Int | Number of records to be returned, default is 50 | No |
page | GET | Int | Page number, each page show 50 records | No |
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$page = 1;
$reslen = 20;
$post = array();
$post['username'] = 'root';
$post['ip'] = '';
$output = $admin->loginlogs($page, $reslen , $post);
print_r(json_encode($output));
?>
Output
{
"title": "Login Logs",
"loginlogs": [
{
"username": "root",
"vpsid": "0",
"time": "1536668301",
"status": "1",
"ip": "192.168.1.188"
},
{
"username": "root",
"vpsid": "0",
"time": "1536589554",
"status": "1",
"ip": "192.168.1.188"
}
],
"timenow": 1536684609,
"time_taken": "0.210"
}