2 Commits

Author SHA1 Message Date
db95b12985 v1.1.0 2022-11-30 10:42:48 -03:00
8648f5a62e v1.0.0 2022-11-29 11:12:35 -03:00
37 changed files with 246 additions and 421 deletions

View File

@ -5,7 +5,7 @@ UI_PATH=./ui
COMPOSE_PROJECT_NAME=emails
COMPOSE_PATH_SEPARATOR=:
COMPOSE_FILE=./docker-compose.yml:${CLI_PATH}/docker-compose.yml:${API_PATH}/docker-compose.yml:${UI_PATH}/docker-compose.yml
COMPOSE_PROFILES=api,ui,cli
COMPOSE_PROFILES=api,ui
ATT_PATH=./attachments
LOGS_PATH=./logs

View File

@ -2,4 +2,5 @@ EMAIL_HOST=imap.gmail.com
EMAIL_PORT=993
EMAIL_USERNAME=@gmail.com
EMAIL_PASSWORD=
ATTACHMENTS_FOLDER=/attachments
EMAIL_FOLDER=
ATTACHMENTS_FOLDER=/attachments

View File

@ -6,52 +6,3 @@ Grab attachments from emails by inbox.
* Choose what mailboxes to watch.
* Select messages that you want to grab attachments from.
* Download (or view in browser) (decrypted) attachments from messages.
## Requirements
* Docker with Docker Compose [https://www.docker.com/](https://www.docker.com/)
## Installation
1. Pull from repository
```
git pull git@git.provm.cl:Incoviba/emails.git
```
Change to latest release
```
git checkout release
```
2. Check the docker-compose.yml files
1. docker-compose.yml - central proxy container
2. api/docker-compose.yml - API container and database
3. cli/docker-compose.yml - CLI container that runs cron jobs
4. ui/docker-compose.yml - UI container
3. Generate the API Key
If you have openssl (comes with most linux distros) you can run this in terminal
```
echo API_KEY=`(openssl rand -hex 128)` >> .key.env
```
4. Check Environment files
1. .env - Docker Compose and Environment settings. Check volumes and ports.
2. .key.env - API_KEY, generated before.
3. .mail.env - Email Identification.
4. api/.env - Encrypted PDF files passwords.
5. api/.db.env - Database configuration.
6. cli/.env - API_URI, for connecting to the api container from the cli container. Change it if the api is someplace else.
7. ui/.env - API_URI, same as from the cli.
5. Check if every configuration is correct before starting the application
```
docker compose config
```
If everything is fine
```
docker compose up -d
```
6. Connect to the UI
Default [http://localhost:8000](http://localhost:8000)
## Development
When development there is a container for adminer, to use it you can add it into `COMPOSE_PROFILES` or run
```
docker compose up -d adminer
```

View File

@ -1,2 +0,0 @@
ADMINER_DESIGN=dracula
ADMINER_PLUGINS="tables-filter table-indexes-structure table-structure struct-comments json-column edit-calendar edit-textarea dump-bz2 dump-date dump-json dump-php enum-option"

View File

@ -1,4 +0,0 @@
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=

View File

@ -1,2 +0,0 @@
PASSWORDS_SEPARATOR=,
PASSWORDS=

View File

@ -12,7 +12,7 @@ class Jobs
{
use Json;
public function schedule(ServerRequestInterface $request, ResponseInterface $response, Service $service, \ProVM\Common\Service\Messages $messagesService): ResponseInterface
public function schedule(ServerRequestInterface $request, ResponseInterface $response, Service $jobsService): ResponseInterface
{
$body = $request->getBody();
$json = \Safe\json_decode($body->getContents());
@ -25,24 +25,21 @@ class Jobs
'scheduled' => 0
];
foreach ($json->messages as $message_id) {
if ($service->schedule($message_id)) {
$message = $messagesService->getRepository()->fetchById($message_id);
$message->doesHaveScheduledDownloads();
$messagesService->getRepository()->save($message);
if ($jobsService->schedule($message_id)) {
$output['scheduled'] ++;
}
}
return $this->withJson($response, $output);
}
public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface
public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $jobsService): ResponseInterface
{
$pending = array_map(function(Job $job) {
return $job->toArray();
}, $service->getPending());
}, $jobsService->getPending());
$output = [
'total' => count($pending),
'pending' => $pending
];
return $this->withJson($response, $output);
}
}
}

