Commit a69d3bf37feb3df7de38d9871135f2a8bc115430
Commits[COMMIT BEGIN]commit a69d3bf37feb3df7de38d9871135f2a8bc115430 Author: 0x4248 <[email protected]> Date: Wed Jan 7 12:38:04 2026 +0000 LWPS: init Signed-off-by: 0x4248 <[email protected]> diff --git a/usr/toolkits/LWPS/Makefile b/usr/toolkits/LWPS/Makefile new file mode 100644 index 0000000..7b700ed --- /dev/null +++ b/usr/toolkits/LWPS/Makefile @@ -0,0 +1,9 @@ + +# Yeah I know im running all -> build -> run but it prevents other build systems +# from freaking out when they see a Makefile with no 'all' target. +all: build + +build: run + +run: + @python3 src/main.py \ No newline at end of file diff --git a/usr/toolkits/LWPS/README b/usr/toolkits/LWPS/README new file mode 100644 index 0000000..f883bc2 --- /dev/null +++ b/usr/toolkits/LWPS/README @@ -0,0 +1,9 @@ +Lightweight PHP Server (LWPS) +=============================== + +A really lightweight PHP development server for quick testing and prototyping. + +This should be pain free, so you can finally regrow your hair after pulling it out trying to set up a dev environment. + + +© 2026 0x4248 and contributors \ No newline at end of file diff --git a/usr/toolkits/LWPS/server/index.php b/usr/toolkits/LWPS/server/index.php new file mode 100644 index 0000000..a3e3cb0 --- /dev/null +++ b/usr/toolkits/LWPS/server/index.php @@ -0,0 +1,43 @@ +<!-- make a var with Hello world and make a H1 Using var --> +<php? $greeting = "Hello, World!"; ?> +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0 +"> + <title>LWPS Server Index</title> + <style> + body { + font-family: monospace, monospace; + margin: 40px; + background-color: #1e1e1e; + color: #d4d4d4 + } + h1{ color: #6fff7dff; } + p { + font-size: 18px; + } + </style> +</head> +<body> + <h1>Congratulations!</h1> + <p><?php echo "If you see this text then it means PHP is working correctly"; ?></p> + <ul> + <li>PHP Version:<code> <?php echo phpversion(); ?></code></li> + <li>Server Software:<code> <?php echo $_SERVER['SERVER_SOFTWARE']; ?></code></li> + </ul> + <h2>README File</h2> + <pre> +<?php + $readme_path = __DIR__ . '/../README'; + if (file_exists($readme_path)) { + echo htmlspecialchars(file_get_contents($readme_path)); + } else { + echo "README file not found."; + } +?> + </pre> +</body> +</html> diff --git a/usr/toolkits/LWPS/src/main.py b/usr/toolkits/LWPS/src/main.py new file mode 100644 index 0000000..2e6bc1b --- /dev/null +++ b/usr/toolkits/LWPS/src/main.py @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: GPL-3.0 +# LWPS - Lightweight PHP Server +# +# Main indexer and server. +# main.py +# +# COPYRIGHT NOTICE +# Copyright (C) 2026 0x4248 and contributors +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the license is not changed. +# +# This software is free and open source. Licensed under the GNU general +# public license version 3.0 as published by the Free Software Foundation. + +import os +import fastapi +import uvicorn +from fastapi.responses import FileResponse +import subprocess + + +BASE_DIR = os.path.join(os.path.dirname(__file__), '..', 'server') +app = fastapi.FastAPI() + +env = os.environ.copy() +env['SERVER_SOFTWARE'] = 'LWPS' +env['DOCUMENT_ROOT'] = BASE_DIR + + +def convert_php(file_path: str) -> str: + """Convert a PHP file to HTML using the PHP CLI.""" + try: + result = subprocess.run( + ['php', file_path], + capture_output=True, + text=True, + check=True, + env=env + ) + return result.stdout + except subprocess.CalledProcessError as e: + error_page_path = os.path.join(os.path.dirname(__file__), 'static', '500.html') + with open(error_page_path, 'r') as f: + error_page = f.read() + return error_page.replace('{{error}}', str(e.stderr)) + except FileNotFoundError: + error_page_path = os.path.join(os.path.dirname(__file__), 'static', '500.html') + with open(error_page_path, 'r') as f: + error_page = f.read() + return error_page.replace('{{error}}', 'PHP CLI not found. Please install PHP.') + [email protected]("/{full_path:path}") +async def serve_file(full_path: str): + file_path = os.path.join(BASE_DIR, full_path) + + if os.path.isdir(file_path): + index_php = os.path.join(file_path, 'index.php') + index_html = os.path.join(file_path, 'index.html') + if os.path.isfile(index_php): + file_path = index_php + elif os.path.isfile(index_html): + file_path = index_html + else: + not_found_page_path = os.path.join(os.path.dirname(__file__), 'static', '404.html') + return FileResponse(not_found_page_path, status_code=404) + + if file_path.endswith('.php') and os.path.isfile(file_path): + html_content = convert_php(file_path) + return fastapi.responses.HTMLResponse(content=html_content) + + if os.path.isfile(file_path): + return FileResponse(file_path) + + not_found_page_path = os.path.join(os.path.dirname(__file__), 'static', '404.html') + return FileResponse(not_found_page_path, status_code=404) + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/usr/toolkits/LWPS/src/static/404.html b/usr/toolkits/LWPS/src/static/404.html new file mode 100644 index 0000000..1fa227c --- /dev/null +++ b/usr/toolkits/LWPS/src/static/404.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>500 Internal Server Error</title> + <style> + *{ + font-family: monospace; + background-color: #1e1e1e; + color: #d4d4d4; + } + + h1{ color: #f44747; } + + .footer{ + text-align: center; + font-size: small; + margin-top: 2em; + position: absolute; + bottom: 0; + width: 100%; + margin-bottom: 1em; + } + + .footer i, .footer hr{ + color: #828282; + } + </style> + </head> + <body> + <h1>File not found (404)</h1> + <i>LWPS encountered an error, showing STDERR:</i> + <hr> + <code>{{error}}</code> + + <div class="footer"> + <hr> + <i>Powered by Lightweight PHP Server (LWPS)</i> + <br> + <i>© 2026 0x4248 and contributors</i> + </div> + </body> +</html> \ No newline at end of file diff --git a/usr/toolkits/LWPS/src/static/500.html b/usr/toolkits/LWPS/src/static/500.html new file mode 100644 index 0000000..4a223ad --- /dev/null +++ b/usr/toolkits/LWPS/src/static/500.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>500 Internal Server Error</title> + <style> + *{ + font-family: monospace; + background-color: #1e1e1e; + color: #d4d4d4; + } + + h1{ color: #f44747; } + + .footer{ + text-align: center; + font-size: small; + margin-top: 2em; + position: absolute; + bottom: 0; + width: 100%; + margin-bottom: 1em; + } + + .footer i, .footer hr{ + color: #828282; + } + </style> + </head> + <body> + <h1>500 Internal Server Error</h1> + <i>LWPS encountered an error, showing STDERR:</i> + <hr> + <code>{{error}}</code> + + <div class="footer"> + <hr> + <i>Powered by Lightweight PHP Server (LWPS)</i> + <br> + <i>© 2026 0x4248 and contributors</i> + </div> + </body> +</html> \ No newline at end of file[COMMIT END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.