Skip to main content

A full-featured web server with PHP support

Project description

Kynlos Python Web Server with PHP Support

This is a Python-based web server that supports serving static files, executing PHP scripts, file uploads, rate limiting, IP whitelisting/blacklisting, HTTPS using self-signed certificates, CORS support, custom error pages, and static file caching. The server is highly configurable via a config.json file.

Features

  • Serves static files from the htdocs directory
  • Executes PHP scripts using the php command
  • Supports file uploads via POST requests to /upload, with uploaded files saved in the htdocs/downloads directory
  • Provides a file download page at htdocs/download.html for accessing uploaded files
  • Rate limiting to prevent abuse (configurable requests per minute)
  • IP whitelisting and blacklisting for access control
  • HTTPS support using self-signed certificates
  • Cross-Origin Resource Sharing (CORS) support
  • Serves custom HTML pages for different HTTP error codes
  • Implements caching for static files to improve performance
  • Customizable entry point (default: index.html)
  • Logging of requests to a log file
  • Graceful shutdown on Ctrl-C
  • Opens the entry point in a web browser on server start

Requirements

  • Python 3.x
  • php command available in PATH (for PHP script execution)
  • OpenSSL Python library (for HTTPS support)

Configuration

The server can be configured using a config.json file in the same directory as the script. The following options are available:

  • port: The port number to run the server on (default: 80)
  • entry_point: The default file to serve when accessing the root URL (default: index.html)
  • use_https: Whether to enable HTTPS using a self-signed certificate (default: false)
  • certfile: The path to the certificate file for HTTPS (default: cert.pem)
  • keyfile: The path to the private key file for HTTPS (default: key.pem)
  • rate_limit: The maximum number of requests per minute per IP (default: 10)
  • log_file: The path to the log file for request logging (default: server.log)
  • whitelist: A list of IP addresses that are allowed to access the server (default: [])
  • blacklist: A list of IP addresses that are blocked from accessing the server (default: [])
  • htdocs_dir: The directory to serve static files from (default: htdocs)
  • downloads_dir: The directory to save uploaded files to (default: htdocs/downloads)
  • cert_config: Configuration options for generating the self-signed certificate
    • key_size: The size of the private key in bits (default: 2048)
    • subject: The subject information for the certificate
      • C: Country (default: US)
      • ST: State (default: California)
      • L: Locality (default: San Francisco)
      • O: Organization (default: My Company)
      • OU: Organizational Unit (default: My Organization)
      • CN: Common Name (default: localhost)
    • serial_number: Serial number (default: 1000)
    • valid_days: Number of days the certificate is valid for (default: 3650)
    • signing_algorithm: The signing algorithm to use (default: sha256)

Usage

  1. Clone the repository or download the main.py file.
  2. Create a config.json file in the same directory as main.py with your desired configuration options.
  3. Place your static files and PHP scripts in the htdocs directory or subdirectories.
  4. Run the server using python main.py.
  5. Access the server in a web browser at http://localhost (or the configured port).
  6. Upload files via the /upload endpoint and access them from the htdocs/download.html page.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is open-source and available under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Kynlos_Web_Server-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Kynlos_Web_Server-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file Kynlos_Web_Server-0.1.0.tar.gz.

File metadata

  • Download URL: Kynlos_Web_Server-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.3

File hashes

Hashes for Kynlos_Web_Server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 129595973157f547f824d2140f69c55e5c6c6a8964dd35598567e041a4d30701
MD5 a8c0ee4ed992f82d73a2bb4d41f34ae4
BLAKE2b-256 35d6083efb0be0d7154e0f91629b7bbf5d245e02a4ebf064422e1bc5baa38358

See more details on using hashes here.

File details

Details for the file Kynlos_Web_Server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Kynlos_Web_Server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbab388cda4f913b0b44ec090b4f9ded86461f042c9aae430097442032290f73
MD5 5bb9d0aa59a313286f8f3fda3212f518
BLAKE2b-256 b13fc2a695294e7f24f6f01abd7e4b9a6456fe36c3df8f103d36352d0b9f3858

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page