Compare commits
No commits in common. "383dc29ba5ba2b0b8139c68979af9813a3c26104" and "cc4a47d3fbe32b9764a4a057f8de361637171dfb" have entirely different histories.
383dc29ba5
...
cc4a47d3fb
27
bin/console
27
bin/console
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/keyhelp-php81
|
#!/usr/bin/keyhelp-php81
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ $version = '0.0.1';
|
||||||
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$configFile = dirname(path: __DIR__) ."/config.json";
|
$configFile = dirname(path: __DIR__) ."/config.json";
|
||||||
if (!file_exists(filename: $configFile)) {
|
if (!file_exists($configFile)) {
|
||||||
echo 'Missing config file' . PHP_EOL;
|
echo 'Missing config file' . PHP_EOL;
|
||||||
if (confirm(message: 'Should I create a new config based on config.json.sample?')) {
|
if (confirm(message: 'Should I create a new config based on config.json.sample?')) {
|
||||||
copy(from: 'config.json.sample', to: 'config.json');
|
copy(from: 'config.json.sample', to: 'config.json');
|
||||||
|
@ -26,9 +25,9 @@ if (!file_exists(filename: $configFile)) {
|
||||||
}
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
$configJSON = file_get_contents(filename: $configFile);
|
$configJSON = file_get_contents($configFile);
|
||||||
|
|
||||||
if (!$config = json_decode(json: $configJSON, associative: true)) {
|
if (!$config = json_decode($configJSON, associative: true)) {
|
||||||
echo 'Error parsing the config file.' . PHP_EOL;
|
echo 'Error parsing the config file.' . PHP_EOL;
|
||||||
echo $configJSON;
|
echo $configJSON;
|
||||||
}
|
}
|
||||||
|
@ -43,27 +42,27 @@ $longOpts = [
|
||||||
'help::'
|
'help::'
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = getopt(short_options: $shortOpts, long_options: $longOpts, rest_index: $restIndex);
|
$options = getopt($shortOpts, $longOpts, rest_index: $restIndex);
|
||||||
|
|
||||||
if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options) ) {
|
if (array_key_exists('v', $options) || array_key_exists('version', $options) ) {
|
||||||
print("bindAPI version: $version" . PHP_EOL);
|
print("bindAPI version: $version" . PHP_EOL);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options) ) {
|
if (array_key_exists('h', $options) || array_key_exists('help', $options) ) {
|
||||||
print("Help …" . PHP_EOL);
|
print("Help …" . PHP_EOL);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options) ) {
|
if (array_key_exists('V', $options) || array_key_exists('verbose', $options) ) {
|
||||||
$config['verbose'] = true;
|
$config['verbose'] = true;
|
||||||
} else {
|
} else {
|
||||||
$config['verbose'] = false;
|
$config['verbose'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = array_slice(array: $argv, offset: $restIndex);
|
$arguments = array_slice($argv, $restIndex);
|
||||||
|
|
||||||
$app = new BindAPI(config: $config, argumentsCount: count(value: $arguments), arguments: $arguments);
|
$app = new BindAPI(config: $config, argumentsCount: count($arguments), arguments: $arguments);
|
||||||
$app->runCommand();
|
$app->runCommand();
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ function confirm(String $message = 'Are you sure? ', array $options = ['y', 'n']
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
// mark default
|
// mark default
|
||||||
if ($option == $default) {
|
if ($option == $default) {
|
||||||
$option = strtoupper(string: $option);
|
$option = strtoupper($option);
|
||||||
}
|
}
|
||||||
if ($first) {
|
if ($first) {
|
||||||
echo $option;
|
echo $option;
|
||||||
|
@ -94,8 +93,8 @@ function confirm(String $message = 'Are you sure? ', array $options = ['y', 'n']
|
||||||
echo '): ';
|
echo '): ';
|
||||||
|
|
||||||
$handle = fopen(filename: "php://stdin", mode: 'r');
|
$handle = fopen(filename: "php://stdin", mode: 'r');
|
||||||
$line = trim(fgetc(stream: $handle));
|
$line = trim(fgetc($handle));
|
||||||
fclose(stream: $handle);
|
fclose($handle);
|
||||||
|
|
||||||
if ($line == '') {
|
if ($line == '') {
|
||||||
// enter
|
// enter
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class ApiKeys
|
||||||
FROM " . DatabaseConnection::TABLE_USER;
|
FROM " . DatabaseConnection::TABLE_USER;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->query(statement: $sql);
|
$statement = $this->databaseConnection->getConnection()->query($sql);
|
||||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
@ -47,7 +47,7 @@ class ApiKeys
|
||||||
";
|
";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':id', var: $id);
|
$statement->bindParam(param: ':id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
|
@ -70,7 +70,7 @@ class ApiKeys
|
||||||
WHERE api_token_prefix = :prefix";
|
WHERE api_token_prefix = :prefix";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':prefix', var: $prefix);
|
$statement->bindParam(param: ':prefix', var: $prefix);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
|
@ -88,7 +88,7 @@ class ApiKeys
|
||||||
$tokenPrefix = uniqid();
|
$tokenPrefix = uniqid();
|
||||||
$result['tokenPrefix'] = $tokenPrefix;
|
$result['tokenPrefix'] = $tokenPrefix;
|
||||||
try {
|
try {
|
||||||
$key = bin2hex(string: random_bytes(length: 24));
|
$key = bin2hex(random_bytes(length: 24));
|
||||||
$result['key'] = $key;
|
$result['key'] = $key;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo $e->getMessage() . PHP_EOL;
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
@ -101,7 +101,7 @@ class ApiKeys
|
||||||
VALUES (:name, :token_prefix, :token)";
|
VALUES (:name, :token_prefix, :token)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
||||||
$statement->bindParam(param: ':token', var: $token);
|
$statement->bindParam(param: ':token', var: $token);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
|
@ -127,7 +127,7 @@ class ApiKeys
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
|
|
Loading…
Reference in New Issue