#!/bin/bash
+echo "-----------ALLO / DECLARATION-----------"
+
# FICHIER DE CONFIGURATION
source ./allo_agent.conf
fi
# TEST DE CONNEXION
-code=$(curl -s -w "%{http_code}" --max-time 5 --output /dev/null "http://${instance_fqdn_interne}/api/rest/allo/version")
-#echo ${instance_fqdn_interne}
-#echo ${code}
+echo "Test d'accès de l'application sur ""${instance_fqdn_interne}""..."
+code=$(curl -s -w "%{http_code}" --max-time 5 "http://""${instance_fqdn_interne}""/api/rest/allo/version" --output /dev/null)
if [ "${code}" == 200 ] || [ "${code}" == 301 ]
then
+ echo "Test OK, récupération des informations..."
+
# REQUETE (en insecure pour le moment)
- curl --max-time 10 -k -X GET -H "${response_accept}" "http://${instance_fqdn_interne}/api/rest/allo/version/" --output "response.json" 2> /dev/null
+ curl --max-time 10 -k -X GET -H "${response_accept}" "http://""${instance_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 et paquet node)
isJSONCorrupted="$(module/json -nq response.json)"
- echo "${isJSONCorrupted}"
+ #echo "${isJSONCorrupted}"
+
# SI LA VARIABLE EST INITIALISEE MAIS VIDE => PAS D'ERREUR
if [[ -z $isJSONCorrupted && ${isJSONCorrupted+x} ]]
then
+ echo "Envoi des information au serveur ALLO..."
+
# RÉCUPÉRATION DES NOMS, UUIDS ET LABELS DES DISQUES
disques=$(blkid /dev/sd* | sed 's/\"//g')
jq '. + { "canal": "'"${instance_canal}"'" }' tmp6.json > request.json
# ENVOI DE L'UPDATE AU SERVEUR
- curl --cert bma.pem --key bma.key -X POST -H "${request_type}" --data-binary "@request.json" -i "https://${allo_serveur_url}/?action=upload_info" --output "response_server" 2> /dev/null
+ curl --cert bma.pem --key bma.key -X POST -H "${request_type}" --data-binary "@request.json" "https://""${allo_serveur_url}""/?action=upload_info" --output "response_server" 2> /dev/null
if [ -e ./response_server ]
- then
- tee response_server -a "$log_file" 2>&1
+ then
+ echo "Réponse du serveur ALLO :"
+ #tee response_server -a "$log_file"
+ cat response_server 2>&1 | tee -a "$log_file"
else
echo "Aucune réponse du serveur !" 2>&1 | tee -a "$log_file"
fi
;;
esac
fi
+echo ""
echo "Votre application n'est plus maintainue par nos services, merci de vous renseigner auprès de votre contact ADULLACT Projet pour plus d'informations.";
} else {
+ // GETTING PDO MANAGERS
+ $versionManager = new PdoVersionManager();
+ $productManager = new PdoProductManager();
+ $warningManager = new PdoWarningManager();
+ $changelogManager = new PdoChangelogManager();
+
// IN CASE OF MANAGER
if($array['usager_type'] === "exploitant") {
// IN CASE OF CUSTOMER
} else if($array['usager_type'] === "client") {
- // CHECKING APPLIANCE NAME
- if ($array['produit'] === $appliance -> getProduct()) {
+ // CHECKING APPLIANCE PRODUCT NAME
+ //if ($array['produit'] === $appliance -> getProduct()) {
- // IF VERSION DIFFERS FROM DB
- // TO-DO : GET CURRENT VERSION OF APPLIANCE VIA CHANGELOG
- //if($array['version'] != $appliance -> getVersion()) {
+ // GETTING CHANGELOG OF APPLIANCE
+ $changelog = $changelogManager -> getChangelog($appliance -> getChangelog());
- // GETTING PDO MANAGERS
- $versionManager = new PdoVersionManager();
- $productManager = new PdoProductManager();
- $warningManager = new PdoWarningManager();
+ // IF CHANGELOG FOR THIS APPLIANCE EXISTS
+ if(isset($changelog) && $changelog -> getId() > 0) {
+
+ // IF VERSION DIFFERS FROM DB
+ $lastVersionValue = $changelogManager -> findLastVersionForId($appliance -> getChangelog()) -> getValue();
+ if($array['version'] === $lastVersionValue) {
+ echo "Informations à jour sur le serveur ALLO.";
+ } else {
// GETTING VERSION ID
$version_id = $versionManager -> getIdByValueAndProductId($array['version'], $productManager->getProductByName($array['produit'])->getId());
// SENDING MAIL TO ADMIN
$to = 'david.calmel@adullact-projet.coop';
- $subject = 'ALLO - Nouvelle warning';
+ $subject = 'ALLO - Nouvelle alerte';
$message = $warningMessage;
$headers = 'From: ne-pas-repondre@allo-serveur';
mail($to, $subject, $message, $headers);
- // GETTING CHANGELOG OF APPLIANCE
- $changelogManager = new PdoChangelogManager();
- $changelog = $changelogManager -> getChangelog($appliance -> getChangelog());
-
- // IF CHANGELOG EXISTS, ADDING NEW WARNING TO IT
- if(isset($changelog) && $changelog -> getId() > 0) {
- $warnings = $changelog -> getWarnings();
- if((array_search("", $warnings)) !== false) {
- $warnings = array($warningManager -> getLastWarning() -> getId());
- } else {
- $warnings[] = $warningManager -> getLastWarning() -> getId();
- }
- $changelog -> setWarnings($warnings);
- $changelogManager -> updateChangelog($changelog);
-
- // IF CHANGELOG DOES NOT EXIST, CREATING NEW ONE
+ // ADDING NEW WARNING TO CHANGELOG
+ $warnings = $changelog -> getWarnings();
+ if((array_search("", $warnings)) !== false) {
+ $warnings = array($warningManager -> getLastWarning() -> getId());
} else {
- $changelog = new Changelog(null, array($warningManager -> getLastWarning() -> getId()), array(""));
- $changelogManager -> createChangelog($changelog);
- $appliance -> setChangelog($changelogManager -> getLastChangelog() -> getId());
- $this -> updateAppliance($appliance);
+ $warnings[] = $warningManager -> getLastWarning() -> getId();
}
- //}
-
- // USELESS ?
- // UPDATING APPLIANCE INFORMATION
- /*$query = $this -> pdo -> prepare(
- 'UPDATE appliances SET version = :version WHERE reference = :reference'
- );
- $query -> bindValue(':reference', $array['reference']);
- $query -> bindValue(':version', $array['version']);
- $query -> execute();*/
- } else {
- echo "Le nom de l'instance applicative est incorrect";
- }
+ $changelog -> setWarnings($warnings);
+ $changelogManager -> updateChangelog($changelog);
+ // TO-DO : ADD CONTACT INFORMATIONS TO MESSAGE
+ echo "Votre version diffère de la dernière déclarée sur le serveur ALLO, merci de contacter machin pour plus d'informations";
+ }
+
+ // IF CHANGELOG DOES NOT EXIST, CREATING NEW ONE (DELETE THIS ?)
+ } /*else {
+ $changelog = new Changelog(null, array($warningManager -> getLastWarning() -> getId()), array(""));
+ $changelogManager -> createChangelog($changelog);
+ $appliance -> setChangelog($changelogManager -> getLastChangelog() -> getId());
+ $this -> updateAppliance($appliance);
+ }*/
} else {
echo "Le type d'usager est inconnu, merci de corriger la configuration.";
}
$version_id = $versionManager->getIdByValueAndProductId($array['version'], $product_id);
// NEW WARNING CREATION, CREATION TYPE
- $warning = new Warning(null, null, "creation",
- "Nouvelle instance applicative declaree : ".$array['produit']." ; version : ".$array['version'], $version_id);
+ $warningMessage = "Nouvelle instance applicative declaree : ".$array['produit']." ; version : ".$array['version'];
+ $warning = new Warning(null, null, "creation", $warningMessage, $version_id);
$warningManager -> createWarning($warning);
+ // SENDING MAIL TO ADMIN
+ $to = 'david.calmel@adullact-projet.coop';
+ $subject = 'ALLO - Nouvelle alerte';
+ $message = $warningMessage;
+ $headers = 'From: ne-pas-repondre@allo-serveur';
+ mail($to, $subject, $message, $headers);
+
// NEW CHANGELOG CREATION
$changelogManager = new PdoChangelogManager();
$changelog = new Changelog(null, array($warningManager -> getLastWarning() -> getId()), array(""));
}
- public function findLastVersion() {
+ public function findLastVersionForId($id) {
- $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs WHERE id = :id');
+ $query -> bindValue('id', $id);
$query -> execute();
// GETTING LAST DECLARED VERSION ID
$lastVersionId = null;
- $results = $query -> fetchAll(PDO::FETCH_ASSOC);
- foreach ($results as $result) {
- $versionArray = explode(';',$result['versions']);
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $versions = explode("|", $result['versions']);
+ foreach ($versions as $version) {
+ $versionArray = explode(';', $version);
$versionId = $versionArray[0];
$versionDeclaration = $versionArray[1];
- if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ if(!isset($lastVersionDeclaration) || $versionDeclaration >= $lastVersionDeclaration) {
$lastVersionDeclaration = $versionDeclaration;
$lastVersionId = $versionId;
}
return $version;
}
- public function findLastVersionDeclaration() {
+ public function findLastVersionDeclarationForId($id) {
- $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs WHERE id = :id');
+ $query -> bindValue('id', $id);
$query -> execute();
// GETTING LAST VERSION DECLARATION
$lastVersionDeclaration = null;
- $results = $query -> fetchAll(PDO::FETCH_ASSOC);
- foreach ($results as $result) {
- $versionArray = explode(';',$result['versions']);
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $versions = explode("|", $result['versions']);
+ foreach ($versions as $version) {
+ $versionArray = explode(';',$version);
$versionDeclaration = $versionArray[1];
- if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ if(!isset($lastVersionDeclaration) || $versionDeclaration >= $lastVersionDeclaration) {
$lastVersionDeclaration = $versionDeclaration;
}
}