View File

@ -1,38 +0,0 @@
<?php
namespace ProVM\Common\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
class Logging
{
public function __construct(LoggerInterface $logger) {
$this->setLogger($logger);
}
protected LoggerInterface $logger;
public function getLogger(): LoggerInterface
{
return $this->logger;
}
public function setLogger(LoggerInterface $logger): Logging
{
$this->logger = $logger;
return $this;
}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
$output = [
'uri' => var_export($request->getUri(), true),
'body' => $request->getBody()->getContents()
];
$this->getLogger()->info(\Safe\json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
return $response;
}
}

View File

@ -18,7 +18,7 @@ services:
env_file:
- ${API_PATH:-.}/.env
- ${API_PATH:-.}/.db.env
- ${API_PATH:-.}/.mail.env
- .mail.env
- .key.env
volumes:
- ${API_PATH:-.}/:/app/api

View File

@ -8,11 +8,6 @@ Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface
try {
$app->run();
} catch (Error | Exception $e) {
$logger = $app->getContainer()->get(Psr\Log\LoggerInterface::class);
if (isset($_REQUEST)) {
$logger->debug(Safe\json_encode(compact('_REQUEST')));
}
$logger->debug(Safe\json_encode(compact('_SERVER')));
$logger->error($e);
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($e);
throw $e;
}

View File

@ -1,2 +0,0 @@
<?php
$app->add($app->getContainer()->get(ProVM\Common\Middleware\Logging::class));

View File

@ -18,5 +18,4 @@ return [
]);
},
'attachments_folder' => $_ENV['ATTACHMENTS_FOLDER'],
'logs_folder' => '/logs',
];
];

View File

@ -7,8 +7,5 @@ return [
$container->get(Nyholm\Psr7\Factory\Psr17Factory::class),
$container->get(Psr\Log\LoggerInterface::class)
);
},
ProVM\Common\Middleware\Logging::class => function(ContainerInterface $container) {
return new ProVM\Common\Middleware\Logging($container->get('request_logger'));
}
];
];

View File

@ -10,23 +10,13 @@ return [
$handler->setFormatter($container->get(Monolog\Formatter\SyslogFormatter::class));
return $handler;
},
'request_logger' => function(ContainerInterface $container) {
$logger = new Monolog\Logger('request_logger');
$handler = new Monolog\Handler\RotatingFileHandler(implode(DIRECTORY_SEPARATOR, [$container->get('logs_folder'), 'requests.log']));
$handler->setFormatter($container->get(Monolog\Formatter\SyslogFormatter::class));
$dedupHandler = new Monolog\Handler\DeduplicationHandler($handler, null, Monolog\Level::Info);
$logger->pushHandler($dedupHandler);
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
return $logger;
},
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
$logger = new Monolog\Logger('file_logger');
$logger->pushHandler($container->get(Monolog\Handler\DeduplicationHandler::class));
//$logger->pushHandler($container->get(Monolog\Handler\RotatingFileHandler::class));
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
return $logger;
}
];
];

View File

@ -108,12 +108,7 @@ class Message implements Model
}
public function getState(string $name): \ProVM\Emails\Model\State\Message
{
try {
return $this->getStates()[$name];
} catch (\Exception $e) {
$this->newState($name);
return $this->getStates()[$name];
}
return $this->getStates()[$name];
}
public function addState(\ProVM\Emails\Model\State\Message $state): Message
{
@ -132,7 +127,6 @@ class Message implements Model
$this->addState((new \ProVM\Emails\Model\State\Message())
->setName($name)
->setMessage($this)
->setValue(false)
);
return $this;
}
@ -149,31 +143,31 @@ class Message implements Model
{
return $this->getState('downloaded_attachments')->getValue() ?? false;
}
public function hasScheduledDownloads(): bool
{
return $this->getState('scheduled_downloads')->getValue() ?? false;
}
public function doesHaveAttachments(): Message
{
if (!isset($this->getStates()['has_attachments'])) {
$this->newState('has_attachments');
}
$this->getState('has_attachments')->setValue(true);
return $this;
}
public function doesHaveValidAttachments(): Message
{
if (!isset($this->getStates()['valid_attachments'])) {
$this->newState('valid_attachments');
}
$this->getState('valid_attachments')->setValue(true);
return $this;
}
public function doesHaveDownloadedAttachments(): Message
{
if (!isset($this->getStates()['downloaded_attachments'])) {
$this->newState('downloaded_attachments');
}
$this->getState('downloaded_attachments')->setValue(true);
return $this;
}
public function doesHaveScheduledDownloads(): Message
{
$this->getState('scheduled_downloads')->setValue(true);
return $this;
}
protected array $attachments;
public function getAttachments(): array
@ -211,12 +205,11 @@ class Message implements Model
'states' => [
'has_attachments' => $this->hasAttachments(),
'valid_attachments' => $this->hasValidAttachments(),
'downloaded_attachments' => $this->hasDownloadedAttachments(),
'scheduled_downloads' => $this->hasScheduledDownloads()
'downloaded_attachments' => $this->hasDownloadedAttachments()
],
'attachments' => $this->hasValidAttachments() ? array_map(function(Attachment $attachment) {
return $attachment->toArray();
}, $this->getAttachments()) : []
];
}
}
}

