Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <center>
- <br><br><br><br><br>
- <?php
- /* ============================== Configuration settings ====================================== */
- /* List of PCs that may be woken */
- $config_network_data_array[] = array("name" => "Shane-EPC", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
- "changed for security");
- $config_network_data_array[] = array("name" => "Demo", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
- "changed for security");
- $config_network_data_array[] = array("name" => "Demo", "MAC" => "changed for security", "IP" => "changed for security", "WakeIP" =>
- "changed for security");
- // Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
- $socket_number = "7";
- $my_password = 'pass';
- $my_username = 'user';
- $html_title = '<H2>TrivisionZero PC Waker</H2>';
- $config_table_columns = array('name', 'IP', 'MAC', 'links');
- # The following function is copied (with some edits, to suppress output and return TRUE or an error message) from:
- # http://www.hackernotcracker.com/2006-04/wol-wake-on-lan-tutorial-with-bonus-php-script.html
- # Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
- # Modified by Allan Barizo http://www.hackernotcracker.com
- flush();
- function WakeOnLan($addr, $mac,$socket_number) {
- $separator = ':';
- if (strstr ( $mac, '-' ) ) {
- $separator = '-';
- }
- $addr_byte = explode($separator, $mac);
- $hw_addr = '';
- for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
- $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
- for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
- // send it to the broadcast address using UDP
- // SQL_BROADCAST option isn't help!!
- $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- if ($s == false) {
- // echo "Error creating socket!n";
- // echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
- return "Error creating socket!nError code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_erro
- ($s));
- // return FALSE;
- }
- else {
- // setting a broadcast option to socket:
- $opt_ret = socket_set_option($s, 1, 6, TRUE);
- if($opt_ret <0) {
- // echo "setsockopt() failed, error: " . strerror($opt_ret) . "n";
- return "setsockopt() failed, error: " . strerror($opt_ret) . "n";
- // return FALSE;
- }
- if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
- // echo "Magic Packet sent successfully!";
- socket_close($s);
- return TRUE;
- }
- else {
- // echo "Magic packet failed!";
- return "Magic packet failed!";
- // return FALSE;
- }
- }
- }
- /* ============================== some predefined texts ====================================== */
- $display_sent = 'Magic Packet sent successfully!';
- $button_text = 'Wake!';
- $button_text2 = 'Wake all selected';
- //this is where I added my username part
- $username_element = "<P>Username: <input type="text" name="username" />";
- $password_element = "<P>Password: <input type="password" name="password" /><input type="submit" name="submit" value = "Login" />";
- $table_html = "<TABLE border="2">n";
- $logout_html = '';
- /* ========================= Test for password protection ==================================== */
- $wake_MAC_array = array();
- if (!isset ($_POST['logout'])) {
- $input_password = $_POST['password'];
- $input_username = $_POST['username'];
- }
- //($my_password === '') is if you want no password
- if (($input_password === $my_password) and ($input_username === $my_username)) {
- $logged_in = TRUE;
- $hidden_login = "<input type="hidden" name="password" value="$my_password"/>";
- if ($my_password !== '') {
- $logout_html = "n<P><input type="submit" name="logout" value="Log Out"/>n";
- }
- if ( (isset ($_POST['tickbox'])) and (is_array($_POST['tickbox']) ) ) {
- $checkbox_array = $_POST['tickbox'];
- foreach ($checkbox_array as $mac_address => $tickbox_setting) {
- $wake_MAC_array[$mac_address] = $tickbox_setting;
- }
- }
- } else {
- $logged_in = FALSE;
- $hidden_login = '';
- $table_html_user = $username_element;
- $table_html = $password_element;
- }
- /* ================================ LOGGED-IN users only ===================================== */
- /* ======================= construct table for listing of devices ============================ */
- if ($logged_in == TRUE) {
- $table_row = "n<TR>";
- foreach ($config_table_columns as $key => $column_heading) {
- $table_row .= '<TD>' . $column_heading . '</TD>';
- }
- $table_row .= '<TD>Wake Up!</TD>';
- $table_row .= '<TD>status</TD>';
- $table_html .= $table_row . "</TR>n";
- foreach ($config_network_data_array as $device_key => $device_values) {
- $table_row = "n<TR>";
- $mac = $device_values['MAC'];
- $device_name = $device_values['name'];
- $status_cell = '<TD> </TD>';
- foreach ($config_table_columns as $key => $column_heading) {
- if (isset ( $device_values[$column_heading])) {
- $value = $device_values[$column_heading];
- if ($column_heading == 'MAC') {
- /* special coding for MAC address column; prepare clickable button */
- $this_MAC = $value;
- $value = "<input type="submit" name="wake_MAC" value = "$value" />";
- if (( $_POST['wake_MAC'] === $this_MAC ) or (array_key_exists ($this_MAC,
- $wake_MAC_array))) {
- $status = WakeOnLan ($device_values['WakeIP'], $this_MAC, $socket_number) ;
- if ( $status === TRUE ) {
- $status = $display_sent;
- }
- $status_cell = "<TD>$status</TD>";
- }
- }
- } elseif ($column_heading == 'links') {
- /* special coding for links column; prepare clickable links from $config_network_links_array */
- $value = '';
- if (isset ( $config_network_links_array[$device_name])) {
- foreach ($config_network_links_array[$device_name] as $link_title => $link_URL) {
- if ( $value !== '') {
- $value .= '<BR />';
- }
- $value .= '<A HREF="' . $link_URL . '">' . $link_title . '</A>';
- }
- }
- } else {
- $value = '';
- }
- if ($value === '') {
- $value = ' ';
- }
- $table_row .= '<TD>' . $value . '</TD>';
- }
- /* now add a checkbox to wake up this device */
- $table_row .= '<TD>' . "<input type="checkbox" name="tickbox[$this_MAC]" />" . '</TD>';
- /* now add the status message (if applicable) for the attempt to send a packet to this device */
- $table_row .= $status_cell;
- $table_html .= $table_row . "</TR>n";
- }
- $table_html .= "</TABLE>n";
- $table_html .= "<P><input type="submit" name="wake all" value = "$button_text2" />n";
- }
- /* =========================================================================================== */
- /* ======================= Now output the html that we've built ============================== */
- echo $html_title;
- echo "<FORM name="input" action="" .$_SERVER['PHP_SELF'] . "" method="post">";
- echo '<P>';
- echo $table_html_user;
- echo $table_html;
- echo $hidden_login;
- echo $logout_html;
- echo "</FORM>n";
- ?>
- </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement