Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SMTP-TLS Report processing #4

Merged
merged 15 commits into from
Sep 19, 2023
Merged

Implement SMTP-TLS Report processing #4

merged 15 commits into from
Sep 19, 2023

Conversation

antedebaas
Copy link
Owner

@antedebaas antedebaas commented Sep 19, 2023

Enable processing of SMTP-TLS Reports

Comment on lines +34 to +81
public function index(): Response
{
$pages=array("page"=>1,"next" => false,"prev" => false);

if(isset($_GET["page"]) && $_GET["page"] > 0)
{
$pages["page"] = intval($_GET["page"]);
} else {
$pages["page"] = 1;
}

if(isset($_GET["perpage"]) && $_GET["perpage"] > 0)
{
$pages['perpage'] = intval($_GET["perpage"]);
} else {
$pages['perpage'] = 17;
}

$repository = $this->em->getRepository(Domains::class);
$domains = $repository->findBy(array('id' => $this->getUser()->getRoles()));

$repository = $this->em->getRepository(DMARC_Reports::class);
if(in_array("ROLE_ADMIN", $this->getUser()->getRoles())) {
$reports = $repository->findBy(array(),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
} else {
$reports = $repository->findBy(array('domain' => $domains),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
}
$totalreports = $repository->getTotalRows($domains);

$repository = $this->em->getRepository(DMARC_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

if(count($reports) == 0 && $totalreports != 0 && $pages["page"] != 1) { return $this->redirectToRoute('app_dmarc_reports'); }

if($totalreports/$pages['perpage'] > $pages["page"]) { $pages["next"] = true; }
if($pages["page"]-1 > 0) { $pages["prev"] = true; }

return $this->render('dmarc_reports/index.html.twig', [
'reports' => $reports,
'pages' => $pages,
'reportsseen' => $reportsseen,
'menuactive' => 'reports',
'breadcrumbs' => array(
array('name' => $this->translator->trans("Reports"), 'url' => $this->router->generate('app_reports')),
array('name' => $this->translator->trans("DMARC"), 'url' => $this->router->generate('app_dmarc_reports'))
),
]);
}

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method index() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
Comment on lines +34 to +81
public function index(): Response
{
$pages=array("page"=>1,"next" => false,"prev" => false);

if(isset($_GET["page"]) && $_GET["page"] > 0)
{
$pages["page"] = intval($_GET["page"]);
} else {
$pages["page"] = 1;
}

if(isset($_GET["perpage"]) && $_GET["perpage"] > 0)
{
$pages['perpage'] = intval($_GET["perpage"]);
} else {
$pages['perpage'] = 17;
}

$repository = $this->em->getRepository(Domains::class);
$domains = $repository->findBy(array('id' => $this->getUser()->getRoles()));

$repository = $this->em->getRepository(DMARC_Reports::class);
if(in_array("ROLE_ADMIN", $this->getUser()->getRoles())) {
$reports = $repository->findBy(array(),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
} else {
$reports = $repository->findBy(array('domain' => $domains),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
}
$totalreports = $repository->getTotalRows($domains);

$repository = $this->em->getRepository(DMARC_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

if(count($reports) == 0 && $totalreports != 0 && $pages["page"] != 1) { return $this->redirectToRoute('app_dmarc_reports'); }

if($totalreports/$pages['perpage'] > $pages["page"]) { $pages["next"] = true; }
if($pages["page"]-1 > 0) { $pages["prev"] = true; }

return $this->render('dmarc_reports/index.html.twig', [
'reports' => $reports,
'pages' => $pages,
'reportsseen' => $reportsseen,
'menuactive' => 'reports',
'breadcrumbs' => array(
array('name' => $this->translator->trans("Reports"), 'url' => $this->router->generate('app_reports')),
array('name' => $this->translator->trans("DMARC"), 'url' => $this->router->generate('app_dmarc_reports'))
),
]);
}

Check warning

Code scanning / PHPMD

Code Size Rules: NPathComplexity Warning

The method index() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
Comment on lines +34 to +81
public function index(): Response
{
$pages=array("page"=>1,"next" => false,"prev" => false);

if(isset($_GET["page"]) && $_GET["page"] > 0)
{
$pages["page"] = intval($_GET["page"]);
} else {
$pages["page"] = 1;
}

if(isset($_GET["perpage"]) && $_GET["perpage"] > 0)
{
$pages['perpage'] = intval($_GET["perpage"]);
} else {
$pages['perpage'] = 17;
}

$repository = $this->em->getRepository(Domains::class);
$domains = $repository->findBy(array('id' => $this->getUser()->getRoles()));

$repository = $this->em->getRepository(SMTPTLS_Reports::class);
if(in_array("ROLE_ADMIN", $this->getUser()->getRoles())) {
$reports = $repository->findBy(array(),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
} else {
$reports = $repository->findOwnedBy(array('domain' => $domains),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
}
$totalreports = $repository->getTotalRows($domains, $this->getUser()->getRoles());

$repository = $this->em->getRepository(SMTPTLS_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

if(count($reports) == 0 && $totalreports != 0 && $pages["page"] != 1) { return $this->redirectToRoute('app_smtptls_reports'); }

if($totalreports/$pages['perpage'] > $pages["page"]) { $pages["next"] = true; }
if($pages["page"]-1 > 0) { $pages["prev"] = true; }

return $this->render('smtptls_reports/index.html.twig', [
'reports' => $reports,
'pages' => $pages,
'reportsseen' => $reportsseen,
'menuactive' => 'reports',
'breadcrumbs' => array(
array('name' => $this->translator->trans("Reports"), 'url' => $this->router->generate('app_reports')),
array('name' => $this->translator->trans("SMTPTLS"), 'url' => $this->router->generate('app_smtptls_reports'))
),
]);
}

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method index() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
Comment on lines +34 to +81
public function index(): Response
{
$pages=array("page"=>1,"next" => false,"prev" => false);

if(isset($_GET["page"]) && $_GET["page"] > 0)
{
$pages["page"] = intval($_GET["page"]);
} else {
$pages["page"] = 1;
}

if(isset($_GET["perpage"]) && $_GET["perpage"] > 0)
{
$pages['perpage'] = intval($_GET["perpage"]);
} else {
$pages['perpage'] = 17;
}

$repository = $this->em->getRepository(Domains::class);
$domains = $repository->findBy(array('id' => $this->getUser()->getRoles()));

$repository = $this->em->getRepository(SMTPTLS_Reports::class);
if(in_array("ROLE_ADMIN", $this->getUser()->getRoles())) {
$reports = $repository->findBy(array(),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
} else {
$reports = $repository->findOwnedBy(array('domain' => $domains),array('id' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]);
}
$totalreports = $repository->getTotalRows($domains, $this->getUser()->getRoles());

$repository = $this->em->getRepository(SMTPTLS_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

if(count($reports) == 0 && $totalreports != 0 && $pages["page"] != 1) { return $this->redirectToRoute('app_smtptls_reports'); }

if($totalreports/$pages['perpage'] > $pages["page"]) { $pages["next"] = true; }
if($pages["page"]-1 > 0) { $pages["prev"] = true; }

return $this->render('smtptls_reports/index.html.twig', [
'reports' => $reports,
'pages' => $pages,
'reportsseen' => $reportsseen,
'menuactive' => 'reports',
'breadcrumbs' => array(
array('name' => $this->translator->trans("Reports"), 'url' => $this->router->generate('app_reports')),
array('name' => $this->translator->trans("SMTPTLS"), 'url' => $this->router->generate('app_smtptls_reports'))
),
]);
}

Check warning

Code scanning / PHPMD

Code Size Rules: NPathComplexity Warning

The method index() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
@antedebaas antedebaas merged commit f9e03de into main Sep 19, 2023
3 checks passed
@antedebaas antedebaas deleted the smtp-tls branch September 19, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant