Change listening port via WebUI JSON?

General support for problems installing or using Deluge
Post Reply
joekamel
New User
New User
Posts: 2
Joined: Fri May 20, 2022 4:13 am

Change listening port via WebUI JSON?

Post by joekamel »

Hello,

My goal is to be able to update via curl request sent to the webUI. Trying to set up a script on my pfsense box to update the listening port deluge when my VPN forwarded port changes. I've messed around with a couple different JSON methods listed in various docs, but no luck.

I tried some of the various API calls listed in a couple places:

https://buildmedia.readthedocs.org/medi ... deluge.pdf
https://deluge.readthedocs.io/en/latest ... ebapi.html

I also checked the links in this thread: viewtopic.php?t=54524

Which pointed me to wayback machine here: https://web.archive.org/web/20150423143 ... n_api.html

All with no luck

I've tried:

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "core.set_config", "params": [{"listen_port":51111}], "id": 6}' http://192.168.3.183:8112/json
And get the following response:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: TwistedWeb
Date: Fri, 20 May 2022 06:23:51 GMT
Content-Type: application/json
Set-Cookie: _session_id=5d975461fd0f20df9271722eeae4b3672671cadddce1812270c9ba44f7a306d04472; Expires=Fri, 20 May 2022 07:23:51 GMT; Path=/json

{"result": null, "error": null, "id": 6}
But no change to core.conf or the incoming port when I check in the webUI.

Am I using the wrong command? If so, is there a list anywhere?

Could really use some help from someone more knowledgeable. Thanks in advance.
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Change listening port via WebUI JSON?

Post by Cas »

The config key should be listen_ports with two values
joekamel
New User
New User
Posts: 2
Joined: Fri May 20, 2022 4:13 am

Re: Change listening port via WebUI JSON?

Post by joekamel »

Thank you. Not trying to be too much of an idiot here, but do you have an example of how the parameter field should be formatted? I haven't been able to find a way to do so, and every attempt I've tried I get JSON not decodable as an error.
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Change listening port via WebUI JSON?

Post by mhertz »

The 2 values should be in a list, so something like this:

Code: Select all

curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "core.set_config", "params": [{"listen_ports": [511113,511113]}], "id": 1}' http://localhost:8112/json                                            
Using e.g:

Code: Select all

curl -c cookies.txt -H "Content-Type: application/json" -d '{"method": "auth.login", "params": ["deluge"], "id": 1}' http://localhost:8112/json   
#curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "web.connected", "params": [], "id": 1}' http://localhost:8112/json 
#curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "web.get_hosts", "params": [], "id": 1}' http://localhost:8112/json                                                                              
#curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "web.get_host_status", "params": ["ADD-HOSTID-HERE"], "id": 1}' http://localhost:8112/json                                                         
curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "web.connect", "params": ["ADD-HOSTID-HERE"], "id": 1}' http://localhost:8112/json                                            
curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "core.set_config", "params": [{"listen_ports": [51113,51113]}], "id": 1}' http://localhost:8112/json                                            
#curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "core.get_config_value", "params": ["listen_ports"], "id": 1}' http://localhost:8112/json                                            
Edit: Sorry for typo of ports being 6 chars, fixed now. Also, obviously 'random_port' should be disabled, as enabled by default, or adding:

Code: Select all

curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "core.set_config", "params": [{"random_port": false}], "id": 1}' http://localhost:8112/json                                            
Or alternatively, keeping the default 'random_port' of 'true', and instead manipulate the specified random port:

Code: Select all

curl -b cookies.txt -H "Content-Type: application/json" -d '{"method": "core.set_config", "params": [{"listen_random_port": 51113}], "id": 1}' http://localhost:8112/json                                            
Last, personally i'd prefer no cookie file, just a var, so e.g.:

Code: Select all

cookie=$(curl -v -H "Content-Type: application/json" -d '{"method": "auth.login", "params": ["deluge"], "id": 1}' http://localhost:8112/json 2>&1 | grep Cookie | cut -d':' -f2)
curl -H "cookie: $cookie" -H "Content-Type: application/json" -d '{"method": "web.connect", "params": ["<HOSTID>"], "id": 1}' http://localhost:8112/json
curl -H "cookie: $cookie" -H "Content-Type: application/json" -d '{"method": "core.set_config", "params": [{"listen_ports": [51114,51114]}], "id": 1}' http://localhost:8112/json
Post Reply