File size: 5,293 Bytes
490ec84
5e1dfdc
490ec84
 
5e1dfdc
 
490ec84
5e1dfdc
490ec84
5e1dfdc
 
 
 
 
 
 
 
 
 
490ec84
 
 
 
 
 
5e1dfdc
 
490ec84
5e1dfdc
 
 
 
 
490ec84
 
 
 
 
 
 
 
5e1dfdc
490ec84
 
 
 
 
5e1dfdc
490ec84
5e1dfdc
 
 
 
 
490ec84
 
5e1dfdc
 
 
 
 
490ec84
 
 
 
 
 
5e1dfdc
 
490ec84
 
 
5e1dfdc
490ec84
 
 
 
 
5e1dfdc
 
 
 
 
 
 
490ec84
 
5e1dfdc
490ec84
5e1dfdc
 
 
 
 
490ec84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e1dfdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490ec84
 
 
 
 
 
 
 
 
 
 
5e1dfdc
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from fastapi import FastAPI, UploadFile, File, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
import pandas as pd
import os, json

# ----------------- Setup -----------------
app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

BASE_DIR = os.path.dirname(__file__)
DATA_DIR = os.path.join(BASE_DIR, "data")
FRONTEND_DIST = os.getenv('STATIC_FILES_DIR', '/app/static')
#FRONTEND_DIST = os.path.join(BASE_DIR, "../frontend/dist/agentic-dashboard")
CREDENTIALS_PATH = os.path.join(DATA_DIR, "user_credentials.json")
ADMIN_ENV_PATH = os.path.join(BASE_DIR, "../.env")
AGENTS_FILE = os.path.join(DATA_DIR, "Agentic_Deployment_Master_Plan_v3.2.csv")

# ----------------- Models -----------------
class SimulationInput(BaseModel):
    asset: str
    capital: float
    risk: int

class IntakeData(BaseModel):
    role: str
    github: str = None
    docker: str = None
    digitalocean: str = None
    google: str = None
    notion: str = None
    custom: str = None

# ----------------- Routes -----------------
@app.get("/")
def serve_frontend():
    index_file = os.path.join(FRONTEND_DIST, "index.html")
    return FileResponse(index_file)

app.mount("/static", StaticFiles(directory=FRONTEND_DIST), name="static")

@app.get("/agent_status")
def agent_status():
    try:
        df = pd.read_csv(AGENTS_FILE)
        enriched = [
            {
                "id": f"agent{idx}",
                "name": row.get("name", f"Agent {idx}"),
                "traits": row.get("traits", "unspecified"),
                "risk": int(row.get("risk", 3)),
                "status": "active",
                "memory_kb": 0,
                "endpoints": ["Google", "Notion", "Shodan"]
            }
            for idx, row in df.iterrows()
        ]
        return {"active_agents": len(enriched), "agents": enriched}
    except Exception as e:
        return {"error": str(e)}

@app.post("/simulate")
def simulate(input: SimulationInput):
    try:
        projected = input.capital * (1 + input.risk / 10)
        return {
            "projected_yield": projected,
            "agent_notes": f"Simulated projection for {input.asset}"
        }
    except Exception as e:
        return {"error": str(e)}

@app.post("/upload_csv")
def upload_csv(file: UploadFile = File(...)):
    try:
        contents = file.file.read()
        path = os.path.join(DATA_DIR, file.filename)
        with open(path, "wb") as f:
            f.write(contents)
        return {"status": "uploaded", "path": path}
    except Exception as e:
        return {"error": str(e)}

@app.post("/intake")
def handle_intake(data: IntakeData):
    try:
        if data.role == "admin":
            creds = {
                "GITHUB_TOKEN": data.github,
                "DOCKER_TOKEN": data.docker,
                "DO_API_KEY": data.digitalocean
            }
            with open(ADMIN_ENV_PATH, "a") as f:
                for k, v in creds.items():
                    if v:
                        f.write(f"{k}={v}\n")
            return {"message": "Admin credentials saved to .env."}
        elif data.role == "user":
            session_data = {
                "google": data.google,
                "notion": data.notion,
                "custom": data.custom
            }
            with open(CREDENTIALS_PATH, "w") as f:
                json.dump(session_data, f)
            return {"message": "User session credentials stored."}
        return {"message": "Invalid role or missing data."}
    except Exception as e:
        return {"error": str(e)}

@app.post("/upload_credentials")
def upload_cred_file(file: UploadFile = File(...)):
    try:
        content = file.file.read()
        with open(CREDENTIALS_PATH, "wb") as f:
            f.write(content)
        return {"message": "Credential file uploaded and stored."}
    except Exception as e:
        return {"error": str(e)}

@app.get("/credentials")
def view_creds():
    try:
        with open(CREDENTIALS_PATH) as f:
            return json.load(f)
    except FileNotFoundError:
        return {"error": "No credentials file found."}

# ----------------- Routers -----------------
from routes.reddit_auth import router as reddit_router
from routes.discord_auth import router as discord_router
from routes.github_auth import router as github_router
from routes.huggingface_auth import router as hf_router
from routes.wayback_lookup import router as wayback_router
from routes.dork_search import router as dork_router
from routes.exploitdb_lookup import router as exploitdb_router
from routes.spreadsheet_intake import router as spreadsheet_router
from routes.neurocircuit_api import router as neurocircuit_router
from routes.mindmap_api import router as mindmap_router

app.include_router(reddit_router)
app.include_router(discord_router)
app.include_router(github_router)
app.include_router(hf_router)
app.include_router(wayback_router)
app.include_router(dork_router)
app.include_router(exploitdb_router)
app.include_router(spreadsheet_router)
app.include_router(neurocircuit_router)
app.include_router(mindmap_router)