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

1st Implementation of MTA-STS Report processing (reverted) #3

Merged
merged 9 commits into from
Sep 19, 2023

Conversation

antedebaas
Copy link
Owner

This project is now also able to process mta-sts reports from the same inbox.

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(MTASTS_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(MTASTS_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

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

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

return $this->render('mtasts_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("MTASTS"), 'url' => $this->router->generate('app_mtasts_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(MTASTS_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(MTASTS_Seen::class);
$reportsseen = $repository->getSeen($reports, $this->getUser()->getId());

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

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

return $this->render('mtasts_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("MTASTS"), 'url' => $this->router->generate('app_mtasts_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 6c181d8 into main Sep 19, 2023
3 checks passed
@antedebaas antedebaas deleted the mta-sts branch September 19, 2023 17:58
Repository owner locked as resolved and limited conversation to collaborators Sep 19, 2023
@antedebaas antedebaas changed the title Implement MTA-STS Report processing 1st Implementation of MTA-STS Report processing (reverted) Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant