2023-10-03 16:56:35 +01:00
.. only :: comment
2024-06-05 09:11:37 +01:00
© Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
.. _WebBrowser:
2023-10-03 16:56:35 +01:00
2024-02-23 08:55:32 +00:00
WebBrowser
2024-02-23 16:49:01 +00:00
##########
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
The `` WebBrowser `` provides a client interface for connecting to the :ref: `WebServer` .
2023-10-03 16:56:35 +01:00
Key features
2024-02-23 16:49:01 +00:00
============
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
- Connects to the :ref: `WebServer` via the `` SoftwareManager `` .
2023-10-03 16:56:35 +01:00
- Simulates HTTP requests and HTTP packet transfer across a network
- Allows the emulation of HTTP requests between client and server:
- Automatically uses `` DNSClient `` to resolve domain names
- GET: performs an HTTP GET request from client to server
- Leverages the Service base class for install/uninstall, status tracking, etc.
Usage
2024-02-23 16:49:01 +00:00
=====
2023-10-03 16:56:35 +01:00
- Install on a Node via the `` SoftwareManager `` to start the `` WebBrowser `` .
2024-07-19 11:54:10 +01:00
- Service runs on HTTP port 80 by default.
2023-10-03 16:56:35 +01:00
- Execute sending an HTTP GET request with `` get_webpage ``
Implementation
2024-02-23 16:49:01 +00:00
==============
2023-10-03 16:56:35 +01:00
- Leverages `` SoftwareManager `` for sending payloads over the network.
- Provides easy interface for making HTTP requests between an HTTP client and server.
- Extends base Service class.
2024-02-23 16:49:01 +00:00
Examples
========
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
Python
""""""
The `` WebBrowser `` utilises :ref: `DNSClient` and :ref: `DNSServer` to resolve a URL.
The :ref: `DNSClient` must be configured to use the :ref: `DNSServer` . The :ref: `DNSServer` should be configured to have the `` WebBrowser `` `` target_url `` within its `` domain_mapping `` .
2023-10-03 16:56:35 +01:00
.. code-block :: python
2024-02-23 16:49:01 +00:00
from primaite.simulator.network.hardware.nodes.host.computer import Computer
2023-10-03 16:56:35 +01:00
from primaite.simulator.system.applications.web_browser import WebBrowser
2024-02-23 16:49:01 +00:00
# Create Computer
computer = Computer(
hostname="computer",
ip_address="192.168.1.2",
subnet_mask="255.255.255.0",
default_gateway="192.168.1.1",
start_up_duration=0,
)
computer.power_on()
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
# Install WebBrowser on computer
computer.software_manager.install(WebBrowser)
web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser")
web_browser.run()
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
# configure the WebBrowser
web_browser.target_url = "arcd.com"
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
# once DNS server is configured with the correct domain mapping
# this should work
web_browser.get_webpage()
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
Via Configuration
"""""""""""""""""
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
.. code-block :: yaml
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
simulation:
network:
nodes:
- ref: example_computer
hostname: example_computer
type: computer
...
applications:
- ref: web_browser
type: WebBrowser
options:
target_url: http://arcd.com/
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
Configuration
=============
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
`` target_url ``
""""""""""""""
The URL that the `` WebBrowser `` will request when `` get_webpage `` is called without parameters.
The URL can be in any format so long as the domain is within it e.g.
The domain `` arcd.com `` can be matched by
2023-10-03 16:56:35 +01:00
2024-02-23 16:49:01 +00:00
- http://arcd.com/
- http://arcd.com/users/
- arcd.com
2024-09-05 08:41:04 +01:00
`` Common Attributes ``
2024-09-05 11:23:52 +01:00
^^^^^^^^^^^^^^^^^^^^^
2024-09-05 08:41:04 +01:00
See :ref: `Common Configuration`