diff --git a/net/wol/Makefile b/net/wol/Makefile new file mode 100644 index 000000000..2354481d8 --- /dev/null +++ b/net/wol/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= wol +PLUGIN_VERSION= 0.1 +PLUGIN_PRIVATE= yes +PLUGIN_DEPENDS= wol +PLUGIN_COMMENT= Wake on LAN Service +PLUGIN_MAINTAINER= franco@opnsense.org + +.include "../../Mk/plugins.mk" diff --git a/net/wol/src/etc/inc/plugins.inc.d/wol.inc b/net/wol/src/etc/inc/plugins.inc.d/wol.inc new file mode 100644 index 000000000..b4af53934 --- /dev/null +++ b/net/wol/src/etc/inc/plugins.inc.d/wol.inc @@ -0,0 +1,41 @@ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +function wol_xmlrpc_sync() +{ + $result = array(); + + $result[] = array( + 'description' => gettext('Wake on LAN'), + 'section' => 'wol', + 'id' => 'wol', + ); + + return $result; +} + diff --git a/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/ACL/ACL.xml b/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/ACL/ACL.xml new file mode 100644 index 000000000..2f1c403c0 --- /dev/null +++ b/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/ACL/ACL.xml @@ -0,0 +1,14 @@ + + + Services: Wake on LAN + + services_wol.php* + + + + Services: Wake on LAN: Edit + + services_wol_edit.php* + + + diff --git a/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/Menu/Menu.xml b/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/Menu/Menu.xml new file mode 100644 index 000000000..5f0df9a6b --- /dev/null +++ b/net/wol/src/opnsense/mvc/app/models/OPNsense/WOL/Menu/Menu.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/net/wol/src/www/services_wol.php b/net/wol/src/www/services_wol.php new file mode 100644 index 000000000..64e782089 --- /dev/null +++ b/net/wol/src/www/services_wol.php @@ -0,0 +1,271 @@ +. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("guiconfig.inc"); +require_once("interfaces.inc"); + +if (empty($config['wol']['wolentry']) || !is_array($config['wol']['wolentry'])) { + $config['wol'] = array(); + $config['wol']['wolentry'] = array(); +} +$a_wol = &$config['wol']['wolentry']; + + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // delete entry + if (isset($_POST['act']) && $_POST['act'] == "del" && isset($_POST['id'])) { + if (!empty($a_wol[$_POST['id']])) { + unset($a_wol[$_POST['id']]); + write_config(); + } + exit; + } elseif (isset($_POST['act']) && $_POST['act'] == "wakeall") { + $savemsg = ""; + $result = array(); + foreach ($a_wol as $wolent) { + $if = $wolent['interface']; + $ipaddr = get_interface_ip($if); + if (!is_ipaddr($ipaddr)) { + continue; + } + $bcip = escapeshellarg(gen_subnet_max($ipaddr, get_interface_subnet($if))); + /* Execute wol command and check return code. */ + if (!mwexec("/usr/local/bin/wol -i {$bcip} ". escapeshellarg($wolent['mac']))) { + $result[] = sprintf(gettext('Sent magic packet to %s (%s).'), htmlspecialchars($wolent['mac']), $wolent['descr']); + } else { + $result[] = sprintf(gettext('Please check the %ssystem log%s, the wol command for %s (%s) did not complete successfully.'), '', '', $wolent['descr'], htmlspecialchars($wolent['mac'])); + } + } + echo json_encode($result); + exit; + } elseif (isset($_POST['mac'])) { + /* input validation */ + if (empty($_POST['mac']) || !is_macaddr($_POST['mac'])) { + $input_errors[] = gettext("A valid MAC address must be specified."); + } + if (empty($_POST['if'])) { + $input_errors[] = gettext("A valid interface must be specified."); + } else { + $ipaddr = get_interface_ip($_POST['if']); + if (!is_ipaddr($ipaddr)) { + $input_errors[] = gettext("A valid ip could not be found!"); + } + } + + if (count($input_errors) == 0) { + /* determine broadcast address */ + $bcip = escapeshellarg(gen_subnet_max($ipaddr, get_interface_subnet($_POST['if']))); + /* Execute wol command and check return code. */ + if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($_POST['mac']))) { + $savemsg = sprintf(gettext('Sent magic packet to %s.'), $_POST['mac']); + } else { + $savemsg = sprintf(gettext('Please check the %ssystem log%s, the wol command for %s did not complete successfully.'), '', '', $_POST['mac']); + } + } + } +} + +include("head.inc"); +?> + + + + +
+
+
+ 0) print_input_errors($input_errors); ?> + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +    +
+ + +
+ " /> + +
  + " /> +
+ + + +
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+ diff --git a/net/wol/src/www/services_wol_edit.php b/net/wol/src/www/services_wol_edit.php new file mode 100644 index 000000000..a3cfa93b6 --- /dev/null +++ b/net/wol/src/www/services_wol_edit.php @@ -0,0 +1,173 @@ +. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("guiconfig.inc"); +require_once("interfaces.inc"); + +function wolcmp($a, $b) { + return strcmp($a['descr'], $b['descr']); +} + + +if (empty($config['wol']['wolentry']) || !is_array($config['wol']['wolentry'])) { + $config['wol'] = array(); + $config['wol']['wolentry'] = array(); +} +$a_wol = &$config['wol']['wolentry']; + +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && !empty($a_wol[$_GET['id']])) { + $id = $_GET['id']; + } + $pconfig = array(); + foreach (array('interface', 'mac', 'descr') as $fieldname) { + if (isset($id) && isset($a_wol[$id][$fieldname])) { + $pconfig[$fieldname] = $a_wol[$id][$fieldname]; + } elseif (isset($_GET[$fieldname])) { + $pconfig[$fieldname] = $_GET[$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['id']) && !empty($a_wol[$_POST['id']])) { + $id = $_POST['id']; + } + $pconfig = $_POST; + $input_errors = array(); + + /* input validation */ + $reqdfields = explode(" ", "interface mac"); + $reqdfieldsn = array(gettext("Interface"),gettext("MAC address")); + + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + + /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */ + $pconfig['mac'] = strtolower(str_replace("-", ":", $pconfig['mac'])); + + if (!empty($pconfig['mac']) && !is_macaddr($_POST['mac'])) { + $input_errors[] = gettext("A valid MAC address must be specified."); + } + if (count($input_errors) == 0) { + $wolent = array(); + $wolent['interface'] = $_POST['interface']; + $wolent['mac'] = $_POST['mac']; + $wolent['descr'] = $_POST['descr']; + + if (isset($id)) { + $a_wol[$id] = $wolent; + } else { + $a_wol[] = $wolent; + } + usort($config['wol']['wolentry'], "wolcmp"); + write_config(); + + header(url_safe('Location: /services_wol.php')); + exit; + } +} + +include("head.inc"); +legacy_html_escape_form_data($pconfig); +?> + + + +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + +
+ + +
+ + +
  + " /> + " onclick="window.location.href='/services_wol.php'" /> + + + +
+
+
+
+
+
+
+
+ diff --git a/net/wol/src/www/widgets/include/wake_on_lan.inc b/net/wol/src/www/widgets/include/wake_on_lan.inc new file mode 100644 index 000000000..d432b2472 --- /dev/null +++ b/net/wol/src/www/widgets/include/wake_on_lan.inc @@ -0,0 +1,4 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ text-" > + + + + "> + +