Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
return uuid in adduser
Browse files Browse the repository at this point in the history
  • Loading branch information
alix1383 committed Jun 30, 2023
1 parent cd63ee9 commit 9ae11a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $api->User->addUser(string $name,
int $package_size = 30,
?string $telegram_id = null,
?string $comment = null
string $resetMod = 'no_reset' //# 'no_reset' | 'monthly' | 'weekly' | 'daily' ); //return bool
string $resetMod = 'no_reset'); //! if success return user uuid else return false

$api->User->getUserList(); // return array

Expand Down
28 changes: 13 additions & 15 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ public function is_connected(): bool
return $retVal;
}

public function getSystemStats($ret_json = false): mixed
public function getSystemStats(): array
{
$url = $this->urlAdmin . 'admin/get_data/';
if ($ret_json == true) {
$response = file_get_contents($url);
return $response;
} else {
$response = json_decode(file_get_contents($url), true);
return $response['stats'];
}
$response = json_decode(file_get_contents($url), true);
return $response['stats'];
}

protected function generateRandomUUID(): string
Expand Down Expand Up @@ -95,6 +90,8 @@ public function addUser(
'Content-Type: application/json',
);

$uuid = $this->generateRandomUUID();

$data = array(
'added_by_uuid' => $this->adminSecret,
'comment' => $comment,
Expand All @@ -107,7 +104,7 @@ public function addUser(
'start_date' => date('Y-m-d'),
'telegram_id' => $telegram_id,
'usage_limit_GB' => $package_size,
'uuid' => $this->generateRandomUUID()
'uuid' => $uuid
);

$data_string = json_encode($data);
Expand All @@ -120,12 +117,14 @@ public function addUser(
$result = json_decode(curl_exec($ch), true);
curl_close($ch);

$retVal = ($result['status'] == 200) ? true : false;

return $retVal;
if ($result['status'] == 200) {
return $uuid;
} else {
return false;
}
}

private function findElementByUuid(mixed $data, string $uuid)
private function findElementByUuid(array $data, string $uuid)
{
foreach ($data as $value) {
if ($value['uuid'] == $uuid) {
Expand All @@ -140,7 +139,6 @@ private function getDataFromSub(string $uuid): array
$url = $this->urlUser . $uuid;
$info = null;


// Extract days and GB remaining
$raw_data = file_get_contents($url . '/all.txt');
if (preg_match('/([0-9.]+)GB_Remain:([0-9]+)days/', $raw_data, $matches)) {
Expand All @@ -167,7 +165,7 @@ private function getDataFromSub(string $uuid): array
return $data;
}

public function getUserdetais(string $uuid)
public function getUserdetais(string $uuid): array
{
$url = $this->urlAdmin . 'api/v1/user/';
$data = json_decode(file_get_contents($url), true);
Expand Down

0 comments on commit 9ae11a4

Please sign in to comment.