diff --git a/wol/scripts/sendmac.sh b/wol/scripts/sendmac.sh new file mode 100644 index 0000000000000000000000000000000000000000..ce6ca56c80657e82ff62baf04cba9b3fd99d4098 --- /dev/null +++ b/wol/scripts/sendmac.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright (C) 2018 Tetras Libre <Contact@Tetras-Libre.fr> +# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3) +echo "$1" | netcat $subnet.52 9999 diff --git a/wol/scripts/wakeonlan.sh b/wol/scripts/wakeonlan.sh old mode 100755 new mode 100644 index 2670f751eeb4accd6b2267a805861a4f2a9e9f71..36b2d68f8a9534de68a69d2c155a53a97a023580 --- a/wol/scripts/wakeonlan.sh +++ b/wol/scripts/wakeonlan.sh @@ -16,10 +16,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -X=$(awk '/Allow from .*255.255.255.0/ {print $3}' /etc/apache2/sites-available/phpmyadmin | \ - cut -d . -f 3) -MAC=$1 -for i in $(seq 100 199); do wakeonlan -i 10.20.$X.$i $MAC; done +IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1) +broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1) +netcat -l $IP 9999 | \ + while read MAC + do + if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ] + then + wakeonlan -i $broadcast "$line" + fi + done diff --git a/wol/www/index.php b/wol/www/index.php index 914733eddea0b859c9839d3be16ce555dbf40687..5efd89b8b9a011dfff0def088b35cf4912addfbb 100644 --- a/wol/www/index.php +++ b/wol/www/index.php @@ -20,14 +20,18 @@ //echo "actions '$action', uuid '$uuid', name '$name', dev '$dev'<br/>"; switch($action){ case "wake" : - $cmd = "../scripts/wakeonlan.sh"; - echo "<p>Mac : '$mac'</p>"; $args = escapeshellarg($mac); + if(preg_match('/^([0-9a-f]{2}:?){6}$/',$mac)){ + $cmd = "../scripts/sendmac.sh"; + echo "<p>Mac : '$mac'</p>"; + }else{ + echo "<p>Adresse MAC invalide : ".$args."</p>"; + } break; } if (strcmp($cmd, "")){ - echo "<p>execution de '$cmd $args'</p>"; - shell_exec("$cmd $args"); + echo "<p>execution de ' $cmd $args '</p>"; + echo "<p>".shell_exec("$cmd $args")."</p>"; } ?> <div id="box">