View File

@ -111,8 +111,7 @@ class Message extends Repository
$valid_states = [
'has_attachments',
'valid_attachments',
'downloaded_attachments',
'scheduled_downloads'
'downloaded_attachments'
];
foreach ($valid_states as $state_name) {
try {
@ -161,4 +160,4 @@ class Message extends Repository
WHERE `mailbox_id` = ? `subject` = ? AND `from` = ? AND `date_time` = ?";
return $this->fetchOne($query, [$mailbox_id, $subject, $from, $dateTime->format('Y-m-d H:i:s')]);
}
}
}

View File

@ -1 +0,0 @@
API_URI=http://proxy:8080

View File

@ -1,38 +0,0 @@
<?php
namespace ProVM\Common\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
class Logging
{
public function __construct(LoggerInterface $logger) {
$this->setLogger($logger);
}
protected LoggerInterface $logger;
public function getLogger(): LoggerInterface
{
return $this->logger;
}
public function setLogger(LoggerInterface $logger): Logging
{
$this->logger = $logger;
return $this;
}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
$output = [
'uri' => var_export($request->getUri(), true),
'body' => $request->getBody()->getContents()
];
$this->getLogger()->info(\Safe\json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
return $response;
}
}

View File

@ -4,12 +4,9 @@ $app = require_once implode(DIRECTORY_SEPARATOR, [
'setup',
'app.php'
]);
Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface::class));
try {
$app->run();
} catch (Error | Exception $e) {
$logger = $app->getContainer()->get(Psr\Log\LoggerInterface::class);
$logger->debug(Safe\json_encode(compact('_SERVER')));
$logger->error($e);
$app->getContainer()->get(\Psr\Log\LoggerInterface::class)->error($e);
throw $e;
}

View File

@ -1,2 +0,0 @@
<?php
$app->add($app->getContainer()->get(ProVM\Common\Middleware\Logging::class));

View File

@ -14,6 +14,5 @@ return [
$container->get('resources_folder'),
'commands'
]);
},
'logs_folder' => '/logs',
}
];

View File

@ -1,8 +0,0 @@
<?php
use Psr\Container\ContainerInterface;
return [
ProVM\Common\Middleware\Logging::class => function(ContainerInterface $container) {
return new ProVM\Common\Middleware\Logging($container->get('request_logger'));
}
];

View File

@ -2,28 +2,14 @@
use Psr\Container\ContainerInterface;
return [
Monolog\Handler\RotatingFileHandler::class => function(ContainerInterface $container) {
$handler = new Monolog\Handler\RotatingFileHandler($container->get('log_file'));
$handler->setFormatter($container->get(Monolog\Formatter\LineFormatter::class));
\Monolog\Handler\RotatingFileHandler::class => function(ContainerInterface $container) {
$handler = new \Monolog\Handler\RotatingFileHandler($container->get('log_file'));
$handler->setFormatter($container->get(\Monolog\Formatter\LineFormatter::class));
return $handler;
},
'request_logger' => function(ContainerInterface $container) {
$logger = new Monolog\Logger('request_logger');
$handler = new Monolog\Handler\RotatingFileHandler(implode(DIRECTORY_SEPARATOR, [$container->get('logs_folder'), 'requests.log']));
$handler->setFormatter($container->get(Monolog\Formatter\SyslogFormatter::class));
$dedupHandler = new Monolog\Handler\DeduplicationHandler($handler, null, Monolog\Level::Info);
$logger->pushHandler($dedupHandler);
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
\Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
$logger = new \Monolog\Logger('file_logger');
$logger->pushHandler($container->get(\Monolog\Handler\RotatingFileHandler::class));
return $logger;
},
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
$logger = new Monolog\Logger('file_logger');
$logger->pushHandler($container->get(Monolog\Handler\RotatingFileHandler::class));
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
return $logger;
},
];
}
];

