Metadata-Version: 2.4
Name: presencelib
Version: 0.1.0
Summary: A library for handling IP-based access control in Flask applications
Author-email: TVLuke <tvluke@chaotikum.org>
Project-URL: Homepage, https://git.chaotikum.org/tvluke/presencelib
Project-URL: Bug Tracker, https://git.chaotikum.org/tvluke/presencelib/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: Flask
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: flask>=2.0.0

# PresenceLib

A library for handling IP-based access control in Flask applications specifically for Chaotikum e.V. space IPs.

## Installation

```bash
# Install locally for development
pip install -e .

# Or add to your requirements.txt
-e ../presencelib  # For local development
# presencelib @ git+https://git.chaotikum.org/chaotikum/presencelib.git  # For production
```

## Usage

The library comes pre-configured with the Chaotikum e.V. space IPs:

```python
from flask import Flask, render_template
from presencelib.decorators import restrict_to_space_ips, is_space_ip

app = Flask(__name__)

# Use the decorator to restrict access to a route
@app.route('/presence')
@restrict_to_space_ips(fallback_function=lambda: render_template("location.html"))
def presence():
    # This function will only be executed if the request is from a space IP
    return "You are in the space!"

# Or use the is_space_ip() function directly
@app.route('/check')
def check_ip():
    if is_space_ip():
        return "You are in the space!"
    else:
        return "You are not in the space."

if __name__ == '__main__':
    app.run()
```

## Features

- Pre-configured with Chaotikum e.V. space IPs
- Restrict access to specific routes using a decorator
- Support for IPv6 ranges
- Test mode for local development (disabled by default)
- Customizable fallback function for unauthorized access

## Advanced Configuration

If you need to modify the default configuration (not typically needed):

```python
from presencelib.decorators import configure_space_ips

# Override the default configuration if needed
configure_space_ips(
    test_mode=True,  # Enable test mode
    accept_localhost=True  # Accept localhost in test mode
)
```
