Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"host": "your.server.example",
"port": 22,
"user": "ubuntu",
"auth_method": "key",
"key_path": "C:\\Users\\<you>\\.ssh\\id_rsa",
"password": ""
"ssh": {
"host": "your.server.example",
"port": 22,
"user": "ubuntu",
"auth_method": "key",
"key_path": "C:\\Users\\<you>\\.ssh\\id_rsa",
"password": ""
},
"odoo": {
"url": "http://your.odoo.server",
"db": "your_database_name",
"login": "admin",
"password": "your_odoo_password"
}
}
26 changes: 8 additions & 18 deletions manage_server.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import argparse
import json
import os
import sys
import time
from typing import Tuple

import paramiko


def load_config(path: str) -> dict:
if not os.path.exists(path):
alt = os.path.join(os.path.dirname(__file__), "config.example.json")
if not os.path.exists(alt):
raise FileNotFoundError("缺少配置文件,请创建 config.json 或保留 config.example.json")
path = alt
print(f"[提示] 使用示例配置:{path}")
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
from utils import load_config


def connect(cfg: dict) -> paramiko.SSHClient:
host = cfg.get("host")
port = int(cfg.get("port", 22))
user = cfg.get("user")
auth_method = cfg.get("auth_method", "key")
key_path = cfg.get("key_path")
password = cfg.get("password") or None
ssh_cfg = cfg.get("ssh", {})
host = ssh_cfg.get("host")
port = int(ssh_cfg.get("port", 22))
user = ssh_cfg.get("user")
auth_method = ssh_cfg.get("auth_method", "key")
key_path = ssh_cfg.get("key_path")
password = ssh_cfg.get("password") or None

if not host or not user:
raise ValueError("配置不完整:需要 host 与 user")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
paramiko>=3.4.0
openpyxl>=3.1.2
requests>=2.31.0
57 changes: 22 additions & 35 deletions test_login.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
from odoo_jsonrpc import OdooClient, OdooRPCError


URL = "http://127.0.0.1:18069"
TARGET_DB = "wuchang_preview_20251107"

# Try common admin credential sets, first one that succeeds wins
CREDENTIALS = [
("admin", "odoo"),
("admin@wuchang.life", "poiuY926"),
]
from utils import load_config


def main():
client = OdooClient(URL)
dbs = client.list_databases() or []
if isinstance(dbs, dict) and dbs.get("databases"):
dbs = dbs["databases"]
if not dbs:
print("[error] No databases found on server")
cfg = load_config()
odoo_cfg = cfg.get("odoo", {})
url = odoo_cfg.get("url")
db = odoo_cfg.get("db")
login = odoo_cfg.get("login")
password = odoo_cfg.get("password")

if not all([url, db, login, password]):
print("[error] Odoo config missing in config.json (url, db, login, password)")
return
print("[info] available databases:", dbs)
db = TARGET_DB if TARGET_DB in dbs else dbs[0]
print("[info] selected db:", db)

last_err = None
for login, password in CREDENTIALS:
try:
client.authenticate(db, login, password)
me = client.search_read("res.users", [["login", "=", login]], ["id", "name", "login", "active"], limit=1)
base_url = client.call_kw("ir.config_parameter", "get_param", [], {"key": "web.base.url"})
print("[ok] login succeeded")
print("db:", db)
print("user:", me)
print("web.base.url:", base_url)
return
except Exception as e:
last_err = e
print(f"[warn] login failed for {login}:", str(e))

if last_err:
print("[error] all credential attempts failed:", str(last_err))
client = OdooClient(url)
try:
client.authenticate(db, login, password)
me = client.search_read("res.users", [["login", "=", login]], ["id", "name", "login"], limit=1)
print("[ok] Login successful")
print(" - URL:", url)
print(" - DB:", db)
print(" - User:", me[0] if me else "N/A")
except OdooRPCError as e:
print(f"[error] Login failed: {e.fault_code} - {e.fault_string}")
except Exception as e:
print(f"[error] An unexpected error occurred: {e}")


if __name__ == "__main__":
Expand Down
15 changes: 15 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json
import os


def load_config():
if not os.path.exists("config.json"):
alt = "config.example.json"
if not os.path.exists(alt):
raise FileNotFoundError("Missing config.json or config.example.json")
print(f"[info] using example config: {alt}")
path = alt
else:
path = "config.json"
with open(path, "r", encoding="utf-8") as f:
return json.load(f)