refactor(dashboard): normalize paths with constants block for echo-core
This commit is contained in:
@@ -21,19 +21,24 @@ from pathlib import Path
|
|||||||
sys.path.insert(0, str(Path(__file__).parent))
|
sys.path.insert(0, str(Path(__file__).parent))
|
||||||
import habits_helpers
|
import habits_helpers
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.parent
|
BASE_DIR = Path(__file__).parent.parent # echo-core/
|
||||||
TOOLS_DIR = BASE_DIR / 'tools'
|
TOOLS_DIR = BASE_DIR / 'tools'
|
||||||
NOTES_DIR = BASE_DIR / 'kb' / 'youtube'
|
NOTES_DIR = BASE_DIR / 'memory' / 'kb' / 'youtube'
|
||||||
KANBAN_DIR = BASE_DIR / 'dashboard'
|
KANBAN_DIR = BASE_DIR / 'dashboard'
|
||||||
WORKSPACE_DIR = Path('/home/moltbot/workspace')
|
WORKSPACE_DIR = Path('/home/moltbot/workspace')
|
||||||
HABITS_FILE = KANBAN_DIR / 'habits.json'
|
HABITS_FILE = KANBAN_DIR / 'habits.json'
|
||||||
|
|
||||||
# Eco (echo-core) constants
|
# Eco (echo-core) constants
|
||||||
ECO_SERVICES = ['echo-core', 'echo-whatsapp-bridge', 'echo-taskboard']
|
ECO_SERVICES = ['echo-core', 'echo-whatsapp-bridge', 'echo-taskboard']
|
||||||
ECHO_CORE_DIR = Path('/home/moltbot/echo-core')
|
ECHO_CORE_DIR = BASE_DIR # same as BASE_DIR now
|
||||||
ECHO_LOG_FILE = ECHO_CORE_DIR / 'logs' / 'echo-core.log'
|
ECHO_LOG_FILE = ECHO_CORE_DIR / 'logs' / 'echo-core.log'
|
||||||
ECHO_SESSIONS_FILE = ECHO_CORE_DIR / 'sessions' / 'active.json'
|
ECHO_SESSIONS_FILE = ECHO_CORE_DIR / 'sessions' / 'active.json'
|
||||||
|
|
||||||
|
# Git + workspace sandbox
|
||||||
|
GIT_WORKSPACE = BASE_DIR # was '/home/moltbot/clawd'
|
||||||
|
ALLOWED_WORKSPACES = [BASE_DIR, WORKSPACE_DIR] # was [clawd, workspace] — clawd dropped
|
||||||
|
VENV_PYTHON = BASE_DIR / '.venv' / 'bin' / 'python3'
|
||||||
|
|
||||||
# Load .env file if present
|
# Load .env file if present
|
||||||
_env_file = Path(__file__).parent / '.env'
|
_env_file = Path(__file__).parent / '.env'
|
||||||
if _env_file.exists():
|
if _env_file.exists():
|
||||||
@@ -178,11 +183,8 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
path = data.get('path', '')
|
path = data.get('path', '')
|
||||||
content = data.get('content', '')
|
content = data.get('content', '')
|
||||||
|
|
||||||
# Allow access to clawd and workspace
|
# Allow access to echo-core and workspace
|
||||||
allowed_dirs = [
|
allowed_dirs = ALLOWED_WORKSPACES
|
||||||
Path('/home/moltbot/clawd'),
|
|
||||||
Path('/home/moltbot/workspace')
|
|
||||||
]
|
|
||||||
|
|
||||||
# Try to resolve against each allowed directory
|
# Try to resolve against each allowed directory
|
||||||
target = None
|
target = None
|
||||||
@@ -231,7 +233,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Call PDF generator script in venv
|
# Call PDF generator script in venv
|
||||||
venv_python = BASE_DIR / 'venv' / 'bin' / 'python3'
|
venv_python = VENV_PYTHON
|
||||||
pdf_script = TOOLS_DIR / 'generate_pdf.py'
|
pdf_script = TOOLS_DIR / 'generate_pdf.py'
|
||||||
|
|
||||||
if not venv_python.exists():
|
if not venv_python.exists():
|
||||||
@@ -326,7 +328,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
def handle_git_status(self):
|
def handle_git_status(self):
|
||||||
"""Get git status for dashboard."""
|
"""Get git status for dashboard."""
|
||||||
try:
|
try:
|
||||||
workspace = Path('/home/moltbot/clawd')
|
workspace = GIT_WORKSPACE
|
||||||
|
|
||||||
# Get current branch
|
# Get current branch
|
||||||
branch = subprocess.run(
|
branch = subprocess.run(
|
||||||
@@ -405,7 +407,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
workspace = Path('/home/moltbot/clawd')
|
workspace = GIT_WORKSPACE
|
||||||
|
|
||||||
# Security check
|
# Security check
|
||||||
target = (workspace / filepath).resolve()
|
target = (workspace / filepath).resolve()
|
||||||
@@ -586,7 +588,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
try:
|
try:
|
||||||
activities = []
|
activities = []
|
||||||
bucharest = ZoneInfo('Europe/Bucharest')
|
bucharest = ZoneInfo('Europe/Bucharest')
|
||||||
workspace = Path('/home/moltbot/clawd')
|
workspace = GIT_WORKSPACE
|
||||||
|
|
||||||
# 1. Cron jobs ran today
|
# 1. Cron jobs ran today
|
||||||
try:
|
try:
|
||||||
@@ -747,10 +749,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
|||||||
action = params.get('action', ['list'])[0]
|
action = params.get('action', ['list'])[0]
|
||||||
|
|
||||||
# Security: only allow access within allowed directories
|
# Security: only allow access within allowed directories
|
||||||
allowed_dirs = [
|
allowed_dirs = ALLOWED_WORKSPACES
|
||||||
Path('/home/moltbot/clawd'),
|
|
||||||
Path('/home/moltbot/workspace')
|
|
||||||
]
|
|
||||||
|
|
||||||
# Try to resolve against each allowed directory
|
# Try to resolve against each allowed directory
|
||||||
target = None
|
target = None
|
||||||
|
|||||||
Reference in New Issue
Block a user