Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Jan 24, 2024
1 parent 3575fa9 commit bf27a6f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 73 deletions.
2 changes: 2 additions & 0 deletions FritzBox Discovery/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ private function getIPAdresses()
$InterfaceDescriptions = array_column($Interfaces, 'Description', 'InterfaceIndex');
$Networks = net_get_interfaces();
$Addresses = [];
$Addresses['ipv6'] = [];
$Addresses['ipv4'] = [];
foreach ($Networks as $InterfaceDescription => $Interface) {
if (!$Interface['up']) {
continue;
Expand Down
93 changes: 48 additions & 45 deletions FritzBox IO/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,55 +119,13 @@ public function RequestAction($Ident, $Value)

public function ApplyChanges()
{
$OldUrl = $this->Url;

//Never delete this line!
parent::ApplyChanges();
if (IPS_GetKernelRunlevel() != KR_READY) { // IPS läuft dann gleich Daten abholen
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}
$this->RegisterHook('/hook/FritzBoxIO' . $this->InstanceID);
$this->SetStatus(IS_INACTIVE);
if ($this->CheckHost()) {
$this->SetSummary($this->Url);
if ($this->ReadPropertyString('Password') == '') {
return;
}
if (($this->Url != $OldUrl) || ($this->ForceLoadXML)) {
if ($this->LoadXMLs()) {
$this->ForceLoadXML = false;
} else {
$this->ShowLastError(self::$http_error[418][0]);
$this->SetStatus(self::isURLnotValid);
return;
}
}
if (!$this->GetConsumerAddress()) {
$this->SetStatus(self::$http_error[501][1]);
return;
}
if ($this->ReadPropertyString('Username') == '') {
$this->Username = $this->GetLastUser();
} else {
$this->Username = $this->ReadPropertyString('Username');
}
if (!$this->getWANConnectionTyp($HttpCode)) {
$this->SetStatus(self::$http_error[$HttpCode][1]);
$this->ShowLastError(self::$http_error[$HttpCode][0]);
return;
}
if ($this->ReadAttributeBoolean('HasTel')) {
$this->getAreaCodes();
$this->checkCallMonitorPort();
}
//Todo
// Eigene Events holen?
// Prüfen ob Antwort kommt ?
$this->SetStatus(IS_ACTIVE);
} else {
$this->Url = '';
$this->SetSummary('');
}
$this->InitConnection();
}

public function ForwardData($JSONString)
Expand Down Expand Up @@ -310,6 +268,51 @@ public function Reboot()
}
return true;
}
protected function InitConnection()
{
$OldUrl = $this->Url;
$this->SetStatus(IS_INACTIVE);
if ($this->CheckHost()) {
$this->SetSummary($this->Url);
if ($this->ReadPropertyString('Password') == '') {
return;
}
if (($this->Url != $OldUrl) || ($this->ForceLoadXML)) {
if ($this->LoadXMLs()) {
$this->ForceLoadXML = false;
} else {
$this->ShowLastError(self::$http_error[418][0]);
$this->SetStatus(self::isURLnotValid);
return;
}
}
if (!$this->GetConsumerAddress()) {
$this->SetStatus(self::$http_error[501][1]);
return;
}
if ($this->ReadPropertyString('Username') == '') {
$this->Username = $this->GetLastUser();
} else {
$this->Username = $this->ReadPropertyString('Username');
}
if (!$this->getWANConnectionTyp($HttpCode)) {
$this->SetStatus(self::$http_error[$HttpCode][1]);
$this->ShowLastError(self::$http_error[$HttpCode][0]);
return;
}
if ($this->ReadAttributeBoolean('HasTel')) {
$this->getAreaCodes();
$this->checkCallMonitorPort();
}
//Todo
// Eigene Events holen?
// Prüfen ob Antwort kommt ?
$this->SetStatus(IS_ACTIVE);
} else {
$this->Url = '';
$this->SetSummary('');
}
}

protected function ProcessHookData()
{
Expand Down Expand Up @@ -589,7 +592,7 @@ private function KernelReady()
$this->UnregisterMessage(0, IPS_KERNELMESSAGE);
$this->RegisterMessage($this->InstanceID, FM_CHILDADDED);
$this->ForceLoadXML = true;
$this->ApplyChanges();
$this->InitConnection();
}

