summaryrefslogtreecommitdiff
path: root/main.c
AgeCommit message (Collapse)Author
2020-09-15ubus: add new RESTful APIRafał Miłecki
Initial uhttpd ubus API was fully based on JSON-RPC. That restricted it from supporting ubus notifications that don't fit its model. Notifications require protocol that allows server to send data without being polled. There are two candidates for that: 1. Server-sent events 2. WebSocket The later one is overcomplex for this simple task so ideally uhttps ubus should support text-based server-sent events. It's not possible with JSON-RPC without violating it. Specification requires server to reply with Response object. Replying with text/event-stream is not allowed. All above led to designing new API that: 1. Uses GET and POST requests 2. Makes use of RESTful URLs 3. Uses JSON-RPC in cleaner form and only for calling ubus methods This new API allows: 1. Listing all ubus objects and their methods using GET <prefix>/list 2. Listing object methods using GET <prefix>/list/<path> 3. Listening to object notifications with GET <prefix>/subscribe/<path> 4. Calling ubus methods using POST <prefix>/call/<path> JSON-RPC custom protocol was also simplified to: 1. Use "method" member for ubus object method name It was possible thanks to using RESTful URLs. Previously "method" had to be "list" or "call". 2. Reply with Error object on ubus method call error This simplified "result" member format as it doesn't need to contain ubus result code anymore. This patch doesn't break or change the old API. The biggest downside of the new API is no support for batch requests. It's cost of using RESTful URLs. It should not matter much as uhttpd supports keep alive. Example usages: 1. Getting all objects and their methods: $ curl http://192.168.1.1/ubus/list { "dhcp": { "ipv4leases": { }, "ipv6leases": { } }, "log": { "read": { "lines": "number", "stream": "boolean", "oneshot": "boolean" }, "write": { "event": "string" } } } 2. Getting object methods: $ curl http://192.168.1.1/ubus/list/log { "read": { "lines": "number", "stream": "boolean", "oneshot": "boolean" }, "write": { "event": "string" } } 3. Subscribing to notifications: $ curl http://192.168.1.1/ubus/subscribe/foo event: status data: {"count":5} 4. Calling ubus object method: $ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "login", "params": {"username": "root", "password": "password" } }' http://192.168.1.1/ubus/call/session { "jsonrpc": "2.0", "id": 1, "result": { "ubus_rpc_session": "01234567890123456789012345678901", (...) } } $ curl -H 'Authorization: Bearer 01234567890123456789012345678901' -d '{ "jsonrpc": "2.0", "id": 1, "method": "write", "params": {"event": "Hello world" } }' http://192.168.1.1/ubus/call/log { "jsonrpc": "2.0", "id": 1, "result": null } Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2020-02-15tls: support specifying accepted TLS ciphersJo-Philipp Wich
Introduce a new `-P` option which allows specifying a colon separated list of accepted TLS ciphers. Depending on the underlying ustream-ssl provider, the list either follows OpenSSL's cipher string format or, in case of mbedTLS, is a simple colon separated cipher whitelist. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-26uhttpd: fix building without TLS and Lua supportPaul Willoughby
Adds ifdefs to fix building without TLS and Lua support Signed-off-by: Paul Willoughby <paulw@spacemonkey.com>
2018-11-01help: document -A optionKarl Pálsson
It's one of the parameters used by default in LuCI, so it should be included in the help output. Signed-off-by: Karl Palsson <karlp@etactica.com>
2018-08-23build: avoid redefining _DEFAULT_SOURCEJo-Philipp Wich
Work around further glibc toolchain annoyances. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-23lua: support multiple Lua prefixesJo-Philipp Wich
Allow -l / -L arguments to be repeated to register multiple Lua prefix handlers in the same process. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-21build: use _DEFAULT_SOURCEJo-Philipp Wich
Add _DEFAULT_SOURCE FTM in order to avoid warnings with recent glibc. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2015-11-08add support for handling redirects via a scriptFelix Fietkau
In a json_script file you can specify rules for rewriting the URL or redirecting the browser either unconditionally, or as a fallback where it would otherwise print a 404 error Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2015-11-06main: sort getopt charactersFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2015-10-17add a -y parameter for cgi-bin redirectsJohn Crispin
this allows an alias entry inside the root folder point at a cgi-bin script -y foo=bar will redirect /foo to /cgi-bin/bar Signed-off-by: John Crispin <blogic@openwrt.org>
2015-05-30add support for enforcing HTTPSJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-09-03main: use proper variable when warning about unsupported featuresJo-Philipp Wich
Reported-by: Sebastian Apel <sebastian.apel@gmx.de> Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-06-10ubus: add CORS header supportJo-Philipp Wich
In order to support cross-domain AJAX requests to the /ubus endpoint we need to implement the Cross-Origin Resource Sharing (CORS) spec in the ubus plugin. - Implement a new option "-X" to enable CORS support in ubus - Implement rudimentary support for "OPTIONS" HTTP requests - Implement essential CORS headers the ubus plugin The current CORS response headers merely reflect the request headers sent by the client, this way any requesting origin is automatically allowed. Cross-domain cookies (Access-Control-Allow-Credentials) are unconditionally enabled. Restricting permitted origins and toggle the credential accepting can be made configurable in a future commit to allow more fine grained control over permitted AJAX clients. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-04-08fix handling of / as cgi prefixFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-22main: strdup command line arguments that are modifiedFelix Fietkau
This ensures that the process will show the correct command line in ps Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-22cgi: compare the physical path instead of the url to detect quirky urlsFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-11-11main: return after processing -d switchJo-Philipp Wich
2013-05-16uhttpd: allow the config to override the default index fileFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-04-17Accept square bracket notation for IPv6 addressesJo-Philipp Wich
2013-01-26set the docroot to the current working directory if none is specified, fixes ↵Jo-Philipp Wich
random null pointer dereferencing
2013-01-25ubus: add option to not authenticate ubus requestsJo-Philipp Wich
2013-01-23make arguments of not compiled functionality non-fatalJo-Philipp Wich
2013-01-19add support for deferring script requests, limit maximum number of script ↵Felix Fietkau
calls to 3, maximum number of connections to 100 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-13relicense to ISCFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-13add an option for configuring http keepaliveFelix Fietkau
2013-01-07add ubus supportFelix Fietkau
2013-01-04fix uninitialized variablesFelix Fietkau
2013-01-04add lua plugin supportFelix Fietkau
2013-01-04remove #ifdef HAVE_CGIFelix Fietkau
2013-01-04add basic tls support, todo: error handlingFelix Fietkau
2013-01-03clean up / fix #includeFelix Fietkau
2013-01-03fix compile errors on linuxFelix Fietkau
2013-01-02enable http keepalive again, it seems to work properly nowFelix Fietkau
2013-01-01add preliminary cgi support, needs fixing for close handlingFelix Fietkau
2013-01-01code cleanupFelix Fietkau
2012-12-31add default cgi prefixFelix Fietkau
2012-12-31add default value for conf.realmFelix Fietkau
2012-12-31set a default for script timeoutFelix Fietkau
2012-12-31exit if no sockets could be boundFelix Fietkau
2012-12-31add full usage help textFelix Fietkau
2012-12-30add forkingFelix Fietkau
2012-12-30add more command line optionsFelix Fietkau
2012-12-30add config parserFelix Fietkau
2012-12-30limit default max_requests to 3Felix Fietkau
2012-12-30Initial implementationFelix Fietkau