Remoto - VFS: sessionsList.cpp Source File
Remoto - VFS
sessionsList.cpp
Go to the documentation of this file.
1 
2 #include "VFS.h"
3 #include "VFS_icons.h"
4 #include "VFS_acl.h"
5 #include "utilities/rutils.h"
6 
7 #include "sessionsList.h"
8 
18 sessionsList::sessionsList(QString authPaths, QString sessions)
20 , _authPaths(authPaths.split(","))
21 , _sessionsPath(sessions+"/sessions")
22 {
23  _authPaths.replaceInStrings(QRegExp("\\s+(.*)"),"\\1"); //trim the auth paths
24  _authPaths.replaceInStrings(QRegExp("(.*)\\s+"),"\\1"); //trim the auth paths
25 }
26 
28 {
29 }
30 
36 {
37 }
38 
45 {
46  return false;
47 }
48 
54 QByteArray sessionsList::icon()
55 {
56  return "data:image/svg+xml;utf8,<svg class=\"menuIcon\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\"><g id=\"ldap\"><path fill=\"rgb(255,255,255)\" class=\"iconWhite\" d=\"M27.92,16.07a11.16,11.16,0,0,0-3.14-.85,4.45,4.45,0,0,1-5.44,0c-5.88.9-7,4.62-7,9.06H23.93c.17-.16.35-.31.52-.48A11.46,11.46,0,0,0,27.92,16.07Z\"/><ellipse fill=\"rgb(255,255,255)\" class=\"iconWhite\" cx=\"22.03\" cy=\"9.9\" rx=\"4.89\" ry=\"5.49\"/><path fill=\"rgb(27,186,217)\" class=\"iconColor\" d=\"M12.71,15.22a4.45,4.45,0,0,1-5.44,0,10.52,10.52,0,0,0-3.18,1,11.46,11.46,0,0,0,3.46,7.62c.17.17.35.32.52.48H19.7C19.7,19.82,19,16.07,12.71,15.22Z\"/><ellipse fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"9.97\" cy=\"9.9\" rx=\"4.89\" ry=\"5.49\"/><ellipse cx=\"16.23\" cy=\"13.18\" rx=\"4.89\" ry=\"5.49\"/><path d=\"M19,18.5a4.45,4.45,0,0,1-5.44,0c-3.84.59-5.66,2.38-6.46,4.78.16.17.31.35.48.52A11.53,11.53,0,0,0,16,27.34a11.51,11.51,0,0,0,8.45-3.5,13.15,13.15,0,0,0,.91-1C24.57,20.63,22.82,19,19,18.5Z\"/></g></svg>";
57  // return VFS_icons::get("users");
58 }
59 
61 {
62  QJsonObject a;
63  r->_metadata["icon"] = QString(icon());
64 
65  QJsonObject f;
66  f["terminate"] = VFS_acl::checkAllowAccess(r,"terminate");
67  f["manage"] = VFS_acl::checkAllowAccess(r,"manage");
68  f["showall"] = VFS_acl::checkAllowAccess(r,"showall");
69  r->_metadata["features"] = f;
70 
71  a["type"] = "openLayout";
72  r->_metadata["action"] = a;
73 
74  QJsonObject l = rutils::jsonResource(":/admin/templates/basicLayout.json");
75  l["icon"] = "@icon@";
76  QJsonObject t;
77  t["openLayout"] = l;
78 
79  r->_metadata["template"] = t;
80  r->_metadata["where"] = "nearest";
81  r->_metadata["type"] = "sessionsList:sessionsList.js";
82  r->_success = true;
83 }
84 
86 {
87  if (!_authPaths.length())
88  { r->_reason = "No authpaths found. Can't list users.";
89  r->_success = false;
90  return;
91  }
92 
93  r->_metadata["authindex"] = 0;
94  r->_metadata["sessionsPath"] = _sessionsPath;
95 
96  VFS_request *s = r->getCallback(this);
97  s->_path = s->_initialPath = _authPaths[0];
99  //printf("read request: %s\n",qUtf8Printable(_authPaths[0]));
100  issueRequest(s);
101 
102  //VFS_request *s = createRequest(VFS_request::ls, _authPaths[0], r->_user, r->_data, r->_metadata );
103  //issueRequest(s);
104  //delete r;
105 }
106 
115 {
116  //FIXME: this shows more responses than it should because of the callback chains.
117  //printf("RECV READ or SUBSCRIBE: %d\n",r->_requestType);
118 
119  if (r->_success)
120  switch(r->_requestType)
121  {
122  case VFS_request::ls: {
123  if (!r->_metadata.contains("authindex"))
124  { r->_success = false;
125  r->_reason = "sessions: invalid or no authindex present.";
126  }
127 
128  int i = r->_metadata.value("authindex").toInt();
129  i++;
130 
131  if (i < _authPaths.length())
132  {
134  s->_metadata["authindex"] = i;
135  s->_session = r->_session;
137  if (r->_callback)
138  s->setCallback(r->_callback);
139  //printf("read request: %s\n",qUtf8Printable(_authPaths[i]));
140  issueRequest(s);
141  delete r;
142 
143  return;
144  }
145  }
146  break;
147 
148  default: break;
149  }
150 
152 }
153 
154 
163 QString sessionsList::code(QString nodename, QString libname, QString &error)
164 {
165  if (libname == "sessionsList.js")
166  return rutils::resourceContents(":/admin/html/sessionsList.js");
167 
168  if (libname == "sessionsList.css")
169  return rutils::resourceContents(":/admin/html/sessionsList.css");
170 
171  return VFS_application::code(nodename,libname,error);
172 }
173 
180 {
181  QJsonObject acl;
182 
183  addACLDefault( acl, true );
184  addACLFeature( acl, "terminate", false, "Allow termination of user sessions.");
185  addACLFeatureGroup( acl, "terminate", "developer", true );
186  addACLFeatureGroup( acl, "terminate", "admin", true );
187  addACLFeature( acl, "manage", false, "Allow management of user session data.");
188  addACLFeatureGroup( acl, "manage", "developer", true );
189  addACLFeatureGroup( acl, "manage", "admin", true );
190  addACLFeature( acl, "showall", false, "Show all users, not just those that have a session.");
191  addACLFeatureGroup( acl, "showall", "developer", true );
192  addACLFeatureGroup( acl, "showall", "admin", true );
193 
194  r->_data.setObject(acl);
195  r->_success = true;
196 }
static bool checkAllowAccess(VFS_session *s, QString path, QString feature="")
Check if a session has access to a resource.
Definition: VFS_acl.cpp:407
A common base class for all things that want to act like an application or include ACL support.
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.
Definition: VFS_node.cpp:1913
virtual void issueRequest(VFS_request *t)
A convenience function.
Definition: VFS_node.cpp:1933
void addACLFeature(QJsonObject &acl, QString feature, bool value, QString description="")
Add a feature to the acl object.
Definition: VFS_node.cpp:2183
static QString code(QString nodename, QString libname, QString &error)
Fetch code or any other resource from a node.
Definition: VFS_node.cpp:1038
void addACLFeatureGroup(QJsonObject &acl, QString feature, QString group, bool value)
Add a feature group to the acl object.
Definition: VFS_node.cpp:2205
void addACLDefault(QJsonObject &acl, bool value, QString description="")
Add a default value to the acl object.
Definition: VFS_node.cpp:2131
virtual void receiveResponse(VFS_request *t)
Once a VFS_request has been completed, a response will be issued back to its _origin.
Definition: VFS_node.cpp:1870
The base class for all requests between nodes.
Definition: VFS_node.h:54
@ ls
list children of a node (1)
Definition: VFS_node.h:65
virtual void setCallback(VFS_request *c)
Chain a callback onto this request.
Definition: VFS_node.cpp:286
requestType _requestType
the action this request is performing or requesting
Definition: VFS_node.h:87
QString _initialPath
the target path when the request was made (relative to the responder)
Definition: VFS_node.h:93
QString _user
who initiated this request, mostly for logging
Definition: VFS_node.h:106
VFS_session * _session
The session associated with this request. This is an optional value, and care should be taken to chec...
Definition: VFS_node.h:105
QString _reason
if something (probably bad) happened, this is the reason
Definition: VFS_node.h:108
QString _path
the target path remnant... the remaining path element once the request has found its target
Definition: VFS_node.h:95
QList< notifyException > _notifyExceptions
a list of nodes not to send responses to for this transaction. For instance if a node submits to a no...
Definition: VFS_node.h:110
bool _success
if the request was successfully completed
Definition: VFS_node.h:107
QJsonDocument _data
the request payload
Definition: VFS_node.h:102
virtual VFS_request * getCallback(VFS_node *receiver)
Create and chain a VFS_request for a receiver.
Definition: VFS_node.cpp:316
VFS_request * _callback
request to execute once this request completes
Definition: VFS_node.h:97
QJsonObject _metadata
the request payload
Definition: VFS_node.h:101
QStringList _authPaths
The VFS_auth paths to report on.
Definition: sessionsList.h:40
bool isContainer()
This always returns false.
virtual ~sessionsList()
virtual void aclDefaults(VFS_request *r)
Return the ACL defaults for this node.
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
virtual void initialize()
Initialize the sessions application.
Q_INVOKABLE sessionsList(QString authPaths, QString sessions)
The sessions constructor.
virtual QByteArray icon()
Return the users icon from VFS_icons.
virtual void receiveResponse(VFS_request *t)
Receive a response from an issued VFS_request.
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
QString _sessionsPath
The VFS_sessions to report for active logins.
Definition: sessionsList.h:41
static QString code(QString nodename, QString libname, QString &error)
Fetch code from this node.
setter error
Set the error value of this widget.
QJsonObject jsonResource(QString resource, bool *ok=nullptr)
Fetch the contents of a Qt resource as a QJsonObject.
Definition: rutils.cpp:90
QByteArray resourceContents(QString resource, bool *ok=nullptr, bool squashHash=false)
Fetch the contents of a Qt resource file.
Definition: rutils.cpp:53