diff options
author | devega <ma.devega@globunet.com> | 2019-05-14 15:07:02 +0200 |
---|---|---|
committer | devega <ma.devega@globunet.com> | 2019-05-14 15:07:02 +0200 |
commit | c29287f02d8fcdae44729ed3d7d05a166f250143 (patch) | |
tree | 82c103b873e4082084c4cdae6d81ccbeafa67f8f | |
parent | 3218b460596cdc369f9f5dcb0abffe7c773e6bb0 (diff) |
- Creado los parámetros en Repositorio. (se guarda el client y secret de acceso Auth2)
- Modificado los end-points de command y trace
- Modificado el recurso enviar comandos: Asignado los parametros timeout al enviar petición al cliente por CURL
- Modificado el recurso trace: Corregido los comandos de Inventario Software y Hardware para recoger el resultado en la variable output.
8 files changed, 197 insertions, 257 deletions
diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/CommandController.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/CommandController.php index 26993874..0a683996 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/CommandController.php +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/CommandController.php @@ -11,6 +11,7 @@ namespace Opengnsys\ServerBundle\Controller\Api; use FOS\RestBundle\Context\Context; +use Opengnsys\ServerBundle\Entity\Enum\ClientStatus; use Opengnsys\ServerBundle\Entity\Trace; use Opengnsys\ServerBundle\Entity\Client; use Opengnsys\ServerBundle\Entity\Command; @@ -276,6 +277,7 @@ class CommandController extends ApiController }else{ foreach ($clients as $client) { + $client->setStatus(ClientStatus::BUSY); $trace = new Trace(); $trace->setClient($client); $trace->setExecutedAt(new \DateTime()); @@ -372,6 +374,9 @@ class CommandController extends ApiController // recibimos la respuesta y la guardamos en una variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. + curl_setopt($ch, CURLOPT_TIMEOUT, 20); //timeout in seconds + $remote_server_output = curl_exec ($ch); $remote_server_error = ""; diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/TraceController.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/TraceController.php index 62f11768..fcac9adc 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/TraceController.php +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Controller/Api/TraceController.php @@ -11,6 +11,7 @@ namespace Opengnsys\ServerBundle\Controller\Api; use FOS\RestBundle\Context\Context; +use Opengnsys\ServerBundle\Entity\Enum\ClientStatus; use Opengnsys\ServerBundle\Entity\Hardware; use Opengnsys\ServerBundle\Entity\HardwareProfile; use Opengnsys\ServerBundle\Entity\Image; @@ -146,14 +147,16 @@ class TraceController extends ApiController if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); - $clientId = $data['client']; + $clientIp = $data['ip']; + $clientMac = $data['mac']; $traceId = $data['trace']; $status = $data['status']; - $output = $data['output']; - $error = $data['error']; + $output = base64_decode($data['output']); + $error = base64_decode($data['error']); $logger->info("----------- COMMAND STATUS -----------"); - $logger->info("client: ".$clientId); + $logger->info("clientId: ".$clientIp); + $logger->info("clientMac: ".$clientMac); $logger->info("trace: ".$traceId); $logger->info("status: ".$status); $logger->info("output: ".$output); @@ -163,64 +166,66 @@ class TraceController extends ApiController $traceRepository = $em->getRepository(Trace::class); $trace = $traceRepository->findOneBy(array("id"=>$traceId)); + // Doble comprobación if($trace != null){ $trace->setStatus($status); $trace->setOutput($output); $trace->setError($error); $trace->setFinishedAt(new \DateTime()); + $client = $trace->getClient(); + switch ($trace->getCommandType()){ case \Opengnsys\ServerBundle\Entity\Enum\CommandType::HARDWARE_INVENTORY: $hardwareRepository = $em->getRepository(Hardware::class); $hardwareProfileRepository = $em->getRepository(HardwareProfile::class); $logger->info("-> HARDWARE_INVENTORY <-"); - $path = $this->getParameter('path_client'); - $client = $trace->getClient(); + //$path = $this->getParameter('path_client'); if($client != null){ - $ip = $client->getIp(); - $file = "hard-".$ip; - - $filePath = $path.$file; - - if(file_exists($filePath)) { - $description = "HardwareProfile-".$client->getName(); - $hardwareProfile = $hardwareProfileRepository->findOneBy(array("description"=>$description)); - if($hardwareProfile == null){ - $logger->info("Crea Hardware Profile: ". $description); - $hardwareProfile = new HardwareProfile(); - $hardwareProfile->setDescription($description); - $em->persist($hardwareProfile); - }else{ - $logger->info("Ya existe Hardware Profile: ". $description); - $hardwareProfile->getHardwares()->clear(); - } + //$ip = $client->getIp(); + //$file = "hard-".$ip; + //$filePath = $path.$file; + + //if(file_exists($filePath)) { + $description = "HardwareProfile-".$client->getName(); + $hardwareProfile = $hardwareProfileRepository->findOneBy(array("description"=>$description)); + if($hardwareProfile == null){ + $logger->info("Crea Hardware Profile: ". $description); + $hardwareProfile = new HardwareProfile(); + $hardwareProfile->setDescription($description); + $em->persist($hardwareProfile); + }else{ + $logger->info("Ya existe Hardware Profile: ". $description); + $hardwareProfile->getHardwares()->clear(); + } - $data = file_get_contents($filePath); - - $data = explode("\n",trim($data)); - unset($data[0]); - foreach ($data as $item){ - $item = explode("=",trim($item)); - - $type = array_key_exists(0, $item)?trim($item[0]):""; - $description = array_key_exists(1, $item)?trim($item[1]):""; - if($type!= "" && $description != ""){ - $logger->info("Hardware: ".$type." = ".$description); - - $hardware = $hardwareRepository->findOneBy(array("type"=>$type, "description"=>$description)); - if($hardware == null){ - $logger->info("-- lo crea nuevo --"); - $hardware = new Hardware(); - $hardware->setType($type); - $hardware->setDescription($description); - } - $hardwareProfile->addHardware($hardware); + //$data = file_get_contents($filePath); + $data = $output; + + $data = explode("\n",trim($data)); + unset($data[0]); + foreach ($data as $item){ + $item = explode("=",trim($item)); + + $type = array_key_exists(0, $item)?trim($item[0]):""; + $description = array_key_exists(1, $item)?trim($item[1]):""; + if($type!= "" && $description != ""){ + $logger->info("Hardware: ".$type." = ".$description); + + $hardware = $hardwareRepository->findOneBy(array("type"=>$type, "description"=>$description)); + if($hardware == null){ + $logger->info("-- lo crea nuevo --"); + $hardware = new Hardware(); + $hardware->setType($type); + $hardware->setDescription($description); } + $hardwareProfile->addHardware($hardware); } - $client->setHardwareProfile($hardwareProfile); } + $client->setHardwareProfile($hardwareProfile); + //} } break; case \Opengnsys\ServerBundle\Entity\Enum\CommandType::CREATE_IMAGE: @@ -228,7 +233,6 @@ class TraceController extends ApiController $partitionRepository = $em->getRepository(Partition::class); $logger->info("-> CREATE_IMAGE <-"); - $client = $trace->getClient(); if($client != null){ $script = $trace->getScript(); @@ -290,77 +294,78 @@ class TraceController extends ApiController $partitionRepository = $em->getRepository(Partition::class); $logger->info("-> SOFTWARE_INVENTORY <-"); - $path = $this->getParameter('path_client'); - $client = $trace->getClient(); + //$path = $this->getParameter('path_client'); if($client != null){ - $ip = $client->getIp(); + //$ip = $client->getIp(); $script = $trace->getScript(); $script = explode("\n", $script); $script = explode(" ", $script[0]); $numDisk = array_key_exists(1, $script)?trim($script[1]):""; $numPartition = array_key_exists(2, $script)?trim($script[2]):""; - $file = "soft-".$ip."-".$numDisk."-".$numPartition; - $filePath = $path.$file; - $logger->info("File: ". $filePath); + //$file = "soft-".$ip."-".$numDisk."-".$numPartition; + //$filePath = $path.$file; + //$logger->info("File: ". $filePath); - if(file_exists($filePath)) { - $description = "SoftwareProfile-".$client->getName()."-".$numDisk."-".$numPartition; - $softwareProfile = $softwareProfileRepository->findOneBy(array("description"=>$description)); - if($softwareProfile == null){ - $logger->info("Crea Software Profile: ". $description); - $softwareProfile = new SoftwareProfile(); - $softwareProfile->setDescription($description); + //if(file_exists($filePath)) { + $description = "SoftwareProfile-".$client->getName()."-".$numDisk."-".$numPartition; + $softwareProfile = $softwareProfileRepository->findOneBy(array("description"=>$description)); + if($softwareProfile == null){ + $logger->info("Crea Software Profile: ". $description); + $softwareProfile = new SoftwareProfile(); + $softwareProfile->setDescription($description); - $em->persist($softwareProfile); - }else{ - $logger->info("Ya existe Software Profile: ". $description); - $softwareProfile->getSoftwares()->clear(); - } + $em->persist($softwareProfile); + }else{ + $logger->info("Ya existe Software Profile: ". $description); + $softwareProfile->getSoftwares()->clear(); + } - $data = file_get_contents($filePath); - - $data = explode("\n",trim($data)); - foreach ($data as $item){ - $item = trim($item); - $type = ""; - $description = $item; - if($description != ""){ - $logger->info("Software: ".$type." = ".$description); - - $software = $softwareRepository->findOneBy(array("description"=>$description)); - if($software == null){ - $logger->info("-- lo crea nuevo --"); - $software = new Software(); - $software->setType($type); - $software->setDescription($description); - } - $softwareProfile->addSoftware($software); + //$data = file_get_contents($filePath); + $data = $output; + + $data = explode("\n",trim($data)); + foreach ($data as $item){ + $item = trim($item); + $type = ""; + $description = $item; + if($description != ""){ + $logger->info("Software: ".$type." = ".$description); + + $software = $softwareRepository->findOneBy(array("description"=>$description)); + if($software == null){ + $logger->info("-- lo crea nuevo --"); + $software = new Software(); + $software->setType($type); + $software->setDescription($description); } + $softwareProfile->addSoftware($software); } + } - $logger->info("Partition"); - $partition = $partitionRepository->findOneBy(array("client"=>$client, "numDisk"=>$numDisk, "numPartition"=>$numPartition)); - if($partition != null){ - $image = $partition->getImage(); - if($image != null){ - $logger->info("Assing Image : " . $image->getCanonicalName() . " to SoftwareProfile: ". $description); - $image->setSoftwareProfile($softwareProfile); - }else{ - $logger->info("Not Found Image in Partition: ". "client: ".$client->getIp()." numDisk: ".$numDisk." numPartition: ".$numPartition); - } + $logger->info("Partition"); + $partition = $partitionRepository->findOneBy(array("client"=>$client, "numDisk"=>$numDisk, "numPartition"=>$numPartition)); + if($partition != null){ + $image = $partition->getImage(); + if($image != null){ + $logger->info("Assing Image : " . $image->getCanonicalName() . " to SoftwareProfile: ". $description); + $image->setSoftwareProfile($softwareProfile); }else{ - $logger->info("Not Found Partition: ". "client: ".$client->getIp()." numDisk: ".$numDisk." numPartition: ".$numPartition); + $logger->info("Not Found Image in Partition: ". "client: ".$client->getIp()." numDisk: ".$numDisk." numPartition: ".$numPartition); } }else{ - $logger->info("Not Found File: ". $filePath); + $logger->info("Not Found Partition: ". "client: ".$client->getIp()." numDisk: ".$numDisk." numPartition: ".$numPartition); } + //}else{ + // $logger->info("Not Found File: ". $filePath); + //} } break; } + $client->setStatus(ClientStatus::OG_LIVE); $em->flush(); $logger->info("Execute Flush"); } diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Enum/ClientStatus.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Enum/ClientStatus.php new file mode 100644 index 00000000..961377fd --- /dev/null +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Enum/ClientStatus.php @@ -0,0 +1,33 @@ +<?php + +namespace Opengnsys\ServerBundle\Entity\Enum; + +abstract class ClientStatus { + + const OFF = "off"; + const INITIALIZING = "initializing"; + const OG_LIVE = "oglive"; + const BUSY = "busy"; + const LINUX = "linux"; + const LINUX_SESSION = "linux_session"; + const MACOS = "macos"; + const WINDOWS = "windows"; + const WINDOWS_SESSION = "windows_session"; + + protected $name = 'CLIENT_STATUS'; + + protected $values = array( + self::POWER_OFF, + self::POWER_ON, + self::CREATE_IMAGE, + self::RUN_SCRIPT, + self::DELETE_CACHE_IMAGE + ); + + //public static $options = array(self::POWER_OFF, self::POWER_ON, self::CREATE_IMAGE, self::RUN_SCRIPT, self::DELETE_CACHE_IMAGE, self::HARDWARE_INVENTORY, self::SOFTWARE_INVENTORY, self::PARTITION_AND_FORMAT, self::RESTART, self::RESTORE_IMAGE); + + public function getValues() + { + return $this->values; + } +} diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Repository.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Repository.php index 9dc37677..1a430edb 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Repository.php +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Entity/Repository.php @@ -10,45 +10,30 @@ class Repository extends BaseEntity /** * @var string */ - private $name; - - /** - * @var string - */ private $ip; /** * @var string */ - private $password; - - /** - * @var string - */ - private $configurationpath; - - /** - * @var string - */ - private $adminpath; + private $name; /** - * @var string + * @var string|null */ - private $pxepath; + private $description; /** - * @var string + * @var string|null */ - private $description; + private $randomId; /** - * @var integer + * @var string|null */ - private $port; + private $secret; /** - * @var integer + * @var int */ private $id; @@ -57,32 +42,9 @@ class Repository extends BaseEntity */ private $organizationalUnit; - /** - * Set name - * - * @param string $name - * - * @return Repository - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return $this->name; - } /** - * Set ip + * Set ip. * * @param string $ip * @@ -96,7 +58,7 @@ class Repository extends BaseEntity } /** - * Get ip + * Get ip. * * @return string */ @@ -106,153 +68,105 @@ class Repository extends BaseEntity } /** - * Set password + * Set name. * - * @param string $password - * - * @return Repository - */ - public function setPassword($password) - { - $this->password = $password; - - return $this; - } - - /** - * Get password - * - * @return string - */ - public function getPassword() - { - return $this->password; - } - - /** - * Set configurationpath - * - * @param string $configurationpath - * - * @return Repository - */ - public function setConfigurationpath($configurationpath) - { - $this->configurationpath = $configurationpath; - - return $this; - } - - /** - * Get configurationpath - * - * @return string - */ - public function getConfigurationpath() - { - return $this->configurationpath; - } - - /** - * Set adminpath - * - * @param string $adminpath + * @param string $name * * @return Repository */ - public function setAdminpath($adminpath) + public function setName($name) { - $this->adminpath = $adminpath; + $this->name = $name; return $this; } /** - * Get adminpath + * Get name. * * @return string */ - public function getAdminpath() + public function getName() { - return $this->adminpath; + return $this->name; } /** - * Set pxepath + * Set description. * - * @param string $pxepath + * @param string|null $description * * @return Repository */ - public function setPxepath($pxepath) + public function setDescription($description = null) { - $this->pxepath = $pxepath; + $this->description = $description; return $this; } /** - * Get pxepath + * Get description. * - * @return string + * @return string|null */ - public function getPxepath() + public function getDescription() { - return $this->pxepath; + return $this->description; } /** - * Set description + * Set randomId. * - * @param string $description + * @param string|null $randomId * * @return Repository */ - public function setDescription($description) + public function setRandomId($randomId = null) { - $this->description = $description; + $this->randomId = $randomId; return $this; } /** - * Get description + * Get randomId. * - * @return string + * @return string|null */ - public function getDescription() + public function getRandomId() { - return $this->description; + return $this->randomId; } /** - * Set port + * Set secret. * - * @param integer $port + * @param string|null $secret * * @return Repository */ - public function setPort($port) + public function setSecret($secret = null) { - $this->port = $port; + $this->secret = $secret; return $this; } /** - * Get port + * Get secret. * - * @return integer + * @return string|null */ - public function getPort() + public function getSecret() { - return $this->port; + return $this->secret; } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -260,9 +174,9 @@ class Repository extends BaseEntity } /** - * Set organizationalUnit + * Set organizationalUnit. * - * @param \Opengnsys\ServerBundle\Entity\OrganizationalUnit $organizationalUnit + * @param \Opengnsys\ServerBundle\Entity\OrganizationalUnit|null $organizationalUnit * * @return Repository */ @@ -274,13 +188,12 @@ class Repository extends BaseEntity } /** - * Get organizationalUnit + * Get organizationalUnit. * - * @return \Opengnsys\ServerBundle\Entity\OrganizationalUnit + * @return \Opengnsys\ServerBundle\Entity\OrganizationalUnit|null */ public function getOrganizationalUnit() { return $this->organizationalUnit; } - } diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/RepositoryType.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/RepositoryType.php index ff7a798a..e562c643 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/RepositoryType.php +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/RepositoryType.php @@ -26,12 +26,9 @@ class RepositoryType extends AbstractType $builder ->add('name') ->add('ip') - ->add('password') - ->add('configurationpath') - ->add('adminpath') - ->add('pxepath') ->add('description') - ->add('port') + ->add('secret') + ->add('randomId') ; } diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/TraceType.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/TraceType.php index 07a342b1..b8c3ebd3 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/TraceType.php +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Form/Type/Api/TraceType.php @@ -24,6 +24,8 @@ class TraceType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder + ->add('ip', TextType::class) + ->add('mac', TextType::class) ->add('client', TextType::class) ->add('trace', TextType::class) ->add('status', TextType::class) diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/doctrine/Repository.orm.xml b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/doctrine/Repository.orm.xml index a8d741de..ad6d35f5 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/doctrine/Repository.orm.xml +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/doctrine/Repository.orm.xml @@ -9,16 +9,13 @@ <generator strategy="AUTO"/> </id> - <field name="name" type="string" column="name" length="250" nullable="false"/> <field name="ip" type="string" column="ip" length="36" nullable="false"/> - <field name="password" type="string" column="password" length="50" nullable="false"/> - <field name="configurationpath" type="string" column="configurationpath" length="250" nullable="false"/> - <field name="adminpath" type="string" column="adminpath" length="250" nullable="false"/> - <field name="pxepath" type="string" column="pxepath" length="250" nullable="false"/> - <field name="port" type="integer" column="port" nullable="true"/> - + <field name="name" type="string" column="name" length="250" nullable="false"/> <field name="description" type="text" column="description" nullable="true"/> + <field name="randomId" type="string" column="random_id" length="255" nullable="true"/> + <field name="secret" type="string" column="secret" length="255" nullable="true"/> + <many-to-one field="organizationalUnit" target-entity="OrganizationalUnit"> <join-columns> <join-column name="organizational_unit_id" referenced-column-name="id"/> diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/serializer/OpengnsysServerBundle/Entity.Repository.yml b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/serializer/OpengnsysServerBundle/Entity.Repository.yml index 06ee85cb..ba19e5be 100644 --- a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/serializer/OpengnsysServerBundle/Entity.Repository.yml +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Resources/config/serializer/OpengnsysServerBundle/Entity.Repository.yml @@ -9,30 +9,18 @@ Opengnsys\ServerBundle\Entity\Repository: groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] expose: true serialized_name: ip - password: - groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] - expose: true - serialized_name: password - configurationpath: - groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] - expose: true - serialized_name: configurationpath - adminpath: - groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] - expose: true - serialized_name: adminpath - pxepath: - groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] - expose: true - serialized_name: pxepath description: groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] expose: true serialized_name: description - port: + randomId: + groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] + expose: true + serialized_name: randomId + secret: groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] expose: true - serialized_name: port + serialized_name: secret id: groups: [opengnsys_server__repository_get, opengnsys_server__repository_cget] expose: true |