private function ShowLastError(string $ErrorMessage, string $ErrorTitle = 'Error')
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"version": "6.1"
},
"version": "0.81",
"build": 81,
"date": 1705493115
"build": 83,
"date": 1706078839
}
60 changes: 34 additions & 26 deletions libs/FritzBoxBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,41 +62,19 @@ public function Destroy()

public function ApplyChanges()
{
//Never delete this line!
if ($this->isSubscribed) {
$this->Unsubscribe();
}
$this->SetReceiveDataFilter('.*NOTHINGTORECEIVE.*');
//Never delete this line!
parent::ApplyChanges();
$this->RegisterMessage($this->InstanceID, FM_CONNECT);
$this->RegisterMessage($this->InstanceID, FM_DISCONNECT);
if (IPS_GetKernelRunlevel() != KR_READY) {
$this->RegisterMessage(0, IPS_KERNELSTARTED);
return;
}
$this->RegisterParent();
$Index = $this->ReadPropertyInteger('Index');
if (count(static::$EventSubURLArray) == 0) {
$Index = -1;
}
if ($Index > -1) {
$Filter = preg_quote(substr(json_encode(static::$EventSubURLArray[$Index]), 1, -1));
if (static::$SecondEventGUID != '') {
$Filter .= '".*|.*"DataID":"' . preg_quote(static::$SecondEventGUID);
}
$this->SetReceiveDataFilter('.*"EventSubURL":"' . $Filter . '".*');
$this->SendDebug('Filter', '.*"EventSubURL":"' . $Filter . '".*', 0);
} else {
if (static::$SecondEventGUID != '') {
$Filter = '.*"DataID":"' . preg_quote(static::$SecondEventGUID) . '".*';
$this->SetReceiveDataFilter($Filter);
$this->SendDebug('FilterSecondEventGUID', $Filter, 0);
} else {
$this->SendDebug('Filter', 'NOTHINGTORECEIVE', 0);
$this->SetReceiveDataFilter('.*NOTHINGTORECEIVE.*');
}
}
$this->Subscribe();
$this->SetEventsFilterAndSubscribe();
}

public function RequestAction($Ident, $Value)
Expand Down Expand Up @@ -137,6 +115,32 @@ public function ReceiveData($JSONString)
}
return null;
}
protected function SetEventsFilterAndSubscribe()
{
$this->RegisterParent();
$Index = $this->ReadPropertyInteger('Index');
if (count(static::$EventSubURLArray) == 0) {
$Index = -1;
}
if ($Index > -1) {
$Filter = preg_quote(substr(json_encode(static::$EventSubURLArray[$Index]), 1, -1));
if (static::$SecondEventGUID != '') {
$Filter .= '".*|.*"DataID":"' . preg_quote(static::$SecondEventGUID);
}
$this->SetReceiveDataFilter('.*"EventSubURL":"' . $Filter . '".*');
$this->SendDebug('Filter', '.*"EventSubURL":"' . $Filter . '".*', 0);
} else {
if (static::$SecondEventGUID != '') {
$Filter = '.*"DataID":"' . preg_quote(static::$SecondEventGUID) . '".*';
$this->SetReceiveDataFilter($Filter);
$this->SendDebug('FilterSecondEventGUID', $Filter, 0);
} else {
$this->SendDebug('Filter', 'NOTHINGTORECEIVE', 0);
$this->SetReceiveDataFilter('.*NOTHINGTORECEIVE.*');
}
}
$this->Subscribe();
}

protected function DecodeEvent($Event)
{
Expand All @@ -154,7 +158,7 @@ protected function DecodeEvent($Event)
protected function KernelReady()
{
$this->UnregisterMessage(0, IPS_KERNELSTARTED);
$this->ApplyChanges();
$this->SetEventsFilterAndSubscribe();
}

/**
Expand All @@ -164,7 +168,11 @@ protected function IOChangeState($State)
{
switch ($State) {
case IS_ACTIVE:
$this->ApplyChanges();
if ($this->isSubscribed) {
$this->Unsubscribe();
}
$this->SetReceiveDataFilter('.*NOTHINGTORECEIVE.*');
$this->SetEventsFilterAndSubscribe();
break;
case IS_INACTIVE:
case IS_EBASE + 1:
Expand Down

0 comments on commit bf27a6f

Please sign in to comment.