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

implementing input-handler option #113

Merged
merged 6 commits into from
Apr 8, 2023
Merged

implementing input-handler option #113

merged 6 commits into from
Apr 8, 2023

Conversation

MindPatch
Copy link
Contributor

This PR adds a new feature to Lotus that allows users to pass custom input data to their Lua scripts via the parse_input function. The parse_input function is expected to return a Lua table that contains the input data. If the function returns data, the input types for URLs, hosts, and paths will be ignored.

To use this feature in your script, set the SCAN_TYPE variable to 4. Lotus will then choose your script for custom input and pass the input data to your script via the INPUT_DATA global variable. The INPUT_DATA variable is a Lua table that contains the input data.

Here is an example parse_input function:

function parse_input(data)
    -- DATA is the input from stdin or text file, the data type is Table contains String
    tab = {
        {
          url = "http://google.com",
          body = "<h1>Hi</h1>"
        },

        {
          url = "http://google.com",
          body = "<h1>Hi</h1>"
        }
    }
    return tab
end

And here is an example main function that uses the input data:

SCAN_TYPE = 4

function main()
    for item, value in pairs(INPUT_DATA) do
        println(string.format("%s: %s",item, value))
    end
end

To run your script with custom input, use the --input-handler option and pass the path to your parse_input function. For example:

$ echo http://google.com| lotus scan main.lua --log log --input-handler test_input.lua

[INFO] URLS: 0
[INFO] HOSTS: 0
[INFO] PATHS: 0
[INFO] CUSTOM: 2
body: <h1>Hi</h1>
url: http://google.com
body: <h1>Hi</h1>
url: http://google.com
🌔 [00:00:00] [########################################]       0/0                                                                             

This will run your script with the custom input and print the output, which will include the custom input data.

@MindPatch MindPatch merged commit 1896837 into 0.5-beta Apr 8, 2023
@MindPatch MindPatch deleted the change_input branch April 8, 2023 08:14
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.

1 participant