|
@@ -2,114 +2,67 @@
|
|
|
|
|
|
namespace FTTHBundle\Controller;
|
|
|
|
|
|
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
-use Symfony\Component\HttpFoundation\Request;
|
|
|
-use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
-use Symfony\Component\HttpFoundation\Response;
|
|
|
-use FTTHBundle\Entity\ONU;
|
|
|
-use FTTHBundle\Entity\PreSale;
|
|
|
-use MapBundle\Entity\Location;
|
|
|
-use WebserviceBundle\Form\Type\RemoteClientType;
|
|
|
-use MapBundle\Form\Type\RemoteMapType;
|
|
|
use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
+use FTTHBundle\Entity\CaptivePortal;
|
|
|
+use Sonata\AdminBundle\Controller\CRUDController;
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
+use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
/**
|
|
|
* CaptivePortal controller.
|
|
|
+ * @RouteResource("CaptivePortal")
|
|
|
*/
|
|
|
-class CaptivePortalController extends Controller
|
|
|
+class CaptivePortalController extends CRUDController
|
|
|
{
|
|
|
-
|
|
|
- public function portalAction(Request $request)
|
|
|
+ public function configurationAction(Request $request)
|
|
|
{
|
|
|
-
|
|
|
- $client = $request->query->get('client');
|
|
|
- $psn = $request->query->get('psn');
|
|
|
- $preSale = $request->query->get('preSale');
|
|
|
- $preSales = $errors = array();
|
|
|
- $result = false;
|
|
|
-
|
|
|
- if(!is_null($client) && !is_null($psn)) {
|
|
|
-
|
|
|
- $em = $this->get("doctrine.orm.entity_manager");
|
|
|
- $em->getFilters()->disable('tenancy_filter');
|
|
|
- $preSales = $em->getRepository(PreSale::class)->findBy(array('clientId' => $client));
|
|
|
- $onu = $em->getRepository(ONU::class)->findOneBy(array('ponSerialNumber' => $psn));
|
|
|
-
|
|
|
- if(empty($preSales)) $errors[] = "We don't register a pending installation to this client.";
|
|
|
-
|
|
|
- if(is_null($onu)) $errors[] = "ONU doesn't exist.";
|
|
|
-
|
|
|
- if(!is_null($preSale) && !is_null($onu)) {
|
|
|
- $sale = $em->getRepository(PreSale::class)->findOneById($preSale);
|
|
|
-
|
|
|
- if($sale) {
|
|
|
- $this->updateOnu($sale->getClientId(), $sale->getProfile(), $onu, $sale->getAddress(), $em);
|
|
|
-
|
|
|
- $onu = $em->getRepository(ONU::class)->findOneBy(array('ponSerialNumber' => $psn));
|
|
|
-
|
|
|
- if($onu->getClientId() == $sale->getClientId() && $onu->getProfile() == $sale->getProfile()) {
|
|
|
- $result = true;
|
|
|
- $em->remove($sale);
|
|
|
- $em->flush();
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ $flashbag = $this->get('session')->getFlashBag();
|
|
|
+ $translator = $this->get('translator');
|
|
|
+
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $captivePortalRepository = $em->getRepository(CaptivePortal::class);
|
|
|
+
|
|
|
+ $configurations = $captivePortalRepository->findAll();
|
|
|
+ $captivePortal = empty($configurations) ? new CaptivePortal() : end($configurations);
|
|
|
+
|
|
|
+ $form = $this->createFormBuilder($captivePortal)
|
|
|
+ ->add('ip', TextType::class, [
|
|
|
+ 'attr' => [
|
|
|
+ 'class' => 'col-xs-12',
|
|
|
+ 'data-mask' => '000.000.000.000',
|
|
|
+ ],
|
|
|
+ 'label' => $translator->trans('form.label_captiveportal_ip', [], 'FTTHBundle'),
|
|
|
+ ])
|
|
|
+ ->add('ip_range', TextType::class, [
|
|
|
+ 'attr' => [
|
|
|
+ 'class' => 'col-xs-12',
|
|
|
+ 'data-mask' => '00',
|
|
|
+ ],
|
|
|
+ 'label' => $translator->trans('form.label_captiveportal_ip_range', [], 'FTTHBundle'),
|
|
|
+ ])
|
|
|
+ ->add('html_page', TextareaType::class, [
|
|
|
+ 'attr' => ['class' => 'col-xs-12'],
|
|
|
+ 'label' => $translator->trans('form.label_captiveportal_html', [], 'FTTHBundle'),
|
|
|
+ ])
|
|
|
+ ->getForm();
|
|
|
+
|
|
|
+ $request = Request::createFromGlobals();
|
|
|
+ $form->handleRequest($request);
|
|
|
+ if ($form->isSubmitted()) {
|
|
|
+ if ($form->isValid()) {
|
|
|
+ $em->persist($captivePortal);
|
|
|
+ $em->flush();
|
|
|
+ $flashbag->add('success', $translator->trans('msg_captiveportal_success', [], 'FTTHBundle'));
|
|
|
+ } else {
|
|
|
+ $flashbag->add('warning', $translator->trans('msg_captiveportal_required_fields', [], 'FTTHBundle'));
|
|
|
}
|
|
|
- $em->getFilters()->enable('tenancy_filter');
|
|
|
+ return new RedirectResponse($this->admin->generateUrl('configuration'));
|
|
|
}
|
|
|
|
|
|
- return $this->render('FTTHBundle:Portal:index.html.twig', array(
|
|
|
- 'result' => $result,
|
|
|
- 'errors' => $errors,
|
|
|
- 'preSales' => $preSales,
|
|
|
- 'client' => $client,
|
|
|
- 'psn' => $psn
|
|
|
- ));
|
|
|
+ return $this->render('FTTHBundle:CaptivePortal:form.html.twig', [
|
|
|
+ 'form' => $form->createView(),
|
|
|
+ ]);
|
|
|
}
|
|
|
-
|
|
|
- private function updateOnu($clientId, $profile, $onu, $address, $em) {
|
|
|
-
|
|
|
- if(!is_null($address) && $this->getParameter('googlemaps_api_key')) {
|
|
|
- $key = $this->getParameter('googlemaps_api_key');
|
|
|
- $addr = urlencode($address);
|
|
|
-
|
|
|
- try {
|
|
|
- $data = $this->getSslPage("https://maps.googleapis.com/maps/api/geocode/json?address={$addr}&key={$key}");
|
|
|
- $data = json_decode($data,true);
|
|
|
- } catch(\Exception $e) {
|
|
|
- $data = array();
|
|
|
- }
|
|
|
-
|
|
|
- if($data['status'] == 'OK') {
|
|
|
- $geoInformation = $data['results'][0];
|
|
|
- $extraData = array();
|
|
|
- $extraData['formatted_address'] = $geoInformation['formatted_address'];
|
|
|
- $extraData['lat'] = $geoInformation['geometry']['location']['lat'];
|
|
|
- $extraData['lng'] = $geoInformation['geometry']['location']['lng'];
|
|
|
- $extraData['zoom'] = 18;
|
|
|
-
|
|
|
- $location = new Location();
|
|
|
- $location->setJsonExtraData($extraData);
|
|
|
-
|
|
|
- $onu->setLocation($location);
|
|
|
- $onu->setJsonExtraData($extraData);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $onu->setClientId($clientId);
|
|
|
- $onu->setProfile($profile);
|
|
|
-
|
|
|
- $em->persist($onu);
|
|
|
- $em->flush();
|
|
|
- }
|
|
|
-
|
|
|
- function getSslPage($url) {
|
|
|
- $ch = curl_init();
|
|
|
- curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
- $result = curl_exec($ch);
|
|
|
- curl_close($ch);
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
}
|