CLI
This commit is contained in:
67
cli/common/Command/DecryptPdf.php
Normal file
67
cli/common/Command/DecryptPdf.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Command;
|
||||
|
||||
use ProVM\Common\Service\Communicator;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'attachments:decrypt',
|
||||
description: 'Decrypt attachments pending',
|
||||
hidden: false
|
||||
)]
|
||||
class DecryptPdf extends Command
|
||||
{
|
||||
public function __construct(Communicator $communicator, string $name = null)
|
||||
{
|
||||
$this->setCommunicator($communicator);
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected Communicator $communicator;
|
||||
public function getCommunicator(): Communicator
|
||||
{
|
||||
return $this->communicator;
|
||||
}
|
||||
public function setCommunicator(Communicator $communicator): DecryptPdf
|
||||
{
|
||||
$this->communicator = $communicator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getAttachments(): array
|
||||
{
|
||||
$response = $this->getCommunicator()->get('/attachments/pending');
|
||||
return \Safe\json_decode($response->getBody()->getContents())->attachments;
|
||||
}
|
||||
protected function decrypt(string $attachment): bool
|
||||
{
|
||||
$response = $this->getCommunicator()->put('/attachments/decrypt', ['attachments' => [$attachment]]);
|
||||
return \Safe\json_decode($response->getBody()->getContents())->status;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Decrypt Attachments');
|
||||
|
||||
$io->section('Grabbing Attachments');
|
||||
$attachments = $this->getAttachments();
|
||||
$io->text('Found ' . count($attachments) . ' attachments.');
|
||||
$io->section('Decrypting Attachments');
|
||||
foreach ($attachments as $attachment) {
|
||||
$status = $this->decrypt($attachment);
|
||||
if ($status) {
|
||||
$io->success("{$attachment} decrypted correctly.");
|
||||
} else {
|
||||
$io->error("Problem decrypting {$attachment}.");
|
||||
}
|
||||
}
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
64
cli/common/Command/GrabAttachments.php
Normal file
64
cli/common/Command/GrabAttachments.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Command;
|
||||
|
||||
use ProVM\Common\Service\Communicator;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'attachments:grab',
|
||||
description: 'Grab attachments from pending messages',
|
||||
aliases: ['attachments:get'],
|
||||
hidden: false
|
||||
)]
|
||||
class GrabAttachments extends Command
|
||||
{
|
||||
public function __construct(Communicator $communicator, string $name = null)
|
||||
{
|
||||
$this->setCommunicator($communicator);
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected Communicator $service;
|
||||
public function getCommunicator(): Communicator
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
public function setCommunicator(Communicator $service): GrabAttachments
|
||||
{
|
||||
$this->service = $service;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getMessages(): array
|
||||
{
|
||||
$response = $this->getCommunicator()->get('/messages/pending');
|
||||
return \Safe\json_decode($response->getBody()->getContents())->messages;
|
||||
}
|
||||
protected function grabAttachments(int $message_uid): int
|
||||
{
|
||||
$response = $this->getCommunicator()->put('/attachments/grab', ['messages' => [$message_uid]]);
|
||||
return \Safe\json_decode($response->getBody()->getContents())->attachment_count;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Grab Attachments');
|
||||
|
||||
$io->section('Grabbing Messages');
|
||||
$messages = $this->getMessages();
|
||||
$io->text('Found ' . count($messages) . ' messages.');
|
||||
$io->section('Grabbing Attachments');
|
||||
foreach ($messages as $message) {
|
||||
$attachments = $this->grabAttachments($message);
|
||||
$io->text("Found {$attachments} attachments for message UID:{$message}.");
|
||||
}
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
66
cli/common/Command/Messages.php
Normal file
66
cli/common/Command/Messages.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Command;
|
||||
|
||||
use ProVM\Common\Service\Communicator;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'messages:grab',
|
||||
description: 'Run grab messages job for registered mailboxes',
|
||||
aliases: ['messages'],
|
||||
hidden: false
|
||||
)]
|
||||
class Messages extends Command
|
||||
{
|
||||
public function __construct(Communicator $communicator, string $name = null)
|
||||
{
|
||||
$this->setCommunicator($communicator);
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected Communicator $communicator;
|
||||
public function getCommunicator(): Communicator
|
||||
{
|
||||
return $this->communicator;
|
||||
}
|
||||
public function setCommunicator(Communicator $communicator): Messages
|
||||
{
|
||||
$this->communicator = $communicator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getMailboxes(): array
|
||||
{
|
||||
$response = $this->getCommunicator()->get('/mailboxes/registered');
|
||||
return \Safe\json_decode($response->getBody()->getContents())->mailboxes;
|
||||
}
|
||||
protected function grabMessages(string $mailbox): int
|
||||
{
|
||||
$response = $this->getCommunicator()->put('/messages/grab', ['mailboxes' => [$mailbox]]);
|
||||
$body = \Safe\json_decode($response->getBody()->getContents());
|
||||
return $body->message_count;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$io->title('Messages');
|
||||
$io->section('Grabbing Registered Mailboxes');
|
||||
|
||||
$mailboxes = $this->getMailboxes();
|
||||
$io->text('Found ' . count($mailboxes) . ' registered mailboxes.');
|
||||
$io->section('Grabbing Messages');
|
||||
foreach ($mailboxes as $mailbox) {
|
||||
$message_count = $this->grabMessages($mailbox->name);
|
||||
$io->text("Found {$message_count} messages in {$mailbox->name}.");
|
||||
}
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user