Set password in config file to authenticate with password instead of priv key.

This commit is contained in:
2018-10-22 20:27:25 +02:00
parent 499b0116e8
commit 4491e551c0
3 changed files with 18 additions and 5 deletions

View File

@@ -1,10 +1,11 @@
[Deluge]
HOST = YOUR_DELUGE_HOST
HOST = YOUR_DELUGE_HOST_IP
PORT = YOUR_DELUGE_PORT
USER = YOUR_DELUGE_USER
PASSWORD = YOUR_DELUGE_PASSWORD
[ssh]
HOST = YOUR_DELUGE_SERVER_IP
HOST = YOUR_SSH_HOST_IP
USER = YOUR_SSH_USER
PKEY = YOUR_SSH_PRIVATE_KEY_DIRECTORY
PKEY = YOUR_SSH_PRIVATE_KEY_DIR
PASSWORD = YOUR_SSH_PASSWORD

View File

@@ -96,6 +96,7 @@ class Deluge(object):
self.ssh_host = config['ssh']['HOST']
self.ssh_user = config['ssh']['USER']
self.ssh_password = config['ssh']['PASSWORD']
self.ssh_pkey = config['ssh']['PKEY']
self._connect()
@@ -110,8 +111,12 @@ class Deluge(object):
def _connect(self):
logger.info('Checking if script on same server as deluge RPC')
if (socket.gethostbyname(socket.gethostname()) != self.host):
self.tunnel = SSHTunnelForwarder(self.ssh_host, ssh_username=self.ssh_user, ssh_pkey=self.ssh_pkey,
local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
if (self.ssh_password):
self.tunnel = SSHTunnelForwarder(self.ssh_host, ssh_username=self.ssh_user, ssh_password=self.ssh_password,
local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
else:
self.tunnel = SSHTunnelForwarder(self.ssh_host, ssh_username=self.ssh_user, ssh_pkey=self.ssh_pkey,
local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
self.tunnel.start()
self.client = DelugeRPCClient(self.host, self.port, self.user, self.password)

7
test.py Normal file
View File

@@ -0,0 +1,7 @@
import deluge_cli
resp = deluge_cli.main('ls')
for el in list(resp):
print(el)
# print(resp)