• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[RE-OPENED] WakeOnLAN, more features
#1
Hi,

I tried to search the forum for a simple way to trigger WOL to client but could not find a english post on this.

So, my question is; do you have to make a task for triggering WOL to client or is there a more simple way of doing this? If so, I have a suggestion to this.. :-)

br,
Chris

edit: need to use task to use WoL. One computer with FI-Agent (?) needs to be online for WoL to work in subnet.
edit2: re-open and change topic subject to better match thread.
  Reply
#2
You must create a task for this
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#3
ddurieux Wrote:You must create a task for this

Ok, then I'll have a suggestion (with some code hopefully) over the weekend for making WOL much more simple / faster to use.

br,
Chris
  Reply
#4
Ok, found some code on a forum that could possible be used to send WoL with PHP. http://www.newit.co.uk/forum/index.php?topic=76.0

I copy/pasted the whole thing for simplicity. You should be able to take some ideas from this and possibly implement it as you please.

http://content.screencast.com/users/su_r...000902.png

http://content.screencast.com/users/su_r...000901.png

Code:
<?php

/* ============================== Configuration settings ====================================== */

/* List of PCs that may be woken */
$config_network_data_array[] = array("name" => "PC #1", "MAC" => "00:00:13:00:C3:A0", "IP" => "192.168.1.14", "WakeIP" =>
"192.168.1.255");
$config_network_data_array[] = array("name" => "PC #2", "MAC" => "00:00:13:00:C3:A1", "IP" => "192.168.1.15", "WakeIP" =>
"192.168.1.255");
$config_network_data_array[] = array("name" => "PC #3", "MAC" => "00:00:13:00:C3:5E", "IP" => "192.168.1.16", "WakeIP" =>
"192.168.1.255");

/* Optional list of URLs associated with the devices listed above */
$config_network_links_array['PC #1'] = array("webmin" => "https://192.168.1.14:10000");
$config_network_links_array['PC #2'] = array("website" => "http://192.168.1.15", "forum" => "http://192.168.1.15/forum");

// 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 = '123';
// If you don't want to password-protect:
$my_password = '';

$html_title = '<H2>My Wake On LAN devices</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';

$password_element = "<P>password: <input type=\"text\" name=\"password\" /><input type=\"submit\" name=\"submit\" value = \"procee
\" />";

$table_html = "<TABLE border=\"2\">\n";
$logout_html = '';

/* ========================= Test for password protection ==================================== */
$wake_MAC_array = array();

if (!isset ($_POST['logout'])) {
   $input_password = $_POST['password'];
}

if (($input_password === $my_password) or ($my_password === '')) {
   $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 = $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>&nbsp;</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 = '&nbsp;';
      }
      $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;
echo $hidden_login;
echo $logout_html;
echo "</FORM>\n";

?>

I don't actually know how FI is doing its WoL but it seems to take forever for a computer to wake up at the moment so my best guess is, that the WoL is handled from a FI-Agent?

br,
Chris
  Reply
#5
For the moment, you must use tasks, and php-wol is not a good idea, because it's server run wol instead the agent (and the agent can be on another network Wink )

But your idea to create a task in assive action is a good idea, I have added a ticket: http://forge.fusioninventory.org/issues/1823
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#6
Thank You for Your reply!

ddurieux Wrote:For the moment, you must use tasks, and php-wol is not a good idea, because it's server run wol instead the agent (and the agent can be on another network Wink )

But your idea to create a task in assive action is a good idea, I have added a ticket: http://forge.fusioninventory.org/issues/1823

Yes, I know that it is good when running on a different subnet than the server etc. It is just that the WoL takes sooo long and sometimes it would be nice to wake the computer a.s.a.p so you can remote desktop it and so on.

Would you consider adding 2 WoL features? :-) It could perhaps also be used with a script for them running on Linux?

br,
Chris
  Reply
#7
You can use push modelin the task, and so agent run immediatly Wink
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#8
ddurieux Wrote:You can use push modelin the task, and so agent run immediatly Wink

Ok, thanks! Then I have something configured wrongly since it can take +1h for the PCs to wake up. I need to look into this more in dept then.

Thanks for confirming, my request is now not necessary anymore and thanks for the help + adding the WoL to "task list".

br,
Chris
  Reply
#9
I just noticed that I have probably never got WoL to work from GLPI with FI. So my question is, should the status change here to something else when computer is powered on / online?

http://content.screencast.com/users/su_r...000913.png

Another cool feature, although I don't know how and if it would be possible, it would be nice to have a site that shows if the computer is online or not (i.e. a red dot if the computer is offline and a green dot if the computer is online). Perhaps it could be possible to assign a FI-Agent on the subnet that sends ping sweeps to the other computers on request?


br,
Chris
  Reply
