Compare commits
3 Commits
0148a36726
...
a871c2a681
Author | SHA1 | Date | |
---|---|---|---|
a871c2a681 | |||
3dba2557e8 | |||
de94029cf6 |
35
README.md
35
README.md
@ -30,14 +30,15 @@ to stdout
|
||||
to a file.
|
||||
|
||||
```
|
||||
usage: tox_savefile.py [-h] [--output OUTPUT]
|
||||
usage: tox_savefile.py [-h]
|
||||
[--command info|decrypt|nodes|edit]
|
||||
[--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp]
|
||||
[--indent INDENT]
|
||||
[--nodes select_tcp|select_udp|select_version|nmap_tcp|nmap_udp,download]
|
||||
[--download_nodes_url DOWNLOAD_NODES_URL]
|
||||
[--edit help|section,num,key,val]
|
||||
profile
|
||||
[--output OUTPUT]
|
||||
profile
|
||||
```
|
||||
Positional arguments:
|
||||
```
|
||||
@ -48,7 +49,7 @@ Optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--command {info,decrypt,nodes,edit}
|
||||
Action command - default: info
|
||||
--output OUTPUT Destination for info/decrypt/nodes - defaults to stdout
|
||||
--output OUTPUT Destination for info/decrypt/nodes - can be the same as input
|
||||
--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp (may require nmap)
|
||||
Format for info command
|
||||
--indent INDENT Indent for yaml/json/pprint
|
||||
@ -111,17 +112,36 @@ Currently it is:
|
||||
NAME,.,Nick_name,str
|
||||
STATUSMESSAGE,.,Status_message,str
|
||||
STATUS,.,Online_status,int
|
||||
NOSPAMKEYS,.,Nospam,hexstr
|
||||
NOSPAMKEYS,.,Public_key,hexstr
|
||||
NOSPAMKEYS,.,Private_key,hexstr
|
||||
```
|
||||
The ```num``` field is to accomodate sections that have lists:
|
||||
* ```.``` is a placeholder for sections that don't have lists.
|
||||
* ```<int>``` is for the nth element of the list, zero-based.
|
||||
* ```*``` is for all elements of the list.
|
||||
|
||||
The ```--output``` can be the same as input as the input file is read
|
||||
and closed before processing starts.
|
||||
|
||||
You can use the ```---edit``` command to synchronize profiles, by
|
||||
keeping the keypair and synchronize profiles between different clients:
|
||||
e.g. your could keep your profile from toxic as master, and copy it over
|
||||
your qtox/toxygen/TriFa profile while preserving their keypair and NOSPAM:
|
||||
|
||||
1. Use ```--command info --info info``` on the target profile to get the
|
||||
```Nospam```, ```Public_key``` and ```Private_key``` of the target.
|
||||
2. Backup the target and copy the source profile to the target.
|
||||
3. Edit the target with the values from 1) with:```
|
||||
--command edit --edit NOSPAMKEYS,.,Nospam,hexstr --output target target
|
||||
--command edit --edit NOSPAMKEYS,.,Public_key,hexstr --output target target
|
||||
--command edit --edit NOSPAMKEYS,.,Private_key,hexstr --output target target
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
If you want to read encrypted profiles, you need to download
|
||||
toxygen to deal with encrypted tox files, from:
|
||||
toxygen_wrapper to deal with encrypted tox files, from:
|
||||
<https://git.plastiras.org/emdee/toxygen_wrapper>
|
||||
Just put the toxygen/toxygen directory on your PYTHONPATH
|
||||
You also need to link your libtoxcore.so and libtoxav.so
|
||||
@ -148,14 +168,9 @@ required. It's available in most distros, or <https://nmap.org/>
|
||||
This has not been tested on Windwoes, but is should be simple to fix.
|
||||
|
||||
Because it's written in Python it is easy to extend to, for example,
|
||||
rekeying a profile when copying a profile to a new device:
|
||||
supporting multidevices:
|
||||
<https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC>
|
||||
|
||||
Or you could keep the keypair and synchronize profiles between different
|
||||
clients: e.g. your could keep your profile from toxic as master,
|
||||
and copy it over your qtox/toxygen/TriFa profile while preserving their
|
||||
ToxId keypair.
|
||||
|
||||
## Specification
|
||||
|
||||
There is a copy of the Tox [spec](https://toktok.ltd/spec.html)
|
||||
|
@ -113,12 +113,19 @@ LOG.trace = trace
|
||||
global bOUT, aOUT, sENC
|
||||
aOUT = {}
|
||||
bOUT = b''
|
||||
sENC = 'utf-8'
|
||||
sENC = sys.getdefaultencoding() # 'utf-8'
|
||||
lNULLS = ['', '[]', 'null']
|
||||
# grep '#''#' logging_tox_savefile.py|sed -e 's/.* //'
|
||||
sEDIT_HELP = """
|
||||
NAME,.,Nick_name,str
|
||||
STATUSMESSAGE,.,Status_message,str
|
||||
STATUS,.,Online_status,int
|
||||
NOSPAMKEYS,.,Nospam,hexstr
|
||||
NOSPAMKEYS,.,Public_key,hexstr
|
||||
NOSPAMKEYS,.,Private_key,hexstr
|
||||
DHT,.,DHTnode,
|
||||
TCP_RELAY,.,TCPnode,
|
||||
PATH_NODE,.,PATHnode,
|
||||
"""
|
||||
|
||||
#messenger.c
|
||||
@ -438,7 +445,7 @@ def process_chunk(index, state, oArgs=None):
|
||||
|
||||
label = dSTATE_TYPE[data_type]
|
||||
if oArgs.command == 'edit' and oArgs.edit:
|
||||
section,num,key,val = oArgs.edit.split(',',3)
|
||||
section,num,key,val = oArgs.edit.split(',', 3)
|
||||
|
||||
diff = index - len(bOUT)
|
||||
if bDEBUG and diff > 0:
|
||||
@ -457,15 +464,48 @@ def process_chunk(index, state, oArgs=None):
|
||||
"Public_key": f"{public_key}",
|
||||
"Private_key": f"{private_key}"}
|
||||
aOUT.update({label: aIN})
|
||||
|
||||
if oArgs.command == 'edit' and section == label:
|
||||
## NOSPAMKEYS,.,Nospam,hexstr
|
||||
if key == "Nospam":
|
||||
assert len(val) == 4*2, val
|
||||
result = bytes.fromhex (val) +result[4:]
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
## NOSPAMKEYS,.,Public_key,hexstr
|
||||
elif key == "Public_key":
|
||||
assert len(val) == 32 * 2, val
|
||||
result = +result[0:4] +bytes.fromhex(val) +result[36:]
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
## NOSPAMKEYS,.,Private_key,hexstr
|
||||
elif key == "Private_key":
|
||||
assert len(val) == 32 * 2, val
|
||||
result = +result[0:36] +bytes.fromhex(val)
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
|
||||
elif data_type == MESSENGER_STATE_TYPE_DHT:
|
||||
LOG.debug(f"process_chunk {label} length={length}")
|
||||
lIN = lProcessDHTnodes(state, index, length, result)
|
||||
if length > 4:
|
||||
lIN = lProcessDHTnodes(state, index, length, result, "DHTnode")
|
||||
else:
|
||||
lIN = []
|
||||
LOG.info(f"NO {label}")
|
||||
aOUT.update({label: lIN})
|
||||
if oArgs.command == 'edit' and section == label:
|
||||
## DHT,.,DHTnode,
|
||||
if num == '.' and key == "DHTnode" and val in lNULLS:
|
||||
# 4 uint32_t (0x159000D)
|
||||
status = 0x159000D
|
||||
# FixMe - dunno
|
||||
result = struct.pack("<L", status)
|
||||
length = 4
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
|
||||
elif data_type == MESSENGER_STATE_TYPE_FRIENDS:
|
||||
LOG.info(f"{label} {length // 2216} FRIENDS {length % 2216}")
|
||||
lIN = lProcessFriends(state, index, length, result)
|
||||
if length > 0:
|
||||
lIN = lProcessFriends(state, index, length, result)
|
||||
else:
|
||||
lIN = []
|
||||
LOG.info(f"NO {label}")
|
||||
aOUT.update({label: lIN})
|
||||
|
||||
elif data_type == MESSENGER_STATE_TYPE_NAME:
|
||||
@ -522,6 +562,12 @@ def process_chunk(index, state, oArgs=None):
|
||||
lIN = []
|
||||
LOG.info(f"NO {label}")
|
||||
aOUT.update({label: lIN})
|
||||
if oArgs.command == 'edit' and section == label:
|
||||
## TCP_RELAY,.,TCPnode,
|
||||
if num == '.' and key == "TCPnode" and val in lNULLS:
|
||||
result = b''
|
||||
length = 0
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
|
||||
elif data_type == MESSENGER_STATE_TYPE_PATH_NODE:
|
||||
#define NUM_SAVED_PATH_NODES 8
|
||||
@ -532,6 +578,12 @@ def process_chunk(index, state, oArgs=None):
|
||||
LOG.debug(f"process_chunk {label} bytes={length}")
|
||||
lIN = lProcessNodeInfo(state, index, length, result, "PATHnode")
|
||||
aOUT.update({label: lIN})
|
||||
if oArgs.command == 'edit' and section == label:
|
||||
## PATH_NODE,.,PATHnode,
|
||||
if num == '.' and key == "PATHnode" and val in lNULLS:
|
||||
result = b''
|
||||
length = 0
|
||||
LOG.info(f"{label} {key} EDITED to {val}")
|
||||
|
||||
elif data_type == MESSENGER_STATE_TYPE_CONFERENCES:
|
||||
lIN = []
|
||||
@ -686,8 +738,9 @@ def oMainArgparser(_=None):
|
||||
choices=['info', 'decrypt', 'nodes', 'edit'],
|
||||
required=True,
|
||||
help='Action command - default: info')
|
||||
# nargs='+',
|
||||
parser.add_argument('--edit', type=str, default='',
|
||||
help='comma seperated SECTION,key,value - unfinished')
|
||||
help='comma seperated SECTION,num,key,value - or help for ')
|
||||
parser.add_argument('--indent', type=int, default=2,
|
||||
help='Indent for yaml/json/pprint')
|
||||
choices=['info', 'save', 'repr', 'yaml','json', 'pprint']
|
||||
|
@ -98,23 +98,32 @@ for the_tox in $tox /tmp/toxic_profile.save ; do
|
||||
--command info --info $elt \
|
||||
--output $the_base.$elt $the_tox '2>'$the_base.$elt.err
|
||||
$EXE $target --command info --info $elt \
|
||||
--output $the_base.$elt $the_tox 2>$the_base.$nmap.err || exit ${i}0
|
||||
--output $the_base.$elt $the_tox 2>$the_base.$nmap.err || exit ${i}0
|
||||
[ -s $the_base.$elt ] || exit ${i}1
|
||||
done
|
||||
|
||||
$EXE $target --command edit --edit help $the_tox 2>/dev/null || exit ${i}2
|
||||
|
||||
INFO $i $the_base.edit1 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
|
||||
# edit the status message
|
||||
INFO $i $the_base.Status_message 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
|
||||
$EXE $target --command edit --edit 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' \
|
||||
--output $the_base.edit1.tox $the_tox 2>&1|grep EDIT
|
||||
[ -s $the_base.edit1.tox ] || exit ${i}3
|
||||
$EXE $target --command info $the_base.edit1.tox 2>&1|grep Toxxed || exit ${i}4
|
||||
--output $the_base.Status_message.tox $the_tox 2>&1|grep EDIT || exit ${i}3
|
||||
[ -s $the_base.Status_message.tox ] || exit ${i}3
|
||||
$EXE $target --command info $the_base.Status_message.tox 2>&1|grep Toxxed || exit ${i}4
|
||||
|
||||
INFO $i $the_base.edit2 'NAME,.,Nick_name,FooBar'
|
||||
# edit the nick_name
|
||||
INFO $i $the_base.Nick_name 'NAME,.,Nick_name,FooBar'
|
||||
$EXE $target --command edit --edit 'NAME,.,Nick_name,FooBar' \
|
||||
--output $the_base.edit2.tox $the_tox 2>&1|grep EDIT
|
||||
[ -s $the_base.edit2.tox ] || exit ${i}5
|
||||
$EXE $target --command info $the_base.edit2.tox 2>&1|grep FooBar || exit ${i}6
|
||||
--output $the_base.Nick_name.tox $the_tox 2>&1|grep EDIT || exit ${i}5
|
||||
[ -s $the_base.Nick_name.tox ] || exit ${i}5
|
||||
$EXE $target --command info $the_base.Nick_name.tox 2>&1|grep FooBar || exit ${i}6
|
||||
|
||||
# set the DHTnodes to empty
|
||||
INFO $i $the_base.noDHT 'DHT,.,DHTnode,'
|
||||
$EXE $target --command edit --edit 'DHT,.,DHTnode,' \
|
||||
--output $the_base.noDHT.tox $the_tox 2>&1|grep EDIT || exit ${i}7
|
||||
[ -s $the_base.noDHT.tox ] || exit ${i}7
|
||||
$EXE $target --command info $the_base.noDHT.tox 2>&1|grep 'NO DHT' || exit ${i}8
|
||||
|
||||
done
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user