<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class MainController extends AbstractController
{
public function homepageAction()
{
return $this->render('main/homepage.html.twig');
}
/**
* @Route("/privacypolicy", name="privacypolicy")
*/
public function policyAction()
{
return $this->render('main/privacypolicy.html.twig');
}
/**
* @Route("/initPortal/{portalName}", name="initPortal")
*/
public function initPortalAction(Request $request, $portalName) {
$portal = $this->getDoctrine()->getRepository('App:CaptivePortal')
->findOneByName($portalName);
/*
* Prüfe ob Portal existiert
*/
if (!$portal) {
throw $this->createNotFoundException(
'No Captive Portal found: '.$portalName
);
}
/*
* Prüfe ob Portal aktiv ist
*/
if(!$portal->getIsActive()) {
throw $this->createAccessDeniedException(
'Captive Portal disabled: '.$portalName
);
}
/**
* Prüfe Sprache von Browser
*/
$lang = $request->getLanguages();
if(in_array("de", $lang)) {
$locale = "de";
} elseif(in_array("en", $lang)) {
$locale = "en";
} else {
$locale = "de";
}
/**
* Checke ob POST Variabeln gesetzt sind und speichere diese in einer Session
*/
$session = $request->getSession();
$session->clear();
$session->set('portalName', $portalName);
$checkPostVarActionUrl = $request->request->get('action');
if(isset($checkPostVarActionUrl)) {
$session->set('actionurl', $request->request->get('action'));
$session->set('redirurl', $request->request->get('redirurl'));
$session->set('client_mac', $request->request->get('client_mac'));
$session->set('client_ip', $request->request->get('client_ip'));
$session->set('zone', $request->request->get('zone'));
$session->set('portalName', $portalName);
}
if(!$session->get('actionurl')) {
$session->set('actionurl', 'http://' . $portal->getFirewallIPAdresse() .':8002/index.php?zone='. $session->get('actionurl'));
$session->set('redirurl', $portal->getRedirectURL());
}
/*
* Prüfe ob Internetzugang frei ist
*/
if($portal->getFreeAccess()) {
return $this->render('client/sendBack.html.twig', [
'actionurl' => $session->get('actionurl'),
'zone' => $session->get('zone'),
'redirurl' => $portal->getRedirectURL(),
'firewall' => $portal->getFirewallType(),
]);
}
if($portal->getInitAction()->getRoute() !== null) {
return $this->redirectToRoute( $portal->getInitAction()->getRoute(), array(
'portalName' => $portalName,
'_locale' => $locale
) );
} else {
return $this->redirectToRoute( 'voucher_login', array(
'portalName' => $portalName,
'_locale' => $locale
) );
}
}
}