#10
1/ wol agent module send magic packet and so can't know if it works.

2/ What's the goal to know if computer is online or not?
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#11
ddurieux Wrote:1/ wol agent module send magic packet and so can't know if it works.

2/ What's the goal to know if computer is online or not?

If I send WoL to a set of +700 computers over the weekend for i.e. Windows updates (forced via WSUS) or for deploying different patches. It would be nice to know if all those computers that were sent WoL-packages actually wakes up and thus are online and ready for getting the patches/updates sent to them.

If there are not PCs waking up, then I know that these will not for sure be updated and needs to be dealt with manually first thing in the working week (perhaps some laptops are not left at work over the weekend and so on).

When possible, I tend to favor distribution of service packs etc. over the weekend so that there is no users getting pissed :-)

br,
Chris

edit: and as You stated, it is not possible to know if WoL actually did work due to agents sending the request. I actually thing it would be a quite good option to have a PC/server in the same subnet for handling ping sweeps. This sounds easy but is quite hard to implement I guess?

disclosure: I don't have GLPI & FI running in a big environment at the moment but it is very possible to get deployed into a +700 PC environment in the near future due to needs of saving money..
  Reply
#12
If a computer don't start on WOL, you can't start. When you run deployment after, you will have an error in this computer.

I have added yesterday (in dev version), a display to see on a task execution the state of the deployment on each computer.
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#13
ddurieux Wrote:If a computer don't start on WOL, you can't start. When you run deployment after, you will have an error in this computer.

Yes, I know that the deployment will not start if the computer is offline. That is why I now have 3rd party programs that sends ping sweeps before deployments (= collects PCs that does not respond on ping to a separate list). When I know what computers are offline, I don't have to worry about troubleshooting why deployment/s don't start.

ddurieux Wrote:I have added yesterday (in dev version), a display to see on a task execution the state of the deployment on each computer.

Thanks a lot!!

Have a great week!

br,
Chris

edit: Something like this is on my mind

Code:
$pinginfo = exec("/bin/ping -v -c $selected_hosts");
echo $pinginfo;
  Reply
#14
That is why I now have 3rd party programs that sends ping sweeps before deployments

=> Yes but if you use DHCP, you can't do this :/
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#15
ddurieux Wrote:That is why I now have 3rd party programs that sends ping sweeps before deployments

=> Yes but if you use DHCP, you can't do this :/

Yes, we have DHCP (needs to convert hostname to IP in the ping sweep.). I'll post an better example with PHP-code later today.

br,
Chris
  Reply
#16
Yes but you see it's a little unstable :p
Co-leader, official developper
DCS official PARTNER: dcs.glpi@dcsit-group.com
  Reply
#17
ddurieux Wrote:Yes but you see it's a little unstable :p

Perhaps it is but it's an unstable world we live in :-)

Actually this is not a big issue for me since I can put a .php site running under GLPI but I thought perhaps other users could benefit also from this.

I'm actually leaning to rely on nmap for this but it can also be used with something like:

Code:
for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done

The result we want to put in a file and then dig or host etc. on the file where PC responds to ping so we can resolve the hostname which is online.

br,
Chris
  Reply
#18
nmap with the following could perhaps be useful in some way (needs some nicer formatting though, any suggestions on howto do this in a good way?):

Code:
nmap -sn -PR 10.1.1.*

br,
Chris
  Reply
#19
Ok, here goes (requires http://pear.php.net/package/Net_Nmap)


Code:
<html>
<head>
<title>Hosts up</title>
</head>
<body>
<?php
require_once 'Net/Nmap.php';

//add in the target your address range to get status
$target = array('10.102.105.1-5');

$options = array('nmap_binary' => '/usr/bin/nmap');

try {
    $nmap = new Net_Nmap;

    $res = $nmap->scan($target);

    $hosts = $nmap->parseXMLOutput();

    //Print results
    foreach ($hosts as $key => $host) {
        echo 'Hostname: ' . $host->getHostname() . "\n";
        echo 'Address: ' . $host->getAddress() . "\n";
        echo 'Status: ' . $host->getStatus() . "\n<br>";
    }
} catch (Net_Nmap_Exception $ne) {
    echo $ne->getMessage();
}


?>
</body>
</html>

More options found here:
http://lucor.github.com/2008/06/discover...-and-nmap/

What do you think?

br,
Chris

edit: the above obviously needs some much nicer formatting, show only up or down etc

Code:
Hostname: unknown Address: 10.102.105.2 Status: down
Hostname: unknown Address: 10.102.105.1 Status: up
Hostname: unknown Address: 10.102.105.3 Status: up
Hostname: computername.domainname 10.102.105.4 Status: up
Hostname: unknown Address: 10.102.105.5 Status: up

edit2: after some thinking, I think this feature should be included in GLPI?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)