[40] | 1 | <? |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | function addDevice($mac, $hostname, $ip, $type) { |
---|
| 7 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 8 | if (!$link) { |
---|
| 9 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 10 | return $buffer; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 15 | if (!$db_selected) { |
---|
| 16 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | //Add switch |
---|
| 22 | $sql = "INSERT INTO DEVICE VALUE('$mac', '$hostname', '$ip', '$type');"; |
---|
| 23 | |
---|
| 24 | if (mysql_query($sql, $link)) { |
---|
| 25 | $buffer = 1; |
---|
| 26 | } else { |
---|
| 27 | $buffer = "CREATE DEVICE $idSwicth: [FAILED] :" . mysql_error() ; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | return $buffer; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | function selectDevice($filter) { |
---|
| 39 | //connect DB |
---|
| 40 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 41 | if (!$link) { |
---|
| 42 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 43 | return $buffer; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 48 | if (!$db_selected) { |
---|
| 49 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | if (empty($filter)) { |
---|
| 54 | $sql = "SELECT * FROM DEVICE"; |
---|
| 55 | }else{ |
---|
| 56 | $sql = "SELECT * FROM DEVICE WHERE $filter ;" ; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | if ($result = mysql_query($sql, $link)) { |
---|
| 61 | //test if $return is_array |
---|
| 62 | return $result ; |
---|
| 63 | |
---|
| 64 | } else { |
---|
| 65 | $buffer = "SELECT DEVICE : [FAILED] :" . mysql_error() ; |
---|
| 66 | return $buffer ; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | function delDevice($hostname) { |
---|
| 77 | |
---|
| 78 | $buffer = ""; |
---|
| 79 | |
---|
| 80 | //connect DB |
---|
| 81 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 82 | if (!$link) { |
---|
| 83 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 84 | return $buffer; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 89 | if (!$db_selected) { |
---|
| 90 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | //Before del user of Table USER, del user in all others Table |
---|
| 95 | //del switch from CMDSWITCH |
---|
| 96 | $sql="DELETE FROM CMDSWITCH WHERE idSwitch='$hostname';"; |
---|
| 97 | if (mysql_query($sql, $link)) { |
---|
| 98 | $buffer .= "DELETE SWITCH $hostname FROM CMDSWITCH: [OK]<BR />"; |
---|
| 99 | } else { |
---|
| 100 | $buffer = "DELETE SWITCH $hostname FROM CMDSWITCH: [FAILED] :" . mysql_error() ; |
---|
| 101 | return $buffer; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | //del switch from SERVICESWITCH |
---|
| 105 | $sql = "DELETE FROM SERVICESWITCH WHERE idSwitch='$hostname'"; |
---|
| 106 | if (mysql_query($sql, $link)) { |
---|
| 107 | $buffer .= "DELETE SWITCH $hostname FROM SERVICESWITCH: [OK]<BR />"; |
---|
| 108 | } else { |
---|
| 109 | $buffer = "DELETE SWITCH $hostname FROM SERVICESWITCH: [FAILED] :" . mysql_error() ; |
---|
| 110 | return $buffer; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | //del switch |
---|
| 115 | $sql = "DELETE FROM SWITCH WHERE idswitch='$hostname';"; |
---|
| 116 | |
---|
| 117 | if (mysql_query($sql, $link)) { |
---|
| 118 | $buffer .= "DELETE SWITCH $hostname: [OK]<BR />"; |
---|
| 119 | } else { |
---|
| 120 | $buffer = "DELETE SWITCH $hostname: [FAILED] :" . mysql_error() ; |
---|
| 121 | return $buffer; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | //dev Device |
---|
| 125 | $sql = "DELETE FROM DEVICE WHERE hostname='$hostname';"; |
---|
| 126 | |
---|
| 127 | if (mysql_query($sql, $link)) { |
---|
| 128 | $buffer .= "DELETE DEVICE $hostname: [OK]<BR />"; |
---|
| 129 | } else { |
---|
| 130 | $buffer = "DELETE DEVICE $hostname: [FAILED] :" . mysql_error() ; |
---|
| 131 | return $buffer; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | return $buffer; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | function updateDevice($hostname, $mac, $ip, $type) { |
---|
| 140 | |
---|
| 141 | //connect DB^M |
---|
| 142 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
| 143 | if (!$link) { |
---|
| 144 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 145 | return $buffer; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
| 150 | if (!$db_selected) { |
---|
| 151 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | //update Device |
---|
| 156 | $sql = "UPDATE DEVICE SET |
---|
| 157 | mac='$mac', |
---|
| 158 | ip='$ip', |
---|
| 159 | type='$type', |
---|
| 160 | hostname='$hostname' |
---|
| 161 | WHERE hostname='$hostname' ;" ; |
---|
| 162 | |
---|
| 163 | if (mysql_query($sql, $link)) { |
---|
| 164 | $buffer = 1; |
---|
| 165 | } else { |
---|
| 166 | $buffer = "UPDATE DEVICE $hostname: [FAILED] :" . mysql_error() ; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | return $buffer; |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | ?> |
---|