forked from plesk/api-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSession.php
47 lines (35 loc) · 1.19 KB
/
Session.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// Copyright 1999-2022. Plesk International GmbH.
namespace PleskX\Api\Operator;
use PleskX\Api\Struct\Session as Struct;
class Session extends \PleskX\Api\Operator
{
public function create(string $username, string $userIp): string
{
$packet = $this->client->getPacket();
$creator = $packet->addChild('server')->addChild('create_session');
$creator->addChild('login', $username);
$loginData = $creator->addChild('data');
$loginData->addChild('user_ip', base64_encode($userIp));
$loginData->addChild('source_server', '');
$response = $this->client->request($packet);
return (string) $response->id;
}
/**
* @return Struct\Info[]
*/
public function get(): array
{
$sessions = [];
$response = $this->request('get');
foreach ($response->session as $sessionInfo) {
$sessions[(string) $sessionInfo->id] = new Struct\Info($sessionInfo);
}
return $sessions;
}
public function terminate(string $sessionId): bool
{
$response = $this->request("terminate.session-id=$sessionId");
return 'ok' === (string) $response->status;
}
}