diff --git a/index.php b/index.php index f435fc4..34f5f75 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,8 @@ // Kickstart the framework // $f3=require('lib/base.php'); require_once './vendor/autoload.php'; + +date_default_timezone_set('Europe/Budapest'); $f3 = \Base::instance(); $f3->set('DB',new DB\Jig('data/')); $db=new \DB\Jig('data/'); @@ -63,6 +65,8 @@ $f3->route('POST /sendsignal', function($f3) { function sendsignal($post) { $iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']); + $macArray = preg_split('/\r\n|\r|\n/', $post['item']['macAddress']); + $label = $post['label']; $messages = []; switch ($post['item']['channel']) { case 'telnet': @@ -78,10 +82,19 @@ function sendsignal($post) { } break; case 'wol': - foreach ($iparray as $ip) { - $result = wol($post['item']['macAddress'], $post['item']['broadcastIP']); - array_push($messages, $result); + if ($label === 'on') { + foreach ($macArray as $mac) { + $result = wol($mac, $post['item']['broadcastIP']); + array_push($messages, $result); + } + + } else { + foreach ($iparray as $ip) { + $result = shutdown($ip); + array_push($messages, $result); + } } + break; default: array_push($messages, ['success' => false, 'message' => 'No channel set for these equipments']); @@ -134,13 +147,24 @@ function udp($ip, $port, $action) { } + +function shutdown($ip) { + $ipdata = explode('@', $ip); + $username = explode(':', $ipdata[0])[0]; + $password = explode(':', $ipdata[0])[1]; + $ipaddress = $ipdata[1]; + $output = shell_exec("net rpc shutdown -f -t 0 -C 'message' -U ". $username . "%" . $password ." -I " . $ipaddress); + return ['success' => true, 'message' => $output . '(' . $ipaddress . ')']; +} + function wol($macAddress, $broadcastIP) { $f = new \Phpwol\Factory(); $magicPacket = $f->magicPacket(); - if ($result = $magicPacket->send($macAddress, $broadcastIP)) { - return ['success' => true, 'message' => 'Successful Wake On Lan']; + $result = $magicPacket->send($macAddress, $broadcastIP); + if ($result) { + return ['success' => true, 'message' => 'Successful Wake On Lan for ' . $macAddress]; } else { - return ['success' => false, 'message' => 'Unsuccessful WOL for IP ' . $macAddress]; + return ['success' => false, 'message' => 'Unsuccessful WOL for MAC address ' . $macAddress]; } } diff --git a/ui/home.htm b/ui/home.htm index b6b49d1..01c20d6 100644 --- a/ui/home.htm +++ b/ui/home.htm @@ -1,6 +1,7 @@
Parancs küldése, kérem várjon.
+= date('Y.m.d H:i') ?>
No equipments, please add one.
-