View File

@ -1 +0,0 @@
API_URI=http://proxy:8080

View File

@ -4,13 +4,14 @@ namespace ProVM\Common\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use ProVM\Common\Service\Api as Service;
use Psr\Log\LoggerInterface;
class Api
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service $service, LoggerInterface $logger): ResponseInterface
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface
{
$json = $request->getParsedBody();
$body = $request->getBody();
$json = \Safe\json_decode($body->getContents(), JSON_OBJECT_AS_ARRAY);
return $service->sendRequest($json);
}
}

View File

@ -1,38 +0,0 @@
<?php
namespace ProVM\Common\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
class Logging
{
public function __construct(LoggerInterface $logger) {
$this->setLogger($logger);
}
protected LoggerInterface $logger;
public function getLogger(): LoggerInterface
{
return $this->logger;
}
public function setLogger(LoggerInterface $logger): Logging
{
$this->logger = $logger;
return $this;
}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
$output = [
'uri' => var_export($request->getUri(), true),
'body' => $request->getParsedBody()
];
$this->getLogger()->info(\Safe\json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
return $response;
}
}

View File

@ -8,11 +8,6 @@ Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface
try {
$app->run();
} catch (Error | Exception $e) {
$logger = $app->getContainer()->get(Psr\Log\LoggerInterface::class);
if (isset($_REQUEST)) {
$logger->debug(Safe\json_encode(compact('_REQUEST')));
}
$logger->debug(Safe\json_encode(compact('_SERVER')));
$logger->error($e);
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($e);
throw $e;
}

View File

@ -1,4 +1,4 @@
<?php
use ProVM\Common\Controller\Api;
$app->post('/api[/]', Api::class);
$app->post('/api', Api::class);

View File

