-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UCRM 5991 - Barcode plugin - Install hook and composer update
- Loading branch information
1 parent
1fa1675
commit 54bae40
Showing
7 changed files
with
199 additions
and
40 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
use UBarcode\Service\TokenInstaller; | ||
use Ubnt\UcrmPluginSdk\Service\PluginLogManager; | ||
|
||
chdir(__DIR__); | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$logger = new Logger('UBarcode'); | ||
$logger->pushHandler(new StreamHandler('data/plugin.log')); | ||
|
||
$logManager = PluginLogManager::create(); | ||
|
||
(new TokenInstaller())->install(); | ||
|
||
$logger->info('Security token has been generated. Use it as a part of request string.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
plugins/barcode-generator/src/src/Service/TokenInstaller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace UBarcode\Service; | ||
|
||
|
||
use Nette\Utils\Json; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use UBarcode\Util\Strings; | ||
|
||
final class TokenInstaller | ||
{ | ||
private string $token; | ||
private Filesystem $filesystem; | ||
|
||
public function __construct() | ||
{ | ||
$this->filesystem = new Filesystem(); | ||
$this->token = Strings::generateUuidWithDashes(); | ||
} | ||
|
||
public function install(): void | ||
{ | ||
$this->filesystem->dumpFile('data/config.json', Json::encode(['token' => $this->token])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UBarcode\Util; | ||
|
||
final class Strings | ||
{ | ||
public static function generateUuidWithDashes(): string | ||
{ | ||
$uuidBin = random_bytes(18); | ||
$uuidBin &= "\xFF\xFF\xFF\xFF\x0F\xFF\xF0\x0F\xFF\x03\xFF\xF0\xFF\xFF\xFF\xFF\xFF\xFF"; | ||
$uuidBin |= "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00"; | ||
$uuidHex = bin2hex($uuidBin); | ||
$uuidHex[8] = $uuidHex[13] = $uuidHex[18] = $uuidHex[23] = '-'; | ||
|
||
return $uuidHex; | ||
} | ||
} |