@@ -1458,6 +1458,7 @@ static void GetURICommandParameter(const std::string &uri, std::string &cmdparam
1458
1458
bool cWebemRequestHandler::CheckAuthentication (WebEmSession & session, const request& req, reply& rep)
1459
1459
{
1460
1460
session.rights = -1 ; // no rights
1461
+ session.id = " " ;
1461
1462
1462
1463
if (myWebem->m_userpasswords .size () == 0 )
1463
1464
{
@@ -1584,7 +1585,7 @@ bool cWebemRequestHandler::CheckAuthentication(WebEmSession & session, const req
1584
1585
}
1585
1586
}
1586
1587
1587
- if (session.rights == 2 )
1588
+ if (( session.rights == 2 ) && (session. id . empty ()) )
1588
1589
{
1589
1590
session.isnew = true ;
1590
1591
return true ;
@@ -1994,14 +1995,44 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
1994
1995
// Set timeout to make session in use
1995
1996
session.timeout = mytime (NULL ) + SHORT_SESSION_TIMEOUT;
1996
1997
1997
- if (session.isnew == true ) {
1998
- bool isJson = (req.uri .find (" json.htm" ) != std::string::npos);
1999
- if (isJson && (session.remote_host == " 127.0.0.1" ))
1998
+ if ((session.isnew == true ) && (session.rights == 2 ) && (req.uri .find (" json.htm" ) != std::string::npos))
1999
+ {
2000
+ // client is possibly a script that does not send cookies - see if we have the IP address registered as a session ID
2001
+ WebEmSession* memSession = myWebem->GetSession (session.remote_host );
2002
+ time_t now = mytime (NULL );
2003
+ if (memSession != NULL )
2000
2004
{
2001
- // never create sessions for script connections that originate from localhost
2002
- return ;
2005
+ if (memSession->expires < now)
2006
+ {
2007
+ myWebem->RemoveSession (session.remote_host );
2008
+ }
2009
+ else
2010
+ {
2011
+ session.isnew = false ;
2012
+ if (memSession->expires - (SHORT_SESSION_TIMEOUT / 2 ) < now)
2013
+ {
2014
+ memSession->expires = now + SHORT_SESSION_TIMEOUT;
2015
+
2016
+ // unsure about the point of the forced removal of 'live' sessions and restore from
2017
+ // database but these 'fake' sessions are memory only and can't be restored that way.
2018
+ // Should I do a RemoveSession() followed by a AddSession()?
2019
+ // For now: keep 'timeout' in sync with 'expires'
2020
+ memSession->timeout = memSession->expires ;
2021
+ }
2022
+ }
2023
+ }
2024
+
2025
+ if (session.isnew == true ) {
2026
+ // register a 'fake' IP based session so we can reference that if the client returns here
2027
+ session.id = session.remote_host ;
2028
+ session.rights = -1 ; // predictable session ID must have no rights
2029
+ session.expires = session.timeout ;
2030
+ myWebem->AddSession (session);
2031
+ session.rights = 2 ; // restore session rights
2003
2032
}
2033
+ }
2004
2034
2035
+ if (session.isnew == true ) {
2005
2036
_log.Log (LOG_STATUS," Incoming connection from: %s" , session.remote_host .c_str ());
2006
2037
// Create a new session ID
2007
2038
session.id = generateSessionID ();
@@ -2012,11 +2043,8 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
2012
2043
}
2013
2044
session.auth_token = generateAuthToken (session, req); // do it after expires to save it also
2014
2045
session.isnew = false ;
2015
- // GB3 Todo: need sane way to keep track of scripts running on other hosts
2016
- if (!isJson)
2017
- myWebem->AddSession (session);
2046
+ myWebem->AddSession (session);
2018
2047
send_cookie (rep, session);
2019
-
2020
2048
} else if (session.forcelogin == true ) {
2021
2049
#ifdef DEBUG_WWW
2022
2050
_log.Log (LOG_STATUS, " [web:%s] Logout : remove session %s" , myWebem->GetPort ().c_str (), session.id .c_str ());
0 commit comments