- changelog added
- added documentation + example of using web server + web browser
- extended web server so that it also accepts ip addresses
- web server can differentiate between a normal page request and one that propagates into a DB request
- rename WebServerService -> WebServer
This commit is contained in:
Czar.Echavez
2023-10-03 16:56:35 +01:00
parent 4b5a73bd32
commit 82da21b073
9 changed files with 180 additions and 16 deletions

View File

@@ -72,6 +72,11 @@ class DNSClient(Service):
:param: session_id: The Session ID the payload is to originate from. Optional.
:param: is_reattempt: Checks if the request has been reattempted. Default is False.
"""
# check if DNS server is configured
if self.dns_server is None:
self.sys_log.error(f"{self.name}: DNS Server is not configured")
return False
# check if the target domain is in the client's DNS cache
payload = DNSPacket(dns_request=DNSRequest(domain_name_request=target_domain))

View File

@@ -1,5 +1,6 @@
from ipaddress import IPv4Address
from typing import Any, Optional
from urllib.parse import urlparse
from primaite.simulator.network.protocols.http import (
HTTPRequestMethod,
@@ -13,7 +14,7 @@ from primaite.simulator.system.applications.database_client import DatabaseClien
from primaite.simulator.system.services.service import Service
class WebServerService(Service):
class WebServer(Service):
"""Class used to represent a Web Server Service in simulation."""
def __init__(self, **kwargs):
@@ -76,13 +77,20 @@ class WebServerService(Service):
"""
response = HTTPResponsePacket(status_code=HTTPStatusCode.BAD_REQUEST, payload=payload)
try:
# get data from DatabaseServer
db_client: DatabaseClient = self.software_manager.software["DatabaseClient"]
# get all users
if db_client.query("SELECT * FROM user;"):
parsed_url = urlparse(payload.request_url)
if parsed_url.path is None or len(parsed_url.path) < 1:
# query succeeded
response.status_code = HTTPStatusCode.OK
if parsed_url.path.startswith("/users"):
# get data from DatabaseServer
db_client: DatabaseClient = self.software_manager.software["DatabaseClient"]
# get all users
if db_client.query("SELECT * FROM user;"):
# query succeeded
response.status_code = HTTPStatusCode.OK
return response
except Exception:
# something went wrong on the server