Commit bc7fc652b482a3237312f8f710ff6216a04083e1

Authored by root
1 parent e7c09f48

Site lie au git

site/accesBase.php
1 1 <?php
2 2 function connexion()
3 3 {
4   - $machine='serveur-etu.polytech-lille.fr' ;
  4 + $machine = 'localhost' ;
5 5 $user='grouille' ;
6 6 $pwd='postgres' ;
7 7 $db='projetCapteurs' ;
... ... @@ -81,6 +81,11 @@
81 81  
82 82 function upload($index,$maxsize=FALSE,$extensions=FALSE)
83 83 {
  84 + //Creation du dossier
  85 + /*$dossier = "upload";
  86 + if(!is_dir($dossier))
  87 + if(!mkdir($dossier, 0777))
  88 + echo "Impossible de creer le dossier";*/
84 89 //Test1: fichier correctement uploadé
85 90 if (!isset($_FILES[$index]) OR $_FILES[$index]['error'] > 0) return FALSE;
86 91 //Test2: taille limite
... ... @@ -90,9 +95,10 @@
90 95 if ($extensions !== FALSE AND !in_array($ext,$extensions)) return FALSE;
91 96 $name = 'binaire';
92 97 $extension_upload = strtolower( substr( strrchr($_FILES['fichier']['name'], '.') ,1) );
93   - $fichier = "upload/{$name}.{$extension_upload}";
  98 + $dossier = "upload/";
  99 + $fichier = $name.".".$extension_upload;
94 100 //$fichier = basename($_FILES[$index]['name']);
95   - return move_uploaded_file($_FILES['fichier']['tmp_name'],$fichier);
  101 + return move_uploaded_file($_FILES['fichier']['tmp_name'],$dossier.$fichier);
96 102 }
97 103  
98 104 function update_values()
... ... @@ -113,14 +119,14 @@
113 119 deconnexion($db);
114 120 }
115 121  
116   - function update_bdd($ip_address, $numero, $name, $data, $date)
  122 + function update_bdd($ip_address, $numero, $data, $date)
117 123 {
  124 + $name = getSensorName($ip_address, $numero);
118 125 $db = connexion();
119 126 $ip_address = (string)$ip_address;
120 127 $numero = (int)$numero;
121   - $name = (string)$name;
122 128 $data = (float)$data;
123   - $query = "UPDATE capteurs SET value='$data' WHERE raspberry='$ip_address' and numero='$numero' and nom='$name'";
  129 + $query = "UPDATE capteurs SET value=$data WHERE raspberry='$ip_address' and numero=$numero and nom='$name'";
124 130 $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
125 131 $query = "INSERT INTO history VALUES('$name', '$data', '$date')";
126 132 $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
... ... @@ -171,6 +177,26 @@
171 177 return $tab;
172 178 }
173 179  
  180 + function getSensorName($raspberry, $numero)
  181 + {
  182 + $db = connexion();
  183 + $query = "SELECT nom FROM capteurs where raspberry = '$raspberry' AND numero = $numero";
  184 + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error());
  185 + $tab = pg_fetch_assoc($result);
  186 + deconnexion($db);
  187 + return $tab['nom'];
  188 + }
  189 +
  190 + function getSensorVersion($rasberry, $numero)
  191 + {
  192 + $db = connexion();
  193 + $query = "SELECT version FROM capteurs where raspberry = '$raspberry' AND numero = $numero";
  194 + $result = pg_query($db, $query) or die("La requète a echoué : ".pg_last_error());
  195 + $tab = pg_fetch_assoc($result);
  196 + deconnexion($db);
  197 + return $tab['version'];
  198 + }
  199 +
