diff --git a/vendor/action/log/log_save copy.php b/vendor/action/log/log_save copy.php
new file mode 100644
index 0000000..52803d1
--- /dev/null
+++ b/vendor/action/log/log_save copy.php
@@ -0,0 +1,510 @@
+setKey($key);
+ $LogValidate->setFile($file);
+
+ /** Verifica se não existem erros a serem informados,
+ * caso não haja erro(s) salvo os dados ou
+ * efetua o cadastro de um novo*/
+
+ /** Verifico a existência de erros */
+ if (!empty($LogValidate->getErrors())) {
+
+ /** Informo */
+ throw new InvalidArgumentException($LogValidate->getErrors(), 0);
+ } else {
+
+ /** Converte o json em objeto para manipular o mesmo */
+ $jsonLog = json_decode($LogValidate->getFile());
+
+ /** Verifica se o cliente informado existe */
+ $ClientResult = $Client->GetCns($jsonLog->cns);
+
+ /** Caso o cliente não exista, cadastro o mesmo */
+ if ($ClientResult->client_id == 0) {
+
+ /** Caso o cliente não exista, cadastra o novo */
+ if (!$Client->Save(
+ null,
+ $jsonLog->cns,
+ $jsonLog->cartorio,
+ null,
+ null,
+ null,
+ null,
+ null
+ )) {
+
+ /** Informo */
+ throw new InvalidArgumentException('Não foi possível cadastrar o cartório', 0);
+ }
+ }
+
+ /** Id do cliente */
+ $clientId = $ClientResult->client_id > 0 ? $ClientResult->client_id : $Client->getId();
+
+ /** Exclui antigas unidades */
+ $StationDisk->Delete($clientId);
+
+ /** Exclui as antigas pastas */
+ $StationFolder->Delete($clientId);
+
+ /** Exclui todas as estações de um determinado cliente */
+ $Station->Delete($clientId);
+
+ /** Cadastra a estação novamente */
+ if (!$Station->Save(
+ null,
+ $clientId,
+ null,
+ trim($jsonLog->estacao),
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ trim($jsonLog->server->sistema_operacional),
+ trim($jsonLog->server->cpu),
+ trim($jsonLog->server->memory)
+ )) {
+
+ /** Informo */
+ throw new InvalidArgumentException($Station->getErrors(), 0);
+ }
+
+ /** Id da estação */
+ $stationId = $Station->getId();
+
+
+ // Percorre cada disco (C:, D:, etc.)
+ foreach ($jsonLog->disk as $drive => $details) {
+
+ // Percorre cada atributo do disco
+ $i = 0;
+ foreach ($details as $key => $value) {
+
+ if ($i == 0) {
+ $capacidade = $value;
+ }
+
+ if ($i == 1) {
+ $utilizados = $value;
+ }
+
+ if ($i == 2) {
+ $disponivel = $value;
+ }
+
+ if ($i == 3) {
+ $disponivel_percentual = $value;
+ }
+
+ $i++;
+ }
+
+ /** Grava o novo disco ou atualiza o atual */
+ if (!$StationDisk->Save(
+ 0,
+ $clientId,
+ $stationId,
+ $drive,
+ $capacidade,
+ $utilizados,
+ $disponivel,
+ $disponivel_percentual
+ )) {
+
+ /** Informo */
+ throw new InvalidArgumentException($StationDisk->getErrors(), 0);
+ }
+ }
+
+ // Percorre a pasta Ged
+ foreach ($jsonLog->ged as $path => $details) {
+
+ /** Verifica se não é informação da partição */
+ if($path !== 'partition'){
+
+ // Percorre cada atributo da pasta
+ foreach ($details as $key => $value) {
+
+ /** Grava uma nova pasta ou atualiza o atual */
+ if (!$StationFolder->Save(
+ 0,
+ $clientId,
+ $stationId,
+ $path,
+ $value,
+ $value
+ )) {
+
+ /** Informo */
+ throw new InvalidArgumentException($StationDisk->getErrors(), 0);
+ }
+ }
+ }
+ }
+
+
+ /** Deleta os dados da partição */
+ $StationFolder->DeletePartition($clientId);
+
+ /** Grava os detalhes da partição GED */
+ $StationFolder->SavePartition($jsonLog->ged->{'partition'},
+ $clientId,
+ $stationId);
+
+ /** Exclui os registros anteriores */
+ $Backup->Delete($clientId, $stationId);
+
+ // Percorre a pasta Backup
+ foreach ($jsonLog->backup as $file => $details) {
+
+
+ // Percorre cada atributo da pasta
+ $i = 0;
+ foreach ($details as $key => $value) {
+
+ if ($i == 0) {
+ $fileDate = $Main->DataDB($value);
+ }
+
+ if ($i == 1) {
+ $fileHour = $value;
+ }
+
+ if ($i == 2) {
+ $period = $value;
+ }
+
+ if ($i == 3) {
+ $day = $value;
+ }
+
+ if ($i == 4) {
+ $size = $value;
+ }
+
+ if ($i == 5) {
+ $path = $value;
+ }
+
+ $i++;
+ }
+
+ /** Grava o arquivo de backup */
+ $Backup->Save(
+ $clientId,
+ $stationId,
+ $file,
+ $fileDate,
+ $fileHour,
+ $period,
+ $day,
+ $size,
+ $path
+ );
+ }
+
+ /** Exclui o registro anterior sobre o banco de dados */
+ $Database->Delete($clientId);
+
+ /** Grava os novos dados do banco de dados */
+ if(!$Database->Save($clientId,
+ $jsonLog->database->file_size_mb,
+ $jsonLog->database->last_modified,
+ $jsonLog->database->db_accessible,
+ json_encode($jsonLog->database->partition))){
+
+ /** Informo */
+ throw new InvalidArgumentException('Não foi possível atualizar as informações de banco de dados', 0);
+
+ }
+
+ /** Exclui o log anterior da estação correspondente */
+ $Log->Delete($clientId, $stationId);
+
+ /** Grava o arquivo de log */
+ if (!$Log->Save($clientId, $stationId, $LogValidate->getFile())) {
+
+ /** Informo */
+ throw new InvalidArgumentException('Não foi possível cadastrar o arquivo de log', 0);
+ }
+
+ /** Gera o PDF com o resumo do cartório */
+
+ /** Aumenta o uso de memória */
+ ini_set('memory_limit', '512M');
+
+ /** Inicio do relatório */
+
+ /** Instancia da classe Mpdf */
+ $mpdf = new \Mpdf\Mpdf([
+ 'mode' => 'utf-8',
+ 'orientation' => 'L'
+ ]);
+
+ /** Prepara o cabeçalho */
+ $header = '
';
+ $header .= ' ';
+ $header .= '  | ';
+ $header .= ' ';
+ $header .= ' ' . $ClientResult->name . '';
+ $header .= ' | ';
+ $header .= '
';
+ $header .= '
';
+
+ /** Define i cabeçalho do relatório */
+ $mpdf->SetHTMLHeader($header);
+
+ /** Define o rodapé do relatório */
+ $mpdf->SetHTMLFooter('
+ ');
+
+ /** Adicionar as margens da página */
+ $mpdf->AddPageByArray([
+ 'margin-top' => 28
+ ]);
+
+
+ /** Consulta a quantidade de registros */
+ $StationResult = $Station->All($clientId);
+
+ /** Lista as estações do cliente */
+ foreach ($StationResult as $StationKey => $Result) {
+
+ /** Inicio do corpo do relatório */
+
+ /** Dados do servidor */
+ $body .= ' ';
+ $body .= ' ';
+ $body .= ' Detalhes Servidor | ';
+ $body .= '
';
+ $body .= ' ';
+ $body .= ' | DESCRIÇÃO | ';
+ $body .= ' SO | ';
+ // $body .= ' CPU | ';
+ $body .= ' MEMÓRIA | ';
+ $body .= '
';
+ $body .= ' ';
+ $body .= ' | ' . $Result->description . ' | ';
+ $body .= ' ' . $Result->operating_system . ' | ';
+ // $body .= ' '.htmlspecialchars($Result->cpu).' | ';
+ $body .= ' ' . $Result->memory . ' | ';
+ $body .= '
';
+ $body .= '
';
+
+
+ /** Discos */
+ $body .= ' ';
+ $body .= ' ';
+ $body .= ' Discos | ';
+ $body .= '
';
+ $body .= ' ';
+ $body .= ' | DESCRIÇÃO | ';
+ $body .= ' CAPACIDADE | ';
+ $body .= ' UTILIZADOS | ';
+ $body .= ' DISPONÍVEL | ';
+ $body .= ' DISPONÍVEL % | ';
+ $body .= '
';
+
+ /** Consulta a quantidade de registros */
+ $StationDiskResult = $StationDisk->All($Result->station_id);
+
+ /** Lista as estações do cliente */
+ foreach ($StationDiskResult as $StationDiskKey => $ResultDisk) {
+
+
+ $body .= ' ';
+ $body .= ' | ' . $ResultDisk->description . ' | ';
+ $body .= ' ' . $ResultDisk->capacity . ' | ';
+ $body .= ' ' . $ResultDisk->used . ' | ';
+ $body .= ' ' . $ResultDisk->available . ' | ';
+ $body .= ' ' . $ResultDisk->available_percentage . '% | ';
+ $body .= '
';
+ $i++;
+ }
+
+ $body .= '
';
+
+
+
+ /** Ged */
+ $body .= ' ';
+ $body .= ' ';
+ $body .= ' Ged | ';
+ $body .= '
';
+ $body .= ' ';
+ $body .= ' | ATUALIZADO | ';
+ $body .= ' PATH | ';
+ $body .= ' QTDE | ';
+ $body .= ' QTDE ATUAL | ';
+ $body .= '
';
+
+ /** Consulta a quantidade de registros */
+ $StationFolderResult = $StationFolder->All($Result->station_id);
+
+ /** Lista as estações do cliente */
+ foreach ($StationFolderResult as $StationFolderKey => $ResultFolder) {
+
+
+ $body .= ' ';
+ $body .= ' | ' . (!empty($ResultFolder->last_update) ? date('d/m/Y H:i:s', strtotime($ResultFolder->last_update)) : null) . ' | ';
+ $body .= ' ' . $ResultFolder->folder_path . ' | ';
+ $body .= ' ' . $ResultFolder->amount_of_files . ' | ';
+ $body .= ' ' . $ResultFolder->amount_of_files_current . ' | ';
+ $body .= '
';
+ $i++;
+ }
+
+ $body .= '
';
+
+
+
+ /** Backup */
+ $body .= ' ';
+ $body .= ' ';
+ $body .= ' Backup | ';
+ $body .= '
';
+ $body .= ' ';
+ $body .= ' | ARQUIVO | ';
+ $body .= ' DATA | ';
+ $body .= ' HORA | ';
+ $body .= ' DIA | ';
+ $body .= ' TAMANHO | ';
+ $body .= ' CAMINHO | ';
+ $body .= '
';
+
+ /** Consulta a quantidade de registros */
+ $BackupResult = $Backup->All($Result->client_id, $Result->station_id);
+
+ /** Lista as estações do cliente */
+ foreach ($BackupResult as $BackupKey => $ResultBackup) {
+
+ /** Verifica se existe arquivo com arquivo menor que 1kb */
+ if (strpos($ResultBackup->size, "B") !== false) {
+
+ /** Limpa o nome do tamanho do arquivo */
+ $size = str_replace('B', '', $ResultBackup->size);
+ $size = str_replace('.', '', $size);
+
+ if ((int)$size < 1024) {
+
+ $robot++;
+ $color++;
+ }
+ }
+
+ $body .= ' ';
+ $body .= ' | ' . $ResultBackup->file . ' | ';
+ $body .= ' ' . date('d/m/Y', strtotime($ResultBackup->file_date)) . ' | ';
+ $body .= ' ' . date('H:i:s', strtotime($ResultBackup->file_hour)) . ' | ';
+ $body .= ' ' . $ResultBackup->day . ' | ';
+ $body .= ' ' . $ResultBackup->size . ' | ';
+ $body .= ' ' . $ResultBackup->path . ' | ';
+ $body .= '
';
+ $i++;
+ $color = 0;
+ }
+
+ $body .= '
';
+
+ $serverName = $Result->description;
+ }
+
+
+ /** Acrescenta os dados ao corpo do relatório */
+ $mpdf->WriteHTML($body);
+
+ /** Nome que será dado ao relatório */
+ $nameFile = $ClientResult->cns . '.pdf';
+
+ /** Salva o relatório em uma pasta temporária */
+ $mpdf->Output($dir . $nameFile);
+
+ /** Verifica se o arquivo PDF foi gerado */
+ if (is_file($dir . $nameFile)) {
+
+ /** Verifica se é para enviar a notificação para o Telegram */
+ if ($robot > 0) {
+
+ /** Monta a mensagem de envio */
+ $message = "(" . $ClientResult->cns . ")" . $ClientResult->name . "\n";
+ $message .= "Data: " . date('d/m/Y') . "\n";
+ $message .= "Hora: " . date('H:i:s') . "\n";
+ $message .= "Estação: " . $Result->description . "\n\n";
+ $message .= "Para gerenciamento completo, acesse:\n";
+ $message .= $urlRel."\n\n";
+ $message .= "Acesse o relatório detalhado no link abaixo:\n";
+ $message .= $urlRel . $dir . $nameFile . "\n\n";
+
+
+ /** Envia o log para o bot */
+ $Log->sendMessage($message, $ClientResult->cns);
+ }
+ }
+ }
+} catch (Exception $exception) {
+
+ /** Preparo o formulario para retorno **/
+ $result = [
+
+ 'cod' => 0,
+ 'message' => '' . $exception->getMessage() . '
',
+ 'title' => 'Atenção',
+ 'type' => 'exception'
+
+ ];
+
+ /** Envio **/
+ echo json_encode($result);
+
+ /** Paro o procedimento **/
+ exit;
+}
diff --git a/vendor/action/log/log_save.php b/vendor/action/log/log_save.php
index 52803d1..06320f1 100644
--- a/vendor/action/log/log_save.php
+++ b/vendor/action/log/log_save.php
@@ -6,24 +6,12 @@ require_once('vendor/library/mpdf/vendor/autoload.php');
/** Importação de classes */
use vendor\model\Log;
use vendor\model\Client;
-use vendor\model\Backup;
-use vendor\model\Station;
-use vendor\model\StationDisk;
-use vendor\model\StationFolder;
-use vendor\model\Database;
-use vendor\controller\log\LogValidate;
try {
/** Instânciamento de classes */
$Log = new Log();
$Client = new Client();
- $Backup = new Backup();
- $Station = new Station();
- $Database = new Database();
- $StationDisk = new StationDisk();
- $LogValidate = new LogValidate();
- $StationFolder = new StationFolder();
/** Parametros de entrada */
$key = isset($_POST['key']) ? (string)filter_input(INPUT_POST, 'key', FILTER_SANITIZE_SPECIAL_CHARS) : '';
@@ -81,193 +69,12 @@ try {
/** Id do cliente */
$clientId = $ClientResult->client_id > 0 ? $ClientResult->client_id : $Client->getId();
- /** Exclui antigas unidades */
- $StationDisk->Delete($clientId);
-
- /** Exclui as antigas pastas */
- $StationFolder->Delete($clientId);
-
- /** Exclui todas as estações de um determinado cliente */
- $Station->Delete($clientId);
-
- /** Cadastra a estação novamente */
- if (!$Station->Save(
- null,
- $clientId,
- null,
- trim($jsonLog->estacao),
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- trim($jsonLog->server->sistema_operacional),
- trim($jsonLog->server->cpu),
- trim($jsonLog->server->memory)
- )) {
-
- /** Informo */
- throw new InvalidArgumentException($Station->getErrors(), 0);
- }
-
- /** Id da estação */
- $stationId = $Station->getId();
-
-
- // Percorre cada disco (C:, D:, etc.)
- foreach ($jsonLog->disk as $drive => $details) {
-
- // Percorre cada atributo do disco
- $i = 0;
- foreach ($details as $key => $value) {
-
- if ($i == 0) {
- $capacidade = $value;
- }
-
- if ($i == 1) {
- $utilizados = $value;
- }
-
- if ($i == 2) {
- $disponivel = $value;
- }
-
- if ($i == 3) {
- $disponivel_percentual = $value;
- }
-
- $i++;
- }
-
- /** Grava o novo disco ou atualiza o atual */
- if (!$StationDisk->Save(
- 0,
- $clientId,
- $stationId,
- $drive,
- $capacidade,
- $utilizados,
- $disponivel,
- $disponivel_percentual
- )) {
-
- /** Informo */
- throw new InvalidArgumentException($StationDisk->getErrors(), 0);
- }
- }
-
- // Percorre a pasta Ged
- foreach ($jsonLog->ged as $path => $details) {
-
- /** Verifica se não é informação da partição */
- if($path !== 'partition'){
-
- // Percorre cada atributo da pasta
- foreach ($details as $key => $value) {
-
- /** Grava uma nova pasta ou atualiza o atual */
- if (!$StationFolder->Save(
- 0,
- $clientId,
- $stationId,
- $path,
- $value,
- $value
- )) {
-
- /** Informo */
- throw new InvalidArgumentException($StationDisk->getErrors(), 0);
- }
- }
- }
- }
-
-
- /** Deleta os dados da partição */
- $StationFolder->DeletePartition($clientId);
-
- /** Grava os detalhes da partição GED */
- $StationFolder->SavePartition($jsonLog->ged->{'partition'},
- $clientId,
- $stationId);
-
- /** Exclui os registros anteriores */
- $Backup->Delete($clientId, $stationId);
-
- // Percorre a pasta Backup
- foreach ($jsonLog->backup as $file => $details) {
-
-
- // Percorre cada atributo da pasta
- $i = 0;
- foreach ($details as $key => $value) {
-
- if ($i == 0) {
- $fileDate = $Main->DataDB($value);
- }
-
- if ($i == 1) {
- $fileHour = $value;
- }
-
- if ($i == 2) {
- $period = $value;
- }
-
- if ($i == 3) {
- $day = $value;
- }
-
- if ($i == 4) {
- $size = $value;
- }
-
- if ($i == 5) {
- $path = $value;
- }
-
- $i++;
- }
-
- /** Grava o arquivo de backup */
- $Backup->Save(
- $clientId,
- $stationId,
- $file,
- $fileDate,
- $fileHour,
- $period,
- $day,
- $size,
- $path
- );
- }
-
- /** Exclui o registro anterior sobre o banco de dados */
- $Database->Delete($clientId);
-
- /** Grava os novos dados do banco de dados */
- if(!$Database->Save($clientId,
- $jsonLog->database->file_size_mb,
- $jsonLog->database->last_modified,
- $jsonLog->database->db_accessible,
- json_encode($jsonLog->database->partition))){
-
- /** Informo */
- throw new InvalidArgumentException('Não foi possível atualizar as informações de banco de dados', 0);
-
- }
/** Exclui o log anterior da estação correspondente */
- $Log->Delete($clientId, $stationId);
+ $Log->Delete($clientId);
/** Grava o arquivo de log */
- if (!$Log->Save($clientId, $stationId, $LogValidate->getFile())) {
+ if (!$Log->Save($clientId, $LogValidate->getFile())) {
/** Informo */
throw new InvalidArgumentException('Não foi possível cadastrar o arquivo de log', 0);
diff --git a/vendor/model/Log.class.php b/vendor/model/Log.class.php
index 4730606..5dc1d7a 100644
--- a/vendor/model/Log.class.php
+++ b/vendor/model/Log.class.php
@@ -163,20 +163,17 @@ class Log
}
/** Insere um novo registro no banco */
- public function Save(int $clientId, int $stationId, string $file)
+ public function Save(int $clientId, string $file)
{
/** Parametros */
$this->clientId = $clientId;
- $this->stationId = $stationId;
$this->file = $file;
/** Consulta SQL */
$this->sql = 'insert into log(client_id,
- station_id,
file
) values (:client_id,
- :station_id,
:file)';
/** Preparo o sql para receber os valores */
@@ -189,7 +186,6 @@ class Log
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('client_id', $this->clientId);
- $this->stmt->bindParam('station_id', $this->stationId);
$this->stmt->bindParam('file', $this->file);
/** Executo o SQL */
@@ -225,17 +221,14 @@ class Log
}
/** Deleta um determinado registro no banco de dados */
- function Delete(int $clientId, int $stationId)
+ function Delete(int $clientId)
{
/** Parametros de entrada */
$this->clientId = $clientId;
- $this->stationId = $stationId;
/** Consulta SQL */
$this->sql = 'delete from log
- where client_id = :client_id
- and station_id = :station_id
- and DATE(date_post) < DATE_SUB(NOW(), INTERVAL 12 HOUR);';
+ where client_id = :client_id';
/** Preparo o sql para receber os valores */
$this->stmt = $this->connection->connect()->prepare($this->sql);
@@ -247,7 +240,6 @@ class Log
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('client_id', $this->clientId);
- $this->stmt->bindParam('station_id', $this->stationId);
/** Executo o SQL */
$this->stmt->execute();