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

Add ability to get JSON data containing URL #86

Merged
merged 9 commits into from
Oct 22, 2022

Conversation

DarkKronicle
Copy link
Contributor

@DarkKronicle DarkKronicle commented Aug 27, 2022

This adds a simple page that returns $message in the JSON format { "url": "<generated_url>" }

Resolves #85

Example of use:

curl -s -X POST -d "secret=<secret>&json=true&submit=" https://<flashpaper>/

@AndrewPaglusch
Copy link
Owner

I really like this change. I will review it entirely and test it out this week. Thank you for your contribution!

Copy link
Owner

@AndrewPaglusch AndrewPaglusch left a comment

Choose a reason for hiding this comment

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

I get a large portion of HTML/CSS back when using json=true. Perhaps you're returning the JSON a little too late in the process.

$ curl -s -X POST -d "secret=foobar&json=true&submit=" https://internal-testing-instance/
<!DOCTYPE html>
<html lang="en">
[... html/css removed ...]{"url":"http:\/\/internal-testing-instance\/?k=dMGiKCM0oAK8R1INkHbOY8QzdeYkJbJtXoQfUvzE"}

html/json_view_code.php Outdated Show resolved Hide resolved
html/json_view_code.php Outdated Show resolved Hide resolved
@DarkKronicle
Copy link
Contributor Author

I get a large portion of HTML/CSS back when using json=true. Perhaps you're returning the JSON a little too late in the process.

$ curl -s -X POST -d "secret=foobar&json=true&submit=" https://internal-testing-instance/
<!DOCTYPE html>
<html lang="en">
[... html/css removed ...]{"url":"http:\/\/internal-testing-instance\/?k=dMGiKCM0oAK8R1INkHbOY8QzdeYkJbJtXoQfUvzE"}

Oh it's probably because it still loads the header in this case

@DarkKronicle
Copy link
Contributor Author

Should be fixed now (pretty sure)

@AndrewPaglusch
Copy link
Owner

AndrewPaglusch commented Sep 3, 2022

I think we can simplify your change a bit by doing something like the following.

Towards the top of index.php, we can do a single check to see if the user is requesting a JSON retrieval code. This allows us to remove the two checks in your PR that decide whether to display the header/footer.

# [...]
require_once("includes/functions.php"); # load functions

# display secret code in json format if requested
if (isset($_POST['json']) && isset($_POST['submit']) && !empty($_POST['secret'])) {
        header("Content-Type: application/json");
        die(display_secret_code(true));
}

require_once('html/header.php'); # display header
# [...]

Below in index.php, we can change the function display_secret_code to be like the following. We rename the $json argument to be $return_only_json and default it to false. This is much easier to understand what the argument is for.

function display_secret_code($return_only_json = false)

Later in the display_secret_code function, we can add this check, which will return the JSON serialized array.

# [...]
if ($return_only_json) {
        return json_encode(array("url" => $message));
}

require_once('html/view_code.php');

This also enables us to remove the html/json_view_code.php file entirely.

@AndrewPaglusch
Copy link
Owner

@DarkKronicle It looks like there hasn't been any movement on this PR for ~3 weeks. Would you like me to finish it up for you, or are you planning on completing the changes I posted in my last message?

@AndrewPaglusch AndrewPaglusch self-assigned this Oct 22, 2022
@AndrewPaglusch AndrewPaglusch merged commit 0bea70a into AndrewPaglusch:master Oct 22, 2022
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.

Get URL without HTML
3 participants