Uname:Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64

Base Dir : /var/www/moonbloom

User : wp-moonbloom


403WebShell
403Webshell
Server IP : 85.155.190.233  /  Your IP : 216.73.216.103
Web Server : nginx/1.24.0
System : Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User : wp-moonbloom ( 1001)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /opt/Gemini_Swarm_Core/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/Gemini_Swarm_Core/scripts//google_developer_knowledge_proxy.py
import sys
import json
import urllib.request
import urllib.error
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request

import os

MCP_ENDPOINT = 'https://developerknowledge.googleapis.com/mcp'

def get_credentials_path():
    env_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
    if env_path and os.path.exists(env_path):
        return env_path
    if sys.platform == 'win32':
        user_profile = os.environ.get('USERPROFILE') or os.path.expanduser('~')
        gemini_key = os.path.join(user_profile, '.gemini', 'gcp-key.json')
        if os.path.exists(gemini_key):
            return gemini_key
        appdata = os.environ.get('APPDATA')
        if appdata:
            win_path = os.path.join(appdata, 'gcloud', 'application_default_credentials.json')
            if os.path.exists(win_path):
                return win_path
    if env_path:
        return env_path
    return '/root/gcp-key.json'

def get_credentials():
    path = get_credentials_path()
    try:
        creds = Credentials.from_authorized_user_file(path)
        return creds
    except Exception as e:
        sys.stderr.write(f"Error loading credentials from {path}: {e}\n")
        sys.stderr.flush()
        return None

def main():
    creds = get_credentials()
    auth_request = Request()

    for line in sys.stdin:
        line = line.strip()
        if not line:
            continue

        try:
            req_data = json.loads(line)
            req_id = req_data.get('id')
        except Exception as e:
            err_resp = {
                "jsonrpc": "2.0",
                "error": {
                    "code": -32700,
                    "message": f"Parse error: {str(e)}"
                },
                "id": None
            }
            sys.stdout.write(json.dumps(err_resp) + "\n")
            sys.stdout.flush()
            continue

        if not creds:
            err_resp = {
                "jsonrpc": "2.0",
                "error": {
                    "code": -32603,
                    "message": "Internal error: GCP credentials not loaded"
                },
                "id": req_id
            }
            sys.stdout.write(json.dumps(err_resp) + "\n")
            sys.stdout.flush()
            continue

        try:
            if not creds.valid:
                creds.refresh(auth_request)
        except Exception as e:
            err_resp = {
                "jsonrpc": "2.0",
                "error": {
                    "code": -32603,
                    "message": f"Authentication error: Failed to refresh OAuth token: {str(e)}"
                },
                "id": req_id
            }
            sys.stdout.write(json.dumps(err_resp) + "\n")
            sys.stdout.flush()
            continue

        try:
            headers = {
                'Authorization': f'Bearer {creds.token}',
                'Content-Type': 'application/json'
            }
            if getattr(creds, 'quota_project_id', None):
                headers['x-goog-user-project'] = creds.quota_project_id
            req = urllib.request.Request(
                MCP_ENDPOINT,
                data=line.encode('utf-8'),
                headers=headers,
                method='POST'
            )
            with urllib.request.urlopen(req, timeout=30) as response:
                resp_data = response.read()
                sys.stdout.buffer.write(resp_data.strip() + b"\n")
                sys.stdout.flush()
        except urllib.error.HTTPError as e:
            try:
                resp_content = e.read()
                sys.stdout.buffer.write(resp_content.strip() + b"\n")
                sys.stdout.flush()
            except Exception:
                err_resp = {
                    "jsonrpc": "2.0",
                    "error": {
                        "code": -32603,
                        "message": f"Remote server HTTP Error {e.code}: {e.reason}"
                    },
                    "id": req_id
                }
                sys.stdout.buffer.write(json.dumps(err_resp).encode('utf-8') + b"\n")
                sys.stdout.flush()
        except Exception as e:
            err_resp = {
                "jsonrpc": "2.0",
                "error": {
                    "code": -32603,
                    "message": f"Network/Internal error: {str(e)}"
                },
                "id": req_id
            }
            sys.stdout.buffer.write(json.dumps(err_resp).encode('utf-8') + b"\n")
            sys.stdout.flush()

if __name__ == '__main__':
    main()

Youez - 2016 - github.com/yon3zu
LinuXploit