* In production mode, flash messages redirect after a time interval.
* In development mode, you need to click the flash message to continue.
*/
- Configure::write('debug', 2);
+ Configure::write('debug', 0);
/**
* Configure the Error handler used to handle errors for your application. By default
*/
// HOME = PAR DEFAUT
//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
- // HOME = PRODUITS
- Router::connect('/', array('controller' => 'produits', 'action' => 'index'));
+ // HOME = INSTANCES
+ Router::connect('/', array('controller' => 'instances', 'action' => 'index'));
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
--- /dev/null
+<?php
+ class AlertesController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ //$this->set('alertes', $this->Alerte->find('all'));
+ $alertes = $this->Alerte->find('all');
+ $this->set(array(
+ 'alertes' => $alertes,
+ '_serialize' => array('alertes')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvaise alerte'));
+ }
+
+ $alerte = $this->Alerte->findById($id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Mauvaise alerte'));
+ }
+ $this->set('alerte', $alerte);
+ }
+
+ public function add() {
+ if ($this->request->is('alerte')) {
+ $this->Alerte->create();
+ if ($this->Alerte->save($this->request->data)) {
+ $this->Session->setFlash(__("L'alerte a été enregistrée."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'alerte impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ $alerte = $this->Alerte->findById($id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+ $this->set('alerte', $alerte);
+
+ if ($this->request->is(array('alerte', 'put'))) {
+ $this->Alerte->id = $id;
+ if ($this->Alerte->save($this->request->data)) {
+ $this->Session->setFlash(__("L'alerte a été mise à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'alerte impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $alerte;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Alerte->delete($id)) {
+ $this->Session->setFlash(
+ __("L'alerte d'id: %s a été supprimée.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>
}
$this->set('exploitant', $exploitant);
- // Récupération des produits de l'exploitant
- $produits_id = explode('|', $this->Exploitant->value('produits'));
- App::import('Controller', 'Produits');
- $produitsController = new ProduitsController;
- $produits = [];
+ // Récupération des instances de l'exploitant
+ $instances_id = explode('|', $this->Exploitant->value('instances'));
+ App::import('Controller', 'Instances');
+ $instancesController = new InstancesController;
+ $instances = array();
- foreach ($produits_id as $produit_id) {
- $produits[] = $produitsController->Produit->findById($produit_id);
+ foreach ($instances_id as $instance_id) {
+ $instances[] = $instancesController->Instance->findById($instance_id);
}
- $this->set('produits', $produits);
+ $this->set('instances', $instances);
if ($this->request->is(array('exploitant', 'put'))) {
$this->Exploitant->id = $id;
--- /dev/null
+<?php
+ class HistoriquesController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ //$this->set('historiques', $this->Historique->find('all'));
+ $historiques = $this->Historique->find('all');
+ $this->set(array(
+ 'historiques' => $historiques,
+ '_serialize' => array('historiques')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+ $this->set('historique', $historique);
+ }
+
+ public function add() {
+ if ($this->request->is('historique')) {
+ $this->Historique->create();
+ if ($this->Historique->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été enregistré."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'historique impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+ $this->set('historique', $historique);
+
+ // Récupération des alertes de l'historique
+ if($this->Historique->value('alertes')) {
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alertes = array();
+ foreach ($alertes_id as $alerte_id) {
+ $alertes[] = $alertesController->Alerte->findById($alerte_id);
+ }
+ //$this->set('alertes', $alertes);
+ $this->set(array(
+ 'alertes' => $alertes,
+ '_serialize' => array('alertes')
+ ));
+ }
+
+ if ($this->request->is(array('historique', 'put'))) {
+ $this->Historique->id = $id;
+ if ($this->Historique->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été mis à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'historique impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $historique;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Historique->delete($id)) {
+ $this->Session->setFlash(
+ __("L'historique d'id: %s a été supprimé.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ public function validerAlerte($id = null, $alerte_id = null) {
+ // Récupération de l'historique
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ // Récupération de l'alerte
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alerte = $alertesController->Alerte->findById($alerte_id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ // Ajout de la version à l'historique
+ $version = $alerte['Alerte']['version'];
+ $creation = $alerte['Alerte']['creation'];
+ switch($alerte['Alerte']['nature']) {
+ case 'patch':
+ if($this->Historique->value('patches')) {
+ $patches = explode('|', $this->Historique->value('patches'));
+ } else {
+ $patches = array();
+ }
+ $patches[] = "{".$version.",".$creation.",".true."}";
+ $this->Historique->value('patches', implode('|', $patches));
+ break;
+
+ case 'maj':
+ break;
+
+ case 'creation':
+ // To-do : Modification état produit
+ break;
+
+ default:
+ break;
+
+ }
+
+ // Suppression de l'alerte
+ $alertesController->Alerte->delete($alerte_id);
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ if(($key = array_search($alerte_id, $alertes_id)) !== false) {
+ unset($alertes_id[$key]);
+ }
+ $this->Historique->value('alertes', implode('|', $alertes_id));
+
+ // Redirection
+ return $this->redirect(array('controller' => 'instances', 'action' => 'index'));
+ }
+
+ public function refuserAlerte($id = null, $alerte_id = null) {
+ // Récupération de l'historique
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ // Récupération de l'alerte
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alerte = $alertesController->Alerte->findById($alerte_id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ // Ajout de la version à l'historique
+ $version = $alerte['Alerte']['version'];
+ $creation = $alerte['Alerte']['creation'];
+ switch($alerte['Alerte']['nature']) {
+ case 'patch':
+ if($this->Historique->value('patches')) {
+ $patches = explode('|', $this->Historique->value('patches'));
+ } else {
+ $patches = array();
+ }
+ $patches[] = "{".$version.",".$creation.",".false."}";
+ $this->Historique->value('patches', implode('|', $patches));
+ break;
+
+ case 'maj':
+ break;
+
+ case 'creation':
+ // To-do : Modification état produit
+ break;
+
+ default:
+ break;
+
+ }
+
+ // Suppression de l'alerte
+ $alertesController->Alerte->delete($alerte_id);
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ if(($key = array_search($alerte_id, $alertes_id)) !== false) {
+ unset($alertes_id[$key]);
+ }
+ if($alertes_id !== ""){
+ $this->Historique->value('alertes', implode('|', $alertes_id));
+ } else {
+ $this->Historique->value('alertes', null);
+ }
+
+ // Redirection
+ return $this->redirect(array('controller' => 'instances', 'action' => 'index'));
+ }
+ }
+?>
--- /dev/null
+<?php
+ class InstancesController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ // IMPORT DES CONTROLLEURS
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ App::import('Controller', 'Historiques');
+ $historiquesController = new HistoriquesController;
+
+ // RÉCUPÉRATION DES INSTANCES
+ $instances = $this->Instance->find('all');
+
+ // RECUPERATION DE L'HISTORIQUE DE CHAQUE INSTANCE
+ $historiques = array();
+ $totalAlertes = array();
+ foreach($instances as $instance) {
+ $historique = $historiquesController->Historique->findById($instance['Instance']['historique']);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+ // RÉCUPÉRATION DES ALERTES DE L'HISTORIQUE
+ if($historique['Historique']['alertes']) {
+ $alertes_id = explode('|', $historique['Historique']['alertes']);
+ $alertes = array();
+ foreach ($alertes_id as $alerte_id) {
+ $alertes[] = $alertesController->Alerte->findById($alerte_id);
+ }
+ // AJOUT DANS LA LISTE DES ALERTES
+ $totalAlertes[$historique['Historique']['id']] = $alertes;
+ }
+ // AJOUT DANS LA LISTE DES HISTORIQUES
+ $historiques[$instance['Instance']['id']] = $historique;
+
+ }
+
+ // ENVOI DES DONNÉES À LA VUE
+ $this->set(array(
+ 'instances' => $instances,
+ '_serialize' => array('instances')
+ ));
+ $this->set(array(
+ 'historiques' => $historiques,
+ '_serialize' => array('historiques')
+ ));
+ $this->set(array(
+ 'totalAlertes' => $totalAlertes,
+ '_serialize' => array('totalAlertes')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvaise instance'));
+ }
+
+ $instance = $this->Instance->findById($id);
+ if (!$instance) {
+ throw new NotFoundException(__('Mauvaise instance'));
+ }
+ $this->set('instance', $instance);
+ }
+
+ public function add() {
+ if ($this->request->is('instance')) {
+ $this->Instance->create();
+ if ($this->Instance->save($this->request->data)) {
+ $this->Session->setFlash(__("L'instance a été enregistrée."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'instance impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Instance introuvable'));
+ }
+
+ $instance = $this->Instance->findById($id);
+ if (!$instance) {
+ throw new NotFoundException(__('Instance introuvable'));
+ }
+
+ if ($this->request->is(array('instance', 'put'))) {
+ $this->Instance->id = $id;
+ if ($this->Instance->save($this->request->data)) {
+ $this->Session->setFlash(__("L'instance a été mise à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'instance impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $instance;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Instance->delete($id)) {
+ $this->Session->setFlash(
+ __("L'instance d'id: %s a été supprimée.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ // API REST
+
+ /*public function rest_get_all() {
+ $instances = $this->Instance->find('all');
+ $this->set(array(
+ 'instances' => $instances,
+ '_serialize' => array('instances')
+ ));
+ }
+
+ public function rest_get($reference) {
+ $instance = $this->Instance->findByReference($reference);
+ $this->set(array(
+ 'instance' => $instance,
+ '_serialize' => array('instance')
+ ));
+ }
+
+ public function rest_create() {
+ if ($this->Instance->save($this->request->data)) {
+ $message = array(
+ 'text' => __('Saved'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }
+
+ public function rest_update($reference) {
+ $this->Instance->reference = $reference;
+ if ($this->Instance->save($this->request->data)) {
+ $message = array(
+ 'text' => __('Saved'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }
+
+ public function rest_delete($reference) {
+ if ($this->Instance->delete($reference)) {
+ $message = array(
+ 'text' => __('Deleted'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }*/
+ }
+?>
--- /dev/null
+<?php
+ class Alerte extends AppModel {
+ /*public $validate = array(
+ 'reference' => array(
+ 'rule' => 'notEmpty'
+ )
+ );*/
+
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Historique extends AppModel {
+ public $validate = array(
+ 'installation' => array(
+ 'rule' => 'notEmpty'
+ )
+ );
+
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Instance extends AppModel {
+ public $validate = array(
+ /*'fqdn' => array(
+ 'rule' => 'notEmpty'
+ ),*/
+ /*'nom' => array(
+ 'rule' => 'notEmpty'
+ ),*/
+ 'version' => array(
+ 'rule' => 'notEmpty'
+ )
+ );
+
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<h1>Ajout d'un alerte</h1>
+<?php
+ echo $this->Form->create('Alerte');
+ echo $this->Form->end("Enregistrer l'alerte");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'alerte</h1>
+<?php
+ echo $this->Form->create('Alerte');
+ echo $this->Form->input('id', array('type' => 'hidden'));
+ echo $this->Form->end("Mettre à jour l'alerte");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Liste d'alertes</h1>
+<table>
+ <tr>
+ <th>Date de d'émission</th>
+ </tr>
+
+ <?php foreach ($alertes as $alerte): ?>
+ <tr>
+ <td>
+ <?php echo $this->Html->link(
+ $alerte['Alerte']['creation'],
+ array('controller' => 'alertes', 'action' => 'edit', $alerte['Alerte']['id'])
+ );
+ ?>
+ </td>
+ <td>
+ <?php
+ echo $this->Form->postLink(
+ 'Supprimer',
+ array('action' => 'delete', $alerte['Alerte']['id']),
+ array('confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($alerte); ?>
+</table>
--- /dev/null
+<h1>Émission le : <?php echo h($alerte['Alerte']['création']); ?></h1>
+
+<p>Alertes : <?php echo h($alerte['Alerte']['alertes']); ?></p>
+
echo $this->Form->create('Exploitant');
echo $this->Form->input('nom');
echo $this->Form->input('reference');
- //echo $this->Form->input('produits');
+ //echo $this->Form->input('instances');
echo $this->Form->end("Enregistrer l'exploitant");
?>
\ No newline at end of file
echo $this->Form->create('Exploitant');
echo $this->Form->input('nom');
echo $this->Form->input('reference');
- //echo $this->Form->input('produits');
- echo "Instances de d'applications liées :";
- foreach ($produits as $produit) {
+ //echo $this->Form->input('instances');
+ echo "Instances d'applications liées :";
+ foreach ($instances as $instance) {
?><p><?php
echo $this->Html->link(
- $produit['Produit']['reference'],
- array('controller' => 'produits', 'action' => 'edit', $produit['Produit']['id'])
+ $instance['Instance']['reference'],
+ array('controller' => 'instances', 'action' => 'edit', $instance['Instance']['id'])
);
?></p><?php
}
<p>Reference : <?php echo h($exploitant['Exploitant']['reference']); ?></p>
-<p>Produits : <?php echo h($exploitant['Exploitant']['exploitants']); ?></p>
+<p>Instances : <?php echo h($exploitant['Exploitant']['exploitants']); ?></p>
--- /dev/null
+<h1>Ajout d'un historique</h1>
+<?php
+ echo $this->Form->create('Historique');
+ echo $this->Form->input('installation');
+ echo $this->Form->end("Enregistrer l'historique");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'historique</h1>
+<?php
+ echo $this->Form->create('Historique');
+ echo $this->Form->input('installation');
+ if(isset($alertes)) {
+ echo "Alertes :";
+?>
+<table>
+ <tr>
+ <th>Date</th>
+ <th>Version</th>
+ <th>Type</th>
+ <!--<th>Message</th>-->
+ <th>Actions</th>
+ </tr>
+ <?php foreach ($alertes as $alerte) { ?>
+ <tr>
+ <td><?php echo $alerte['Alerte']['creation']; ?></td>
+ <td><?php echo $alerte['Alerte']['version']; ?></td>
+ <td><?php echo $alerte['Alerte']['nature']; ?></td>
+ <!--<td><?php /*echo $alerte['Alerte']['message'];*/ ?></td>-->
+ <td>
+ <?php
+ echo $this->Html->link(
+ 'Valider',
+ array('controller' => 'historiques', 'action' => 'validerAlerte', $historique['Historique']['id'], $alerte['Alerte']['id'])
+ )
+ . " - " .
+ $this->Html->link(
+ 'Refuser',
+ array('controller' => 'historiques', 'action' => 'refuserAlerte', $historique['Historique']['id'], $alerte['Alerte']['id'])
+ );
+ ?>
+ </td>
+ </tr>
+<?php } ?>
+</table>
+<?php
+ }
+ echo $this->Form->input('id', array('type' => 'hidden'));
+ echo $this->Form->end("Mettre à jour l'historique");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Liste d'historiques</h1>
+<table>
+ <tr>
+ <th>Date d'installation</th>
+ </tr>
+
+ <?php foreach ($historiques as $historique): ?>
+ <tr>
+ <td>
+ <?php echo $this->Html->link(
+ $historique['Historique']['installation'],
+ array('controller' => 'historiques', 'action' => 'edit', $historique['Historique']['id'])
+ );
+ ?>
+ </td>
+ <td>
+ <?php
+ echo $this->Form->postLink(
+ 'Supprimer',
+ array('action' => 'delete', $historique['Historique']['id']),
+ array('confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($historique); ?>
+ <?php echo $this->Html->link(
+ 'Ajouter un historique',
+ array('controller' => 'historiques', 'action' => 'add')
+ ); ?>
+</table>
--- /dev/null
+<h1>Installation : <?php echo h($historique['Historique']['installation']); ?></h1>
+
+<p>Alertes : <?php echo h($historique['Historique']['alertes']); ?></p>
+
--- /dev/null
+<h1>Ajout d'une instance</h1>
+<?php
+echo $this->Form->create('Instance');
+echo $this->Form->input('nom');
+echo $this->Form->input('version');
+echo $this->Form->input('reference');
+echo $this->Form->input('fqdn_interne');
+echo $this->Form->input('fqdn_externe');
+echo $this->Form->input('clients');
+// TO-DO : Ajout de client
+echo $this->Form->input('exploitant');
+echo $this->Form->input('systeme');
+echo $this->Form->input('uid');
+echo $this->Form->end("Enregistrer l'instance");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'instance</h1>
+<?php
+echo $this->Form->create('Instance');
+echo $this->Form->input('nom');
+echo $this->Form->input('reference');
+echo $this->Form->input('exploitant');
+echo $this->Form->input('version');
+echo $this->Form->input('fqdn_interne');
+echo $this->Form->input('maintenu');
+//echo $this->Form->input('fqdn_externe');
+//echo $this->Form->input('systeme');
+//echo $this->Form->input('uid');
+echo $this->Form->input('id', array('type' => 'hidden'));
+echo $this->Form->end("Mettre à jour l'instance");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Liste d'instances</h1>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Historique</th>
+ <th>Version</th>
+ <th>Référence</th>
+ <th>Actions</th>
+ </tr>
+
+ <?php foreach ($instances as $instance): ?>
+ <tr>
+ <td>
+ <?php echo $this->Html->link(
+ $instance['Instance']['nom'],
+ array('controller' => 'instances', 'action' => 'edit', $instance['Instance']['id'])
+ );
+ ?>
+ </td>
+ <td>
+ <table>
+ <?php $historique = $historiques[$instance['Instance']['id']]; ?>
+ <tr>
+ <th>Création</th>
+ <?php if(array_key_exists($historique['Historique']['id'], $totalAlertes)) { ?>
+ <th>Alertes</th>
+ <th>Actions</th>
+ <?php } ?>
+ </tr>
+ <tr>
+ <td>
+ <?php echo $historique['Historique']['installation'] ?>
+ </td>
+ <?php if(array_key_exists($historique['Historique']['id'], $totalAlertes)) { ?>
+ <?php foreach ($totalAlertes[$historiques[$instance['Instance']['id']]['Historique']['id']] as $alerte): ?>
+ <td>
+ <?php echo $alerte['Alerte']['message'] ?>
+ </td>
+ <td>
+ <?php
+ echo $this->Html->link(
+ 'Valider',
+ array('controller' => 'historiques', 'action' => 'validerAlerte', $historique['Historique']['id'], $alerte['Alerte']['id'])
+ )
+ . " - " .
+ $this->Html->link(
+ 'Refuser',
+ array('controller' => 'historiques', 'action' => 'refuserAlerte', $historique['Historique']['id'], $alerte['Alerte']['id'])
+ );
+ ?>
+ </td>
+ <?php endforeach; ?>
+ <?php unset($alerte);
+ } ?>
+ </tr>
+ </table>
+ </td>
+ <td><?php echo $instance['Instance']['version']; ?></td>
+ <td><?php echo $instance['Instance']['reference']; ?></td>
+ <td>
+ <?php
+ echo $this->Form->postLink(
+ 'Supprimer',
+ array('action' => 'delete', $instance['Instance']['id']),
+ array('confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($instance); ?>
+ <?php echo $this->Html->link(
+ 'Ajouter une instance',
+ array('controller' => 'instances', 'action' => 'add')
+ ); ?>
+</table>
--- /dev/null
+<h1>Instance : <?php echo h($instance['Instance']['nom']); ?></h1>
+
+<p>Version : <?php echo h($instance['Instance']['version']); ?></p>
+
+<p>Maintenu : <?php echo h($instance['Instance']['maintenu']); ?></p>
###### CONFIGURATION ALLO AGENT ######
-# REFERENCE INSTANCE APPLICATION SUR ALLO = NOM FICHE INSTALL SUGAR = NOM PRODUIT / REF CLIENT + TYPE + DATE (AAAAMMJJhhmm)
-
-# Client classique
-produit_reference="IP/CCLEZI_201309250000"
-
+# Référence de l'instance sur ALLO
+produit_reference="IP/CDG01_0203150918"
# Type d'usager (exploitant|client)
-usager_type="exploitant"
-
-# Type d'instance du produit (qualif|prod) -> inutile avec reference ?
-produit_type="prod"
-
+usager_type="client"
+# Type d'instance du produit (qualif|prod)
+produit_type="qualif"
# Fqdn interne
-#produit.fqdn.interne="parapheur.test.adullact.org:8080/alfresco/service" # I-PARAPHEUR
-#produit.fqdn.interne="asalaedev.asalae.dev.adullact.org" # AS@LAE
produit_fqdn_interne="api_test"
-
# Fqdn externe
-#produit.fqdn.externe=""
-
+#produit.fqdn.externe="instance.mondomaine.fr"
# ALLO Serveur
allo_serveur_url="allo_serveur"
-
-## Configuration du header http
# Type de données acceptées
response_accept="Accept: application/json"
# Type de données envoyées
request_type="Content-Type: application/json"
-
# Logs
log_file="allo_agent.log"
HTTP/1.1 200 OK\r
-Date: Mon, 16 Feb 2015 15:16:53 GMT\r
-Server: Apache/2.4.6 (Ubuntu)\r
-X-Powered-By: PHP/5.5.3-1ubuntu2.6\r
+Date: Mon, 02 Mar 2015 10:21:27 GMT\r
+Server: Apache/2.2.22 (Ubuntu)\r
+X-Powered-By: PHP/5.3.10-1ubuntu3.16\r
Access-Control-Allow-Origin: *\r
+Vary: Accept-Encoding\r
Content-Length: 0\r
Content-Type: text/html; charset=utf-8\r
\r
case $opt in
# Initialisation
i)
- echo "Cette option n'est pas encore disponible."
+ ./init.sh
;;
# Declaration / Upload des infos
d)
--- /dev/null
+###### CONFIGURATION ALLO AGENT ######
+
+# REFERENCE INSTANCE APPLICATION SUR ALLO = NOM FICHE INSTALL SUGAR = NOM PRODUIT / REF CLIENT + TYPE + DATE (AAAAMMJJhhmm)
+
+# Client classique
+produit_reference="TEST"
+
+# Type d'usager (exploitant|client)
+usager_type="client"
+
+# Type d'instance du produit (qualif|prod) -> inutile avec reference ?
+produit_type="prod"
+
+# Fqdn interne
+produit_fqdn_interne="asalaedev.asalae.dev.adullact.org" # AS@LAE
+
+# Fqdn externe
+#produit.fqdn.externe=""
+
+# ALLO Serveur
+allo_serveur_url="allo_serveur"
+
+## Configuration du header http
+# Type de données acceptées
+response_accept="Accept: application/json"
+# Type de données envoyées
+request_type="Content-Type: application/json"
+
+# Logs
+log_file="allo_agent.log"
--- /dev/null
+#!/bin/bash
+
+# SCRIPT D'INITIALISATION DES VARAIBLES DE LA CONFIGURATION DE ALLO
+echo "------------------------------------------------------------------------"
+echo "Initialisation de ALLO, merci de renseigner les informations suivantes :"
+echo "------------------------------------------------------------------------"
+read -p "FQDN (interne) de l'application [instance.mondomaine.local] : "
+if [ "$REPLY" == "" ]
+then
+ fqdn_interne="instance.mondomaine.local"
+else
+ fqdn_interne="$REPLY"
+fi
+read -p "FQDN (externe) de l'application [instance.mondomaine.fr] : "
+if [ "$REPLY" == "" ]
+then
+ fqdn_externe="instance.mondomaine.fr"
+else
+ fqdn_externe="$REPLY"
+fi
+read -p "Canal de mise à jour [QUALIF/prod] : "
+if [ "$REPLY" == "" ]
+then
+ canal="qualif"
+else
+ canal="$REPLY"
+fi
+read -p "Type d'usager [CLIENT/exploitant] : "
+if [ "$REPLY" == "" ]
+then
+ usager="client"
+else
+ usager="$REPLY"
+fi
+# To-do : choix entre générer ref client et utiliser une existante
+read -p "Type de la communauté [ville/ca/cr/cc/cg/cdg/sdis/AUTRE(laisser vide)] : "
+type_com="$REPLY"
+read -p "Nom de la communauté/du client [] : "
+nom_com="$REPLY"
+# To-do : ajout numéro de fin (code postal ?)
+reference_client_mini="${type_com:0:5}${nom_com:0:4}"
+reference_client=${reference_client_mini^^}
+
+echo "FQDN interne : "${fqdn_interne}
+echo "FQDN externe : "${fqdn_externe}
+echo "Canal de mise à jour : "${canal}
+echo "Type d'usager : "${usager}
+echo "Référence client : "${reference_client}
+# To-do : boucler tant que infos pas correctes
+
+# TEST DE CONNEXION
+fqdn_interne="api_test"
+code=$(curl -s -w "%{http_code}" --max-time 5 --output /dev/null "http://${fqdn_interne}/api/rest/allo/version")
+
+if [ "${code}" == 200 ] || [ "${code}" == 301 ]
+then
+ # REQUETE (en insecure pour le moment)
+ curl --max-time 10 -k -X GET -H "Accept: application/json" "http://${fqdn_interne}/api/rest/allo/version/" --output "response.json" 2> /dev/null
+
+ # LOG DE LA REPONSE
+ #echo "$(cat response.json)" 2>&1 | tee -a $log_file
+
+ # VALIDATION DU JSON (nécessite outil de validation json)
+ #isJSONCorrupted=$(cat response.json | module/json -nq)
+
+ # SI LA VARIABLE EST INITIALISEE MAIS VIDE => PAS D'ERREUR
+ #if [[ -z $isJSONCorrupted && ${isJSONCorrupted+x} ]]
+ #then
+ produit="$(jq -r '.produit' response.json)"
+ echo "Produit : "${produit}
+
+ case "${produit}" in
+ "i-Parapheur")
+ prefixe="IP"
+ ;;
+ *)
+ #echo "Produit non reconnu" 2>&1 | tee -a $log_file
+ ;;
+ esac
+ #fi
+fi
+
+
+# Création du allo_agent.conf
+# To-do : possibilité de mise à jour d'une conf existante
+configuration="allo_agent.conf"
+now="$(date +'%d%m%y%H%M')"
+if [ -e "${configuration}" ]
+then
+ rm "${configuration}"
+fi
+touch "${configuration}"
+echo "###### CONFIGURATION ALLO AGENT ######" >> $configuration
+echo "" >> $configuration
+echo "# Référence de l'instance sur ALLO" >> $configuration
+echo 'produit_reference="'${prefixe}'/'${reference_client}'_'${now}'"' >> $configuration
+echo "# Type d'usager (exploitant|client)" >> $configuration
+echo 'usager_type="'${usager}'"' >> $configuration
+echo "# Type d'instance du produit (qualif|prod)" >> $configuration
+echo 'produit_type="'${canal}'"' >> $configuration
+echo "# Fqdn interne" >> $configuration
+echo 'produit_fqdn_interne="'${fqdn_interne}'"' >> $configuration
+echo "# Fqdn externe" >> $configuration
+echo '#produit.fqdn.externe="'${fqdn_externe}'"' >> $configuration
+echo "# ALLO Serveur" >> $configuration
+echo 'allo_serveur_url="allo_serveur"' >> $configuration
+echo "# Type de données acceptées" >> $configuration
+echo 'response_accept="Accept: application/json"' >> $configuration
+echo "# Type de données envoyées" >> $configuration
+echo 'request_type="Content-Type: application/json"' >> $configuration
+echo "# Logs" >> $configuration
+echo 'log_file="allo_agent.log"' >> $configuration
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ interface AlerteManager {
+
+ function createAlerte($alerte);
+ function updateAlerte($alerte);
+ function getAlerte($id);
+ function getLastAlerte();
+ function getAlertes();
+ function removeAlerte($alerte);
+ }
+
+?>
\ No newline at end of file
function createHistorique($historique);
function updateHistorique($historique);
function getHistorique($id);
+ function getLastHistorique();
function getHistoriques();
function removeHistorique($historique);
}
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ interface InstanceManager {
+
+ function createInstance($instance);
+ function updateInstance($instance);
+ function updateInstanceInfos($array);
+ function getInstance($id);
+ function getInstances();
+ function removeInstance($instance);
+ }
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoAlerteManager extends AbstractPdoManager implements AlerteManager {
+
+ public function createAlerte($alerte) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO alertes (creation, nature, message) VALUES (NOW(), :nature, :message);'
+ );
+ $query -> bindValue(':nature', $alerte -> getNature());
+ $query -> bindValue(':message', $alerte -> getMessage());
+ $query -> execute();
+ }
+
+ public function updateAlerte($alerte) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE alertes
+ SET creation = :creation,
+ nature = :nature,
+ message = :message
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $alerte -> getId());
+ $query -> bindValue(':creation', $alerte -> getCreation());
+ $query -> bindValue(':nature', $alerte -> getNature());
+ $query -> bindValue(':message', $alerte -> getMessage());
+ $query -> execute();
+ }
+
+ public function getAlerte($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM alertes WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $alerte = new Alerte($result['id'], $result['creation'], $result['nature'], $result['message']);
+
+ $query->closeCursor();
+
+ return $alerte;
+ }
+
+ public function getLastAlerte() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM alertes WHERE id = LAST_INSERT_ID()');
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $alerte = new Alerte($result['id'], $result['creation'], $result['nature'], $result['message']);
+
+ $query->closeCursor();
+
+ return $alerte;
+ }
+
+ public function getAlertes() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM alertes');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $alertes = array();
+ foreach ($results as $result) {
+ $alertes[] = new Alerte($result['id'], $result['creation'], $result['nature'], $result['message']);
+ }
+
+ $query->closeCursor();
+
+ return $alertes;
+ }
+
+ public function removeAlerte($alerte) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM alertes WHERE id = :id');
+ $query -> bindValue('id', $alerte -> getId());
+ $query -> execute();
+ }
+
+ }
+
+?>
public function createExploitant($exploitant) {
$query = $this -> pdo -> prepare(
- 'INSERT INTO exploitants (nom, reference, produits) VALUES (:nom, :reference, :produits)'
+ 'INSERT INTO exploitants (nom, reference, instances) VALUES (:nom, :reference, :instances)'
);
$query -> bindValue(':nom', $exploitant -> getNom());
$query -> bindValue(':reference', $exploitant -> getReference());
- $query -> bindValue(':produits', implode("|", $exploitant -> getProduits()));
+ $query -> bindValue(':instances', implode("|", $exploitant -> getInstances()));
$query -> execute();
$query -> closeCursor();
public function updateExploitant($exploitant) {
$query = $this -> pdo -> prepare(
- 'UPDATE exploitants SET nom = :nom, reference = :reference, produits = :produits WHERE id = :id'
+ 'UPDATE exploitants SET nom = :nom, reference = :reference, instances = :instances WHERE id = :id'
);
$query -> bindValue(':id', $exploitant -> getId());
$query -> bindValue(':nom', $exploitant -> getNom());
$query -> bindValue(':reference', $exploitant -> getReference());
- $query -> bindValue(':produits', implode("|", $exploitant -> getProduits()));
+ $query -> bindValue(':instances', implode("|", $exploitant -> getInstances()));
$query -> execute();
-
+ $query -> closeCursor();
}
public function getExploitant($id) {
$query -> execute();
$result = $query -> fetch(PDO::FETCH_ASSOC);
- $exploitant = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['produits']));
+ $exploitant = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['instances']));
$query->closeCursor();
$results = $query -> fetchAll(PDO::FETCH_ASSOC);
$exploitants = array();
foreach ($results as $result) {
- $exploitants[] = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['produits']));
+ $exploitants[] = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['instances']));
}
$query->closeCursor();
$query -> execute();
$result = $query -> fetch(PDO::FETCH_ASSOC);
- $exploitant = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['produits']));
+ $exploitant = new Exploitant($result['id'], $result['nom'], $result['reference'], explode("|", $result['instances']));
$query->closeCursor();
public function createHistorique($historique) {
$query = $this -> pdo -> prepare(
- 'INSERT INTO historiques (installation) VALUES (:installation)'
+ 'INSERT INTO historiques (installation, alertes) VALUES (NOW(), :alertes)'
);
- $query -> bindValue(':installation', $historique -> getInstallation());
+ $query -> bindValue(':alertes', implode("|", $historique -> getAlertes()));
$query -> execute();
- $query -> closeCursor();
-
+ $query -> closeCursor();
}
public function updateHistorique($historique) {
$query = $this -> pdo -> prepare(
- 'UPDATE historiques SET installation = :installation WHERE id = :id'
+ 'UPDATE historiques SET installation = :installation, alertes = :alertes WHERE id = :id'
);
$query -> bindValue(':id', $historique -> getId());
$query -> bindValue(':installation', $historique -> getInstallation());
+ $query -> bindValue(':alertes', implode("|", $historique -> getAlertes()));
$query -> execute();
-
+ $query -> closeCursor();
}
public function getHistorique($id) {
$query -> execute();
$result = $query -> fetch(PDO::FETCH_ASSOC);
- $historique = new Historique($result['id'], $result['installation']);
+ $historique = new Historique($result['id'], $result['installation'], explode("|", $result['alertes']));
+
+ $query->closeCursor();
+
+ return $historique;
+ }
+
+ public function getLastHistorique() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM historiques WHERE id = LAST_INSERT_ID()');
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $historique = new Historique($result['id'], $result['installation'], explode("|", $result['alertes']));
$query->closeCursor();
$results = $query -> fetchAll(PDO::FETCH_ASSOC);
$historiques = array();
foreach ($results as $result) {
- $historiques[] = new Historique($result['id'], $result['installation']);
+ $historiques[] = new Historique($result['id'], $result['installation'], explode("|", $result['alertes']));
}
$query->closeCursor();
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoInstanceManager extends AbstractPdoManager implements InstanceManager {
+
+ public function createInstance($instance) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO instances (
+ nom,
+ exploitant,
+ reference,
+ version,
+ historique,
+ maintenu
+ ) VALUES (
+ :nom,
+ :exploitant,
+ :reference,
+ :version,
+ :historique,
+ :maintenu
+ )'
+ );
+ $query -> bindValue(':nom', $instance -> getNom());
+ $query -> bindValue(':exploitant', $instance -> getExploitant());
+ $query -> bindValue(':reference', $instance -> getReference());
+ $query -> bindValue(':version', $instance -> getVersion());
+ $query -> bindValue(':historique', $instance -> getHistorique());
+ $query -> bindValue(':maintenu', $instance -> estMaintenu());
+ $query -> execute();
+ $query -> closeCursor();
+
+ }
+
+ public function updateInstance($instance) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE instances
+ SET nom = :nom,
+ exploitant = :exploitant,
+ reference = :reference,
+ version = :version,
+ historique = :historique,
+ maintenu = :maintenu
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $instance -> getId());
+ $query -> bindValue(':nom', $instance -> getNom());
+ $query -> bindValue(':exploitant', $instance -> getExploitant());
+ $query -> bindValue(':reference', $instance -> getReference());
+ $query -> bindValue(':version', $instance -> getVersion());
+ $query -> bindValue(':historique', $instance -> getHistorique());
+ $query -> bindValue(':maintenu', $instance -> estMaintenu());
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function updateInstanceInfos($array) {
+ $instance = $this -> getInstanceByReference($array['reference']);
+ // LE INSTANCE EXISTE : MISE À JOUR DES INFORMATIONS DE VERSION
+ if($instance -> getId() > 0) {
+ // CAS EXPLOITANT
+ if($array['usager_type'] === "exploitant") {
+ // RECUPERATION DE L'EXPLOITANT DU INSTANCE
+ $exploitantManager = new PdoExploitantManager();
+ $exploitant = $exploitantManager -> getExploitantByReference($instance -> getExploitant());
+ // MISE À JOUR DE TOUS LES INSTANCES EN CHARGE DE L'EXPLOITANT
+ $array['usager_type'] = "client";
+ $instances_id = $exploitant -> getInstances();
+ foreach ($instances_id as $instance_id) {
+ $array['reference'] = $this -> getInstance($instance_id) -> getReference();
+ $this -> updateInstanceInfos($array);
+ }
+ // CAS CLIENT
+ } else if($array['usager_type'] === "client") {
+ // VERIFICATION DU NOM DE L'INSTANCE
+ if ($array['produit'] === $instance -> getNom()) {
+ // SI LA VERSION DIFFÈRE DE LA DB, CREATION D'UNE ALERTE
+ if($array['version'] != $instance -> getVersion()) {
+ // CREATION D'UNE NOUVELLE ALERTE
+ $alerteManager = new PdoAlerteManager();
+ // To-do : séparer patches des majs
+ $alerte = new Alerte(null, null, "version",
+ "Version declaree ".$array['version']." differente de l'actuelle : ".$instance -> getVersion());
+ $alerteManager -> createAlerte($alerte);
+ // RECUPERATION DE L'HISTORIQUE DU INSTANCE
+ $historiqueManager = new PdoHistoriqueManager();
+ $historique = $historiqueManager -> getHistorique($instance -> getHistorique());
+ // AJOUT DANS UN HISTORIQUE DEJÀ EXISTANT
+ if($historique -> getId() > 0) {
+ $alertes = $historique -> getAlertes();
+ if((array_search("", $alertes)) !== false) {
+ $alertes = array($alerteManager -> getLastAlerte() -> getId());
+ } else {
+ $alertes[] = $alerteManager -> getLastAlerte() -> getId();
+ }
+ $historique -> setAlertes($alertes);
+ $historiqueManager -> updateHistorique($historique);
+ // CREATION D'UN NOUVEL HISTORIQUE
+ } else {
+ $historique = new Historique(null, null, array($alerteManager -> getLastAlerte() -> getId()));
+ $historiqueManager -> createHistorique($historique);
+ $instance -> setHistorique($historiqueManager -> getLastHistorique() -> getId());
+ $this -> updateInstance($instance);
+ }
+ }
+ // MISE À JOUR DES INFOS DE L'INSTANCE
+ $query = $this -> pdo -> prepare(
+ 'UPDATE instances SET version = :version WHERE reference = :reference'
+ );
+ $query -> bindValue(':reference', $array['reference']);
+ $query -> bindValue(':version', $array['version']);
+ $query -> execute();
+ } else {
+ echo "Erreur de nom de l'instance";
+ }
+ }
+ // INSTANCE INEXISTANT
+ } else {
+ // CREATION D'UNE NOUVELLE ALERTE
+ $alerteManager = new PdoAlerteManager();
+ $alerte = new Alerte(null, null, "creation",
+ "Nouvelle instance declaree : ".$array['produit']." ; version : ".$array['version']);
+ $alerteManager -> createAlerte($alerte);
+ // CREATION D'UN NOUVEL HISTORIQUE
+ $historiqueManager = new PdoHistoriqueManager();
+ $historique = new Historique(null, null, array($alerteManager -> getLastAlerte() -> getId()));
+ $historiqueManager -> createHistorique($historique);
+ // CRÉATION D'UNE NOUVELLE INSTANCE
+ // To-do : gestion des comptes exploitants
+ $instance = new Instance(null, $array['produit'], null, $array['reference'], $array['version'], $historiqueManager -> getLastHistorique() -> getId(), true);
+ $this->createInstance($instance);
+ }
+
+
+ }
+
+ public function getInstance($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM instances WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $instance = new Instance(
+ $result['id'],
+ $result['nom'],
+ $result['exploitant'],
+ $result['reference'],
+ $result['version'],
+ $result['historique'],
+ $result['maintenu']
+ );
+
+ $query->closeCursor();
+
+ return $instance;
+ }
+
+ public function getInstanceByReference($reference) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM instances WHERE reference = :reference');
+ $query -> bindValue(':reference', $reference);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $instance = new Instance(
+ $result['id'],
+ $result['nom'],
+ $result['exploitant'],
+ $result['reference'],
+ $result['version'],
+ $result['historique'],
+ $result['maintenu']
+ );
+
+ $query->closeCursor();
+
+ return $instance;
+ }
+
+ public function getInstances() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM instances');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $instances = array();
+ foreach ($results as $result) {
+ $instances[] = new Instance(
+ $result['id'],
+ $result['nom'],
+ $result['exploitant'],
+ $result['reference'],
+ $result['version'],
+ $result['historique'],
+ $result['maintenu']
+ );
+ }
+
+ $query->closeCursor();
+
+ return $instances;
+ }
+
+ public function removeInstance($instance) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM instances WHERE id = :id');
+ $query -> bindValue('id', $instance -> getId());
+ $query -> execute();
+
+ }
+
+ }
+
+?>
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Alerte {
+
+ protected $id, $creation, $nature, $message;
+
+ /// CONSTRUCTEUR
+ function __construct($id = null, $creation = null, $nature = null, $message = null) {
+
+ $this -> id = $id;
+ $this -> creation = $creation;
+ $this -> nature = $nature;
+ $this -> message = $message;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["creation"] = $this -> creation;
+ $array["nature"] = $this -> nature;
+ $array["message"] = $this -> message;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getCreation() { return $this->creation; }
+ public function getNature() { return $this->nature; }
+ public function getMessage() { return $this->message; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setCreation($creation) { $this->creation = $creation; }
+ public function setNature($nature) { $this->nature = $nature; }
+ public function setMessage($message) { $this->message = $message; }
+
+ }
+
+?>
\ No newline at end of file
\r
class Exploitant {\r
\r
- protected $id, $nom, $reference, $produits;\r
+ protected $id, $nom, $reference, $instances;\r
\r
/// CONSTRUCTEUR\r
- function __construct($id = null, $nom = null, $reference = null, $produits = null) {\r
+ function __construct($id = null, $nom = null, $reference = null, $instances = null) {\r
\r
$this -> id = $id;\r
$this -> nom = $nom;\r
$this -> reference = $reference;\r
- $this -> produits = $produits;\r
+ $this -> instances = $instances;\r
\r
}\r
\r
$array["id"] = $this -> id;\r
$array["nom"] = $this -> nom;\r
$array["reference"] = $this -> reference;\r
- $array["produits"] = $this -> produits;\r
+ $array["instances"] = $this -> instances;\r
\r
return json_encode($array);\r
}\r
public function getId() { return $this -> id; }\r
public function getNom() { return $this->nom; }\r
public function getReference() { return $this->reference; }\r
- public function getProduits() { return $this->produits; }\r
+ public function getInstances() { return $this->instances; }\r
\r
/// SETTERS\r
public function setId($id) { $this -> id = $id; }\r
public function setNom($nom) { $this->nom = $nom; }\r
public function setReference($reference) { $this->reference = $reference; }\r
- public function setProduits($produits) { $this->produits = $produits; }\r
+ public function setInstances($instances) { $this->instances = $instances; }\r
\r
}\r
\r
class Historique {
- protected $id, $installation;
+ protected $id, $installation, $alertes;
/// CONSTRUCTEUR
- function __construct($id = null, $installation = null) {
+ function __construct($id = null, $installation = null, $alertes = null) {
$this -> id = $id;
$this -> installation = $installation;
+ $this -> alertes = $alertes;
}
public function getJSONP() {
$array["id"] = $this -> id;
$array["installation"] = $this -> installation;
+ $array["alertes"] = $this -> alertes;
return json_encode($array);
}
/// GETTERS
public function getId() { return $this -> id; }
public function getInstallation() { return $this->installation; }
+ public function getAlertes() { return $this->alertes; }
/// SETTERS
public function setId($id) { $this -> id = $id; }
public function setInstallation($installation) { $this->installation = $installation; }
+ public function setAlertes($alertes) { $this->alertes = $alertes; }
}
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Instance {
+
+ protected $id, $nom, $exploitant, $reference, $version, $historique, $maintenu;
+
+ /// CONSTRUCTEUR
+ function __construct($id = null, $nom = null, $exploitant = null, $reference = null, $version = null, $historique = null, $maintenu = null) {
+
+ $this -> id = $id;
+ $this -> nom = $nom;
+ // Référence client de l'exploitant
+ $this -> exploitant = $exploitant;
+ // Référence / identifiant du instance
+ $this -> reference = $reference;
+ // Version actuelle
+ $this -> version = $version;
+ // Id de l'historique de màj / patchs
+ $this -> historique = $historique;
+ // Pseudo-booleen : vaut 1 si le instance est encore maintenu, 0 sinon
+ $this -> maintenu = $maintenu;
+
+ // TO-DO : AJOUT DE :
+ /*
+ - fqdnInterne
+ - fqdnExterne
+ - systeme
+ - uid
+ */
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["nom"] = $this -> nom;
+ $array["exploitant"] = $this -> exploitant;
+ $array["reference"] = $this -> reference;
+ $array["version"] = $this -> version;
+ $array["historique"] = $this -> historique;
+ $array["maintenu"] = $this -> maintenu;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getNom() { return $this->nom; }
+ public function getExploitant() { return $this->exploitant; }
+ public function getReference() { return $this->reference; }
+ public function getVersion() { return $this->version; }
+ public function getHistorique() { return $this->historique; }
+ public function estMaintenu() { return $this->maintenu; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setNom($nom) { $this->nom = $nom; }
+ public function setExploitant($exploitant) { $this->exploitant = $exploitant; }
+ public function setReference($reference) { $this->reference = $reference; }
+ public function setVersion($version) { $this->version = $version; }
+ public function setHistorique($historique) { $this->historique = $historique; }
+ public function setMaintenu($maintenu) { $this->maintenu = $maintenu; }
+
+ }
+
+?>
\ No newline at end of file
\r
function api_delete() {\r
$exploitantManager = new PdoExploitantManager();\r
- $produitManager = new PdoProduitManager();\r
- $historiqueManager = new PdoHistoriqueManager();\r
+ $instanceManager = new PdoInstanceManager();\r
+ $historiqueManager = new PdoAlerteManager();\r
\r
// OPERATION DE SUPPRESSION UNIQUEMENT VIA INTERFACE WEBADMIN :\r
// -> Pour le moment AW a accès à la db directement, donc pas besoin de WS\r
$_GET['exploitant']['id'],\r
$_GET['exploitant']['nom'],\r
$_GET['exploitant']['reference'],\r
- $_GET['exploitant']['produits']\r
+ $_GET['exploitant']['instances']\r
);\r
$exploitantManager -> removeExploitant($exploitant);\r
break;\r
\r
- case 'remove_produit' :\r
- $produit = new Produit(\r
- $_GET['produit']['id'], \r
- $_GET['produit']['nom'],\r
- $_GET['produit']['exploitant'], \r
- $_GET['produit']['reference'], \r
- $_GET['produit']['version']\r
- $_GET['produit']['historique']\r
+ case 'remove_instance' :\r
+ $instance = new Instance(\r
+ $_GET['instance']['id'], \r
+ $_GET['instance']['nom'],\r
+ $_GET['instance']['exploitant'], \r
+ $_GET['instance']['reference'], \r
+ $_GET['instance']['version']\r
+ $_GET['instance']['historique']\r
);\r
- $produitManager -> removeProduit($produit);\r
+ $instanceManager -> removeInstance($instance);\r
break;\r
\r
case 'remove_historique' :\r
\r
function api_get() {\r
$exploitantManager = new PdoExploitantManager();\r
- $produitManager = new PdoProduitManager();\r
+ $instanceManager = new PdoInstanceManager();\r
$historiqueManager = new PdoHistoriqueManager();\r
+ $alerteManager = new PdoAlerteManager();\r
\r
switch ($_GET['action']) {\r
case 'get_exploitant' :\r
}\r
break;\r
\r
- case 'get_produit' :\r
- echo $produitManager -> getProduit($_GET['id']) -> getJSON();\r
+ case 'get_instance' :\r
+ echo $instanceManager -> getInstance($_GET['id']) -> getJSON();\r
break;\r
\r
- case 'get_produits' :\r
- $produits = $produitManager -> getProduits();\r
- if (!empty($produits)) {\r
+ case 'get_instances' :\r
+ $instances = $instanceManager -> getInstances();\r
+ if (!empty($instances)) {\r
$i = 0;\r
echo '[';\r
- foreach ($produits as $produit) {\r
- echo $produit -> getJSON();\r
- if ($i != sizeof($produits) - 1) {\r
+ foreach ($instances as $instance) {\r
+ echo $instance -> getJSON();\r
+ if ($i != sizeof($instances) - 1) {\r
echo ',';\r
}\r
$i++;\r
$i = 0;\r
echo '[';\r
foreach ($historiques as $historique) {\r
- echo $historique -> getJSON();\r
+ echo $historique -> getJSONP();\r
if ($i != sizeof($historiques) - 1) {\r
echo ',';\r
}\r
echo ']';\r
}\r
break;\r
+\r
+ case 'get_alerte' :\r
+ echo $alerteManager -> getAlerte($_GET['id']) -> getJSON();\r
+ break;\r
+\r
+ case 'get_alertes' :\r
+ $alertes = $alerteManager -> getAlertes();\r
+ if (!empty($alertes)) {\r
+ $i = 0;\r
+ echo '[';\r
+ foreach ($alertes as $alerte) {\r
+ echo $alerte -> getJSON();\r
+ if ($i != sizeof($alertes) - 1) {\r
+ echo ',';\r
+ }\r
+ $i++;\r
+ }\r
+ echo ']';\r
+ }\r
+ break;\r
}\r
}\r
\r
\r
function api_post() {\r
$exploitantManager = new PdoExploitantManager();\r
- $produitManager = new PdoProduitManager();\r
- $historiqueManager = new PdoHistoriqueManager();\r
+ $instanceManager = new PdoInstanceManager();\r
+ $historiqueManager = new PdoAlerteManager();\r
\r
// OPERATION DE CREATION/UPDATE UNIQUEMENT VIA INTERFACE WEBADMIN :\r
// -> Pour le moment AW a accès à la db directement, donc pas besoin de WS\r
null, // l'ID en base est auto-généré, donc laissé vide ici\r
$_POST['nom'], \r
$_POST['reference'], \r
- $_POST['produits']\r
+ $_POST['instances']\r
);\r
$exploitantManager -> createExploitant($exploitant);\r
break;\r
$_POST['id'], \r
$_POST['nom'], \r
$_POST['reference'], \r
- $_POST['produits']\r
+ $_POST['instances']\r
);\r
$exploitantManager -> updateExploitant($exploitant);\r
break;\r
\r
- case 'add_produit' :\r
- $produit = new Produit(\r
+ case 'add_instance' :\r
+ $instance = new Instance(\r
null, // l'ID en base est auto-généré, donc laissé vide ici\r
$_POST['nom'], \r
$_POST['exploitant'], \r
$_POST['version'],\r
$_POST['historique']\r
);\r
- $produitManager -> addProduit($produit);\r
+ $instanceManager -> addInstance($instance);\r
break;\r
\r
- case 'update_produit' :\r
- $produit = new Produit(\r
+ case 'update_instance' :\r
+ $instance = new Instance(\r
$_POST['id'], \r
$_POST['nom'], \r
$_POST['exploitant'], \r
$_POST['version'],\r
$_POST['historique']\r
);\r
- $produitManager -> updateProduit($produit);\r
+ $instanceManager -> updateInstance($instance);\r
break;\r
\r
case 'create_historique' :\r
$data = file_get_contents("php://input");\r
//file_put_contents('uploads/data', $data);\r
\r
- $produitManager = new PdoProduitManager();\r
+ $instanceManager = new PdoInstanceManager();\r
\r
if ($_GET['action'] == 'upload_info') {\r
// DECODE JSON\r
//var_dump($array);\r
\r
if (!is_null($array) && assert($array)) {\r
- // MISE A JOUR PRODUIT\r
- $produitManager -> updateProduitInfos($array);\r
+ // MISE A JOUR INSTANCE\r
+ $instanceManager -> updateInstanceInfos($array);\r
}\r
}\r
\r
header('Content-Type: text/html; charset=utf-8');\r
\r
require_once('classes/models/Exploitant.class.php');\r
- require_once('classes/models/Produit.class.php');\r
+ require_once('classes/models/Instance.class.php');\r
require_once('classes/models/Historique.class.php');\r
+ require_once('classes/models/Alerte.class.php');\r
\r
require_once('classes/manager/ExploitantManager.class.php');\r
- require_once('classes/manager/ProduitManager.class.php');\r
+ require_once('classes/manager/InstanceManager.class.php');\r
require_once('classes/manager/HistoriqueManager.class.php');\r
+ require_once('classes/manager/AlerteManager.class.php');\r
\r
require_once('classes/manager/pdo/AbstractPdoManager.php');\r
\r
require_once('classes/manager/pdo/PdoExploitantManager.php');\r
- require_once('classes/manager/pdo/PdoProduitManager.php');\r
+ require_once('classes/manager/pdo/PdoInstanceManager.php');\r
require_once('classes/manager/pdo/PdoHistoriqueManager.php');\r
+ require_once('classes/manager/pdo/PdoAlerteManager.php');\r
\r
?>
\ No newline at end of file