2 #include <QRandomGenerator>
65 , _tokendata(tokendata)
67 , _developerGroup(developerGroup)
68 , _pruneProbability(pruneProbability)
106 if (r->
_path ==
"preferences.rfm")
108 else if (r->
_path ==
"preferencesBase.rfm")
110 else if (r->
_path ==
"tokenauth")
127 if (r->
_path ==
"preferences.rfm")
137 r->
_data.setObject(p);
140 else if (r->
_path ==
"preferencesBase.rfm")
144 r->
_data.setObject(p);
147 else if (r->
_path ==
"tokenauth")
149 QJsonObject o = r->
_data.object();
150 QString token = o[
"authtoken"].toString(
"");
152 if (token.isEmpty() || token.contains(
"/"))
154 r->
_reason =
"No valid authtoken provided.";
164 rr->
_data.setObject(QJsonObject());
190 QDateTime exp = (
_ttl > 0 ) ? QDateTime::currentDateTimeUtc().addSecs(
_ttl-1 ) : QDateTime();
192 QJsonObject o = r->
_data.object();
195 if (o.contains(
"expire"))
196 exp.setSecsSinceEpoch( o[
"expire"].toInt()*60 );
198 QString user = o[
"username"].toString();
200 QString type = o[
"type"].toString();
201 QString authpath = o[
"authpath"].toString();
203 QString address = o[
"address"].toString();
204 QJsonObject parameters = o[
"parameters"].toObject();
205 QString token = o[
"authtoken"].toString(
"");
210 if (!token.isEmpty())
213 VFS_session *session =
new VFS_session(client,
this, user, type, home, authpath, exp, address, parameters, token);
259 VFS::WARN( r->
_reason = QString(
"Could not create a session for '%1'. Is the home directory writable?").arg(r->
_user) );
267 {
VFS::WARN( r->
_reason = QString(
"Unable to append session '%1'. Is the session name valid?").arg(sessionName) );
278 QJsonObject o = r->
_data.object();
281 QJsonObject authtoken;
282 authtoken[
"token"] = session->
authtoken();
284 o[
"authtoken"] = authtoken;
286 r->
_data.setObject(o);
297 QJsonObject o = r->
_data.object();
298 QJsonObject credentials = r->
_metadata[
"credentials"].toObject();
299 QString token = credentials[
"authtoken"].toString();
301 credentials.remove(
"authtoken");
302 credentials.remove(
"expire");
305 if (!token.isEmpty() && r->
_success)
307 int now = (qint32) (QDateTime::currentDateTimeUtc().toSecsSinceEpoch()/60);
308 int expire = o[
"expire"].toInt(0);
309 QString user = o[
"username"].toString(
"");
310 QString authpath = o[
"authpath"].toString(
"");
326 r->
_reason = QString(
"Invalid session data: missing user.");
328 else if (authpath.isEmpty())
331 r->
_reason = QString(
"Invalid session data: missing authpath.");
333 else if (expire < now)
336 r->
_reason = QString(
"Authtoken '%1' has expired.").arg(token);
344 credentials[
"username"] = user;
345 credentials[
"authtoken"] = token;
346 credentials[
"expire"] = expire;
347 credentials[
"authpath"] = authpath;
352 r->
_reason = QString(
"Invalid token: '%1'").arg(token);
356 r->
_data.setObject(credentials);
399 QUuid
id = QUuid::createUuid();
400 return id.toString(QUuid::WithoutBraces);
510 QJsonObject o = r->
_data.object();
519 QJsonObject o = r->
_data.object();
549 VFS::LOG( QString(
" Pruner checking: %1\n").arg(qUtf8Printable(p)),8,
"pruner");
571 if ( o[
"username"].toString(
"").isEmpty() )
return false;
572 if ( o[
"authpath"].toString(
"").isEmpty() )
return false;
574 int now = (qint32) (QDateTime::currentDateTimeUtc().toSecsSinceEpoch()/60);
576 if ( o[
"expire"].toInt(0) > now )
return false;
588 VFS::WARN( QString(
" Pruner pruning: %1\n").arg(qUtf8Printable(p)),8,
"pruner");
static char * get(QString which="")
Fetch an icon from the library.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="server")
Append a VFS_node as a child of this node.
virtual VFS_request * createRequest(VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
Create a new VFS_request with this object as _origin.
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
Q_INVOKABLE VFS_node()
The VFS_node constructor will add its instance to the VFS_node::__allNodes global node registry,...
QString uniqueChildName(QString name)
Generate a unique child name.
virtual void issueRequest(VFS_request *t)
A convenience function.
VFS_node * find(QString path)
Find a node by string path.
virtual void ls(VFS_request *r)
List the contents of this node.
QString className()
Return the class name of a node.
virtual void receiveResponse(VFS_request *t)
Once a VFS_request has been completed, a response will be issued back to its _origin.
The base class for all requests between nodes.
@ read
read full contents (4)
@ ls
list children of a node (1)
@ create
create a new file/path (2)
@ rm
delete an existing file/path (3)
VFS_node * _origin
the origin of the request
requestType _requestType
the action this request is performing or requesting
QString _initialPath
the target path when the request was made (relative to the responder)
QString _user
who initiated this request, mostly for logging
VFS_session * _session
The session associated with this request. This is an optional value, and care should be taken to chec...
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
virtual VFS_request * getCallback(VFS_node *receiver)
Create and chain a VFS_request for a receiver.
QJsonObject _metadata
the request payload
The VFS_session object represents a single session.
virtual void initializeUser(VFS_request *r)
Check and create session files for a user.
qint64 secondsToExpire()
Given the current time, calculate the number of seconds until this session will expire.
bool isMemberOf(QString group)
Check if this session's group list includes the specified group.
QString authtoken()
Return the file component of the _authtoken path.
static void initializeTypes()
Initialize the VFS_session::_sessionTypes member.
VFS_sessionTokenPruner _pruner
Our pruner.
QString _cwd
The VFS path of this node.
virtual void receiveResponse(VFS_request *t)
VFS_sessionManager::receiveResponse.
Q_INVOKABLE VFS_sessionManager(QString cwd, QString userdata, qint64 ttl, QString tokendata="", QString developerGroup="", double pruneProbability=0.1)
Create a session node, whose job is to return session data for a user.
qint64 _ttl
Number of seconds for sessions to live once created (time to live)
virtual void read(VFS_request *r)
Read from the sessionManager.
QString _tokendata
A VFS path to store session tokens.
virtual VFS_node * find(VFS_request *r)
Find a node using a VFS_request.
VFS_node * _sessions
A VFS_node to hold current sessions.
double _pruneProbability
The probability that a prune will happen.
virtual void write(VFS_request *r)
Write to the session manager to create a session.
QString _userdata
A VFS path to store user data.
QString _developerGroup
Name of the group used for development mode. Members of this group will have additional preferences a...
QString generateAuthtoken()
Generate a new unique authtoken for this session.
virtual QByteArray icon()
Return the user icon from VFS_icons.
virtual ~VFS_sessionManager()
virtual QString getCWD()
Return the manager's _cwd value.
virtual QString reportDetails()
Return information about any current sessions.
void pruneTokens()
Run a session token prune on a separate thread.
VFS_sessionTokenPruner(QString path)
Create a VFS_sessionTokenPruner.
void pruneEntry(QString p)
Request to remove a token entry.
virtual void receiveResponse(VFS_request *t)
Receive a response on a pruner request.
QString _path
The VFS path to prune.
QStringList _pathList
The list of paths remaining to check.
bool checkEntry(QJsonObject e)
Check a token entry for validity.
bool running()
Return the _running state of the pruner.
void stop()
Stop the prune operation if it is running.
virtual ~VFS_sessionTokenPruner()
Destroy the pruner.
void peel()
Remove a path from the stack or stop processing if empty.
bool run()
Attempt to run the prune operation.
bool _running
The running state of the pruner.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
getter path
a getter DOCME
QJsonObject jsonResource(QString resource, bool *ok=nullptr)
Fetch the contents of a Qt resource as a QJsonObject.