The registrator
is a http webservice for assigning internal node numbers for freifunk (or other) mesh networks (aka. "ghetto dhcp").
You can reach the service somewhere else, but below is some help on how to use it.
The API is browser-, curl
-, wget
- and scripting-friendly:
JSON
-onlyHTTP
verbs and parameters, we use simple paths (i.e. GET /PUT/resource/item
, not PUT /resource/item
)HTTP
headers, we also use JSON
couchDB
as database backendconfig.sample.json
to config.json
and make your settings for couchDB
This is a knoten
:
{
"number": 178,
"ntwork_id_": "testnet",
"mac": "90f652c79eb0", // optional, defeats double-registration, is validated
"pass": "yoursecret", // never returned by API!
"created_at": 1361993339696 // set internally on registration!
"last_seen": 1361993339696 // set by sending 'heartbeat' to API!
}
This is a "reserved" knoten
:
{
"number": 178, // this number is reserved. it was created internally on startup.
"ntwork_id_": "testnet", // in the networks.config, every net can have a "reserved" array ( like [178])
"pass": "yoursecret", // "reserved" knoten have no pass - anyone can set it!
(…)
}
✓
Auto-Register a knoten:
$ MAC=f00; PASS="secret"
$ wget "http://reg.js.ars.is/POST/knoten?mac=$MAC&pass=$PASS"
Response:
{ "status" : 201, "msg" : "ok",
"result" : { "number" : "178", "mac" : "90f652c79eb0", "last_seen":1361996823533 }
}
✓
Update a knoten
("heartbeat"):
$ NR=178; $MAC=f00; $PASS="secret"
$ wget "http://reg.js.ars.is/PUT/knoten/$NR?mac=$MAC&pass=$PASS"
Response:
{ "status" : 200, "msg" : "ok",
"result" : { "number" : "178", "mac" : "90f652c79eb0", "last_seen":1361996823533 }
}
HTTP
JSON
POST /
=== GET /POST
)http
's){ "status": "514", "message": "I'm a teapot!" }
All methods deal with just one kind of resource (a single router, or "knoten"). It follows a list of applicable methods (or actions).
KNOTEN
Returns an array of all registered knoten.
/knoten
GET
curl "http://reg.js.ars.is/testnet/knoten"
Example response:
{
"status": 200,
"msg": "ok",
"result": [ 1, 2, 3 ]
}
KNOTEN
infoReturns an array of all registered knoten.
/knoten/:number
GET
curl "http://reg.js.ars.is/testnet/knoten/178"
Example response:
{
"status": 200,
"msg": "ok",
"result": {
"number": "178",
"mac": "xxxx",
"last_seen": 1362151832050
}
}
KNOTEN
/knoten
POST
MAC
, PASS
curl "http://reg.js.ars.is/POST/testnet/knoten?mac=12345&pass=secret"
Example response:
{ "status": 200,
"msg": "ok",
"result": {
"number": "2",
"mac": "12345",
"last_seen": 1362151832050
}
}
KNOTEN
("heartbeat")Marks the knoten "as seen" (so it will not be deleted from the pool).
If there is no knoten with the supplied number, the server may create it if all parameters are given (this enables costum registration with a wunsch-number).
If there is already a knoten with this number but no pass, it is a "reserved" number. The pass is set by whoever sends the first valid update.
/knoten/:number
PUT
MAC
, PASS
curl "http://reg.js.ars.is/PUT/testnet/knoten/178?mac=caffee&pass=secret"
Example response:
{ "status": 200,
"msg": "ok",
"result": {
"number": "178",
"mac": "caffee",
"last_seen" :1362151832050
}
}
Just a timestamp from the server. If we do our own DHCP
, why not NTP
as well… ;)
/time
GET
curl "http://reg.js.ars.is/GET/time"
Example response:
{ "now": 1362153043220 }
# wget works as well
# alias curl=wget
# register a new knoten
MAC="02caffeebabe"; PASS="mysecr3t"
curl "http://reg.js.ars.is/POST/testnet/knoten?mac=$MAC&pass=$PASS"
# > {"status":200,"msg":"ok","result":{"number":56,"mac":"1a2b3c4d5e6f7a8b9c","last_seen":1362248264834}}
# lets pretend the router lost power/connection/foo
# and did not get the answer. what happens?
# we send it again:
curl "http://reg.js.ars.is/POST/testnet/knoten?mac=$MAC&pass=$PASS"
# > {"status":303,"msg":"MAC already registered!","result":{"location":"/knoten/56","number":"56","mac":"1a2b3c4d5e6f7a8b9c"}}
# that is good for scripting. you can ignore the status
# since you will always get a valid "result" if possible.
# example:
MAC="anewmac12345678"; PASS="mysecr3t2"
curl "http://reg.js.ars.is/POST/testnet/knoten?mac=$MAC&pass=$PASS" | jq ".result.number"
# > 58
# (we do it again and get the same 303 error as before. but jq output the same info)
curl "http://reg.js.ars.is/POST/testnet/knoten?mac=$MAC&pass=$PASS" | jq ".result.number"
# > 58
# same goes for the heartbeat
# first, save our own number if we don't know yet or don't have one
MYNUMBER=$(curl "http://reg.js.ars.is/POST/testnet/knoten?mac=$MAC&pass=$PASS" | jq ".result.number")
echo $MYNUMBER
# > 58
# now send heartbeat
curl "http://reg.js.ars.is/PUT/testnet/knoten/$MYNUMBER?mac=$MAC&pass=$PASS"
# > {"status":200,"msg":"ok","result":{"number":"58","mac":"anewmac12345678","last_seen":1362248708614}}
# does not matter how often you send it
curl "http://reg.js.ars.is/PUT/testnet/knoten/$MYNUMBER?mac=$MAC&pass=$PASS"
# > {"status":200,"msg":"ok","result":{"number":"58","mac":"anewmac12345678","last_seen":1362248714726}}
curl "http://reg.js.ars.is/PUT/testnet/knoten/$MYNUMBER?mac=$MAC&pass=$PASS"
# > {"status":200,"msg":"ok","result":{"number":"58","mac":"anewmac12345678","last_seen":1362248716503}}
DB entry with just number, but no mac and pass? It's a "reserved" number. It won't be assigned by autoregistration, but anyone can capture the number by sending a valid heartbeat
.
This enables smooth migration from existing networks.
To "reserve" existing numbers, you could import these Knoten directly to the database:
KNOTEN="1 2 3 4 5"
NETWORK="YourNetworkName"
for NUMBER in $KNOTEN; do curl -X POST -H 'Content-Type: application/json' -d "{ \"_id\": \"knoten/network/$NETWORK/$NUMBER\", \"network_id\": \"$NETWORK\", \"resource\": \"knoten\"}" http://user:passwd@localhost:5984/registrator; done
This is a network (can only be set up manually):
{
"name": "testnet",
"active": true,
"public": true,
"url": "http://github.com/eins78/registrator",
"minimum": 2,
"maximum": 1000,
"lease_days": 30
}
Not implemented
render html on front page
give help
list networks
network pages
knoten
auto-update with socket.io