Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $device = $_POST["device"];
- $port = $_POST["port"];
- $enabled = $_POST["enabled"];
- $poeEnabled = $_POST["poeEnabled"];
- $whitelist = [
- "DEVICE1" => [4, 5, 6],
- "DEVICE2" => [],
- ];
- if(!$whitelist[$device] || !in_array($port, $whitelist[$device])) {
- return http_response_code(404);
- };
- $body = [
- 'enabled' => $enabled,
- 'poeEnabled' => $poeEnabled,
- ];
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "https://api.meraki.com/api/v0/devices/" . $device . "/switchPorts/" . $port,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 0,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "PUT",
- CURLOPT_POSTFIELDS => json_encode($body),
- CURLOPT_HTTPHEADER => array(
- "Content-Type: application/json",
- "Accept: application/json",
- "X-Cisco-Meraki-API-Key: yourapikey"
- ),
- ));
- $response = curl_exec($curl);
- curl_close($curl);
- return $response;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement