Skip to content

Commit

Permalink
Add option for unix-socket in config.yml
Browse files Browse the repository at this point in the history
Add configuration option to allow using unix-socket to connect
with the daemonized telegram-cli (i.e.  using the command `telegram-cli -d -S
/var/run/telegram.sock`).

If null value is set for the socket pack the TCP connection is used.
If a path is set for the socket TCP connection options are ignored.

WHY: With unix-socket running telegram-cli as a daemon is more secure.
With tpc connection the interface to user personal data served by telegram-cli
is accessible system wide.
With unix-socket user can set specific privileges on the socket
and thus restrict the access to that interface.
  • Loading branch information
tmmsartor committed Dec 2, 2016
1 parent cc492bd commit a8a902a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@

## Technical options ##

# Use a unix socket to communicate with telegram-cli
# Should match the path passed to telegram-cli with the -S option
#
# NB: Setting tg_sock to some not false value will cause the script
# to ignore the next options about TCP connection

# tg_sock: "/var/run/telegram.sock"
tg_sock: null

# Address of the machine you are running telegram-cli on
# If this is not localhost telegram-cli must be invoked with --accept-any-tcp
tg_host: 'localhost'
Expand Down
12 changes: 9 additions & 3 deletions telegram-history-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@

def connect_socket
return if defined?($sock) && $sock
$log.info('Attaching to telegram-cli control socket at %s:%d' %
[$config['tg_host'], $config['tg_port']])
$sock = TCPSocket.open($config['tg_host'], $config['tg_port'])

if $config['tg_sock']
$log.info('Attaching to telegram-cli control socket at /var/run/telegram.sock')
$sock = UNIXSocket.new($config['tg_sock'])
else
$log.info('Attaching to telegram-cli control socket at %s:%d' %
[$config['tg_host'], $config['tg_port']])
$sock = TCPSocket.open($config['tg_host'], $config['tg_port'])
end
end

def disconnect_socket
Expand Down

0 comments on commit a8a902a

Please sign in to comment.