Skip to content

Commit

Permalink
Merge pull request #15 from oyeaussie/dev
Browse files Browse the repository at this point in the history
Added package to composer
  • Loading branch information
oyeaussie authored Jul 12, 2024
2 parents d8ae84b + 906ed30 commit b61e835
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 12 deletions.
43 changes: 31 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oyeaussie/phppwnedpasswordsdownloader",
"description": "PHP downloader for HaveIBeenPwned",
"description": "PHPPwnedPasswordsDownloader is a tool to download pwned password hash files from HaveIBeenPwned API",
"keywords": [
"HaveIBeenPwned",
"downloader"
Expand All @@ -9,7 +9,26 @@
{
"name": "Oyeaussie",
"email": "email@oyeaussie.com",
"homepage": "https://github.com/oyeaussie"
"homepage": "https://www.oyeaussie.com"
}
],
"support": {
"source": "https://github.com/oyeaussie/PHPPwnedPasswordsDownloader",
"issues": "https://github.com/oyeaussie/PHPPwnedPasswordsDownloader/issues",
"docs": "https://github.com/oyeaussie/PHPPwnedPasswordsDownloader/wiki/1.-Description"
},
"funding": [
{
"url": "https://github.com/sponsors/oyeaussie",
"type": "github"
},
{
"url": "https://opencollective.com/oyeaussie",
"type": "opencollective"
},
{
"url": "https://buymeacoffee.com/oyeaussie",
"type": "other"
}
],
"require": {
Expand All @@ -20,19 +39,19 @@
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0",
"wp-cli/php-cli-tools": "*",
"nesbot/carbon": "*"
"nesbot/carbon": "*",
"carbon-cli/carbon-cli": "*",
"wp-cli/php-cli-tools": "^0.11.22",
"guzzlehttp/guzzle": "^7.8",
"league/flysystem": "^3.28"
},
"autoload": {
"psr-4": {
"PHPPwnedPasswordsDownloader\\": "src/"
}
},
"require": {
"guzzlehttp/guzzle": "^7.8",
"league/flysystem": "^3.28"
},
"require-dev": {
"wp-cli/php-cli-tools": "^0.11.22",
"nesbot/carbon": "^3.6"
}
}
"bin": [
"src/bin/hibp"
],
"minimum-stability": "dev"
}
1 change: 1 addition & 0 deletions src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ protected function processErrors()
$this->noChange = 0;
$this->recordErrors = false;

\cli\line('');
\cli\line('%bTrying hash ' . $errorHash . ' again...%w');

if ($this->run()) {
Expand Down
108 changes: 108 additions & 0 deletions src/bin/hibp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env php
<?php

use PHPPwnedPasswordsDownloader\Compare;
use PHPPwnedPasswordsDownloader\Download;
use PHPPwnedPasswordsDownloader\Help;
use PHPPwnedPasswordsDownloader\Index;
use PHPPwnedPasswordsDownloader\Lookup;
use PHPPwnedPasswordsDownloader\Sort;
use PHPPwnedPasswordsDownloader\Update;

include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';

try {
if (PHP_SAPI === 'cli') {
\cli\line('%wThis is a CLI tool to download, index, cache, sort and lookup pwned password. Type ./hibp --help for list of commands.%w');
\cli\line('');

$method = null;

array_splice($argv, 0, 1);//Remove index.php

if (count($argv) > 0) {
if ($argv[0] === '--help' || $argv[0] === '-h') {//help
(new Help($method))->show();

return true;
} else {
$argv = processArguments($argv, $method);

if (array_key_exists('--help', $argv)) {
(new \PHPPwnedPasswordsDownloader\Help())->show($method);

return true;
}

if ($method === 'download') {//download
(new Download($argv))->run();
} else if ($method === 'sort') {//sort
(new Sort($argv))->run();
} else if ($method === 'index') {//index
(new Index($argv))->run();
} else if ($method === 'lookup') {//lookup
(new Lookup($argv))->search();
} else if ($method === 'compare') {//compare downloads to generate update json and update php file.
(new Compare($argv))->run();
}
}
}
} else if (isset($_GET['since'])) {
$updates = (new Update())->getUpdates();

if ($updates) {
header('Content-Type: application/json; charset=utf-8');

echo json_encode($updates);
}
} else {
echo "This is a CLI tool to download, index, cache, sort and lookup pwned password. From CLI, type ./hibp --help for list of commands.";

exit;
}
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
}

function processArguments($argv, &$method)
{
$method = $argv[0];

array_splice($argv, 0, 1);

if (count($argv) === 0) {
return [];
}

$arguments = [];

foreach ($argv as $key => $args) {
if (!str_contains($args, '--')) {
throwInvalidArgumentException($args);

exit;
}

$args = explode('=', $args);

if (count($args) === 1 && !in_array('--help', $args)) {
throwInvalidArgumentException($args[0]);

exit;
} else if (count($args) === 1 && in_array('--help', $args)) {
$arguments['--help'] = true;

return $arguments;
} else {
$arguments[$args[0]] = $args[1];
}

}

return $arguments;
}

function throwInvalidArgumentException($arg)
{
\cli\line('%RIncorrect argument format of argument ' . $arg . '. Argument format is --{argument_name}={argument_value}. See --help for more details.%w');
}

0 comments on commit b61e835

Please sign in to comment.