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

View File

@ -23,9 +23,11 @@ class DeviceManager{
}
public function create ($name, $token) {
$defaultRoom = RoomManager::getDefaultRoomId();
$device = array (
'name' => $name,
'token' => $token,
'room_id' => $defaultRoom,
);
try {
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{
public static $rooms;
function getDefaultRoomId() {
$defaultRoom = Db::loadOne("SELECT id FROM rooms WHERE default = 1");
return $defaultRoom['id'];
}
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");
return $allRoom;

View File

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