mxwhoami
This commit is contained in:
parent
8df08611a9
commit
bf3d383615
4 changed files with 40 additions and 15 deletions
|
|
@ -58,7 +58,8 @@ usage:
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
mxdiscover --help
|
mxdiscover --help
|
||||||
mxwhoami
|
mxpassitem --help
|
||||||
|
mxwhoami --help
|
||||||
mxtoken
|
mxtoken
|
||||||
mxaccountinfo
|
mxaccountinfo
|
||||||
mxclearaccount
|
mxclearaccount
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,16 @@ func cliv0_mkmxtoken(id *C.char, pw *C.char) *C.char {
|
||||||
func cliv0_whoami(hs *C.char, tk *C.char) *C.char {
|
func cliv0_whoami(hs *C.char, tk *C.char) *C.char {
|
||||||
_hs := C.GoString(hs)
|
_hs := C.GoString(hs)
|
||||||
_tk := C.GoString(tk)
|
_tk := C.GoString(tk)
|
||||||
result := mxutils.Whoami(_hs, _tk)
|
resp, err := mxutils.Whoami(_hs, _tk)
|
||||||
return C.CString(result)
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
out, err := json.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
s := string(out)
|
||||||
|
return C.CString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export cliv0_accountinfo
|
//export cliv0_accountinfo
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,12 @@ func MkToken(ids string, pw string) string {
|
||||||
return resp.AccessToken
|
return resp.AccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
func Whoami(hs string, accessToken string) string {
|
func Whoami(hs string, accessToken string) (*mautrix.RespWhoami, error) {
|
||||||
return "nope. whoami"
|
mauclient, err := mautrix.NewClient(hs, "", accessToken)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return mauclient.Whoami(context.Background())
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountInfo(hs string, accessToken string) string {
|
func AccountInfo(hs string, accessToken string) string {
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,30 @@
|
||||||
# Copyright (C) 2026 saces@c-base.org
|
# Copyright (C) 2026 saces@c-base.org
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import sys
|
import json
|
||||||
from _pygomx import lib, ffi
|
|
||||||
|
import click
|
||||||
|
from _pygomx import ffi, lib
|
||||||
|
|
||||||
|
|
||||||
def whoami():
|
@click.command()
|
||||||
if len(sys.argv) != 3:
|
@click.option("-u", "--url", "hs_url", metavar="url", help="homeserver url")
|
||||||
print("usage: ", sys.argv[0], " url accesstoken")
|
@click.option("-t", "--token", "token", metavar="token", help="access token")
|
||||||
return 1
|
def whoami(hs_url, token):
|
||||||
|
"""this token belongs to?"""
|
||||||
|
|
||||||
url = sys.argv[1].encode(encoding="utf-8")
|
if hs_url is None and token is None:
|
||||||
tk = sys.argv[2].encode(encoding="utf-8")
|
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
|
||||||
|
|
||||||
r = lib.cliv0_whoami(url, tk)
|
result = ffi.string(r).decode("utf-8")
|
||||||
|
lib.FreeCString(r)
|
||||||
|
|
||||||
|
result_dict = json.loads(result)
|
||||||
|
hs_url = result_dict["Matrixhost"]
|
||||||
|
token = result_dict["Token"]
|
||||||
|
|
||||||
|
r = lib.cliv0_whoami(
|
||||||
|
hs_url.encode(encoding="utf-8"), token.encode(encoding="utf-8")
|
||||||
|
)
|
||||||
result = ffi.string(r)
|
result = ffi.string(r)
|
||||||
lib.FreeCString(r)
|
lib.FreeCString(r)
|
||||||
print(result)
|
print(result.decode("utf-8"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue