diff --git a/.env_example b/.env_example new file mode 100644 index 0000000..d9056ae --- /dev/null +++ b/.env_example @@ -0,0 +1,27 @@ +# THIS IS AN EXAMPLE +# CHANGE IT IN PRODUCTION + +# Postgres Setup +POSTGRES_DB=jupyter +POSTGRES_USER=jupyter +POSTGRES_PASSWORD=1234 + +# Jupyter Setup (Run openssl rand -hex 32) +JUPYTERHUB_CRYPT_KEY=5bb3affb5036422b0ac201e9cadde6ab783c7742861006c04e65e46d2bf3564b +JUPYTERHUB_AUTH_TOKEN=c546bb0e1dbcb73b41092b2e7e46fa69f8c031c14ea0cd94cc6696349ffacceb +LOG_LEVEL=INFO +JUPYTERHUB_BASE_URL=/jupyter/ +NATIVE_AUTH_MIN_PASSWORD_LENGTH=8 +JUPYTERHUB_ADMIN_USER=admin +ENABLE_LAB=1 +SPAWNER_DEFAULT_URL=/lab +NOTEBOOK_MEMORY_LIMIT=500M +NOTEBOOK_CPU_LIMIT=1.0 +HUB_IP=jupyterhub # Name of the Docker container + +# Docker +DOCKER_NETWORK_NAME=jupyter_network +POSTGRES_PORT=5432 +JUPYTERHUB_PORT=8000 +NGINX_HTTP_PORT=8080 +NGINX_HTTPS_PORT=8443 diff --git a/jupyter-share/compose.yml b/jupyter-share/compose.yml deleted file mode 100644 index e69de29..0000000 diff --git a/jupyterhub/jupyterhub_config.py b/jupyterhub/jupyterhub_config.py index 16b09f2..c55b332 100644 --- a/jupyterhub/jupyterhub_config.py +++ b/jupyterhub/jupyterhub_config.py @@ -3,7 +3,9 @@ import sys from dockerspawner import DockerSpawner from jupyterhub.utils import random_port from nativeauthenticator import NativeAuthenticator -#from nbgrader.auth import JupyterHubAuthPlugin +import subprocess + +# from nbgrader.auth import JupyterHubAuthPlugin from traitlets import Unicode, Bool, Int, Float import secrets @@ -11,86 +13,93 @@ import string from datetime import datetime, timedelta from typing import Optional + def generate_api_token( length: int = 32, prefix: Optional[str] = None, ) -> dict: """ Generate a secure random API token with optional prefix and expiration. - + Args: length: Length of the token (default: 32) prefix: Optional prefix for the token (e.g., 'hub_') expiration_days: Optional expiration in days from now - + Returns: - token: The generated token """ # Generate cryptographically secure random string alphabet = string.ascii_letters + string.digits - token = ''.join(secrets.choice(alphabet) for _ in range(length)) - + token = "".join(secrets.choice(alphabet) for _ in range(length)) + # Add prefix if specified if prefix: token = f"{prefix}{token}" - - return token -import subprocess + return token + def is_service_available_cmd(host, port): """Check service using system commands""" try: subprocess.run( - ['nc', '-z', host, str(port)], + ["nc", "-z", host, str(port)], check=True, timeout=3, stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL + stderr=subprocess.DEVNULL, ) return True except (subprocess.TimeoutExpired, subprocess.CalledProcessError): return False + # Configuration file for JupyterHub c = get_config() -# Base URL configuration (The new way, dont use ip/port/bind_url attributes it throws a warning and is deprecated) -port = int(os.environ.get('JUPYTERHUB_PORT', '8000')) -base_url = os.environ.get('JUPYTERHUB_BASE_URL', '/jupyter/') +# Base URL configuration +# The new way, dont use ip/port/bind_url +# attributes it throws a warning and is deprecated +port = int(os.environ.get("JUPYTERHUB_PORT", "8000")) +base_url = os.environ.get("JUPYTERHUB_BASE_URL", "/jupyter/") c.JupyterHub.bind_url = f"http://0.0.0.0:{port}{base_url}" # Database configuration c.JupyterHub.db_url = f"postgresql://{os.environ['POSTGRES_USER']}:{os.environ['POSTGRES_PASSWORD']}@stack-{os.environ['POSTGRES_HOST']}:5432/{os.environ['POSTGRES_DB']}" -#c.JupyterHub.db_url = 'sqlite:///jupyterhub.sqlite' +# c.JupyterHub.db_url = 'sqlite:///jupyterhub.sqlite' # Authenticator configuration - NativeAuthenticator c.JupyterHub.authenticator_class = NativeAuthenticator # Native Authenticator settings -#c.NativeAuthenticator.create_system_users = True -c.NativeAuthenticator.minimum_password_length = int(os.environ.get('NATIVE_AUTH_MIN_PASSWORD_LENGTH', '8')) +# c.NativeAuthenticator.create_system_users = True +c.NativeAuthenticator.minimum_password_length = int( + os.environ.get("NATIVE_AUTH_MIN_PASSWORD_LENGTH", "8") +) c.NativeAuthenticator.check_common_password = True c.NativeAuthenticator.enable_signup = True c.NativeAuthenticator.ask_email_on_signup = False c.NativeAuthenticator.allow_2fa = False # Admin configuration -admin_user = os.environ.get('JUPYTERHUB_ADMIN_USER', 'admin') -c.Authenticator.admin_users = {admin_user, 'DerGrumpf'} +admin_user = os.environ.get("JUPYTERHUB_ADMIN_USER", "admin") +c.Authenticator.admin_users = {admin_user} c.Authenticator.any_allow_config = True c.Authenticator.allow_all = True # Custom logo and templates -c.JupyterHub.logo_file = '/srv/jupyterhub/templates/logo.png' -c.JupyterHub.template_paths = ['/etc/jupyterhub/templates'] +c.JupyterHub.logo_file = "/srv/jupyterhub/templates/logo.png" +c.JupyterHub.template_paths = ["/etc/jupyterhub/templates"] # Hub environment for containers c.JupyterHub.spawner_class = DockerSpawner -c.Spawner.ip = '0.0.0.0' -c.DockerSpawner.image = os.environ.get('NOTEBOOK_IMAGE', 'jupyter/scipy-notebook:latest') +c.Spawner.ip = "0.0.0.0" +c.DockerSpawner.image = os.environ.get( + "NOTEBOOK_IMAGE", "jupyter/scipy-notebook:latest" +) '''network_name = os.environ.get('DOCKER_NETWORK_NAME', 'stack_default') c.DockerSpawner.network_name = network_name c.DockerSpawner.extra_host_config = { @@ -142,7 +151,7 @@ def pre_spawn_hook(spawner): c.DockerSpawner.pre_spawn_hook = pre_spawn_hook ''' -''' +""" # Services configuration for NBGrader c.JupyterHub.services = [ { @@ -162,15 +171,15 @@ c.JupyterHub.services = [ } } ] -''' -''' +""" +""" # NBGrader configuration c.JupyterHub.load_groups = { 'nbgrader-instructors': ['instructor'], 'nbgrader-students': [] } -''' -''' +""" +""" # NBGrader Config c.JupyterHub.services = [ { @@ -194,14 +203,14 @@ c.JupyterHub.services = [ 'user': 'root' } ] -''' +""" # Security settings -c.JupyterHub.cookie_secret_file = '/srv/jupyterhub/cookie_secret' -c.ConfigurableHTTPProxy.auth_token = os.environ.get('JUPYTERHUB_AUTH_TOKEN', '') +c.JupyterHub.cookie_secret_file = "/srv/jupyterhub/cookie_secret" +c.ConfigurableHTTPProxy.auth_token = os.environ.get("JUPYTERHUB_AUTH_TOKEN", "") # Logging -c.JupyterHub.log_level = os.environ.get('LOG_LEVEL', 'INFO') +c.JupyterHub.log_level = os.environ.get("LOG_LEVEL", "INFO") # Shutdown settings c.JupyterHub.shutdown_on_logout = False diff --git a/nginx/discord.html b/nginx/discord.html deleted file mode 100644 index ea59dd8..0000000 --- a/nginx/discord.html +++ /dev/null @@ -1,360 +0,0 @@ - - - - - - Discord Mod Simulator 2025 - - - -
-

Discord Mod Simulator 2025

-
-
- Members - 1000 -
-
- Activity - 50% -
-
- Reputation - 50% -
-
- Day - 1 -
-
- -
- Welcome to Discord Mod Simulator 2025! As a moderator, you must balance keeping the server active while maintaining order. Make your decisions carefully! -
- -
- -
- -
-
Game started. Good luck!
-
-
- - - -