Skip to content

Commit

Permalink
Refactor project structure, integrate WebServer in HiddenEye
Browse files Browse the repository at this point in the history
The refactoring includes hiddeneye_reborn/network/server.py and introducing functionalities for running a rudimentary web server. In addition, a new file, hiddeneye_reborn/public/index.html, has been created and its directory set as the web server's serving path in the main HiddenEye application file. The project version has been updated as part of these changes.
  • Loading branch information
sTiKyt committed Feb 15, 2024
1 parent 4981b27 commit a2446b3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion hiddeneye_reborn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# TODO Write DocString
__version__ = "0.1.3"
__version__ = "0.2.0"
6 changes: 6 additions & 0 deletions hiddeneye_reborn/hiddeneye.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .core.text_interface.main import args
from .network.verification import verify_connection

from .network.server import WebServer

from rich.traceback import install

LOGGING_LEVEL = logging.DEBUG
Expand Down Expand Up @@ -31,6 +33,10 @@ def run_app():
initialize_app()
configure_and_log_app()

# testing stuff:
server = WebServer(port=8080, host="localhost")
server.serve(directory="hiddeneye_reborn/public")


if __name__ == "__main__":
run_app()
35 changes: 35 additions & 0 deletions hiddeneye_reborn/network/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import http.server
import socketserver
from threading import Thread


class WebServer:
def __init__(self, port: int = 8080, host: str = "localhost"):
self.port = port
self.host = host
self.server = None
self.thread = None
self.directory = None

def start(self):
if not self.server:
os.chdir(self.directory)
handler = http.server.SimpleHTTPRequestHandler
self.server = socketserver.TCPServer((self.host, self.port), handler)
self.thread = Thread(target=self.server.serve_forever)
self.thread.start()
else:
print('Server already started')

def stop(self):
if self.server:
self.server.shutdown()
self.server = None
self.thread = None
else:
print('No server to stop')

def serve(self, directory: str):
self.directory = directory
self.start()
File renamed without changes.
15 changes: 15 additions & 0 deletions hiddeneye_reborn/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>

<html lang="">
<head>
<title>Simple Web Server</title>
</head>
<body>
<h1>Simple Web Server</h1>
<p>This is a simple web server.</p>
<!-- Adding additional content -->
<h2>Additional content: </h2>
<p>Welcome to our web page. It is designed to provide a simple and smooth experience.</p>
<p>Feel free to explore and let us know if you need any assistance.</p>
</body>
</html>
20 changes: 0 additions & 20 deletions hiddeneye_reborn/templating/template_mirrors/github.txt.example

This file was deleted.

Empty file.

0 comments on commit a2446b3

Please sign in to comment.