Simple PHP site for issuing wake-on-LAN commands on a button press
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 3.4KB

  1. <?php
  2. // -------------------------------------------
  3. // Wake On LAN Webclient -- on private LAN
  4. // copyright: Jannik Beyerstedt | https://jannikbeyerstedt.de
  5. // license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
  6. // -------------------------------------------
  7. if (isset($_GET['wake'])) {
  8. $return = shell_exec('wakeonlan '.$_GET['wake']);
  9. }
  10. $clients = ["kvm-nuc.fra80" =>"b8:ae:ed:ec:18:f7",
  11. "stavromulabeta.fra80" =>"70:85:c2:49:31:2d",
  12. "magrathea.fra80" =>"60:03:08:9c:25:6a",
  13. "anke-pc.fra80" =>"00:25:11:64:71:7c"];
  14. ?>
  15. <!DOCTYPE html>
  16. <html lang="de">
  17. <head>
  18. <meta charset="utf-8">
  19. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  20. <title>WakeOnLan @ UrsaMinor.fra80</title>
  21. <style>
  22. body {
  23. max-width: 500px;
  24. margin: 0 auto;
  25. padding: 0 10px;
  26. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
  27. }
  28. body > h1:first-child { margin-top: 0.3em; }
  29. small {
  30. font-size: 0.7em;
  31. font-weight: 500;
  32. }
  33. ul {
  34. padding-left: 20px;
  35. }
  36. li {
  37. margin-bottom: 1.5em;
  38. }
  39. a, a:visited {
  40. color: blue;
  41. }
  42. div.info {
  43. margin: -10px; padding: 10px;
  44. background-color: #e2e2e2;
  45. border: 1px solid #787878;
  46. border-radius: 5px;
  47. }
  48. div.info > p:first-child {
  49. margin-top: 0;
  50. }
  51. .red { color: red; }
  52. .green { color: green; }
  53. </style>
  54. </head>
  55. <body>
  56. <h1>Wake On LAN Service</h1>
  57. <?php if (isset($return)) : ?>
  58. <div class="info">
  59. <p>The command returned:</p>
  60. <pre><?php echo $return; ?></pre>
  61. <a href="index.php">OK</a>
  62. </div>
  63. <?php endif; ?>
  64. <p>I can try to wake up the following clients for you:</p>
  65. <ul id="clients">
  66. <?php foreach ($clients as $name=>$mac) : ?>
  67. <li data="<?php echo $name ?>">
  68. <a href="?wake=<?php echo $mac ?>">wake up</a> <?php echo $name ?> (<?php echo $mac ?>)
  69. </li>
  70. <?php endforeach; ?>
  71. </ul>
  72. </body>
  73. <script type="text/javascript">
  74. clients = document.getElementById("clients").children;
  75. for (var i = 0; i < clients.length; i++) {
  76. element = clients[i];
  77. hostname = clients[i].attributes['data'].value;
  78. console.log("ping: " + hostname);
  79. asyncRequest(element, hostname);
  80. }
  81. function asyncRequest(element, hostname) {
  82. var xhttp = new XMLHttpRequest();
  83. xhttp.onreadystatechange = function(){
  84. if (this.readyState == 4) {
  85. if (this.status == 200) {
  86. callBack(element, xhttp.responseText, this.status);
  87. } else {
  88. console.log("Error requesting ping: " + this.status + ", " + xhttp.responseText);
  89. }
  90. }
  91. };
  92. xhttp.open("GET", "ping.php?hostname=" + hostname, true);
  93. xhttp.send();
  94. function callBack(element, response, statusCode) {
  95. var node = document.createElement("span");
  96. node.innerHTML = "&#8226;";
  97. if (xhttp.responseText.substring(0, 1) == "1") {
  98. node.className = "green";
  99. element.appendChild(node);
  100. element.append(" online");
  101. } else {
  102. node.className = "red";
  103. element.appendChild(node);
  104. element.append(" offline");
  105. }
  106. }
  107. }
  108. </script>
  109. </html>