Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard socket and FTL response #2164

Merged
merged 5 commits into from
Apr 8, 2022
Merged

Guard socket and FTL response #2164

merged 5 commits into from
Apr 8, 2022

Conversation

yubiuser
Copy link
Member

@yubiuser yubiuser commented Apr 5, 2022

  • I have read and understood the contributors guide, as well as this entire template.
  • I have made only one major change in my proposed changes.
  • I have commented my proposed changes within the code.
  • I have tested my proposed changes.
  • I am willing to help maintain this change if there are issues with it later.
  • I give this submission freely and claim no ownership.
  • It is compatible with the EUPL 1.2 license
  • I have squashed any insignificant commits. (git rebase)
  • I have Signed Off all commits. (git commit --signoff)

What does this PR aim to accomplish?:
When the FTL socket dies unexpectedly (i.e. by Pi-hole restart) and the web interface is still open, $data = array("FTLnotrunning" => true); is send to the calling functions. However, there was no guarding so far for this response, which leads to errors within the calling functions. This PR adds a check for the $data = array("FTLnotrunning" => true); response and only proceeds the calling function if this data is not present.
Additionally, it guards the fclose($socket); by checking for is_resource($socket))

@yubiuser yubiuser requested a review from a team April 5, 2022 13:09
Copy link
Member

@rdwebdesign rdwebdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the reason for this change, but I have 2 questions:

What is returned to javascript, if PHP founds "FTLnotrunning"? Nothing?
How does javascript handle this kind of error?

@yubiuser
Copy link
Member Author

yubiuser commented Apr 5, 2022

Good question. So far I just return nothing. But I looked and most calls in js are guarded with

    if ("FTLnotrunning" in data) {
      return;
    }

So I think a nice solution is to return an array with FTLnotrunning => true and make sure we have such a guard as above.

@rdwebdesign
Copy link
Member

I agree.
JS is already expecting a "complete return value" or FTLnotrunning => true.

@yubiuser
Copy link
Member Author

yubiuser commented Apr 7, 2022

Added the remaining js guard for php returning FTLnotrunning to queries.js. It will notify the user and send an empty array data to datatables resulting in an empty query log.

Bildschirmfoto zu 2022-04-07 19-33-53

@yubiuser yubiuser requested review from rdwebdesign and a team April 7, 2022 17:40
@yubiuser
Copy link
Member Author

yubiuser commented Apr 7, 2022

The tests will pass after #2166 has been merged and the branch has been rebased.

Signed-off-by: Christian König <ckoenig@posteo.de>
Signed-off-by: Christian König <ckoenig@posteo.de>
Signed-off-by: Christian König <ckoenig@posteo.de>
Signed-off-by: Christian König <ckoenig@posteo.de>
Signed-off-by: Christian König <ckoenig@posteo.de>
@yubiuser yubiuser merged commit 6c756c0 into devel Apr 8, 2022
@yubiuser yubiuser deleted the socket branch April 8, 2022 22:11
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-ftl-v5-15-web-v5-12-and-core-v5-10-released/54987/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants