[40] | 1 | <? |
---|
| 2 | |
---|
| 3 | require('./conf/config.php'); |
---|
| 4 | |
---|
| 5 | /**************************************************************************** |
---|
| 6 | * |
---|
| 7 | * addSwitch($idSwitch, $ip, $mac, $type, $location, $level, $portIgnore) |
---|
| 8 | * selectSwitch($idSwitch) |
---|
| 9 | * delSwitch($idSwicth) |
---|
| 10 | * upateSwitch($idSwitch, $ip, $mac, $type, $location, $level, $portIgnore) |
---|
| 11 | * addSwitchService($idSwitch, $idService) |
---|
| 12 | * selectSwitchService($idSwitch, $idService) |
---|
| 13 | * delSwitchService($idSwitch, $idService) |
---|
| 14 | * |
---|
| 15 | *****************************************************************************/ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | //TODO: prévoir la syntaxe pour le champs portIgnore |
---|
| 22 | //TODO: prévoir l'ajout de routeur |
---|
| 23 | |
---|
| 24 | function addSwitch($idSwitch, $location, $level, $portIgnore) { |
---|
| 25 | //connect DB |
---|
| 26 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 27 | if (!$link) { |
---|
| 28 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 29 | return $buffer; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 34 | if (!$db_selected) { |
---|
| 35 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | //Add switch |
---|
| 41 | $sql = "INSERT INTO SWITCH VALUE('$idSwitch', '$location', '$level', '$portIgnore');"; |
---|
| 42 | |
---|
| 43 | if (mysql_query($sql, $link)) { |
---|
| 44 | $buffer = 1; |
---|
| 45 | } else { |
---|
| 46 | $buffer = "CREATE SWITCH $idSwicth: [FAILED] :" . mysql_error() ; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | return $buffer; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | function selectSwitch($idSwitch) { |
---|
| 54 | //connect DB |
---|
| 55 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 56 | if (!$link) { |
---|
| 57 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 58 | return $buffer; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 63 | if (!$db_selected) { |
---|
| 64 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | if (empty($idSwitch)) { |
---|
| 69 | $sql = "SELECT * FROM SWITCH, DEVICE WHERE SWITCH.idSwitch = DEVICE.hostname"; |
---|
| 70 | }else{ |
---|
| 71 | $sql = "SELECT * FROM SWITCH, DEVICE WHERE SWITCH.idSwitch = DEVICE.hostname AND idSwitch='$idSwitch'; "; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | if ($result = mysql_query($sql, $link)) { |
---|
| 76 | //test if $return is_array |
---|
| 77 | return $result ; |
---|
| 78 | |
---|
| 79 | } else { |
---|
| 80 | $buffer = "SELECT SWITCH $idSwitch: [FAILED] :" . mysql_error() ; |
---|
| 81 | return $buffer ; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | function delSwitch($idSwitch) { |
---|
| 93 | |
---|
| 94 | $buffer = ""; |
---|
| 95 | |
---|
| 96 | //connect DB |
---|
| 97 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 98 | if (!$link) { |
---|
| 99 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 100 | return $buffer; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 105 | if (!$db_selected) { |
---|
| 106 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | //Before del user of Table USER, del user in all others Table |
---|
| 111 | //del switch from CMDSWITCH |
---|
| 112 | $sql="DELETE FROM CMDSWITCH WHERE idSwitch='$idSwitch';"; |
---|
| 113 | if (mysql_query($sql, $link)) { |
---|
| 114 | $buffer .= "DELETE SWITCH $idSwitch FROM CMDSWITCH: [OK]<BR />"; |
---|
| 115 | } else { |
---|
| 116 | $buffer = "DELETE SWITCH $idSwitch FROM CMDSWITCH: [FAILED] :" . mysql_error() ; |
---|
| 117 | return $buffer; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | //del switch from SERVICESWITCH |
---|
| 121 | $sql = "DELETE FROM SERVICESWITCH WHERE idSwitch='$idSwitch'"; |
---|
| 122 | if (mysql_query($sql, $link)) { |
---|
| 123 | $buffer .= "DELETE SWITCH $idSwitch FROM SERVICESWITCH: [OK]<BR />"; |
---|
| 124 | } else { |
---|
| 125 | $buffer = "DELETE SWITCH $idSwitch FROM SERVICESWITCH: [FAILED] :" . mysql_error() ; |
---|
| 126 | return $buffer; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | //del switch |
---|
| 131 | $sql = "DELETE FROM SWITCH WHERE idswitch='$idSwitch';"; |
---|
| 132 | |
---|
| 133 | if (mysql_query($sql, $link)) { |
---|
| 134 | $buffer .= "DELETE SWITCH $idSwitch: [OK]<BR />"; |
---|
| 135 | } else { |
---|
| 136 | $buffer = "DELETE SWITCH $idSwitch: [FAILED] :" . mysql_error() ; |
---|
| 137 | return $buffer; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | return $buffer; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | function updateSwitch($idSwitch, $location, $level, $portIgnore ) { |
---|
| 147 | |
---|
| 148 | //connect DB |
---|
| 149 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 150 | if (!$link) { |
---|
| 151 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 152 | return $buffer; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 157 | if (!$db_selected) { |
---|
| 158 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | //update switch |
---|
| 163 | $sql = "UPDATE SWITCH SET |
---|
| 164 | location='$location', |
---|
| 165 | level='$level', |
---|
| 166 | portIgnore='$portIgnore' |
---|
| 167 | WHERE idSwitch='$idSwitch' ;" ; |
---|
| 168 | |
---|
| 169 | if (mysql_query($sql, $link)) { |
---|
| 170 | $buffer = 1; |
---|
| 171 | } else { |
---|
| 172 | $buffer = "UPDATE SWITCH $idSwicth: [FAILED] :" . mysql_error() ; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | return $buffer; |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | function addSwitchService($idSwitch, $idService) { |
---|
| 182 | |
---|
| 183 | //connect DB |
---|
| 184 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 185 | if (!$link) { |
---|
| 186 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 187 | return $buffer; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 192 | if (!$db_selected) { |
---|
| 193 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | //Add switch for a service |
---|
| 198 | $sql = "INSERT INTO SERVICESWITCH VALUE('$idService', '$idSwitch');"; |
---|
| 199 | |
---|
| 200 | if (mysql_query($sql, $link)) { |
---|
| 201 | $buffer = 1 ; |
---|
| 202 | }else{ |
---|
| 203 | $buffer = "CREATE SERVICESWITCH $idService: [FAILED] :" . mysql_error() ; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | return $buffer; |
---|
| 207 | |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | function selectSwitchService($idSwitch, $idService) { |
---|
| 212 | //connect DB |
---|
| 213 | |
---|
| 214 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 215 | if (!$link) { |
---|
| 216 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 217 | return $buffer; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 223 | if (!$db_selected) { |
---|
| 224 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | if ( empty($idSwitch) && empty($idService)) { |
---|
| 228 | $sql = "SELECT * FROM SERVICESWITCH"; |
---|
| 229 | |
---|
| 230 | }else{ |
---|
| 231 | if ( !empty($idSwitch) && !empty($idService) ) { |
---|
| 232 | $sql = "SELECT * FROM SERVICESWITCH |
---|
| 233 | WHERE idSwitch='$idSwitch' |
---|
| 234 | AND idService='$idService';"; |
---|
| 235 | }else{ |
---|
| 236 | if ( !empty($idSwitch) && empty($idService) ) { |
---|
| 237 | |
---|
| 238 | $sql = "SELECT * FROM SERVICESWITCH |
---|
| 239 | WHERE idSwitch='$idSwitch';"; |
---|
| 240 | }else{ |
---|
| 241 | $sql = "SELECT * FROM SERVICESWITCH |
---|
| 242 | WHERE idService='$idService';"; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | if ($result = mysql_query($sql, $link)) { |
---|
| 248 | return $result ; |
---|
| 249 | }else{ |
---|
| 250 | $buffer = "SELECT SWITCH $idSwitch for SERVICE $idService : [FAILED] :" . mysql_error() ; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | function delSwitchService($idSwitch, $idService) { |
---|
| 260 | |
---|
| 261 | //connect DB |
---|
| 262 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 263 | if (!$link) { |
---|
| 264 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 265 | return $buffer; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 269 | if (!$db_selected) { |
---|
| 270 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | //del switch for a service |
---|
| 275 | $sql = "DELETE FROM SERVICESWITCH WHERE idSwitch='$idSwitch' |
---|
| 276 | AND idService='$idService' ;"; |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | if (mysql_query($sql, $link)) { |
---|
| 280 | $buffer = "DELETE SWITCH $idSwitch for SERVICE $idService : [OK] "; |
---|
| 281 | }else{ |
---|
| 282 | $buffer = "DELETE SWITCH $idSwitch for SERVICE $idService : [FAILED] :" . mysql_error() ; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | return $buffer; |
---|
| 286 | |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | ?> |
---|