@ -17,8 +17,7 @@
states = {
attachments: false,
valid: false,
downloaded: false,
scheduled: false
downloaded: false
}
attachments
@ -82,15 +81,10 @@
const map_keys = {
has_attachments: 'attachments',
valid_attachments: 'valid',
downloaded_attachments: 'downloaded',
scheduled_downloads: 'scheduled'
downloaded_attachments: 'downloaded'
}
Object.keys(states).forEach(k => {
if (k in map_keys) {
this.states[map_keys[k]] = states[k]
} else {
this.states[map_keys[k]] = false
}
this.states[map_keys[k]] = states[k]
})
return this
},
@ -109,9 +103,6 @@
},
downloaded: () => {
return this.states.downloaded
},
scheduled: () => {
return this.states.scheduled
}
}
}
@ -128,99 +119,80 @@
downloaded: () => {
this.states.downloaded = true
return this
},
scheduled: () => {
this.states.scheduled = true
return this
}
}
}
draw() {
return {
row: () => {
const format = Intl.DateTimeFormat('es-CL', {dateStyle: 'full', timeStyle: 'short'})
let date = new Date()
try {
date = new Date(this.get().date())
} catch (e) {
console.debug(e)
}
const valid = $('<td></td>').html($('<i></i>').addClass(this.has().valid() ? 'green check circle icon' : 'red times circle icon'))
if (this.has().valid() && this.get().attachments().length > 0) {
const list = $('<div></div>').addClass('ui list')
this.get().attachments().forEach(attachment => {
list.append($('<div></div>').addClass('item').html(attachment.filename))
})
valid.append(
$('<div></div>').addClass('ui popup').append(list)
)
}
const tr = $('<tr></tr>').attr('data-id', this.get().id()).append(
$('<td></td>').html(this.get().subject())
).append(
$('<td></td>').html(format.format(date))
).append(
$('<td></td>').html(this.get().from().full)
).append(
$('<td></td>').html($('<i></i>').addClass(this.has().attachments() ? 'green check circle icon' : 'red times circle icon'))
).append(
valid
).append(
$('<td></td>').html($('<i></i>').addClass(this.has().downloaded() ? 'green check circle icon' : 'red times circle icon'))
).append(
$('<td></td>').append(
(this.has().attachments() && this.has().valid() && !this.has().downloaded()) ?
((this.has().scheduled()) ? this.draw().scheduledButton() : this.draw().scheduleButton()) : ''
)
)
if (this.has().downloaded()) {
tr.find('td').each((i, td) => {
const content = $(td).html()
if (content.indexOf('icon') > -1) {
return
}
$(td).html('')
$(td).append(
$('<a></a>').attr('href', '{{$urls->base}}/emails/message/' + this.id).html(content)
)
})
}
return tr
},
scheduleButton: () => {
return $('<button></button>').addClass('ui mini circular icon button').append(
$('<i></i>').addClass('clock icon')
).click(e => {
this.download().attachments(e)
})
},
scheduledButton: () => {
return $('<i></i>').addClass('ui green circular inverted check icon')
},
schedulingButton: () => {
return $('<i></i>').addClass('ui circular inverted redo loading icon')
}
const format = Intl.DateTimeFormat('es-CL', {dateStyle: 'full', timeStyle: 'short'})
let date = new Date()
try {
date = new Date(this.get().date())
} catch (e) {
console.debug(e)
}
const valid = $('<td></td>').html($('<i></i>').addClass(this.has().valid() ? 'green check circle icon' : 'red times circle icon'))
if (this.has().valid() && this.get().attachments().length > 0) {
const list = $('<div></div>').addClass('ui list')
this.get().attachments().forEach(attachment => {
list.append($('<div></div>').addClass('item').html(attachment.filename))
})
valid.append(
$('<div></div>').addClass('ui popup').append(list)
)
}
const tr = $('<tr></tr>').append(
$('<td></td>').html(this.get().subject())
).append(
$('<td></td>').html(format.format(date))
).append(
$('<td></td>').html(this.get().from().full)
).append(
$('<td></td>').html($('<i></i>').addClass(this.has().attachments() ? 'green check circle icon' : 'red times circle icon'))
).append(
valid
).append(
$('<td></td>').html($('<i></i>').addClass(this.has().downloaded() ? 'green check circle icon' : 'red times circle icon'))
).append(
$('<td></td>').append(
(this.has().attachments() && this.has().valid() && !this.has().downloaded()) ?
$('<button></button>').addClass('ui mini green circular icon button').append(
$('<i></i>').addClass('clock icon')
).click(() => {
this.download().attachments(this.get().id())
}) : ''
)
)
if (this.has().downloaded()) {
tr.find('td').each((i, td) => {
const content = $(td).html()
if (content.indexOf('icon') > -1) {
return
}
$(td).html('')
$(td).append(
$('<a></a>').attr('href', '{{$urls->base}}/emails/message/' + this.id).html(content)
)
})
}
return tr
}
download() {
return {
attachments: event => {
const td = $(event.currentTarget).parent()
const id = this.get().id()
attachments: id => {
const uri = '/messages/schedule'
const data = {
messages: [
id
]
}
td.html('').append(this.draw().schedulingButton())
return Send.put({
uri,
data
}).then(response => {
if (response.scheduled > 0) {
td.html('').append(this.draw().scheduledButton())
alert('Scheduled Attachments Job')
}
})
}
@ -233,6 +205,9 @@
name: '',
count: ''
},
page: 1,
current: 0,
shown: 10,
total: null,
visible: [],
get: function() {
@ -246,13 +221,7 @@
},
messages: () => {
const uri = '/mailbox/{{$mailbox_id}}/messages/valid'
return Send.get(uri).then((response, status, jqXHR) => {
if (parseInt(jqXHR.status/100) !== 2 || jqXHR.status === 204) {
$(this.id.results).html('').append(
this.draw().empty()
)
return
}
return Send.get(uri).then(response => {
if (this.total === null) {
$(this.id.count).html(' (' + response.total + ')')
this.total = response.total
@ -275,6 +244,7 @@
}
},
draw: function() {
const columns = 8
return {
loader: () => {
$(this.id.results).html('').append(
@ -294,6 +264,8 @@
this.draw().head()
).append(
this.draw().body()
).append(
this.draw().footer()
)
},
head: () => {
@ -308,8 +280,43 @@
}
values.push(v)
}
const dropdown = $('<div></div>').addClass('ui scrolling dropdown').append(
$('<i></i>').addClass('dropdown icon')
).append(
$('<div></div>').addClass('text').html(this.shown)
).dropdown({
values,
onChange: (value, text, $choice) => {
if (value === this.shown) {
return
}
this.shown = parseInt(value)
// Trigger pending transition
$choice.parent().parent().dropdown('hide')
this.get()
}
})
return $('<thead></thead>').append(
$('<tr></tr>').append(
$('<th></th>').addClass('right aligned').attr('colspan', columns).append(
dropdown
).append(
$('<span></span>').addClass('ui basic label').html((this.current + 1) + ' - ' + Math.min(this.shown + this.current, this.total ?? 99999999))
).append(
$('<button></button>').addClass('ui mini circular icon button').append(
$('<i></i>').addClass('left chevron icon')
).click(() => {
this.prev()
})
).append(
$('<button></button>').addClass('ui mini circular icon button').append(
$('<i></i>').addClass('right chevron icon')
).click(() => {
this.next()
})
)
)
).append(
$('<tr></tr>').append(
$('<th></th>').html('#')
).append(
@ -332,7 +339,7 @@
body: () => {
const tbody = $('<tbody></tbody>')
this.visible.forEach((m, i) => {
const row = m.draw().row()
const row = m.draw()
row.prepend(
$('<td></td>').html(i + this.current + 1)
)
@ -340,12 +347,94 @@
})
return tbody
},
footer: () => {
const pages = this.lastPage()
const paging = $('<div></div>').addClass('ui right floated pagination menu')
if (this.page !== 1) {
paging.append(
$('<a></a>').addClass('icon item').append(
$('<i></i>').addClass('step backward icon')
).click(() => {
this.first()
})
)
}
for (let i = 0; i < pages; i ++) {
const page = $('<a></a>').addClass('item').html(i + 1).click(() => {
this.goto(i + 1)
})
if (i + 1 === this.page) {
page.addClass('active')
}
paging.append(page)
}
if (this.page !== this.lastPage()) {
paging.append(
$('<a></a>').addClass('icon item').append(
$('<i></i>').addClass('step forward icon')
).click(() => {
this.last()
})
)
}
return $('<tfoot></tfoot>').append(
$('<tr></tr>').append(
$('<th></th>').attr('colspan', columns).append(paging)
)
)
},
empty: () => {
$(this.id.count).html(' (0)')
return $('<div></div>').addClass('ui message').html('No messages found.')
}
}
},
lastPage: function() {
let pages = Math.floor(this.total / this.shown)
if (this.total / this.shown > pages) {
pages ++
}
return pages
},
first: function() {
if (this.current === 0) {
return
}
this.page = 1
this.current = 0
this.get()
},
next: function() {
if (this.current + this.shown >= this.total) {
return
}
this.page ++
this.current += this.shown
this.get()
},
goto: function(page) {
if (this.page === page) {
return
}
this.page = page
this.current = (this.page - 1) * this.shown
this.get()
},
prev: function() {
if (this.current < this.shown) {
return
}
this.page --
this.current -= this.shown
this.get()
},
last: function() {
if (this.page === this.lastPage()) {
return
}
this.page = this.lastPage()
this.current = (this.page - 1) * this.shown
this.get()
},
setup: function() {
this.get().mailbox().then(() => {
this.get().messages()
@ -359,4 +448,4 @@
messages.setup()
})
</script>
@endpush
@endpush

View File

@ -3,7 +3,7 @@
@section('emails_content')
<h3>Message - <span id="subject"></span> - <span id="from"></span></h3>
<h4 id="date_time"></h4>
<div class="ui bulleted link list" id="attachments"></div>
<div class="ui list" id="attachments"></div>
@endsection
@push('page_scripts')
@ -82,7 +82,7 @@
attachments: parent => {
this.get().attachments().forEach(attachment => {
parent.append(
$('<a></a>').attr('href', '{{$urls->base}}/attachment/' + attachment.id).attr('download', attachment.fullname).html(attachment.fullname)
$('<a></a>').attr('href', _urls.base + '/attachment/' + attachment.id).attr('download', attachment.fullname).html(attachment.fullname)
)
})
}
@ -100,4 +100,4 @@
message.setup('{{$message_id}}')
})
</script>
@endpush
@endpush

View File

@ -14,8 +14,7 @@
const uri = '/mailboxes/registered'
this.draw().loading()
return Send.get(uri).then((response, status, jqXHR) => {
if (parseInt(jqXHR.status / 100) !== 2 || jqXHR.status === 204) {
this.draw().empty()
if (parseInt(jqXHR.status / 100) !== 2) {
return
}
if (jqXHR.status === 200) {
@ -45,7 +44,7 @@
const parent = $(this.div_id)
parent.html('')
if (this.mailboxes.length === 0) {
this.draw().empty()
parent.html('No mailboxes registered.')
return
}
const list = $('<div></div>').addClass('ui list')
@ -55,13 +54,6 @@
)
})
parent.append(list)
},
empty: () => {
const parent = $(this.div_id)
parent.html('')
parent.append(
$('<div></div>').addClass('ui message').html('No mailboxes registered.')
)
}
}
}
@ -71,4 +63,4 @@
mailboxes.get()
})
</script>
@endpush
@endpush

View File

@ -3,17 +3,18 @@
base_url: '{{$urls->api}}',
base: function({method, uri, data = null}) {
const request = {
uri: uri,
uri: uri.replace(/^\//g, ''),
method
}
const options = {
url: this.base_url,
method: 'post',
contentType: 'application/json'
}
if (method.toLowerCase() !== 'get' && data !== null) {
request['data'] = data
}
options['data'] = request
options['data'] = JSON.stringify(request)
return $.ajax(options)
},
get: function(uri) {
@ -29,5 +30,5 @@
return this.base({method: 'delete', uri, data})
}
}
//const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
</script>
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
</script>

View File

@ -1,2 +0,0 @@
<?php
$app->add($app->getContainer()->get(ProVM\Common\Middleware\Logging::class));

View File

@ -20,7 +20,6 @@ return [
$arr['base'],
'cache'
]);
$arr['logs'] = '/logs';
return (object) $arr;
}
];
];

