src/Controller/MainController.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Request;
  6. class MainController extends AbstractController
  7. {
  8.     public function homepageAction()
  9.     {
  10.         return $this->render('main/homepage.html.twig');
  11.     }
  12.     /**
  13.      * @Route("/privacypolicy", name="privacypolicy")
  14.      */
  15.     public function policyAction()
  16.     {
  17.         return $this->render('main/privacypolicy.html.twig');
  18.     }
  19.     /**
  20.      * @Route("/initPortal/{portalName}", name="initPortal")
  21.      */
  22.     public function initPortalAction(Request $request$portalName) {
  23.         $portal $this->getDoctrine()->getRepository('App:CaptivePortal')
  24.                        ->findOneByName($portalName);
  25.         /*
  26.          * Prüfe ob Portal existiert
  27.          */
  28.         if (!$portal) {
  29.             throw $this->createNotFoundException(
  30.                 'No Captive Portal found: '.$portalName
  31.             );
  32.         }
  33.         /*
  34.          * Prüfe ob Portal aktiv ist
  35.          */
  36.         if(!$portal->getIsActive()) {
  37.             throw $this->createAccessDeniedException(
  38.                 'Captive Portal disabled: '.$portalName
  39.             );
  40.         }
  41.         /**
  42.          * Prüfe Sprache von Browser
  43.          */
  44.         $lang $request->getLanguages();
  45.         if(in_array("de"$lang)) {
  46.             $locale "de";
  47.         } elseif(in_array("en"$lang)) {
  48.             $locale "en";
  49.         } else {
  50.             $locale "de";
  51.         }
  52.         /**
  53.          * Checke ob POST Variabeln gesetzt sind und speichere diese in einer Session
  54.          */
  55.         $session $request->getSession();
  56.         $session->clear();
  57.         $session->set('portalName'$portalName);
  58.         $checkPostVarActionUrl $request->request->get('action');
  59.         if(isset($checkPostVarActionUrl)) {
  60.             $session->set('actionurl'$request->request->get('action'));
  61.             $session->set('redirurl'$request->request->get('redirurl'));
  62.             $session->set('client_mac'$request->request->get('client_mac'));
  63.             $session->set('client_ip'$request->request->get('client_ip'));
  64.             $session->set('zone'$request->request->get('zone'));
  65.             $session->set('portalName'$portalName);
  66.         }
  67.         if(!$session->get('actionurl')) {
  68.             $session->set('actionurl''http://' $portal->getFirewallIPAdresse() .':8002/index.php?zone='$session->get('actionurl'));
  69.             $session->set('redirurl'$portal->getRedirectURL());
  70.         }
  71.         /*
  72.          * Prüfe ob Internetzugang frei ist
  73.          */
  74.         if($portal->getFreeAccess()) {
  75.             return $this->render('client/sendBack.html.twig', [
  76.                 'actionurl' => $session->get('actionurl'),
  77.                 'zone' => $session->get('zone'),
  78.                 'redirurl' => $portal->getRedirectURL(),
  79.                 'firewall' => $portal->getFirewallType(),
  80.             ]);
  81.         }
  82.         if($portal->getInitAction()->getRoute() !== null) {
  83.             return $this->redirectToRoute$portal->getInitAction()->getRoute(), array(
  84.                 'portalName' => $portalName,
  85.                 '_locale'    => $locale
  86.             ) );
  87.         } else {
  88.             return $this->redirectToRoute'voucher_login', array(
  89.                 'portalName' => $portalName,
  90.                 '_locale'    => $locale
  91.             ) );
  92.         }
  93.     }
  94. }