Static ip generator :)

This commit is contained in:
JonatanRek 2019-11-27 17:05:49 +01:00
parent 9e6968bf6c
commit 7337e3c7d9
5 changed files with 28 additions and 0 deletions

View File

@ -189,6 +189,7 @@ if ($values != null || $values != "") {
$jsonAnswer = [ $jsonAnswer = [
'device' => [ 'device' => [
'hostname' => $hostname, 'hostname' => $hostname,
'ipAddress' => $device['ip_address'],
], ],
'state' => 'succes', 'state' => 'succes',
]; ];
@ -223,6 +224,7 @@ if ($values != null || $values != "") {
'device' => [ 'device' => [
'hostname' => $device['name'], 'hostname' => $device['name'],
'sleepTime' => $device['sleep_time'], 'sleepTime' => $device['sleep_time'],
'ipAddress' => $device['ip_address'],
], ],
'state' => 'succes', 'state' => 'succes',
'value' => $subDeviceLastReordValue 'value' => $subDeviceLastReordValue

View File

@ -23,9 +23,11 @@ class DeviceManager{
} }
public function create ($name, $token) { public function create ($name, $token) {
$defaultRoom = RoomManager::getDefaultRoomId();
$device = array ( $device = array (
'name' => $name, 'name' => $name,
'token' => $token, 'token' => $token,
'room_id' => $defaultRoom,
); );
try { try {
Db::add ('devices', $device); Db::add ('devices', $device);

View File

@ -0,0 +1,18 @@
<?php
/**
*
*/
class NetvorkManager
{
function __construct()
{
// code...
}
function validateIp($ip = '0.0.0.0'){
if (!filter_var($ip, FILTER_VALIDATE_IP)){
return false;
}
}
}

View File

@ -2,6 +2,11 @@
class RoomManager{ class RoomManager{
public static $rooms; public static $rooms;
function getDefaultRoomId() {
$defaultRoom = Db::loadOne("SELECT id FROM rooms WHERE default = 1");
return $defaultRoom['id'];
}
function getAllRooms () { function getAllRooms () {
$allRoom = Db::loadAll ("SELECT rooms.*, COUNT(devices.device_id) as device_count FROM rooms LEFT JOIN devices ON (devices.room_id=rooms.room_id) GROUP BY rooms.room_id"); $allRoom = Db::loadAll ("SELECT rooms.*, COUNT(devices.device_id) as device_count FROM rooms LEFT JOIN devices ON (devices.room_id=rooms.room_id) GROUP BY rooms.room_id");
return $allRoom; return $allRoom;

View File

@ -157,6 +157,7 @@ class Home extends Template
'room' => $deviceData['room_id'], 'room' => $deviceData['room_id'],
'token' => $deviceData['token'], 'token' => $deviceData['token'],
'type' => $deviceData['type'], 'type' => $deviceData['type'],
'ip' => $deviceData['ip_address'],
'sleepTime' => $deviceData['sleep_time'], 'sleepTime' => $deviceData['sleep_time'],
'approved' => $deviceData['approved'], 'approved' => $deviceData['approved'],
'permission' => $permissionArray, 'permission' => $permissionArray,