View File

@ -4,7 +4,7 @@ use Psr\Container\ContainerInterface;
return [
Psr\Http\Client\ClientInterface::class => function(ContainerInterface $container) {
return new GuzzleHttp\Client([
'base_uri' => $container->get('urls')->api,
'base_uri' => "http://proxy:8080",
'headers' => [
'Authorization' => [
"Bearer {$container->get('api_key')}"
@ -15,4 +15,4 @@ return [
Psr\Http\Message\RequestFactoryInterface::class => function(ContainerInterface $container) {
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
},
];
];

View File

@ -1,8 +0,0 @@
<?php
use Psr\Container\ContainerInterface;
return [
ProVM\Common\Middleware\Logging::class => function(ContainerInterface $container) {
return new ProVM\Common\Middleware\Logging($container->get('request_logger'));
}
];

View File

@ -10,23 +10,13 @@ return [
$handler->setFormatter($container->get(Monolog\Formatter\SyslogFormatter::class));
return $handler;
},
'request_logger' => function(ContainerInterface $container) {
$logger = new Monolog\Logger('request_logger');
$handler = new Monolog\Handler\RotatingFileHandler(implode(DIRECTORY_SEPARATOR, [$container->get('folders')->logs, 'requests.log']));
$handler->setFormatter($container->get(Monolog\Formatter\SyslogFormatter::class));
$dedupHandler = new Monolog\Handler\DeduplicationHandler($handler, null, Monolog\Level::Info);
$logger->pushHandler($dedupHandler);
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
return $logger;
},
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
$logger = new Monolog\Logger('file_logger');
$logger->pushHandler($container->get(Monolog\Handler\DeduplicationHandler::class));
//$logger->pushHandler($container->get(Monolog\Handler\RotatingFileHandler::class));
$logger->pushProcessor($container->get(Monolog\Processor\PsrLogMessageProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\IntrospectionProcessor::class));
$logger->pushProcessor($container->get(Monolog\Processor\MemoryUsageProcessor::class));
return $logger;
},
];
}
];