Guest User

Untitled

a guest
Oct 31st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. html, body, ul, li, ol, form, fieldset, legend {
  5. margin: 0;
  6. padding: 0;
  7. }
  8.  
  9.  
  10. body {
  11. margin: 20px;
  12. font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  13. }
  14.  
  15. p, label {
  16. font-size: 90%;
  17. }
  18.  
  19. label {
  20. display: block;
  21. width: 200px;
  22. float: left;
  23. }
  24.  
  25. input[type=text], input[type=password] {
  26. margin-bottom: 10px;
  27. width: 200px;
  28. }
  29.  
  30. form {
  31. padding: 10px;
  32. border: 1px solid #CCC;
  33. background-color: #FCFCFC;
  34. width: 410px;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <?php
  40.  
  41. error_reporting(E_ERROR | E_PARSE);
  42.  
  43. function wake($mac, $ipaddr) {
  44. $data = "";
  45. for ($i = 0; $i < 6; $i++) {
  46. $data .= chr(255);
  47. }
  48. for ($i = 0; $i < 16; $i++) {
  49. for ($v = 0; $v < 12; $v = $v + 2) {
  50. $data .= chr(hexdec(substr($mac, $v, 2)));
  51. }
  52. }
  53. $endpoint = fsockopen("udp://".$ipaddr, 9);
  54. fwrite($endpoint, $data, 102);
  55. echo "<p>Magic packet sent</p>";
  56. echo "<p>Wake another?</p>";
  57. }
  58.  
  59.  
  60.  
  61. if ($_GET['macaddr'] && $_GET['ipaddr'] && $_GET["passwd"] && $_GET["username"]) {
  62. //type username and password to wake after creation/update
  63. //setpassword
  64. $validmac = filter_input(INPUT_GET, "macaddr", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^([0-9A-F]{2}[:-]){5}[0-9A-F]{2}$/i")) );
  65. $validmac = preg_replace('/([-:])?/', '', $validmac);
  66. if ($validmac) {
  67.  
  68. $database = mysql_connect("localhost", "harry", "temphehe");
  69.  
  70. if ($database) {
  71.  
  72. if (mysql_select_db('wolexample', $database)) {
  73. //escapes
  74. $username = mysql_real_escape_string($_GET["username"], $database);
  75. $ipaddr = mysql_real_escape_string($_GET['ipaddr'], $database);
  76. $password = sha1(mysql_real_escape_string($_GET["passwd"], $database));
  77. $result = mysql_query("SELECT password FROM users WHERE username = '$username'", $database);
  78. if ($result) {
  79. $row = mysql_fetch_assoc($result);
  80. if ($row) {
  81. //we have a user! Now check the pass
  82. if ($row['password'] == sha1($_GET['passwd'])) {
  83. if ((mysql_query("UPDATE users SET macaddr = '$validmac', ipaddr = '$ipaddr' WHERE username = '$username' AND password = '$password'", $database))) {
  84. echo "Info updated successfully";
  85.  
  86. }
  87. else {
  88. echo "Catastrophic failiure updating database";
  89. }
  90. }
  91. else {
  92. echo "Wrong password";
  93. }
  94. }
  95. else {
  96. //make a user
  97. if (mysql_query("INSERT INTO users VALUES ('$username', '$password', '$validmac', '$ipaddr')", $database)) {
  98. echo "New user added successfully";
  99. } else {
  100. echo "Catastrophic failiure adding user to database";
  101. }
  102. }
  103. }
  104. } else {
  105. echo "Catastrophic failiure selecting database";
  106. }
  107. } else {
  108. echo "Catastrophic failiure connecting to database";
  109. }
  110. } else {
  111. echo "Bad input!";
  112. }
  113. }
  114.  
  115. if ($_GET['username'] && $_GET['passwd'] && !$_GET['macaddr'] && !$_GET['ipaddr']) {
  116. $database = mysql_connect("localhost", "harry", "temphehe");
  117.  
  118.  
  119. if ($database) {
  120. if (mysql_select_db('wolexample', $database)) {
  121.  
  122. //escapes
  123. $username = mysql_real_escape_string($_GET["username"], $database);
  124. $result = mysql_query("SELECT macaddr, ipaddr , password FROM users WHERE username = '$username'", $database);
  125.  
  126. if ($result) {
  127. $row = mysql_fetch_assoc($result);
  128. if ($row) {
  129. if ($row['password'] == sha1($_GET['passwd'])) {
  130. wake($row['macaddr'], $row['ipaddr']);
  131. }
  132. else {
  133. echo "Wrong password";
  134. }
  135. }
  136. else {
  137. echo "Username does not exist, try creating it";
  138. }
  139. }
  140. else {
  141. echo "Catastrophic failiure querying database";
  142. }
  143. }
  144. else {
  145. echo "Catastrophic failiure selecting database";
  146. }
  147.  
  148. }
  149. else {
  150. echo "Catastrophic failiure connecting to database";
  151. }
  152. }
  153. if ($_GET['macaddr'] && $_GET['ipaddr'] && !($_GET['username']) && !($_GET['passwd'])) {
  154. $validmac = filter_input(INPUT_GET, "macaddr", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^([0-9A-F]{2}[:-]){5}[0-9A-F]{2}$/i")) );
  155. $validmac = preg_replace('/([-:])?/', '', $validmac);
  156. if ($validmac) {
  157. wake($validmac, $_GET['ipaddr']);
  158. }
  159. else {
  160. echo "Bad input!";
  161. }
  162. }
  163. ?>
  164. <h1>Wake on LAN</h1>
  165. <form name="wol" action="wol.php" method="get">
  166. <label for="ipaddr">IP address/hostname:</label><input type="text" name="ipaddr"><br>
  167. <label for "macaddr">MAC address:</label><input type="text" name="macaddr"><br>
  168. <p>To save or retrieve your IP address and MAC address, enter a username and password. After creating/updating your info, you'll need to enter your new login info and press the button again, as a user is created/updated when all fields are filled.</p>
  169. <label for="username">Username:</label><input type="text" name="username"><br>
  170. <label for="passwd">Password:</label><input type="password" name="passwd"><br>
  171. <input type="submit" value="Wake/Add data to database">
  172. </form>
  173. </body>
  174. </html>
Add Comment
Please, Sign In to add comment