Explorar o código

Merge branch 'master' of https://gitlab.com/interlink-sa/flowdat3/modules/ftth into ftth#48

Maximiliano Schvindt %!s(int64=6) %!d(string=hai) anos
pai
achega
7c6cebcd18

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
app/DoctrineMigrations/src/action.yml


+ 50 - 0
src/RadiusBundle/EventListener/NASPreUpdateListener.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace RadiusBundle\EventListener;
+
+use Doctrine\ORM\Event\LifecycleEventArgs;
+use RadiusBundle\Entity\NAS;
+
+class NASPreUpdateListener
+{
+
+    /**
+     * Check if host ip of a NAS changes
+     * and try to delete it from freeradius DB
+     * 
+     * @param LifecycleEventArgs $args
+     */
+    public function preUpdate(LifecycleEventArgs $args)
+    {
+        try {
+            $this->em = $args->getEntityManager();
+            $entity = $args->getEntity();
+            if ($entity instanceof NAS) {
+                $meta = $this->em->getClassMetadata(get_class($entity));
+                $uow = $this->em->getUnitOfWork();
+                $uow->recomputeSingleEntityChangeSet($meta, $entity);
+                $changeset = $uow->getEntityChangeSet($entity);
+    
+                if (isset($changeset['host'])) {
+                    $radiusJSON = [
+                        'acct_enabled' => $entity->isAcctEnabled(),
+                        'community' => $entity->getSnmpComunity(),
+                        'description' => 'NAS-' . $entity->getId(),
+                        'nasname' => $changeset['host'][0],
+                        'ports' => null,
+                        'secret' => $entity->getRadiusPassword(),
+                        'server' => 'radius',
+                        'shortname' => $changeset['host'][0],
+                        'type' => 'Mikrotik',
+                    ];
+                    $file = '/tmp/radius-client-' . $entity->getId() . '.json';
+                    file_put_contents($file, json_encode($radiusJSON));
+                    shell_exec('/opt/json-wsdl/console wsdl:op "http://freeradius/radius.php?class=AccessServiceManager&wsdl" deleteRadiusClient ' . $file);
+                }
+            }
+        } catch (\Exception $ex) {
+
+        }
+    }
+
+}

+ 5 - 0
src/RadiusBundle/Resources/config/services.yml

@@ -14,3 +14,8 @@ services:
             - { name: sonata.admin, manager_type: orm, group: Radius, label: NAS, label_catalogue: RadiusBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:
             - [setTranslationDomain, [RadiusBundle]]
+
+    nas.pre_update.listener:
+        class: RadiusBundle\EventListener\NASPreUpdateListener
+        tags:
+            - { name: doctrine.event_listener, event: preUpdate }