Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. $device = $_POST["device"];
  4. $port = $_POST["port"];
  5. $enabled = $_POST["enabled"];
  6. $poeEnabled = $_POST["poeEnabled"];
  7.  
  8. $whitelist = [
  9. "DEVICE1" => [4, 5, 6],
  10. "DEVICE2" => [],
  11. ];
  12.  
  13. if(!$whitelist[$device] || !in_array($port, $whitelist[$device])) {
  14. return http_response_code(404);
  15. };
  16.  
  17. $body = [
  18. 'enabled' => $enabled,
  19. 'poeEnabled' => $poeEnabled,
  20. ];
  21.  
  22. $curl = curl_init();
  23.  
  24. curl_setopt_array($curl, array(
  25. CURLOPT_URL => "https://api.meraki.com/api/v0/devices/" . $device . "/switchPorts/" . $port,
  26. CURLOPT_RETURNTRANSFER => true,
  27. CURLOPT_ENCODING => "",
  28. CURLOPT_MAXREDIRS => 10,
  29. CURLOPT_TIMEOUT => 0,
  30. CURLOPT_FOLLOWLOCATION => true,
  31. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  32. CURLOPT_CUSTOMREQUEST => "PUT",
  33. CURLOPT_POSTFIELDS => json_encode($body),
  34. CURLOPT_HTTPHEADER => array(
  35. "Content-Type: application/json",
  36. "Accept: application/json",
  37. "X-Cisco-Meraki-API-Key: yourapikey"
  38. ),
  39. ));
  40.  
  41. $response = curl_exec($curl);
  42.  
  43. curl_close($curl);
  44. return $response;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement