From a8876c385c873b1dced90594916a0508186145a5 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Thu, 26 Jul 2018 11:53:59 +0200 Subject: [PATCH] Better solution using two containers --- wol/scripts/sendmac.sh | 20 ++++++++++++++++++++ wol/scripts/wakeonlan.sh | 14 ++++++++++---- wol/www/index.php | 12 ++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 wol/scripts/sendmac.sh mode change 100755 => 100644 wol/scripts/wakeonlan.sh diff --git a/wol/scripts/sendmac.sh b/wol/scripts/sendmac.sh new file mode 100644 index 0000000..ce6ca56 --- /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 2670f75..36b2d68 --- 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 914733e..5efd89b 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"> -- GitLab