--- /dev/null
+<?php
+
+class InitCommand extends Command {
+
+ public function needLogin(){
+ return true;
+ }
+
+ public function getDescription(){
+ return "Initialise l'agent Allo";
+ }
+
+ public function go(){
+
+ if ($this->getAlloUUID()){
+ throw new Exception("Cette instance est déjà configuré. Veuillez la supprimer d'abord.");
+ }
+
+ do {
+ $ap_id = $client_reference = $this->readline("Référence du client: ");
+ $contracts_list = $this->getAlloServeur()->listContract($ap_id);
+ if (! $contracts_list){
+ echo "[ERREUR] La référence client {$ap_id} n'existe pas sur le serveur ALLO ou le client n'a pas de contrat\n";
+ }
+ } while(! $contracts_list);
+
+ echo "Client {$ap_id} : ".count($contracts_list)." contrats disponibles: \n";
+ $num = 0;
+ foreach($contracts_list as $i => $contract){
+ $num = $i+1;
+ echo "\t$num.\t{$contract['number']}\t{$contract['state']}\t{$contract['start_date']}\t{$contract['end_date']}\n";
+ }
+
+ do {
+ $choix_contat = $this->readline("Choix du contrat [1-{$num}]: ");
+ if (! isset($contracts_list[$choix_contat -1])){
+ echo "[ERREUR] Choix non disponible !\n";
+ }
+ } while(! isset($contracts_list[$choix_contat -1]));
+
+ $contrat = $contracts_list[$choix_contat -1];
+
+ echo "Choix du contrat : {$contrat['number']}\n";
+ do {
+ list($fqdn,$content) = $this->readFQDN();
+ } while(! $fqdn);
+
+
+ $channel_list = $this->getAlloServeur()->listChannel();
+
+ echo "\nCanaux disponibles:\n";
+ foreach($channel_list as $i => $channel_info){
+ $num = $i+1;
+ echo "\t$num.\t{$channel_info['channel_key']}\t{$channel_info['libelle']}\n";
+ }
+
+ $nb_channel = count($channel_list);
+
+ do {
+ $channel_num = $this->readline("Choix du canal [1-$nb_channel]: ");
+ if (! isset($channel_list[$channel_num-1])){
+ echo "Choix non disponible\n";
+ }
+ } while(! isset($channel_list[$channel_num-1]));
+ $channel_key = $channel_list[$channel_num-1]['channel_key'];
+
+
+ $type_hebergement_list = $this->getAlloServeur()->listTypeHebergement();
+ echo "\nType d'hébergement:\n";
+ foreach($type_hebergement_list as $i => $type_hebergement_info){
+ $num = $i+1;
+ echo "\t$num.\t{$type_hebergement_info['type_hebergement_key']}\t{$type_hebergement_info['libelle']}\n";
+ }
+
+ $nb_type_hebergement = count($type_hebergement_list);
+
+ do {
+ $type_hebergement_num = $this->readline("Choix du type d'hébergement [1-$nb_type_hebergement]: ");
+ if (! isset($type_hebergement_list[$type_hebergement_num-1])){
+ echo "Choix non disponible\n";
+ }
+ } while(! isset($type_hebergement_list[$type_hebergement_num-1]));
+ $type_hebergement_key = $type_hebergement_list[$type_hebergement_num-1]['type_hebergement_key'];
+
+
+ $appliance_uuid = $this->getAlloServeur()->applianceCreate($contrat['number'],$fqdn,$channel_key,$content['produit'],$type_hebergement_key);
+ $this->setAlloUUID($appliance_uuid);
+ echo "Allo configuré avec succès\n";
+ }
+
+
+ public function readFQDN(){
+ $fdqn = $this->readline("FDQN du service (accessible ici):");
+ try {
+ $content = $this->getInfoFromInstance($fdqn);
+ } catch (Exception$e){
+ echo "[ERREUR] ".$e->getMessage()."\n";
+ return array(false,false);
+ }
+ return array($fdqn,$content);
+ }
+}
\ No newline at end of file