Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. <center>
  2. <br><br><br><br><br>
  3. <?php
  4. /* ============================== Configuration settings ====================================== */
  5.  
  6. /* List of PCs that may be woken */
  7. $config_network_data_array[] = array("name" => "Shane-EPC", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
  8. "changed for security");
  9. $config_network_data_array[] = array("name" => "Demo", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
  10. "changed for security");
  11. $config_network_data_array[] = array("name" => "Demo", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
  12. "changed for security");
  13.  
  14. // Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
  15. $socket_number = "7";
  16.  
  17. $my_password = 'pass';
  18. $my_username = 'user';
  19.  
  20. $html_title = '<H2>TrivisionZero PC Waker</H2>';
  21.  
  22. $config_table_columns = array('name', 'IP', 'MAC', 'links');
  23.  
  24. # The following function is copied (with some edits, to suppress output and return TRUE or an error message) from:
  25. # http://www.hackernotcracker.com/2006-04/wol-wake-on-lan-tutorial-with-bonus-php-script.html
  26.  
  27. # Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
  28. # Modified by Allan Barizo http://www.hackernotcracker.com
  29.  
  30. flush();
  31.  
  32. function WakeOnLan($addr, $mac,$socket_number) {
  33.  
  34. $separator = ':';
  35. if (strstr ( $mac, '-' ) ) {
  36. $separator = '-';
  37. }
  38. $addr_byte = explode($separator, $mac);
  39.  
  40. $hw_addr = '';
  41. for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
  42. $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  43. for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
  44. // send it to the broadcast address using UDP
  45. // SQL_BROADCAST option isn't help!!
  46. $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  47. if ($s == false) {
  48. // echo "Error creating socket!n";
  49. // echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
  50. return "Error creating socket!nError code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_erro
  51. ($s));
  52. // return FALSE;
  53. }
  54. else {
  55. // setting a broadcast option to socket:
  56. $opt_ret = socket_set_option($s, 1, 6, TRUE);
  57. if($opt_ret <0) {
  58. // echo "setsockopt() failed, error: " . strerror($opt_ret) . "n";
  59. return "setsockopt() failed, error: " . strerror($opt_ret) . "n";
  60. // return FALSE;
  61. }
  62. if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
  63. // echo "Magic Packet sent successfully!";
  64. socket_close($s);
  65. return TRUE;
  66. }
  67. else {
  68. // echo "Magic packet failed!";
  69. return "Magic packet failed!";
  70. // return FALSE;
  71. }
  72. }
  73. }
  74.  
  75. /* ============================== some predefined texts ====================================== */
  76.  
  77. $display_sent = 'Magic Packet sent successfully!';
  78. $button_text = 'Wake!';
  79. $button_text2 = 'Wake all selected';
  80.  
  81. //this is where I added my username part
  82. $username_element = "<P>Username: <input type="text" name="username" />";
  83. $password_element = "<P>Password: <input type="password" name="password" /><input type="submit" name="submit" value = "Login" />";
  84.  
  85.  
  86. $table_html = "<TABLE border="2">n";
  87. $logout_html = '';
  88.  
  89. /* ========================= Test for password protection ==================================== */
  90. $wake_MAC_array = array();
  91.  
  92. if (!isset ($_POST['logout'])) {
  93. $input_password = $_POST['password'];
  94. $input_username = $_POST['username'];
  95.  
  96. }
  97. //($my_password === '') is if you want no password
  98. if (($input_password === $my_password) and ($input_username === $my_username)) {
  99. $logged_in = TRUE;
  100. $hidden_login = "<input type="hidden" name="password" value="$my_password"/>";
  101. if ($my_password !== '') {
  102. $logout_html = "n<P><input type="submit" name="logout" value="Log Out"/>n";
  103. }
  104. if ( (isset ($_POST['tickbox'])) and (is_array($_POST['tickbox']) ) ) {
  105. $checkbox_array = $_POST['tickbox'];
  106. foreach ($checkbox_array as $mac_address => $tickbox_setting) {
  107. $wake_MAC_array[$mac_address] = $tickbox_setting;
  108. }
  109.  
  110. }
  111.  
  112. } else {
  113. $logged_in = FALSE;
  114. $hidden_login = '';
  115. $table_html_user = $username_element;
  116. $table_html = $password_element;
  117. }
  118.  
  119. /* ================================ LOGGED-IN users only ===================================== */
  120. /* ======================= construct table for listing of devices ============================ */
  121.  
  122. if ($logged_in == TRUE) {
  123. $table_row = "n<TR>";
  124. foreach ($config_table_columns as $key => $column_heading) {
  125. $table_row .= '<TD>' . $column_heading . '</TD>';
  126. }
  127. $table_row .= '<TD>Wake Up!</TD>';
  128. $table_row .= '<TD>status</TD>';
  129. $table_html .= $table_row . "</TR>n";
  130. foreach ($config_network_data_array as $device_key => $device_values) {
  131. $table_row = "n<TR>";
  132. $mac = $device_values['MAC'];
  133. $device_name = $device_values['name'];
  134. $status_cell = '<TD>&nbsp;</TD>';
  135. foreach ($config_table_columns as $key => $column_heading) {
  136. if (isset ( $device_values[$column_heading])) {
  137. $value = $device_values[$column_heading];
  138. if ($column_heading == 'MAC') {
  139. /* special coding for MAC address column; prepare clickable button */
  140. $this_MAC = $value;
  141. $value = "<input type="submit" name="wake_MAC" value = "$value" />";
  142.  
  143. if (( $_POST['wake_MAC'] === $this_MAC ) or (array_key_exists ($this_MAC,
  144. $wake_MAC_array))) {
  145. $status = WakeOnLan ($device_values['WakeIP'], $this_MAC, $socket_number) ;
  146. if ( $status === TRUE ) {
  147. $status = $display_sent;
  148. }
  149. $status_cell = "<TD>$status</TD>";
  150. }
  151. }
  152. } elseif ($column_heading == 'links') {
  153. /* special coding for links column; prepare clickable links from $config_network_links_array */
  154. $value = '';
  155. if (isset ( $config_network_links_array[$device_name])) {
  156. foreach ($config_network_links_array[$device_name] as $link_title => $link_URL) {
  157. if ( $value !== '') {
  158. $value .= '<BR />';
  159. }
  160. $value .= '<A HREF="' . $link_URL . '">' . $link_title . '</A>';
  161. }
  162. }
  163. } else {
  164. $value = '';
  165. }
  166. if ($value === '') {
  167. $value = '&nbsp;';
  168. }
  169. $table_row .= '<TD>' . $value . '</TD>';
  170. }
  171. /* now add a checkbox to wake up this device */
  172. $table_row .= '<TD>' . "<input type="checkbox" name="tickbox[$this_MAC]" />" . '</TD>';
  173. /* now add the status message (if applicable) for the attempt to send a packet to this device */
  174. $table_row .= $status_cell;
  175. $table_html .= $table_row . "</TR>n";
  176. }
  177. $table_html .= "</TABLE>n";
  178. $table_html .= "<P><input type="submit" name="wake all" value = "$button_text2" />n";
  179. }
  180. /* =========================================================================================== */
  181. /* ======================= Now output the html that we've built ============================== */
  182.  
  183. echo $html_title;
  184.  
  185. echo "<FORM name="input" action="" .$_SERVER['PHP_SELF'] . "" method="post">";
  186. echo '<P>';
  187. echo $table_html_user;
  188. echo $table_html;
  189. echo $hidden_login;
  190. echo $logout_html;
  191. echo "</FORM>n";
  192.  
  193. ?>
  194. </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement