| Both sides previous revision Previous revision Next revision | Previous revision |
| docs:guide-developer:ubus:session [2020/01/11 13:06] – stokito | docs:guide-developer:ubus:session [2020/02/02 15:13] (current) – [Example of manual session creation] stokito |
|---|
| |
| ^ Path ^ Procedure ^ Signature ^ Description ^ | ^ Path ^ Procedure ^ Signature ^ Description ^ |
| | ''session'' | ''create'' | ''{ "timeout": //timeout// }'' | Create a new session and return its ID, set the session timeout to ''//timeout//'' | | | ''session'' | ''create'' | ''{ "timeout": //timeout// }'' | Create a new session and return its ID, set the session timeout to ''//timeout//'' in seconds (set ''0'' for no expire) | |
| | ''session'' | ''list'' | ''{ "ubus_rpc_session": "//sid//" }'' | Dump session info specified by ''//sid//'', if no ID is given, list all sessions | | | ''session'' | ''list'' | ''{ "ubus_rpc_session": "//sid//" }'' | Dump session info specified by ''//sid//'', if no ID is given, list all sessions | |
| | ''session'' | ''grant'' | ''{ "ubus_rpc_session": "//sid//", "scope": "//scope//", | | ''session'' | ''grant'' | ''{ "ubus_rpc_session": "//sid//", "scope": "//scope//", |
| |
| **Note:** When using ubus over HTTP, setting ''ubus_rpc_session'' isn't allowed, it's automatically set to the calling session. | **Note:** When using ubus over HTTP, setting ''ubus_rpc_session'' isn't allowed, it's automatically set to the calling session. |
| | |
| | **Note:** Sessions are stored in memory so they will persist as long as ''rpcd'' is running |
| | |
| |
| ==== login call description ==== | ==== login call description ==== |
| |
| Use ''session.login'' to authorize and create a new session. The ''timeout'' argument is optional, it is set in seconds and by default is 5 minutes (300 seconds). | Use ''session.login'' to authorize and create a new session. The ''timeout'' argument is optional, it is set in seconds and by default is 5 minutes (300 seconds). |
| The session timeout is automatically reset on every use. | The session timeout is automatically reset on every use. |
| |
| } | } |
| } | } |
| </code> | </code> |
| |
| To list all active sessions call ''session list''. | To list all active sessions call ''session list''. |
| |
| |
| | ==== Example of manual session creation ==== |
| | Create a session then grant access to all functions of ''file'' and to the ''board'' object function of ''system'' object. |
| | Also set a custom attribute ''username'' to ''alice'' then check if the sid have an access to ''system.reboot'' function (and there is npo such access) |
| | <code> |
| | root@OpenWrt:~# ubus call session create '{"timeout": 3600}' |
| | { |
| | "ubus_rpc_session": "8c1af812b4b148fcbb92434c74cf61c1", |
| | "timeout": 3600, |
| | "expires": 3600, |
| | "acls": { |
| | |
| | }, |
| | "data": { |
| | |
| | } |
| | } |
| | root@OpenWrt:~# ubus call session grant '{"ubus_rpc_session": "bf11e5cd01cd262ae692600a6a45ccfc", "scope": "write", "objects": [["file", "*"], ["system", "board"]]}' |
| | root@OpenWrt:~# ubus call session set '{"ubus_rpc_session": "bf11e5cd01cd262ae692600a6a45ccfc", "values": { "username": "alice" } }' |
| | root@OpenWrt:~# ubus call session list '{"ubus_rpc_session": "bf11e5cd01cd262ae692600a6a45ccfc"}' |
| | { |
| | "ubus_rpc_session": "bf11e5cd01cd262ae692600a6a45ccfc", |
| | "timeout": 3600, |
| | "expires": 3600, |
| | "acls": { |
| | "ubus": { |
| | "file": [ |
| | "*" |
| | ], |
| | "system": [ |
| | "board" |
| | ] |
| | } |
| | }, |
| | "data": { |
| | "username": "alice" |
| | } |
| | } |
| | root@OpenWrt:~# ubus call session access '{ "ubus_rpc_session": "bf11e5cd01cd262ae692600a6a45ccfc", "scope": "ubus", "object": "system", "function": "reboot" }' |
| | { |
| | "access": false |
| | } |
| | </code> |
| |