I need to upload response page

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

I need to upload response page

I am currently in the process of planning to upload a custom webpage to my Palo Alto device. However, I would like to automate this process through an API call. I have the HTML content for the webpage stored in a variable and I would like to upload it to the following path. Any references or suggestions in this regard would be greatly appreciated.

The manual update path is as follows:

Device -> Response Page -> URL Filtering and Category Match Block Page

There is already one predefined file in place, so if there's a way to update that without uploading a new file, that would also be acceptable for me.

I would be very grateful for any suggestions or assistance. Thank you in advance.

 

 

6 REPLIES 6

Cyber Elite
Cyber Elite

Hi @Indranil-Chowdhury ,

 

Here is an example for the application block page.  https://live.paloaltonetworks.com/t5/api-articles/modify-response-pages-from-xml-api/ta-p/62167

 

You would only need to modify the syntax to do the same for the URL block page.

 

For drive-by browsers, here is a cool doc on creating custom response pages.  https://live.paloaltonetworks.com/t5/blogs/tips-amp-tricks-how-to-customize-your-response-pages/ba-p...  That's where I found the example above.

 

Thanks,

 

Tom

Help the community: Like helpful comments and mark solutions.

Thankyou so much for your response.

I am preparing the script for uploading the HML page to box under url category.
I need help to understand where i am going wrong here. I am sharing code below.

 

$deviceUrl = "https://1.2.3.4:4443/esp/restapi.esp?key=" + $retrieve_token

 

$htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<title>Custom Response Page</title>
</head>
<body>
<h1>This is a custom response page</h1>
<p>Custom content for the response page goes here...</p>
</body>
</html>
"@

 

# Convert the HTML content to Base64
$htmlContentBase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($htmlContent))

 

# Define the XML API request body with the encoded HTML content
$xmlRequestBody = @"
<request>
<system>
<response-pages>
<entry name="Application-block-page">
<html-content>$htmlContentBase64</html-content>
</entry>
</response-pages>
</system>
</request>
"@

 

$response1 = Invoke-RestMethod -Uri $deviceUrl -Method Post -Body $xmlRequestBody -ContentType "application/xml"

Cyber Elite
Cyber Elite

What error are you getting?

Help the community: Like helpful comments and mark solutions.

Cyber Elite
Cyber Elite

Hi @Indranil-Chowdhury ,

 

If you are not able to discern the error in your code output, I can't help you.  I did provide you with the XML URL to upload a page, which you requested.

 

You could try to use curl or Postman to verify the URL works outside of your script.

 

Thanks,

 

Tom

Help the community: Like helpful comments and mark solutions.

can you please help me with curl command to upload the page. It will be helpful.

I got the error now. Sorry for the delay in response. I was busy in other assignments and jumping back here. Let me paste my function and the response here. I want to upload in URL FILTERING AND CATAGORY MATCH BLOCK PAGE

 

    def update_webpage_to_device(self, api_key, device_serial😞
        URL = f"https://{self.panorama}/api"

        # Open the file in binary mode to upload
        file_path = "webpage.txt"
        with open(file_path, 'rb') as file:
            files = {'file': (file_path, file, 'text/html')}
           
            # API parameters for importing the block page
            category=  "url-block-page"
            params = {
                "key": api_key,
                "type": "import",
                "category": "url-block-page",
                "target": device_serial
                }
               
            try:
                # Send the import request to Panorama
                response = requests.post(URL, params=params, files=files, verify=False)
                print(response.text)
                # Check if file was imported successfully
                if response.status_code == 200 and "<response status=\"success\">" in response.text:
                    print(f"{category} imported successfully.")
                else:
                    # Log the error message and attempt a re-upload
                    print(f"Failed to import {category}. Response: {response.text}")
                    print("Retrying upload...")
                       
                    # Re-attempt upload after a delay or with updated params
                    response = requests.post(URL, params=params, files=files, verify=False)
                    if response.status_code == 200 and "<response status=\"success\">" in response.text:
                        print(f"Re-upload successful for {category}.")
                    else:
                        print(f"Re-upload failed for {category}. Final response: {response.text}")
            except Exception as e:
                print(f"An error occurred while updating {category}: {e}")
 
Result
====
<response status="error"><msg><line>Filename /opt/pancfg/tmp/0000064104 does not exist</line></msg></response>
Failed to import url-block-page. Response: <response status="error"><msg><line>Filename /opt/pancfg/tmp/0000064104 does not exist</line></msg></response>
Retrying upload...
Re-upload failed for url-block-page. Final response: <response status="error"><msg><line>Filename /opt/pancfg/tmp/0000064105 does not exist</line></msg></response>
  • 1926 Views
  • 6 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!