Alte sitzungen beenden

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Hi es wäre toll wenn es einen Button geben würde wo man alte sitzungen mit einem Klick beenden könnte. Bei mir sind über 100 stk. drinne und jede einzeln zu löschen ist sehr anstrengend

English please, this is an international community!

My English ist not so good. I hope this is correttly

Hi, it would be great if there was a button where you could end old sessions with one click. I have over 100 pieces. inside and deleting each one individually is very tiring

Why do you have that much sessions?
maybe random mac with your smartphone in your wifi?
Greets

I have no idea. I mostly go in with the browser. I think if I don’t set the logout it will keep the connection open

Screenshot 2024-10-20 212931

Do you have your browser configured to delete all cookies when you close it? I think that could explain that behaviour.

yes it is. The cookies was all delete when browser close

If you now have disabled the cookies deletion, all you have to do is delete the old sessions. I cant’t help you with doing them all in one go however, sorry.

where is this in option to show all active sessions? cant find it in MainUI

open the ‘hamburger’ menu on the top left on your screen, that will give you the OpenHab menu. Now go to the lowest entry in the menu with the shield and the little lock symbol and unlock administration. When you’re logged in it wil give you the logged-in username. Now click on that and you’ll get an overview of active sessions.

ou wow… got sessions from 2022 :see_no_evil:

Have a look to the REST API.
You would need to write a small piece of code to kick them out using calls to /rest/auth/logout

Ok, and what would this code look like?

  • login to the REST API
  • query for existing sessions ( same that you see in the browser )
  • delete the old sessions and use the arguments that you got from previous call

This API is also used when you use the browser.

stop openhab, backup openhab and edit the user db

/var/lib/openhab/jsondb/users.json

Delete all entries contained in „sessions“ key.
You need to know what you are doing or at least understand the structure of json files.

i wrote a rule with RulesDSL

var jsonpath = sendHttpGetRequest ("http://user:password@192.168.0.9:8080/rest/auth/sessions")    //your openhab login and IP
var length = transform("JSONPATH", "$.length()", jsonpath)
var ilength = Integer::parseInt(length)
ilength = ilength - 5		            //How much sessions left over
val type = "application/x-www-form-urlencoded"
var	i = 0
while (i < ilength) {
	var sessionidpath = "$.[" + i + "].sessionId"
	var sessionid = transform("JSONPATH", sessionidpath, jsonpath)
	var data = "id="+sessionid.toString
	sendHttpPostRequest("http://user:password@192.168.0.9:8080/rest/auth/logout",type,data,5000)   //your openhab login and IP
	i=i+1
}

start this rule once per month with a cron timer and i think its ok.. Or put in scratchpad and run.
if you want you can put some Loginfo into it to see whats going on there..

Greets

    val type = "application/x-www-form-urlencoded"
    // val headers = newHashMap("Authorization" -> "Basic tokenvalbase64enc ?? ") //either 
    val headers = newHashMap("X-OPENHAB-TOKEN" -> "oh.scope.tokenval")   //or
    var jsonpath = sendHttpGetRequest ("http://yourip:8080/rest/auth/sessions",headers,5000)    //your openhab IP
    var length = transform("JSONPATH", "$.length()", jsonpath)
    var ilength = Integer::parseInt(length)
    ilength = ilength - 5		            //How much sessions left over
    
    var	i = 0
    while (i < ilength) {
        var sessionidpath = "$.[" + i + "].sessionId"
        var sessionid = transform("JSONPATH", sessionidpath, jsonpath)
        var data = "id="+sessionid.toString

        sendHttpPostRequest("http://yourip:8080/rest/auth/logout",type,data,headers,5000)   //your openhab IP
        i=i+1
    }

did the trick for me.

Thank you very much. It´s work :yum:

Here is the code with with Blockly.
@Thommy2012 Perhaps you can translate the topic into English so that others can find it? Maybe: How do I delete all sessions on the profile page?

image