Browse Source

on/off mods

master
Enzo Angiulli 4 years ago
parent
commit
05e95fb876
  1. 36
      index.php
  2. 25
      ui/home.htm

36
index.php

@ -3,6 +3,8 @@
// Kickstart the framework // Kickstart the framework
// $f3=require('lib/base.php'); // $f3=require('lib/base.php');
require_once './vendor/autoload.php'; require_once './vendor/autoload.php';
date_default_timezone_set('Europe/Budapest');
$f3 = \Base::instance(); $f3 = \Base::instance();
$f3->set('DB',new DB\Jig('data/')); $f3->set('DB',new DB\Jig('data/'));
$db=new \DB\Jig('data/'); $db=new \DB\Jig('data/');
@ -63,6 +65,8 @@ $f3->route('POST /sendsignal', function($f3) {
function sendsignal($post) { function sendsignal($post) {
$iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']); $iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']);
$macArray = preg_split('/\r\n|\r|\n/', $post['item']['macAddress']);
$label = $post['label'];
$messages = []; $messages = [];
switch ($post['item']['channel']) { switch ($post['item']['channel']) {
case 'telnet': case 'telnet':
@ -78,10 +82,19 @@ function sendsignal($post) {
} }
break; break;
case 'wol': case 'wol':
foreach ($iparray as $ip) { if ($label === 'on') {
$result = wol($post['item']['macAddress'], $post['item']['broadcastIP']); foreach ($macArray as $mac) {
array_push($messages, $result); $result = wol($mac, $post['item']['broadcastIP']);
array_push($messages, $result);
}
} else {
foreach ($iparray as $ip) {
$result = shutdown($ip);
array_push($messages, $result);
}
} }
break; break;
default: default:
array_push($messages, ['success' => false, 'message' => 'No channel set for these equipments']); 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) { function wol($macAddress, $broadcastIP) {
$f = new \Phpwol\Factory(); $f = new \Phpwol\Factory();
$magicPacket = $f->magicPacket(); $magicPacket = $f->magicPacket();
if ($result = $magicPacket->send($macAddress, $broadcastIP)) { $result = $magicPacket->send($macAddress, $broadcastIP);
return ['success' => true, 'message' => 'Successful Wake On Lan']; if ($result) {
return ['success' => true, 'message' => 'Successful Wake On Lan for ' . $macAddress];
} else { } else {
return ['success' => false, 'message' => 'Unsuccessful WOL for IP ' . $macAddress]; return ['success' => false, 'message' => 'Unsuccessful WOL for MAC address ' . $macAddress];
} }
} }

25
ui/home.htm

@ -1,6 +1,7 @@
<div id="app"> <div id="app">
<div v-for="message in messages" :class="{'error': !message.success}" class="messages">{{message.message}}</div> <div v-for="message in messages" :class="{'error': !message.success}" class="messages">{{message.message}}</div>
<p v-show="sending" style="position:absolute;top: 10px; right: 10px;">Parancs küldése, kérem várjon.</p> <p v-show="sending" style="position:absolute;top: 10px; right: 10px;">Parancs küldése, kérem várjon.</p>
<p><?= date('Y.m.d H:i') ?></p>
<p v-if="loading">No equipments, please add one.</p> <p v-if="loading">No equipments, please add one.</p>
<div class="buttons" v-else> <div class="buttons" v-else>
<div class="button" v-for="item in items"> <div class="button" v-for="item in items">
@ -8,8 +9,8 @@
<p>{{item.name}}</p> <p>{{item.name}}</p>
</div> </div>
<div> <div>
<a v-on:click="sendsignal(item, item.oncommand)" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-play" aria-hidden="true"></i></a> <a v-on:click="sendsignal(item, item.oncommand, 'on')" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-play" aria-hidden="true"></i></a>
<a v-on:click="sendsignal(item, item.offcommand)" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-stop" aria-hidden="true"></i></a> <a v-on:click="sendsignal(item, item.offcommand, 'off')" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-stop" aria-hidden="true"></i></a>
</div> </div>
<div v-show="admin"> <div v-show="admin">
<a v-on:click="delitem(item)" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-trash" aria-hidden="true"></i></a> <a v-on:click="delitem(item)" href="javascript:void(0)" class="addbtn darker"><i class="fa fa-trash" aria-hidden="true"></i></a>
@ -30,7 +31,7 @@
Channel<br> Channel<br>
<label>UDP<br><input type="radio" name="channel" value="udp" v-model="newitem.channel"></label> <label>UDP<br><input type="radio" name="channel" value="udp" v-model="newitem.channel"></label>
<label>TELNET<br><input type="radio" name="channel" value="telnet" v-model="newitem.channel"> </label> <label>TELNET<br><input type="radio" name="channel" value="telnet" v-model="newitem.channel"> </label>
<label>WOL<br><input type="radio" name="channel" value="wol" v-model="newitem.channel"> </label> <label>ON/OFF<br><input type="radio" name="channel" value="wol" v-model="newitem.channel"> </label>
</label> </label>
</div> </div>
<label for="name" v-show="newitem.channel != ''"> <label for="name" v-show="newitem.channel != ''">
@ -41,7 +42,7 @@
What is the on command?<br> What is the on command?<br>
<input type="text" name="oncommand" v-model="newitem.oncommand"> <br> <input type="text" name="oncommand" v-model="newitem.oncommand"> <br>
</label> </label>
<label for="ontime" v-show="newitem.channel != ''"> <label for="ontime" v-show="['udp', 'telnet', 'wol'].indexOf(newitem.channel) >= 0">
When to send the on command?<br> When to send the on command?<br>
<input type="time" name="ontime" v-model="newitem.ontime"> <br> <input type="time" name="ontime" v-model="newitem.ontime"> <br>
</label> </label>
@ -49,7 +50,7 @@
What is the off command?<br> What is the off command?<br>
<input type="text" name="offcommand" v-model="newitem.offcommand"> <br> <input type="text" name="offcommand" v-model="newitem.offcommand"> <br>
</label> </label>
<label for="offtime" v-show="['udp', 'telnet'].indexOf(newitem.channel) >= 0"> <label for="offtime" v-show="['udp', 'telnet','shutdown', 'wol'].indexOf(newitem.channel) >= 0">
When to send the off command?<br> When to send the off command?<br>
<input type="time" name="offtime" v-model="newitem.offtime"> <br> <input type="time" name="offtime" v-model="newitem.offtime"> <br>
</label> </label>
@ -66,12 +67,14 @@
<label>sunday<br><input type="checkbox" v-model="newitem.days" value="Sunday"></label> <label>sunday<br><input type="checkbox" v-model="newitem.days" value="Sunday"></label>
</label> </label>
</div> </div>
<div v-show="['udp', 'telnet'].indexOf(newitem.channel) >= 0"> <div v-show="['udp', 'telnet','shutdown', 'wol'].indexOf(newitem.channel) >= 0">
<label for="ip"> <label for="ip">
What ip-s to send the signal to? (Each IP: new line!)<br> What ip-s to send the signal to? (Each IP: new line!)<br>
<small v-show="newitem.channel === 'wol'">Enter <strong>username:password@IP.AD.RESS</strong><br></small>
<textarea name="ip" v-model="newitem.ip" rows="10"> <textarea name="ip" v-model="newitem.ip" rows="10">
</textarea> </textarea>
</label> </label>
<label for="port" v-show="newitem.channel != ''"> <label for="port" v-show="newitem.channel != ''">
What is the network port?<br> What is the network port?<br>
@ -80,7 +83,7 @@
</div> </div>
<div v-show="newitem.channel === 'wol'"> <div v-show="newitem.channel === 'wol'">
<label for="macAdress"> <label for="macAdress">
What MAC Addresses to send the signal to? (Each MAC Address: new line!)<br> What MAC:Add:ress:es to send the signal to? (Each MAC Address: new line!)<br>
<textarea name="macAdress" v-model="newitem.macAddress" rows="10"> <textarea name="macAdress" v-model="newitem.macAddress" rows="10">
</textarea> </textarea>
@ -145,13 +148,13 @@ var app = new Vue({
add: function() { add: function() {
this.adding = !this.adding this.adding = !this.adding
}, },
sendsignal: function(item, action) { sendsignal: function(item, action, label) {
if (this.sending) { return alert('Please wait, the signal is sending')} if (this.sending) { return alert('Please wait, the signal is sending')}
this.sending = true this.sending = true
console.log(`sending signal ${action} to ${item.name}`) console.log(`sending signal ${action} to ${item.name}`)
axios axios
.post('sendsignal', {'item': item, 'action': action}).then(response => { .post('sendsignal', {'item': item, 'action': action, 'label': label}).then(response => {
this.messages = response.data this.messages = response.data
this.sending = false this.sending = false
}, error => { }, error => {
@ -168,7 +171,9 @@ var app = new Vue({
} }
}, },
showinfo: function(item) { showinfo: function(item) {
alert(this.dump(item,2)) this.newitem = item;
this.adding = true;
// alert(this.dump(item,2))
}, },
dump: function(arr,level) { dump: function(arr,level) {
var dumped_text = ""; var dumped_text = "";

Loading…
Cancel
Save