Update README.md

Changed compiling method with make
Updated and checked status of development
Added Prerequisites
Better understanding
This commit is contained in:
2025-02-12 19:51:14 +01:00
committed by GitHub
parent 921663a19c
commit 77e1cbbd07

247
README.md
View File

@@ -1,191 +1,150 @@
# Carbon HTTP Server # Carbon HTTP Server
This is a simple HTTP server for linux operating system written in C. It supports basic HTTP requests, logging, etc. A high-performance HTTP/HTTPS server written in C for Linux systems, featuring advanced security, caching, and async I/O.
NOTE: This program is being used as a fun projects to see limits of C. I'll be not responsible for any vulnerabilities.
If you find vulnerabilities please report them.
## Features ## Core Features
* Handles GET requests for static files. - ✅ Multi-threaded HTTP/HTTPS server with epoll-based async I/O
* Supports a control menu for managing server status, logging, and configuration (currently basic). - ✅ SSL/TLS support with automatic HTTP to HTTPS redirection
* Uses pthreads for concurrent client handling. - ✅ Advanced rate limiting and DDoS protection
* Includes basic logging functionality with timestamps. - ✅ File caching system for improved performance
* Configuration is loaded from a JSON file (`server.json`). - ✅ Thread pooling for efficient connection handling
- ✅ Comprehensive security headers and MIME type detection
- ✅ JSON-based configuration
- ✅ Detailed logging system with rotation
## Future development ## Security Features
This section outlines potential features and improvements planned for future releases of the server. - ✅ Buffer overflow prevention
- ✅ Path traversal protection
- ✅ Input sanitization
- ✅ SSL/TLS with modern cipher suites
- ✅ Security headers (CSP, HSTS, X-Frame-Options, etc.)
- ✅ Rate limiting per IP
- ✅ Automatic HTTPS redirection
### Prioraty features ## Performance Features
| Enhancement | Description | Priority | Completion | - ✅ Epoll-based asynchronous I/O
|-----------------------------|--------------------------------------------------|-----------|----------------------| - ✅ Thread pool for connection handling
| **Basic HTTP and HTTPS server Functionality** | Switching from HTTP to HTTPS | Medium | ✅ | - ✅ File caching system
| **Logging Mechanism** | Add logging mechanism for better error handleling | Low | ✅ | - ✅ SendFile() optimization for file transfers
| **SSL/TLS Support** | Implement SSL/TLS Support for HTTP/s | High | ✅ | - ✅ Keep-alive connection support
- ✅ TCP optimization (NODELAY, buffer sizes)
### Planned Features
| Enhancement | Description | Priority | Completion |
|-----------------------------|--------------------------------------------------|-----------|----------------------|
| **WebSocket Support** | Implement WebSocket protocol for real-time communication. | Medium | ❌ |
| **Rate Limiting** | Add rate limiting to prevent abuse and DDoS attacks. | High | ❌ |
| **User Authentication** | Implement user authentication for secure access to certain endpoints. | High | ❌|
| **API Documentation** | Create comprehensive API documentation using Swagger or similar tools. | Medium | ❌ |
| **Load Balancing** | Support for load balancing across multiple server instances. | Low | ❌ |
### Performance Improvements
| Enhancement | Description | Priority | Completion |
|-----------------------------|--------------------------------------------------|-----------|----------------------|
| **Connecting Pooling** | Implement connection pooling to improve performance under load. | High | ❌ |
| **Asynchronous I/O** | Use asynchronous I/O to handle more connections efficiently. | Medium | ❌|
| **Caching Mechanism** | Introduce caching for static resources to reduce server load. | Medium | ❌ |
### Security Enhancements
| Enhancement | Description | Priority | Completion |
|-----------------------------|--------------------------------------------------|-----------|----------------------|
| **Buffer Overflow Prevention** | Implement comprehensive input validation to prevent injection attacks. | High | ❌ |
| **HTTPS Redirect** | Automatically redirect HTTP traffic to HTTPS. | High | ✅|
| **Security Audits** | Conduct regular security audits and vulnerability assessments. | Medium | ❌ |
### Community Contributions
| Contribution Area | Description | Priority | Notes |
|-----------------------------|--------------------------------------------------|-----------|----------------------|
| **Documentation** | Improve and expand documentation for developers and users. | Medium | Open for contributions |
| **Testing** | Create unit tests and integration tests for better coverage. | High | Contributions welcome |
| **Feature Requests** | Encourage users to submit feature requests and suggestions. | Low | Use GitHub Issues |
## Build Instructions ## Build Instructions
1. **Prerequisites:** ### Prerequisites
* GCC compiler
* Make (recommended)
* OpenSSL libraries (`libssl`, `libcrypto`)
* pthreads library
* cJSON library
2. **Clone the repository (optional):**
```bash ```bash
git clone https://github.com/Azreyo/Carbon # Install required dependencies
cd Carbon/ sudo apt-get update
sudo apt-get install -y \
build-essential \
libssl-dev \
libcjson-dev \
libmagic-dev \
pkg-config
``` ```
3. **Compile:** ### Compilation
```bash ```bash
gcc server.c config_parser.c server_config.c -o server -lssl -lcrypto -lpthread -pthread -lcjson -lcjson -I/usr/include/cjson # Using Make (recommended)
``` make # Normal build
Compile it in gcc make debug # Debug build
make release # Optimized release build
# Manual compilation
gcc server.c config_parser.c server_config.c -o server \
-D_GNU_SOURCE \
-Wall -Wextra -O2 \
-lssl -lcrypto -lpthread -lmagic -lcjson
```
### SSL Certificate Setup
```bash ```bash
make # Create certificates directory
mkdir -p certs
# Generate self-signed certificate
openssl req -x509 -newkey rsa:2048 \
-keyout certs/key.pem \
-out certs/cert.pem \
-days 365 -nodes
``` ```
This command will use the provided `Makefile` to compile the source files, link the necessary libraries, and create the executable in the `bin` directory. ### Configuration
```bash Create `server.json`:
make clean
```
Cleanup of the unnecessary files after compiling.
4. **Create `www` directory:**
```bash
mkdir www
```
Place your HTML files (e.g., `index.html`) inside the `www` directory.
5. **Create `server.json`:**
Create a `server.json` file in the same directory as the executable with the following structure:
```json ```json
{ {
"port": 8080, "port": 8080,
"use_https": false, "use_https": true,
"log_file": "server.log", "log_file": "/var/log/carbon-server/server.log",
"max_threads": 4, "verbose": true,
"running": true "max_threads": 32,
"cache_size": 100,
"rate_limit": {
"window": 60,
"max_requests": 100
}
} }
``` ```
Adjust the values as needed. `use_https` is not yet implemented. ### Directory Structure
5. **Create systemd automatic startup**
```bash ```bash
#!/bin/bash mkdir -p www/{css,js,images}
server_path=$(jq -r '.server_path' server.json)
config_path=$(jq -r 'config_path' server.json)
if [ ! -x "$server_path" ]; then
echo "Error: Server executable not found or not executable: $server_path"
exit 1
fi
if [ ! -f "$config_path" ]; then
echo "Error: Config file not found $config_path"
exit 1
fi
nohup "$server_path" --config "$config_path" &> server.log &
echo "Server started in the background. Check server.log for output"
exit 0
``` ```
Code for automatic startup.
## Running the Server
```bash ```bash
chmod +x start_server.sh # Allow ports
./start_server.sh sudo ufw allow 8080/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
# Run the server
./server
``` ```
Permissions `+x`. ## Planned Features
| Feature | Priority | Status |
|---------|----------|--------|
| WebSocket Support | Medium | ❌ |
| User Authentication | High | ❌ |
| API Documentation | Medium | ❌ |
| Load Balancing | Low | ❌ |
| Security Audits | Medium | ❌ |
## Run Instructions ## Contributing
1. **Get IP address of your device that the program will run on:** 1. Fork the repository
```bash 2. Create your feature branch
ip address 3. Commit your changes
``` 4. Push to the branch
5. Create a Pull Request
2. **Enable port 8080 for ufw** ## License
```bash This project is licensed under the MIT License - see the LICENSE file for details.
sudo ufw allow 8080 # 8080 is the default port
```
3. **Run it and enjoy** ## Security
```bash While this server implements various security measures, it's recommended to:
./bin/server # Run the executable from the bin directory - Use a reverse proxy (like Nginx) in production
``` - Obtain proper SSL certificates (Let's Encrypt)
- Regularly update dependencies
- Monitor server logs
- Conduct security audits
## Acknowledgments
## For using HTTP/s - OpenSSL for SSL/TLS support
- cJSON for configuration parsing
```bash - libmagic for MIME type detection
mkdir certs # Create certs folder
cd certs
```
Create certs folder to create certificates to it.
```bash
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
```
Generating pairs of keys `key.pem and` and `cert.pem` for 365 days.
Note: its only self-signed browser may get Potential Security Risk.
For further use on domains is recommended Let's encrypt.