nyxnor/onionjuggler

[BUG] read the tor file completely to get hs info to delete or print

nyxnor opened this issue · 5 comments

I am no longer satisfied with grepping 7 lines starting from match:

"${su_cmd}" grep -A 7 -E "^HiddenServiceDir ${tor_data_dir_services}/${service}$|^HiddenServiceDir ${tor_data_dir_services}/${service}/$" "${file}" | while IFS= read -r line; do

I used 7 as an arbitrary number and I could choose any other arbitrary number. But the solution is to read the file until the configuration is not HiddenService anymore or it is HiddenServiceDir of another service.

The other problem is the sed deleting lines. Before, every line was unique with HiddenServiceDir and HiddenServicePort, but HiddenServiceVersion is the same for every onion service, this means that when deleting a service, it would be deleting every version line from every service.

fixed on 5be0329

the problem is that it cannot contain lines not starting with HiddenService between the blocks, for example, a commented line would make this fail, or an empty line also.

Works

HiddenServiceDir /var/lib/tor/services/ssh
HiddenServiceVersion 3				
HiddenServicePort 22 127.0.0.1:22

Fail:

HiddenServiceDir /var/lib/tor/services/ssh
HiddenServiceVersion 3				

HiddenServicePort 22 127.0.0.1:22

Fail:

HiddenServiceDir /var/lib/tor/services/ssh
HiddenServiceVersion 3				
HiddenServicePort 22 127.0.0.1:22
#HiddenServicePort 80 127.0.0.1:80

before, this would fail even harder, as stated on the first port.
A fix for this will be done when I can imagine a proper solution.

A fix for this will be done when I can imagine a proper soluti

how, just how? It is not easy to know when to stop parsing.

I'm thinking of:

  • reading dump config to get the service block, service_block print "${service}" "${tor_dump_config_hs}" already does that.
  • then compare against the block found on the torrc.
  • maybe try to loop till the last line of the service block printed by service_block()?

problem is that the script creates and deletes correctly if there is no manual intervention on the hiddenservice block. There is no clean way to removing a block if user has made breaking changes to it.