In order to use EventSource web content's interface to server-sent events when ubus authentication is enabled, a session id has to be passed. Evensource interface does not allow to use bearer authentication header field. One of the possible solutions is to pass sid in url.
Signed-off-by: Wojciech Jowsa <[email protected]> --- ubus.c | 8 +++++++- uhttpd.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ubus.c b/ubus.c index cc7447e..06f5128 100644 --- a/ubus.c +++ b/ubus.c @@ -369,6 +369,10 @@ static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path) sid = uh_ubus_get_auth(cl->hdr.head); + if(!strcmp(sid, UH_UBUS_DEFAULT_SID) && du->sid != NULL) { + sid = du->sid; + } + if (!conf.ubus_noauth && !uh_ubus_allowed(sid, path, ":subscribe")) { uh_ubus_send_header(cl, 200, "OK", "application/json"); uh_ubus_posix_error(cl, EACCES); @@ -940,8 +944,10 @@ static void uh_ubus_handle_request(struct client *cl, char *url, struct path_inf return; } chr = strchr(du->url_path, '?'); - if (chr) + if (chr) { + du->sid = chr + 1; chr[0] = '\0'; + } du->legacy = false; diff --git a/uhttpd.h b/uhttpd.h index e61e176..99372be 100644 --- a/uhttpd.h +++ b/uhttpd.h @@ -211,6 +211,7 @@ struct dispatch_ubus { struct json_object *jsobj; struct json_object *jsobj_cur; char *url_path; + char *sid; int post_len; uint32_t obj; -- 2.25.1 _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
