24 using namespace boost;
32 if (
m_conf->
get(
"global",
"enable_compression",
"true") ==
"true") {
36 LOG(
INFO) <<
"WsFsDaemon::WsFsDaemon() : Compression is enabled";
50 LOG(
DEBUG) <<
"WsFsDaemon::workerRoutine : starting new worker";
52 sock.connect (
"inproc://workers");
73 send(sock,
"notlogged");
76 }
catch (zmq::error_t err) {
77 LOG(
ERROR) <<
"WsFsDaemon::bind() : Error listening " << err.what();
88 LOG(
ERROR) <<
"WsFsDaemon::bind() : Could not update WsFileSystemTree";
92 string protocol =
m_conf->
get(
"global",
"protocol",
"tcp");
93 string host =
m_conf->
get(
"global",
"host",
"127.0.0.1");
94 string port =
m_conf->
get(
"global",
"port",
"5555");
99 LOG(
INFO) <<
"WsFsDaemon::bind() : Binding server using " << protocol <<
" on " << host <<
":" << port;
100 clients.bind((protocol +
"://" + host +
":" + port).c_str());
101 }
catch (zmq::error_t err) {
102 LOG(
ERROR) <<
"WsFsDaemon::bind() : Cannot bind socket : " << err.what();
105 socket_t workers(*
m_context, ZMQ_DEALER);
106 workers.bind(
"inproc://workers");
111 for (
int thread_nbr = 0; thread_nbr != numWorkers; thread_nbr++) {
115 zmq::proxy (clients, workers, NULL);
116 LOG(
INFO) <<
"WsFsDaemon::bind() : Binding server Success !";
131 if (memcpy ((
void*) reply.data (), data, r) == NULL) {
132 LOG(
ERROR) <<
"WsFsDaemon::send() : Could not memcpy in Server";
137 if (sock.send (reply) < 0) {
138 LOG(
ERROR) <<
"WsFsDaemon::send() : Could not send on socket ";
143 message_t reply(s.length());
144 if (memcpy ((
void*) reply.data (), s.c_str(), s.length()) == NULL) {
145 LOG(
ERROR) <<
"WsFsDaemon::send() : Could not memcpy in Server";
148 if (sock.send (reply) < 0) {
149 LOG(
ERROR) <<
"WsFsDaemon::send() : Could not send on socket ";
153 }
catch (zmq::error_t err) {
154 LOG(
ERROR) <<
"WsFsDaemon::send() : Error sending " << err.what();
164 if (sock.recv (&request) < 0) {
165 LOG(
ERROR) <<
"WsFsDaemon::receive() : Could not receive on socket";
169 }
catch (zmq::error_t err) {
170 LOG(
ERROR) <<
"WsFsDaemon::send() : Error sending " << err.what();
182 if (!reader.parse(s, root,
false)) {
183 LOG(
ERROR) <<
"WsFsDaemon::parse() : Could not parse received input";
192 if (v == Value::null) {
193 LOG(
ERROR) <<
"WsFsDaemon::handleRequest() : Could not find request type";
200 int requestType = v.asInt();
201 LOG(
INFO) <<
"WsFsDaemon::handleRequest() : Received request : " << requestType <<
" from user " << uid <<
" ip " << ip;
203 if (requestType ==
Auth)
207 LOG(
ERROR) <<
"WsFsDaemon::handleRequest() : User is not logged " << uid <<
" ip " << ip <<
" request : " << requestType;
210 switch (requestType) {
269 LOG(
ERROR) <<
"WsFsDaemon::handleRequest() : Undefined request type " << requestType;
284 LOG(
DEBUG) <<
"WsFsDaemon::handleAuthRequest() : Session active for " << uid;
290 return send(sock, answer.toStyledString());
292 LOG(
INFO) <<
"WsFsDaemon::handleAuthRequest() : Received authentification request from user " << uid;
305 groups.insert(c.
getUid());
312 LOG(
INFO) <<
"WsFsDaemon::handleAuthRequest() : new uid is " << c.
getUid();
313 return send(sock, answer.toStyledString());
321 set<string> groups =
m_userMap[uid]->getGroups();
339 set<string> groups =
m_userMap[uid]->getGroups();
343 return send(sock, boost::lexical_cast<string>(perms));
366 set<string> groups =
m_userMap[uid]->getGroups();
371 return send(sock, answer->
getRoot().toStyledString());
383 set<string> groups =
m_userMap[uid]->getGroups();
386 return send(sock, answer);
396 set<string> groups =
m_userMap[uid]->getGroups();
399 vector<WsResultItem>::iterator it;
402 for (it = l.begin(); it != l.end(); ++it, ++i) {
409 return send(sock, answer.toStyledString());
427 set<string> groups =
m_userMap[uid]->getGroups();
430 return send(sock,
"true");
432 return send(sock,
"false");
440 set<string> groups =
m_userMap[uid]->getGroups();
443 return send(sock,
"true");
445 return send(sock,
"false");
454 set<string> groups =
m_userMap[uid]->getGroups();
470 set<string> groups =
m_userMap[uid]->getGroups();
485 set<string> groups =
m_userMap[uid]->getGroups();
498 set<string> groups =
m_userMap[uid]->getGroups();
512 set<string> groups =
m_userMap[uid]->getGroups();
525 set<string> groups =
m_userMap[uid]->getGroups();
527 string rs = boost::lexical_cast<
string>(ret);
528 return send(sock, rs);
537 set<string> groups =
m_userMap[uid]->getGroups();
539 string rs = boost::lexical_cast<
string>(ret);
540 return send(sock, rs);
548 set<string> groups =
m_userMap[uid]->getGroups();
554 return send(sock, answer.toStyledString());
563 return send(sock, rootPath);
571 return send(sock, version);
579 }
else ret = string(static_cast<char*>(msg.data()), msg.size());
586 return m_userMap[uid]->isValidSession(uid, pass, ip);
Reprensents a User session.
DaemonStatus handlePermRequest(zmq::socket_t &sock, Json::Value &root)
sends the permissions of a path to the client
void setSurname(const std::string &surname)
set the surname of the user
Reprensents the menu tree of a group. If a group does not have access to a Node, this Node will not s...
int putLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
unlocks the file by deleting the .config/locks/filename.lock file Only the owner of the lock can unlo...
RequestType enum variables.
DaemonStatus bind(unsigned int numWorkers=1)
start listening on the port
const std::string Surname
WsGlobalProperties * m_conf
std::string getProperty(const std::set< std::string > &groups, const std::string §ion, const std::string &p, const std::string &prop)
get a property for a node corresponding to the path
std::string getUid()
return the user uid WsAuthenticator::authentify must be called before
map< string, WsUserSession * > m_userMap
void setName(const std::string &name)
set the name of the user
std::string getSurname()
return the user surname WsAuthenticator::authentify must be called before
DaemonStatus handleRenameNodeRequest(zmq::socket_t &sock, Json::Value &root)
rename a node
string rawDataToString(zmq::message_t &msg)
converts raw data received on the socket to string
int saveProperty(const std::set< std::string > &groups, const std::string &path, const std::string §ion, const std::string &attr, const std::string &val)
save a property of the node. The user must have access and edit rights for the node.
DaemonStatus parse(const std::string &s, Json::Value &root)
Parses the received data (json)
int saveProperties(const std::set< std::string > &groups, const std::string &json, const std::string &path)
save the properties of the node. The user must have access and edit rights for the node...
DaemonStatus handleCreateNodeRequest(zmq::socket_t &sock, Json::Value &root)
create a node requested by the client
bool isActiveSession(const std::string &uid, const std::string &pass, const std::string &ip)
returns true or false whether the section of a user is still active or not
std::string getEmail()
return the user email WsAuthenticator::authentify must be called before
const std::string NodeType
WsDecompressor * m_decompressor
Redirect operations to adequate class.
Reprensents an access tree.
DaemonStatus handleSavePropertiesRequest(zmq::socket_t &sock, Json::Value &root)
saves the properties received by the client for a node
Loads Authentification module and acts as an interface.
Serializes a tree (WsAccessTree, WsMenuTree).
DaemonStatus receive(zmq::socket_t &sock, std::string &receivedData)
read data from the socket
WsAccessTree * getAccessTree(const std::set< std::string > &groups)
Get the access tree starting from rootPath.
WsFsTreeOperations * m_operation
const std::string & getName()
DaemonStatus handleIsLockedRequest(zmq::socket_t &sock, Json::Value &root)
checks the lock for the path
void setGroups(const std::set< std::string > &groups)
sets the groups of a user
const std::string ModifyDate
std::vector< WsResultItem > getSearchResults(const std::set< std::string > &groups, const std::string &terms)
Get the results for searching for "terms".
zmq::context_t * m_context
int renameNode(const std::set< std::string > &groups, const std::string &uid, const string &path, const string &newPath)
renames a node
const std::string NewPath
DaemonStatus send(zmq::socket_t &sock, const std::string &s)
Sends data on the socket.
int getLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
const std::string Section
WsNodeProperties * getProperties(const std::set< std::string > &groups, const std::string &p)
get properties of a node corresponding to the path
const std::string & getEmail()
const std::string getSerializedForm()
returns the serailized form of the directory
DaemonStatus handleSavePropertyRequest(zmq::socket_t &sock, Json::Value &root)
saves one property received by a client for a node
Json::Value getRoot()
Return the root of the Json tree.
int getPermissions(const std::set< std::string > &groups, const std::string &p)
Get the permissions for a path for a set of groups.
int serialize()
serialize the given data structur
void setEmail(const std::string &email)
set the email of the user
DaemonStatus handlePropsRequest(zmq::socket_t &sock, Json::Value &root)
sends all the properties of a node
DaemonStatus handleGetTreeVersion(zmq::socket_t &sock, Json::Value &root)
sends the last tree version to the client
DaemonStatus handlePutLockRequest(zmq::socket_t &sock, Json::Value &root)
releases the lock for the path
Serialize the menuTree to send it over network.
int deleteNode(const std::set< std::string > &groups, const std::string &uid, const string &path)
delete a node. The user must be an Admin on editor to remove the node
long decompress(const char *data, size_t size, std::string &uncompressedData)
decompress the input data and store result in uncompressedData
WsFsDaemon(WsGlobalProperties *props)
constructor for the server
int isLocked(const std::set< std::string > groups, const std::string &uid, const std::string &path, std::string &id)
check is the path is already locked
std::set< std::string > getUserGroups()
return the user groups WsAuthenticator::authentify must be called before
long compress(const std::string &data, char **compressedData)
compress the input string (data) and puts it in compressedData.
std::set< std::string > getAllGroups()
return all the possible groups WsAuthenticator::authentify must be called before
bool isAdministrator(const std::set< std::string > &groups)
const std::string & getFsTreeStamp()
Get the stamp of the last WsFileSystemTree.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
DaemonStatus handleGetLockRequest(zmq::socket_t &sock, Json::Value &root)
Acquires the lock for the path.
DaemonStatus handlePropRequest(zmq::socket_t &sock, Json::Value &root)
sends a property of a node to the client
const std::string getRootPath()
WsCompressor * m_compressor
DaemonStatus handleAuthRequest(zmq::socket_t &sock, Json::Value &root)
Authenticate user on server Loads the groups which the user belongs to, uid, email, etc..
const std::string & getSurname()
const std::string getSerializedForm()
returns the Json text representing the given structure
set< string > m_allGroups
DaemonStatus handleAccessTreeRequest(zmq::socket_t &sock, Json::Value &root)
Sends the accesstree to the client.
static WsLogWriter * instance()
returns the instance of the WsLogWriter class. If no instance is existing, a new instance will be ret...
bool isEditor(const std::set< std::string > &groups)
int authentify(const std::string &uid, const std::string &pass="", const std::string &ip="")
authentify the user.
DaemonStatus handleRootPathRequest(zmq::socket_t &sock, Json::Value &root)
send the rootPath to the client
const std::string Success
Take charge of FS operations.
DaemonStatus workerRoutine()
const std::string Failure
const std::string Property
std::string getFirstName()
return the user name WsAuthenticator::authentify must be called before
int createNode(const std::set< std::string > &groups, const std::string &uid, const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
DaemonStatus handleIsAdminRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of an admin request so that the client can know if he is an admin or not ...
DaemonStatus handleClearCache(zmq::socket_t &sock, Json::Value &root)
clears the user from the cache
DaemonStatus handleSearchRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of a search request to the client. Only nodes where the user has access are returned...
DaemonStatus handleAllGroupsRequest(zmq::socket_t &sock, Json::Value &root)
sends all the groups available to the client
DaemonStatus handleRequest(zmq::socket_t &sock, Json::Value &root)
Handle received request and redirect to correct method.
DaemonStatus handleIsEditorRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of an editor request so that the client can know if he is an editor or not ...
int update()
Update the WsFileSystemTree.
DaemonStatus handleDeleteNodeRequest(zmq::socket_t &sock, Json::Value &root)
delete a node requested by the client