Skip to content

Commit

Permalink
Read scgi address & port from /root/.rtorrent.rc
Browse files Browse the repository at this point in the history
This allows choosing a not yet used port in rtorrent config to fix #14 & #22.
  • Loading branch information
wolandmaster committed Jun 27, 2021
1 parent e7fa1f2 commit 3ce483d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rTorrent frontend for OpenWrt's LuCI web interface
- RSS feed downloader (automatically download torrents that match the specified criteria)

## Screenshots
[luci-app-rtorrent 0.2.0](https://github.com/wolandmaster/luci-app-rtorrent/wiki/Screenshots)
[luci-app-rtorrent 0.2.0](https://github.com/wolandmaster/luci-app-rtorrent/wiki/Screenshots)

## Install instructions

Expand All @@ -33,7 +33,7 @@ opkg install rtorrent-rpc screen
directory = /path/to/downloads/
session = /path/to/session/
scgi_port = 127.0.0.1:5000
scgi_port = 127.0.0.1:6000
schedule2 = rss_downloader, 60, 300, ((execute.throw, /usr/lib/lua/rss_downloader.lua, --uci))
```
Expand All @@ -45,7 +45,7 @@ schedule2 = rss_downloader, 60, 300, ((execute.throw, /usr/lib/lua/rss_downloade
START=99
STOP=99
start() {
start() {
HOME=/root screen -dmS rtorrent nice -19 rtorrent
}
Expand Down
2 changes: 1 addition & 1 deletion control/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: luci-app-rtorrent
Version: 0.2.1
Version: 0.2.2
Depends: libc, rtorrent-rpc, luaexpat, luasocket, luasec, luci-compat, luci-lib-httpprotoutils
Source: https://github.com/wolandmaster/luci-app-rtorrent
Section: luci
Expand Down
1 change: 1 addition & 0 deletions control/postinst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
rm -fr /tmp/luci-indexcache* /tmp/luci-modulecache
[ -x ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
default_postinst $0 $@
27 changes: 14 additions & 13 deletions src/usr/lib/lua/rtorrent.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
-- Copyright 2014-2021 Sandor Balazsi <[email protected]>
-- Licensed to the public under the GNU General Public License.

local ipairs, string, tostring, tonumber, table = ipairs, string, tostring, tonumber, table
local assert, type, unpack = assert, type, unpack
local assert, ipairs, tostring, string, table, unpack = assert, ipairs, tostring, string, table, unpack

local nixio = require "nixio"
local fs = require "nixio.fs"
local socket = require "socket"
local xmlrpc = require "xmlrpc"
local scgi = require "xmlrpc.scgi"

local SCGI_ADDRESS = "localhost"
local SCGI_PORT = 5000
local rtorrent_config_file = "/root/.rtorrent.rc"

module "rtorrent"

function format(results, commands)
local function format(results, commands)
local formatted_results = {}
for _, result in ipairs(results) do
local formatted = {}
Expand All @@ -27,15 +25,18 @@ function format(results, commands)
end

function call(method, ...)
local ok, res = scgi.call(SCGI_ADDRESS, SCGI_PORT, method, ...)
local address, port = ("\n" .. tostring(fs.readfile(rtorrent_config_file)))
:match("\n%s*scgi_port%s*=%s*([^:]+):(%d+)")
assert(address, "\n\nError: scgi port not defined in your " .. rtorrent_config_file .. " config file!\n"
.. 'Please add to it, e.g.: "scgi_port = 127.0.0.1:6000".\n')
local ok, res = scgi.call(address, port, method, ...)
if not ok and res == "socket connect failed" then
assert(ok, "\n\nFailed to connect to rtorrent: rpc port not reachable!\n"
.. "Possible reasons:\n"
.. "- not the rpc version of rtorrent is installed\n"
.. "- scgi port is not defined in .rtorrent.rc (scgi_port = 127.0.0.1:5000)\n"
.. "- rtorrent is not running (ps | grep [r]torrent)\n")
assert(ok, "\n\nFailed to connect to rtorrent: rpc port not reachable"
.. " on " .. address .. ":" .. port .. "!\nPossible reasons:\n"
.. "- rtorrent is not running (ps w | grep [r]torrent)\n"
.. "- not the rpc version of rtorrent is installed\n")
end
assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res)))
assert(ok, string.format("\n\nXML-RPC call failed: %s!\n", tostring(res)))
return res
end

Expand Down

0 comments on commit 3ce483d

Please sign in to comment.