1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
<?php
require_once("BaseXml.php");
class Machine extends BaseXml {
public function __construct($fichier, $xsd_validation="reseau.xsd") {
parent::__construct($fichier, $xsd_validation="reseau.xsd");
}
public function ajouterMachine($v_ip="",$v_nom="",$v_type="poste",$v_description){
try{
if (trim($v_ip)!="" and trim($v_nom)!="") {
echo '<center class="alerte">soit ip soit un nom mais pas les deux<br></center>';
return false;
}
if (trim($v_ip)!="" or trim($v_nom)!="") {
if (trim($v_nom)!="") {
$v_ip=gethostbyname($v_nom);
if ($v_ip==$v_nom) {
echo '<center class="alerte">probleme de resolution du nom quoi !!!<br></center>';
$v_ip="0.0.0.0";
//return false;
}
}
if (trim($v_ip)!="") {
$v_nom=gethostbyaddr($v_ip);
if ($v_ip==$v_nom) {
echo '<center class="alerte">probleme de resolution du ip quoi !!!<br></center>';
$v_nom="machine x";
//return false;
}
}
if (!$this->chercherNoeudViaXpath("ip",$v_ip))
{
$reseau = $this->doc_xml->documentElement;
//creation du noeud machine
$machine = new DOMElement("machine");
$reseau->appendChild($machine);
//determination du id
$v_id= $this->idSuivant();
if (!$v_id) $v_id=1;
$id = new DOMAttr("id",$v_id);
$res = $machine->setAttributeNode($id);
//ajout des elements de machine
if (!$this->chercherNoeudViaXpath("nom",$v_nom))
{
$nom = new DOMElement("nom",$v_nom);
$machine->appendChild($nom);
unset($nom);
}
else {
echo '<center class="alerte">nom deja existant quoi!!!<br></center>';
return false;
}
// ajout du ip
$ips = new DOMElement("ips");
$ip= new DOMElement("ip",$v_ip);
$machine->appendChild($ips);
$ips->appendChild($ip);
unset($ips);
unset($ip);
// ajout du type
$type = new DOMElement("type",$v_type);
$machine->appendChild($type);
unset($type);
// ajout de la description
if ($v_description=="") $v_description="Rien a signaler quoi !";
$description = new DOMElement("description",$v_description);
$machine->appendChild($description);
// ajout des statistiques
$statistiques = new DOMElement("statistiques");
$machine->appendChild($statistiques);
unset($statistiques);
// sauvegarder l'ajout
$this->sauvegarderFichier();
unset($machine);
unset($reseau);
return true;
}
else{
echo '<center class="alerte">ip deja existant quoi !!!<br></center>';
return false;
}
}
else {
echo '<center class="alerte">vous devez au moins donner un ip ou bien un nom<br></center>';
return false;
}
}
catch (DOMException $e) {
echo $e->getMessage()."<br>";
return false;
}
}
public function ajouterObjetStatistiques($id_machine,$nature,$date,$valeur) {
try{
//ajout d'un objet
$xpath = new DOMXPath($this->doc_xml);
$statistiques = $xpath->query("//machine[@id='".$id_machine."']/statistiques");
$objet = new DOMElement("objet");
$statistiques->item(0)->appendChild($objet);
//determination de son id
$v_id= $this->nbrNoeudsViaXpath("//machine[@id='".$id_machine."']/statistiques/objet");
$id = new DOMAttr("id",$v_id+1);
$res = $objet->setAttributeNode($id);
//ajout des ses fils
$nat = new DOMElement("nature",$nature);
$objet->appendChild($nat);
unset($nat);
$dat = new DOMElement("date",$date);
$objet->appendChild($dat);
unset($dat);
$val = new DOMElement("valeur",$valeur);
$objet->appendChild($val);
unset($val);
// sauvegarder l'ajout
$this->sauvegarderFichier();
unset($objet);
unset($xpath);
unset($statistiques);
return true;
}
catch (DOMException $e) {
echo $e->getMessage()."<br>";
return false;
}
}
public function modifierInfo($id_machine,$noeud,$valeur){
$expression ="//machine[@id='".$id_machine."']/".$noeud;
if ($this->modifierNoeudViaXpath($expression,trim($valeur)))
return true;
return false;
}
public function supprimerMachine($id_machine){
$expression ="//machine[@id='".$id_machine."']";
if ($this->supprimerNoeudViaXpath($expression))
return true;
return false;
}
public function ajouterIp($id,$ip){
if (!$this->chercherNoeudViaXpath("ip",$ip))
{
$expression ="//machine[@id='".$id."']/ips";
if ($this->insererNoeudViaXpath($expression,"ip",$ip))
return true;
return false;
}
else{
echo '<center class="alerte">ip deja existant quoi !!!<br></center>';
return false;
}
}
public function supprimerIp($ip){
$expression ="//machine/ips/ip[.='".$ip."']";
if ($this->supprimerNoeudViaXpath($expression))
return true;
return false;
}
public function idSuivant(){
try{
$maxid=0;
$xpath = new DOMXPath($this->doc_xml);
$machines = $xpath->query("//machine");
foreach ( $machines as $machine ) {
$id = $machine->getAttributeNode('id')->nodeValue;
if ($id>$maxid)
$maxid=$id;
}//for
return $maxid+1;
}
catch (DOMException $e) {
echo $e->getMessage()."<br>";
return false;
}
}
public function consulterReseau(){
try{
$xpath = new DOMXPath($this->doc_xml);
$machines = $xpath->query("//machine");
foreach ( $machines as $machine ) {
$id = $machine->getAttributeNode('id')->nodeValue;
$enfant = $machine->childNodes;
foreach($enfant as $noeud){
switch ($noeud->nodeName) {
case "nom":
$nom = $noeud->nodeValue;
break;
case "type":
$type = $noeud->nodeValue;
break;
case "description":
$description = stripslashes($noeud->nodeValue);
break;
case "ips":
$ips = $noeud->childNodes;
break;
}//switch
}//for
/////////////////////////////////////////////////////////////////////////////////
echo '<table width="90%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td>
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td align="left" class="cellhaut" width="80%"><div class="titre">Nom:</div> '.$nom.'</td>
<td align="right" class="cellhaut"><div class="titre">Type:</div> '.$type.'</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" class="cellmilieuhaut"><div class="titre">IPs:</div><br>';
$chaineip = '';
$i=0;
foreach($ips as $ip){
if ($i==0) {
$ip1=$ip->nodeValue;
$i++;
}
$chaineip .= $ip->nodeValue.'-';
echo $ip->nodeValue;
echo '<br>';
}//for ips
echo '</td>
</tr>
<tr>
<td class="cellmilieubas"><div class="titre">Description:</div> '.$description.'</td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr class="cellbas">
<td align="center" width="25%"><a href="modifier_eq.php?id='.$id.'&nom='.$nom.'&type='.$type.'&description='.$description.'">Modifier</a></td>
<td align="center" width="25%"><a href="supprimer_eq.php?id='.$id.'">Supprimer</a></td>
<td align="center" width="25%"><a href="ajouter_ip.php?id='.$id.'&nom='.$nom.'">Ajouter IP</a></td>
<td align="center" width="25%"><a href="supprimer_ip.php?chaineip='.$chaineip.'">Supprimer IP</a> </td>
</tr>
</table>
</td>
</tr>
<tr><td>
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="33%"></td>
<td class="cellbas" align="center"><a href="consulter_snmp.php?nom='.$nom.'&ip1='.$ip1.'">Consultation SNMP</a></td>
<td width="33%"></td>
</tr>
</table>
</td></tr>
</table>
<hr size="10" align="center" color="#FFFFFF"/>';
/////////////////////////////////////////////////////////////////////////////////
}//for machines
return true;
}
catch (DOMException $e) {
echo $e->getMessage()."<br>";
return false;
}
}//function
}
?> |
Partager