174 200 function add($nom, $type, $raspberry, $numero, $unite)
175 201 {
176 202 $db = connexion();
... ...
site/envoiFichiers.php
1 1 <?php
2 2 session_start();
3 3 $error = false;
  4 +/*$error2 = false;
4 5  
5 6 if ( isset($_POST['sensor']) && count($_POST['sensor']<>0) ) {
6 7 $xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\r\n"
... ... @@ -8,13 +9,53 @@ if ( isset($_POST[&#39;sensor&#39;]) &amp;&amp; count($_POST[&#39;sensor&#39;]&lt;&gt;0) ) {
8 9 foreach($_POST['sensor'] as $sensor => $value)
9 10 {
10 11 $val = explode(":", $value);
11   - if(count($types)<>0 && !in_array($val[2], $types)) {$error = true;}
  12 + if(count($types)<>0 && !in_array($val[2], $types)) {$error2 = true;}
12 13 else {$types[] = $val[2];}
13 14 $xml = $xml. '<sensor>' . '<raspberry>' . htmlspecialchars($val[0]) . '</raspberry>' . '<numero>' . htmlspecialchars($val[1]) . '</numero>' . '</sensor>';
14 15 $xml = $xml."\r\n";
15 16 }
16 17 $xml = $xml.'</all>';
17   - if(!$error) {file_put_contents('upload/sensor.xml', $xml) ;}
  18 + if(!$error2) {file_put_contents('upload/sensor.xml', $xml) ;}
  19 +}*/
  20 +
  21 +if(isset($_POST['sensor']) && count($_POST['sensor']<>0))
  22 +{
  23 + $ini = "";
  24 + $arduino_simple = "[Arduino]\r\n";
  25 + $arduino_spi = "[Arduino_spi]\r\n";
  26 + $nucleo = "[Nucleo]\r\n";
  27 + $a_simple = false;
  28 + $a_spi = false;
  29 + $n = false;
  30 + foreach($_POST['sensor'] as $sensor => $value)
  31 + {
  32 + $val = explode(":", $value);
  33 + if(count($types)<>0 && !in_array($val[2], $types)) {$error = true;}
  34 + else {$types[] = $val[2];}
  35 + $version = 1;//getSensorVersion($val[0], $val[1]);
  36 + if($version == 0)
  37 + {
  38 + $a_simple = true;
  39 + $arduino_simple = $arduino_simple.$val[0]." capteur=".$val[1]."\n";
  40 + }
  41 + elseif($version == 1)
  42 + {
  43 + $a_spi = true;
  44 + $arduino_spi = $arduino_spi.$val[0]." capteur=".$val[1]."\n";
  45 + }
  46 + elseif($version == 2)
  47 + {
  48 + $n = true;
  49 + $nucleo = $nucleo.$val[0]." capteur=".$val[1]."\n";
  50 + }
  51 + }
  52 + echo $arduino_simple;
  53 + echo $arduino_spi;
  54 + echo $nucleo;
  55 + if($a_simple) {$ini = $ini.$arduino_simple."\n";}
  56 + if($a_spi) {$ini = $ini.$arduino_spi."\n";}
  57 + if($n) {$ini = $ini.$nucleo."\n";}
  58 + if(!$error) {file_put_contents('upload/inventaire.ini', $ini);}
18 59 }
19 60 ?>
20 61 <!DOCTYPE html>
... ...
site/logo.php
... ... @@ -2,6 +2,6 @@
2 2 <div class="col-6 col-md-6 offset-md-3 offset-3 logo">
3 3 <br/>
4 4 <br/>
5   - <img src="img/font.png" alt="Logo du site"/>
  5 + <img src="img/font.png" alt="Logo du site" style="width: 100%; height: auto;"/>
6 6 </div>
7 7 </div>
... ...
site/requests.php
1 1 <?php
2 2  
3 3 require("accesBase.php");
4   -update_bdd($_POST['ip_address'], $_POST['numero'], $_POST['name'], $_POST['data'], $_POST['date']);
  4 +update_bdd($_POST['ip_address'], $_POST['numero'], $_POST['data'], $_POST['date']);
5 5  
6 6 ?>
... ...