Added editing NOSPAMKEYS

This commit is contained in:
emdee 2022-10-04 14:20:18 +00:00
parent 0148a36726
commit de94029cf6
2 changed files with 41 additions and 5 deletions

View File

@ -30,13 +30,14 @@ to stdout
to a file. to a file.
``` ```
usage: tox_savefile.py [-h] [--output OUTPUT] usage: tox_savefile.py [-h]
[--command info|decrypt|nodes|edit] [--command info|decrypt|nodes|edit]
[--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp] [--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp]
[--indent INDENT] [--indent INDENT]
[--nodes select_tcp|select_udp|select_version|nmap_tcp|nmap_udp,download] [--nodes select_tcp|select_udp|select_version|nmap_tcp|nmap_udp,download]
[--download_nodes_url DOWNLOAD_NODES_URL] [--download_nodes_url DOWNLOAD_NODES_URL]
[--edit help|section,num,key,val] [--edit help|section,num,key,val]
[--output OUTPUT]
profile profile
``` ```
Positional arguments: Positional arguments:
@ -48,7 +49,7 @@ Optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--command {info,decrypt,nodes,edit} --command {info,decrypt,nodes,edit}
Action command - default: info 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) --info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp (may require nmap)
Format for info command Format for info command
--indent INDENT Indent for yaml/json/pprint --indent INDENT Indent for yaml/json/pprint
@ -111,12 +112,27 @@ Currently it is:
NAME,.,Nick_name,str NAME,.,Nick_name,str
STATUSMESSAGE,.,Status_message,str STATUSMESSAGE,.,Status_message,str
STATUS,.,Online_status,int 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: The ```num``` field is to accomodate sections that have lists:
* ```.``` is a placeholder for sections that don't have lists. * ```.``` is a placeholder for sections that don't have lists.
* ```<int>``` is for the nth element of the list, zero-based. * ```<int>``` is for the nth element of the list, zero-based.
* ```*``` is for all elements of the list. * ```*``` 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:
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 the the target.
3. Edit the target with 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 ## Requirements

View File

@ -438,6 +438,9 @@ def process_chunk(index, state, oArgs=None):
label = dSTATE_TYPE[data_type] label = dSTATE_TYPE[data_type]
if oArgs.command == 'edit' and oArgs.edit: if oArgs.command == 'edit' and oArgs.edit:
# if ':' in oArgs.edit:
# section,num,key,val = oArgs.edit.split(':')[0].split(',',3)
# else:
section,num,key,val = oArgs.edit.split(',',3) section,num,key,val = oArgs.edit.split(',',3)
diff = index - len(bOUT) diff = index - len(bOUT)
@ -457,6 +460,22 @@ def process_chunk(index, state, oArgs=None):
"Public_key": f"{public_key}", "Public_key": f"{public_key}",
"Private_key": f"{private_key}"} "Private_key": f"{private_key}"}
aOUT.update({label: aIN}) 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: elif data_type == MESSENGER_STATE_TYPE_DHT:
LOG.debug(f"process_chunk {label} length={length}") LOG.debug(f"process_chunk {label} length={length}")
@ -686,8 +705,9 @@ def oMainArgparser(_=None):
choices=['info', 'decrypt', 'nodes', 'edit'], choices=['info', 'decrypt', 'nodes', 'edit'],
required=True, required=True,
help='Action command - default: info') help='Action command - default: info')
# nargs='+',
parser.add_argument('--edit', type=str, default='', 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, parser.add_argument('--indent', type=int, default=2,
help='Indent for yaml/json/pprint') help='Indent for yaml/json/pprint')
choices=['info', 'save', 'repr', 'yaml','json', 'pprint'] choices=['info', 'save', 'repr', 'yaml','json', 'pprint']