-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update setup.py for Django compatibility and improve directory …
…structure
- Loading branch information
Showing
2 changed files
with
145 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,74 +3,92 @@ | |
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>GHOSTSec - {{ title }}</title> | ||
<title>GHOSTSec - {% block title %}{% endblock %}</title> | ||
<!-- Bootstrap CSS --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
<!-- Custom CSS --> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"> | ||
<link rel="stylesheet" href="{% static 'css/main.css' %}"> | ||
{% block extra_css %}{% endblock %} | ||
</head> | ||
<body> | ||
<body class="d-flex flex-column min-vh-100"> | ||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
<div class="container"> | ||
<a class="navbar-brand" href="{{ url_for('main.home') }}">GHOSTSec</a> | ||
<a class="navbar-brand" href="{% url 'home' %}">GHOSTSec</a> | ||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarNav"> | ||
<ul class="navbar-nav me-auto"> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('main.home') }}">Home</a> | ||
<a class="nav-link" href="{% url 'home' %}">Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('main.about') }}">About</a> | ||
<a class="nav-link" href="{% url 'about' %}">About</a> | ||
</li> | ||
{% if current_user.is_authenticated %} | ||
{% if user.is_authenticated %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('main.dashboard') }}">Dashboard</a> | ||
<a class="nav-link" href="{% url 'dashboard' %}">Dashboard</a> | ||
</li> | ||
<li class="nav-item dropdown"> | ||
<a class="nav-link dropdown-toggle" href="#" id="learningDropdown" role="button" data-bs-toggle="dropdown"> | ||
Learning | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li><a class="dropdown-item" href="{% url 'python_learning' %}">Python</a></li> | ||
<li><a class="dropdown-item" href="{% url 'kali_learning' %}">Kali Linux</a></li> | ||
<li><a class="dropdown-item" href="{% url 'ctf_game' %}">CTF Games</a></li> | ||
</ul> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
<ul class="navbar-nav"> | ||
{% if current_user.is_authenticated %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a> | ||
{% if user.is_authenticated %} | ||
<li class="nav-item dropdown"> | ||
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown"> | ||
{{ user.username }} | ||
</a> | ||
<ul class="dropdown-menu dropdown-menu-end"> | ||
<li><a class="dropdown-item" href="{% url 'profile' %}">Profile</a></li> | ||
<li><hr class="dropdown-divider"></li> | ||
<li><a class="dropdown-item" href="{% url 'logout' %}">Logout</a></li> | ||
</ul> | ||
</li> | ||
{% else %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a> | ||
<a class="nav-link" href="{% url 'login' %}">Login</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('auth.register') }}">Register</a> | ||
<a class="nav-link" href="{% url 'register' %}">Register</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<main class="container mt-4"> | ||
{% with messages = get_flashed_messages(with_categories=true) %} | ||
{% if messages %} | ||
{% for category, message in messages %} | ||
<div class="alert alert-{{ category }}"> | ||
{{ message }} | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
{% endwith %} | ||
<main class="container mt-4 flex-grow-1"> | ||
{% if messages %} | ||
{% for message in messages %} | ||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show"> | ||
{{ message }} | ||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button> | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% block content %}{% endblock %} | ||
</main> | ||
|
||
<footer class="footer mt-auto py-3 bg-light"> | ||
<div class="container text-center"> | ||
<span class="text-muted">© 2024 GHOSTSec. All rights reserved.</span> | ||
<span class="text-muted"> GHOSTSec. All rights reserved.</span> | ||
</div> | ||
</footer> | ||
|
||
<!-- Bootstrap JS --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
<!-- Custom JS --> | ||
<script src="{{ url_for('static', filename='js/main.js') }}"></script> | ||
<script src="{% static 'js/main.js' %}"></script> | ||
{% block extra_js %}{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,128 @@ | ||
import os | ||
import sys | ||
from pathlib import Path | ||
from cryptography.fernet import Fernet | ||
from django.core.management.utils import get_random_secret_key | ||
|
||
def setup_environment(): | ||
"""Set up GhostSec Django environment""" | ||
print("Setting up GhostSec environment...") | ||
|
||
# Get absolute paths | ||
base_dir = os.path.abspath(os.path.dirname(__file__)) | ||
instance_dir = os.path.join(base_dir, 'instance') | ||
db_path = os.path.join(instance_dir, 'ghostsec.db') | ||
|
||
# Create necessary directories with proper permissions | ||
directories = ['logs', 'uploads', 'instance'] | ||
# Create necessary directories | ||
directories = [ | ||
'logs', | ||
'media', | ||
'static', | ||
'staticfiles', | ||
os.path.join('ghostsec', 'static'), | ||
os.path.join('ghostsec', 'media'), | ||
] | ||
|
||
for directory in directories: | ||
dir_path = Path(os.path.join(base_dir, directory)) | ||
dir_path.mkdir(exist_ok=True) | ||
# Ensure directory has write permissions | ||
os.chmod(dir_path, 0o777) | ||
dir_path.mkdir(exist_ok=True, parents=True) | ||
print(f"Created directory: {directory}") | ||
|
||
# Generate encryption key | ||
encryption_key = Fernet.generate_key() | ||
|
||
# Environment variables | ||
env_vars = { | ||
'SECRET_KEY': 'dev_secret_key_12345', | ||
'DATABASE_URL': f'sqlite:///{db_path}', | ||
'FLASK_APP': 'ghostsec', | ||
'FLASK_ENV': 'development', | ||
'DEBUG': 'True', | ||
'ENCRYPTION_KEY': encryption_key.decode(), | ||
'MAIL_SERVER': 'smtp.gmail.com', | ||
'MAIL_PORT': '587', | ||
'MAIL_USE_TLS': 'True', | ||
'MAIL_USERNAME': '[email protected]', | ||
'MAIL_PASSWORD': 'your_app_password', | ||
'DJANGO_SECRET_KEY': get_random_secret_key(), | ||
'DJANGO_DEBUG': 'True', | ||
'DJANGO_ALLOWED_HOSTS': 'localhost,127.0.0.1', | ||
'DATABASE_URL': 'sqlite:///db.sqlite3', | ||
'EMAIL_HOST': 'smtp.gmail.com', | ||
'EMAIL_PORT': '587', | ||
'EMAIL_USE_TLS': 'True', | ||
'EMAIL_HOST_USER': '[email protected]', | ||
'EMAIL_HOST_PASSWORD': 'your_app_password', | ||
'ADMIN_EMAIL': '[email protected]', | ||
'MAX_CONTENT_LENGTH': str(16 * 1024 * 1024), # 16MB | ||
'UPLOAD_FOLDER': os.path.join(base_dir, 'uploads'), | ||
'RATELIMIT_STORAGE_URL': 'memory://', | ||
'RATELIMIT_DEFAULT': '200/day;50/hour', | ||
'RATELIMIT_HEADERS_ENABLED': 'True' | ||
'MEDIA_ROOT': os.path.join(base_dir, 'media'), | ||
'STATIC_ROOT': os.path.join(base_dir, 'staticfiles'), | ||
} | ||
|
||
# Write to .env file | ||
with open(os.path.join(base_dir, '.env'), 'w') as f: | ||
for key, value in env_vars.items(): | ||
f.write(f"{key}={value}\n") | ||
print("Created .env file with default configuration") | ||
env_path = os.path.join(base_dir, '.env') | ||
if not os.path.exists(env_path): | ||
with open(env_path, 'w') as f: | ||
for key, value in env_vars.items(): | ||
f.write(f"{key}={value}\n") | ||
print("Created .env file with default configuration") | ||
else: | ||
print(".env file already exists, skipping creation") | ||
|
||
# Initialize database | ||
print("Initializing database...") | ||
try: | ||
# Create the database directory if it doesn't exist | ||
db_dir = Path(instance_dir) | ||
db_dir.mkdir(exist_ok=True) | ||
os.chmod(db_dir, 0o777) | ||
|
||
# Touch the database file to ensure it exists with proper permissions | ||
with open(db_path, 'a') as f: | ||
pass | ||
os.chmod(db_path, 0o666) | ||
|
||
from init_db import init_database | ||
init_database() | ||
except Exception as e: | ||
print(f"Error initializing database: {str(e)}") | ||
return False | ||
# Create a README if it doesn't exist | ||
readme_path = os.path.join(base_dir, 'README.md') | ||
if not os.path.exists(readme_path): | ||
with open(readme_path, 'w') as f: | ||
f.write("""# GhostSec Web Platform | ||
A Django-based cybersecurity learning and collaboration platform. | ||
## Setup Instructions | ||
1. Create a virtual environment: | ||
```bash | ||
python -m venv venv | ||
source venv/bin/activate # Linux/Mac | ||
venv\\Scripts\\activate # Windows | ||
``` | ||
2. Install dependencies: | ||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
3. Run migrations: | ||
```bash | ||
python manage.py migrate | ||
``` | ||
4. Create a superuser: | ||
```bash | ||
python manage.py createsuperuser | ||
``` | ||
5. Run the development server: | ||
```bash | ||
python manage.py runserver | ||
``` | ||
## Features | ||
- User Authentication System | ||
- CTF (Capture The Flag) Module | ||
- Learning Environments | ||
- Malware Analysis Labs | ||
- Marketplace | ||
- Forum | ||
- News/Blog Section | ||
- Programming Exercises | ||
## Development | ||
- Framework: Django 4.2.7 | ||
- Database: SQLite (default) | ||
- Static Files: WhiteNoise | ||
- Forms: Crispy Forms with Bootstrap 4 | ||
## Deployment | ||
For deployment instructions, see `docs/deployment.md`. | ||
## License | ||
Copyright 2024 GhostSec. All rights reserved. | ||
""") | ||
print("Created README.md file") | ||
else: | ||
print("README.md already exists, skipping creation") | ||
|
||
print("\nSetup completed successfully!") | ||
print("\nDefault admin credentials:") | ||
print("Email: [email protected]") | ||
print("Password: Anonymous@23!") | ||
return True | ||
|
||
if __name__ == '__main__': | ||
if setup_environment(): | ||
print("\nYou can now run the application using:") | ||
print("python debug_app.py") | ||
else: | ||
print("\nSetup failed. Please check the error messages above.") | ||
print("\nSetup complete! You can now run the application using:") | ||
print("python manage.py migrate") | ||
print("python manage.py createsuperuser") | ||
print("python manage.py runserver") |