Contents

Setup Trac with XML-RPC/JSON-RPC plugin on Linux in 5 minutes

Install Trac & simple setup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# ref: https://github.com/edgewall/trac/blob/trunk/INSTALL.rst
pip2 install Trac  # installs trac-admin and tracd

mkdir -p ~/work/trac-test/

trac-admin --help
trac-admin ~/work/trac-test/ initenv  # enter (My Project), enter (sqlite:db/trac.db)

tracd --help

# ref: http://localhost:8000/wiki/TracStandalone#UsingAuthentication
touch ~/work/trac-test/.htpass
htpasswd ~/work/trac-test/.htpass admin  # New password: 1
htpasswd ~/work/trac-test/.htpass user0  # New password: 1
cat ~/work/trac-test/.htpass
# example:
# admin:$apr1$o5/zHFun$D37IY76DeiSPNFQ61Lb83.
# user0:$apr1$ZKPNxUQN$9mSHbW3ENYDsqG8eLaQbf0

tracd --port 8000 -s --basic-auth="trac-test,$HOME/work/trac-test/.htpass,realm" ~/work/trac-test/
# -s: single:
#   without -s (multi project):  http://localhost:8000/trac-test/wiki/WikiStart
#   with    -s (single project): http://localhost:8000/wiki/WikiStart
curl http://localhost:8000/wiki/WikiStart

# http://localhost:8000/wiki/TracInstall#ConfiguringAuthentication
trac-admin ~/work/trac-test/ help
trac-admin ~/work/trac-test/ permission --help
trac-admin ~/work/trac-test/ permission list  # user0 not appear
trac-admin ~/work/trac-test/ permission add admin TRAC_ADMIN
trac-admin ~/work/trac-test/ permission add user0 TRAC_ADMIN
trac-admin ~/work/trac-test/ permission list  # user0 TRAC_ADMIN

Install XML-RPC Plugin RPC

Official repository is broken

As of 2020-01-24, official repository is broken on latest Trac (1.4.2). If we do pip2 install svn+https://trac-hacks.org/svn/xmlrpcplugin/trunk, http://localhost:8000/login/rpc will shows error:

/trac-json-rpc/2020-05-26-18-10-06.png
XML-RPC plugin in official repository is broken

This is known BUG. As in this BUG ticket, Gasol Wu fixed this issue in their repository, which can be installed by pip2 install svn+https://github.com/Gasol/trac-xmlrpcplugin/branches/trac-1.5/trunk#egg=TracXMLRPC. Here we use it.

1
2
3
4
5
6
7
pip2 install svn+https://github.com/Gasol/trac-xmlrpcplugin/branches/trac-1.5/trunk#egg=TracXMLRPC

trac-admin ~/work/trac-test/ config --help
trac-admin ~/work/trac-test/ config set components 'tracrpc.*' enabled
trac-admin ~/work/trac-test/ config get components 'tracrpc.*'  # enabled
cat ~/work/trac-test/conf/trac.ini | grep rpc  # tracrpc.* = enabled
trac-admin ~/work/trac-test/ permission add authenticated XML_RPC

Now we can access http://localhost:8000/login/rpc :

/trac-json-rpc/2020-05-26-18-13-09.png
http://localhost:8000/login/rpc

1
2
pip3 install httpie
http -v --auth user0:1 POST http://localhost:8000/login/rpc method=wiki.getPage params:='["WikiStart"]'

output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
POST /login/rpc HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Authorization: Basic d3NoOjE=
Connection: keep-alive
Content-Length: 51
Content-Type: application/json
Host: localhost:8000
User-Agent: HTTPie/2.3.0

{
    "method": "wiki.getPage",
    "params": [
        "WikiStart"
    ]
}


HTTP/1.1 200 OK
Content-Length: 1662
Content-Type: application/json
Date: Wed, 27 Jan 2021 12:01:53 GMT
Server: tracd/1.4.2 Python/2.7.18

{
    "error": null,
    "id": null,
    "result": "= Welcome to Trac\n\nTrac is a '''minimalistic''' approach to '''web-based''' management of\n'''software projects'''. Its goal is to simplify effective tracking and\nhandling of software issues, enhancements and overall progress.\n\nAll aspects of Trac have been designed with the single goal to\n'''help developers write great software''' while '''staying out of the way'''\nand imposing as little as possible on a team's established process and\nculture.\n\nAs all Wiki pages, this page is editable, this means that you can\nmodify the contents of this page simply by using your\nweb-browser. Simply click on the \"Edit this page\" link at the bottom\nof the page. WikiFormatting will give you a detailed description of\navailable Wiki formatting commands.\n\n\"[wiki:TracAdmin trac-admin] ''yourenvdir'' initenv\" created\na new Trac environment, containing a default set of wiki pages and some sample\ndata. This newly created environment also contains\n[wiki:TracGuide documentation] to help you get started with your project.\n\nYou can use [wiki:TracAdmin trac-admin] to configure\n[http://trac.edgewall.org/ Trac] to better fit your project, especially in\nregard to ''components'', ''versions'' and ''milestones''.\n\n\nTracGuide is a good place to start.\n\nEnjoy! [[BR]]\n''The Trac Team''\n\n== Starting Points\n\n * TracGuide --  Built-in Documentation\n * [http://trac.edgewall.org/ The Trac project] -- Trac Open Source Project\n * [http://trac.edgewall.org/wiki/TracFaq Trac FAQ] -- Frequently Asked Questions\n * TracSupport --  Trac Support\n\nFor a complete list of local wiki pages, see TitleIndex.\n"
}

JSON-RPC quick tutorial

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.listMethods
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodHelp      params:='["system.listMethods"]'
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodHelp      params:='["system.methodHelp"]'
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodHelp      params:='["system.methodSignature"]'
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodSignature params:='["system.listMethods"]'      # (ret)array
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodSignature params:='["system.methodHelp"]'       # (ret)string, (arg)string
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.methodSignature params:='["system.methodSignature"]'  # (ret)array,  (arg)string
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=system.getAPIVersion  # 1.1.9

http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=ticket.getActions params:='[1]'  # leave resolve reassign accept
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=ticket.get params:='[1]'
http -v --verify=no --auth user0:1 POST http://localhost:8000/login/rpc method=ticket.getTicketFields