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

Restore Teleporter functionality #2738

Merged
merged 3 commits into from
Oct 26, 2023
Merged

Restore Teleporter functionality #2738

merged 3 commits into from
Oct 26, 2023

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Oct 11, 2023

What does this implement/fix?

Restore Teleporter functionality. Concerning compatibility, https://caniuse.com/url tells us it can be used in any sufficiently recent browser except IE and Opera Mini. If you have a better approach, I'd love to see it.

Related issue or feature (if applicable): N/A

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories developmental branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

…aniuse.com/url tells us it can be used iny any sufficiently recent browser except IE and Opera Mini

Signed-off-by: DL6ER <[email protected]>
@DL6ER DL6ER requested a review from a team October 11, 2023 20:38
@DL6ER DL6ER changed the title Restore Teleporter functionality. Restore Teleporter functionality Oct 11, 2023
@DL6ER DL6ER requested review from yubiuser and a team October 12, 2023 19:31
Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

Nice work. However, while my header is attachment; filename="pi-hole_nanopi_teleporter_2023-10-12_22-19-38.zip", my suggested file name is _pi-hole_nanopi_teleporter_2023-10-12_22-19-38.zip_.

See the leading and trainling _

@rdwebdesign
Copy link
Member

This is happening because the quotes are part of the string and they are replaced by _.

@rdwebdesign
Copy link
Member

rdwebdesign commented Oct 17, 2023

When the button is clicked, the API sends a payload containing the zip file. To download the file, code creates a "fake" link, triggers a Click event and removes the link after the download.

This is how the link looks like:

<a href="blob:http://192.168.0.20…-a302fce919ff" download='"pi-hole_pidev_teleporter_2023-10-16_23-54-13.zip"'>

(The value of download parameter is received with double-quotes ("pi-hole_pidev_teleporter_2023-10-16_23-54-13.zip").

Each browser deals with these quotes in slightly different ways:

  • Firefox just removes them. The file name is correctly used.
  • Chrome and Edge replace them with _. The file name starts and ends with underscores (_pi-hole_pidev_teleporter_2023-10-16_23-54-13.zip_).
  • Safari (iOS) changes the file name into "pi-hole_pidev_teleporter_2023-10-16_23-54-13.zip".zip (very strange).

I didn't test other browsers.

These are the Response Headers received:

cache-control: no-cache, no-store, must-revalidate, private, max-age=0
connection: close
content-disposition: attachment; filename="pi-hole_pidev_teleporter_2023-10-16_23-54-13.zip"
content-length: 16104
content-security-policy: default-src 'self' 'unsafe-inline';
content-type: application/zip
date: Tue, 17 Oct 2023 02:54:13 GMT
expires: 0
pragma: no-cache
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 0

Do we need to send the filename with quotes and remove them on the javascript? Or can we send it without quotes?

https://github.com/pi-hole/FTL/blob/529d7f7a3013a472b9387256232e560571d77932/src/api/teleporter.c#L38-L40

Can we use this?

        snprintf(pi_hole_extra_headers, sizeof(pi_hole_extra_headers),
                 "Content-Disposition: attachment; filename=%s",
                 filename);

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

The final messages says

 Import successful
Processed files:

/etc/pihole/pihole.toml
/etc/pihole/dhcp.leases
/etc/pihole/gravity.db

However, it's not gravity.db that have been restored by only the lists, clients, groups,.... We may need to add a hint that users should run pihole -g.

@DL6ER DL6ER merged commit cb3d3c1 into development-v6 Oct 26, 2023
7 checks passed
@DL6ER DL6ER deleted the fix/teleporter_csrf branch October 26, 2023 15:00
@DL6ER DL6ER mentioned this pull request Oct 30, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants