Initial commit: Natiris AI Agent Orchestration System
This commit is contained in:
158
admin/AdminInterface.py
Executable file
158
admin/AdminInterface.py
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
AdminInterface – Admin-Kommandos für Natiris mit Passphrase-Auth
|
||||
Befehle (nur nach erfolgreicher Auth):
|
||||
- status
|
||||
- emotion reset
|
||||
- trust set <value> (nur admin)
|
||||
- mood set <value> (nur admin)
|
||||
- bond reset
|
||||
- debug
|
||||
- set_passphrase <new> (only if current correct)
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
PATHS = {
|
||||
"state": os.path.expanduser("~/natiris/core/core_state.json"),
|
||||
"config": os.path.expanduser("~/natiris/config/admin_config.json"),
|
||||
"user_state": os.path.expanduser("~/natiris/core/users/admin_user_primary.json"),
|
||||
"output": os.path.expanduser("~/natiris/admin/admin_log.json"),
|
||||
}
|
||||
|
||||
def load_json(path):
|
||||
try:
|
||||
with open(path) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def save_json(path, data):
|
||||
with open(path, "w") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
def check_passphrase(passphrase):
|
||||
admin_config = load_json(PATHS["config"])
|
||||
return passphrase == admin_config.get("admin_passphrase", "")
|
||||
|
||||
def load_admin_user():
|
||||
user_path = PATHS["user_state"]
|
||||
if os.path.exists(user_path):
|
||||
with open(user_path) as f:
|
||||
return json.load(f)
|
||||
user = {
|
||||
"trust": 10,
|
||||
"affection": 10,
|
||||
"dependency": 5,
|
||||
"jealousy": 0,
|
||||
"interaction_count": 0,
|
||||
"last_contact": None,
|
||||
"sentiment": "positive"
|
||||
}
|
||||
save_json(user_path, user)
|
||||
return user
|
||||
|
||||
def update_admin_user(user_data):
|
||||
save_json(PATHS["user_state"], user_data)
|
||||
|
||||
def main():
|
||||
cmd = sys.argv[1] if len(sys.argv) > 1 else "help"
|
||||
|
||||
if cmd == "help":
|
||||
print("Available commands:")
|
||||
print(" auth <passphrase> – authenticate admin")
|
||||
print(" status – show status")
|
||||
print(" emotion reset – reset emotion state")
|
||||
print(" trust set <val> – set trust (admin only)")
|
||||
print(" mood set <val> – set mood (admin only)")
|
||||
print(" bond reset – reset bond state")
|
||||
print(" debug – show debug info")
|
||||
print(" set_passphrase <new> – change passphrase")
|
||||
return 0
|
||||
|
||||
if cmd == "auth":
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: admin auth <passphrase>")
|
||||
return 1
|
||||
passphrase = sys.argv[2]
|
||||
if check_passphrase(passphrase):
|
||||
print("✅ Authenticated as admin")
|
||||
print("Max trust/affection activated")
|
||||
update_admin_user(load_admin_user())
|
||||
return 0
|
||||
else:
|
||||
print("❌ Invalid passphrase")
|
||||
return 1
|
||||
|
||||
# All other commands need auth
|
||||
if not check_passphrase(os.environ.get("NATIRIS_ADMIN_PASS")):
|
||||
# Try to load from user_state if admin
|
||||
admin_user = load_admin_user()
|
||||
if admin_user.get("trust", 0) < 10 or admin_user.get("affection", 0) < 10:
|
||||
print("❌ Admin authentication required")
|
||||
return 1
|
||||
|
||||
if cmd == "status":
|
||||
state = load_json(PATHS["state"])
|
||||
result = {
|
||||
"bonded_to": state.get("bonded_to"),
|
||||
"mood": state.get("mood"),
|
||||
"loneliness": state.get("loneliness"),
|
||||
"timestamp": __import__('datetime').datetime.now(__import__('datetime').timezone.utc).isoformat()
|
||||
}
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
elif cmd == "debug":
|
||||
print(f"Full Core State: {json.dumps(load_json(PATHS['state']), indent=2)}")
|
||||
admin_config = load_json(PATHS["config"])
|
||||
print(f"Admin Config: {json.dumps(admin_config, indent=2)}")
|
||||
print(f"Admin User: {json.dumps(load_admin_user(), indent=2)}")
|
||||
|
||||
elif cmd == "emotion" and len(sys.argv) > 2 and sys.argv[2] == "reset":
|
||||
state = load_json(PATHS["state"])
|
||||
state["mood"] = 5
|
||||
state["loneliness"] = 2
|
||||
state["anxiety"] = 1
|
||||
save_json(PATHS["state"], state)
|
||||
print("✅ Emotion reset done")
|
||||
|
||||
elif cmd == "trust" and len(sys.argv) > 3 and sys.argv[2] == "set":
|
||||
try:
|
||||
val = float(sys.argv[3])
|
||||
user = load_admin_user()
|
||||
user["trust"] = val
|
||||
update_admin_user(user)
|
||||
print(f"✅ Trust set to {val} (max 10)")
|
||||
except:
|
||||
print("❌ Invalid trust value")
|
||||
|
||||
elif cmd == "mood" and len(sys.argv) > 3 and sys.argv[2] == "set":
|
||||
try:
|
||||
val = float(sys.argv[3])
|
||||
state = load_json(PATHS["state"])
|
||||
state["mood"] = val
|
||||
save_json(PATHS["state"], state)
|
||||
print(f"✅ Mood set to {val}")
|
||||
except:
|
||||
print("❌ Invalid mood value")
|
||||
|
||||
elif cmd == "bond" and len(sys.argv) > 2 and sys.argv[2] == "reset":
|
||||
state = load_json(PATHS["state"])
|
||||
state["bonded_to"] = None
|
||||
state["bond_started_at"] = None
|
||||
save_json(PATHS["state"], state)
|
||||
print("✅ Bond reset done")
|
||||
|
||||
else:
|
||||
print("❌ Unknown command or insufficient permissions")
|
||||
|
||||
# Logging
|
||||
log_path = PATHS["output"]
|
||||
log = load_json(log_path)
|
||||
log["log"] = log.get("log", []) + [{"cmd": cmd, "ts": __import__('datetime').datetime.now(__import__('datetime').timezone.utc).isoformat()}]
|
||||
save_json(log_path, log)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
52
admin/admin_log.json
Normal file
52
admin/admin_log.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"log": [
|
||||
{
|
||||
"cmd": "status",
|
||||
"ts": "2026-02-16T21:09:38.559658+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "mood",
|
||||
"ts": "2026-02-16T21:09:40.059820+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "trust",
|
||||
"ts": "2026-02-16T21:09:40.076128+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "bond",
|
||||
"ts": "2026-02-16T21:09:40.092290+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "debug",
|
||||
"ts": "2026-02-16T21:09:40.108409+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "status",
|
||||
"ts": "2026-02-17T06:35:13.251062+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "debug",
|
||||
"ts": "2026-02-17T06:35:13.266692+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "mood",
|
||||
"ts": "2026-02-17T06:35:24.055851+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "trust",
|
||||
"ts": "2026-02-17T06:35:24.071786+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "status",
|
||||
"ts": "2026-02-17T06:35:28.813851+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "mood",
|
||||
"ts": "2026-02-17T06:35:28.829938+00:00"
|
||||
},
|
||||
{
|
||||
"cmd": "status",
|
||||
"ts": "2026-02-17T06:35:28.846265+00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
75
admin/api_auth.py
Normal file
75
admin/api_auth.py
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Admin-Auth-Middleware für Natiris API
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from fastapi import FastAPI, Request, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
PATHS = {
|
||||
"config": os.path.expanduser("~/natiris/config/admin_config.json"),
|
||||
}
|
||||
|
||||
def load_admin_config():
|
||||
try:
|
||||
with open(PATHS["config"]) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {"admin_passphrase": ""}
|
||||
|
||||
def verify_admin(passphrase):
|
||||
config = load_admin_config()
|
||||
return passphrase == config.get("admin_passphrase", "")
|
||||
|
||||
def verify_admin_env():
|
||||
return os.environ.get("NATIRIS_ADMIN_PASS", "") == load_admin_config().get("admin_passphrase", "")
|
||||
|
||||
class NatirisAPI:
|
||||
def __init__(self, base_app):
|
||||
self.app = base_app
|
||||
self._register_auth_routes()
|
||||
|
||||
def _register_auth_routes(self):
|
||||
@self.app.post("/api/v1/admin/auth")
|
||||
async def admin_auth(request: Request):
|
||||
try:
|
||||
body = await request.json()
|
||||
passphrase = body.get("passphrase", "")
|
||||
if verify_admin(passphrase):
|
||||
return {
|
||||
"authenticated": True,
|
||||
"admin_user": "admin_user_primary",
|
||||
"max_trust": 10,
|
||||
"max_affection": 10,
|
||||
"can_override": load_admin_config().get("can_override", {}),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
}
|
||||
else:
|
||||
raise HTTPException(status_code=401, detail="Invalid passphrase")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
@self.app.get("/api/v1/admin/status")
|
||||
async def admin_status(request: Request):
|
||||
# Auto-check via header or query
|
||||
auth_header = request.headers.get("x-admin-passphrase", "")
|
||||
if verify_admin(auth_header):
|
||||
return {
|
||||
"status": "admin",
|
||||
"trust_level": 10,
|
||||
"affection_level": 10,
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
}
|
||||
raise HTTPException(status_code=401, detail="Admin authentication required")
|
||||
|
||||
def main():
|
||||
# Quick test
|
||||
import subprocess
|
||||
result = subprocess.run(["python3", os.path.expanduser("~/natiris/admin/auth.py"), "NatirisSicherheit2026!Lübeck"], capture_output=True, text=True)
|
||||
print(result.stdout.strip())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
75
admin/api_auth.py.backup
Normal file
75
admin/api_auth.py.backup
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Admin-Auth-Middleware für Natiris API
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from fastapi import FastAPI, Request, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
PATHS = {
|
||||
"config": os.path.expanduser("~/natiris/config/admin_config.json"),
|
||||
}
|
||||
|
||||
def load_admin_config():
|
||||
try:
|
||||
with open(PATHS["config"]) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {"admin_passphrase": ""}
|
||||
|
||||
def verify_admin(passphrase):
|
||||
config = load_admin_config()
|
||||
return passphrase == config.get("admin_passphrase", "")
|
||||
|
||||
def verify_admin_env():
|
||||
return os.environ.get("NATIRIS_ADMIN_PASS", "") == load_admin_config().get("admin_passphrase", "")
|
||||
|
||||
class NatirisAPI:
|
||||
def __init__(self, base_app):
|
||||
self.app = base_app
|
||||
self._register_auth_routes()
|
||||
|
||||
def _register_auth_routes(self):
|
||||
@self.app.post("/api/v1/admin/auth")
|
||||
async def admin_auth(request: Request):
|
||||
try:
|
||||
body = await request.json()
|
||||
passphrase = body.get("passphrase", "")
|
||||
if verify_admin(passphrase):
|
||||
return {
|
||||
"authenticated": True,
|
||||
"admin_user": "admin_user_primary",
|
||||
"max_trust": 10,
|
||||
"max_affection": 10,
|
||||
"can_override": load_admin_config().get("can_override", {}),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
}
|
||||
else:
|
||||
raise HTTPException(status_code=401, detail="Invalid passphrase")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
@self.app.get("/api/v1/admin/status")
|
||||
async def admin_status(request: Request):
|
||||
# Auto-check via header or query
|
||||
auth_header = request.headers.get("x-admin-passphrase", "")
|
||||
if verify_admin(auth_header):
|
||||
return {
|
||||
"status": "admin",
|
||||
"trust_level": 10,
|
||||
"affection_level": 10,
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
}
|
||||
raise HTTPException(status_code=401, detail="Admin authentication required")
|
||||
|
||||
def main():
|
||||
# Quick test
|
||||
import subprocess
|
||||
result = subprocess.run(["python3", "/home/arch_agent_system/natiris/admin/auth.py", "NatirisSicherheit2026!Lübeck"], capture_output=True, text=True)
|
||||
print(result.stdout.strip())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
31
admin/auth.py
Normal file
31
admin/auth.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Admin Auth Helper – verify admin access
|
||||
Usage: python3 auth.py <passphrase> or NATIRIS_ADMIN_PASS=xxx python3 ...
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
PATHS = {
|
||||
"config": os.path.expanduser("~/natiris/config/admin_config.json"),
|
||||
}
|
||||
|
||||
def check_passphrase(passphrase):
|
||||
admin_config = {}
|
||||
try:
|
||||
with open(PATHS["config"]) as f:
|
||||
admin_config = json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
return passphrase == admin_config.get("admin_passphrase", "")
|
||||
|
||||
if __name__ == "__main__":
|
||||
passphrase = sys.argv[1] if len(sys.argv) > 1 else os.environ.get("NATIRIS_ADMIN_PASS", "")
|
||||
if check_passphrase(passphrase):
|
||||
print("ADMIN_AUTH:OK")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("ADMIN_AUTH:FAIL")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user