Support groupfolder scan
This commit is contained in:
11
src/definitions.h
Normal file
11
src/definitions.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _LOCATIONS_H
|
||||||
|
#define _LOCATIONS_H
|
||||||
|
|
||||||
|
#define LOGFILE "journalctl -u smbd --since now -f"
|
||||||
|
|
||||||
|
#define USER_LOG_LOCATION 3
|
||||||
|
|
||||||
|
#define SCAN_CMD_USR "docker exec --user www-data nextcloud /var/www/html/occ files:scan --path="
|
||||||
|
#define SCAN_CMD_GRP "docker exec --user www-data nextcloud /var/www/html/occ groupfolder:scan "
|
||||||
|
|
||||||
|
#endif // _LOCATIONS_H
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#ifndef _LOCATIONS_H
|
|
||||||
#define _LOCATIONS_H
|
|
||||||
|
|
||||||
#define LOGFILE "journalctl -u smbd --since now -f"
|
|
||||||
|
|
||||||
#define USER_LOG_LOCATION 3
|
|
||||||
|
|
||||||
#endif // _LOCATIONS_H
|
|
||||||
@@ -12,8 +12,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "usermanager.h"
|
#include "usermanager.h"
|
||||||
|
|
||||||
#define SCAN_CMD_USR "docker exec --user www-data nextcloud /var/www/html/occ files:scan --path="
|
|
||||||
|
|
||||||
userManager manager;
|
userManager manager;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
@@ -30,7 +28,7 @@ void readingThreadFunc()
|
|||||||
if (line.find('|') == std::string::npos)
|
if (line.find('|') == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::vector<std::string> x = splitLogFile(line, '|');
|
std::vector<std::string> x = splitString(line, '|');
|
||||||
std::string user(x.at(USER_LOG_LOCATION));
|
std::string user(x.at(USER_LOG_LOCATION));
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -70,7 +68,7 @@ void scannerThreadFunc()
|
|||||||
}
|
}
|
||||||
else if (child == 0) // child
|
else if (child == 0) // child
|
||||||
{
|
{
|
||||||
std::string cmd = (std::string(SCAN_CMD_USR) + user);
|
std::string cmd = userManager::getScanCommandFromUser(user);
|
||||||
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
|
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
|
||||||
std::cerr << "Scan failed" << std::endl;
|
std::cerr << "Scan failed" << std::endl;
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "usermanager.h"
|
#include "usermanager.h"
|
||||||
|
|
||||||
std::vector<std::string> splitLogFile(const std::string& input, char delimiter = '|')
|
std::vector<std::string> splitString(const std::string& str, char delimiter = '|')
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
std::stringstream ss(input);
|
std::stringstream ss(str);
|
||||||
std::string token;
|
std::string token;
|
||||||
|
|
||||||
while (std::getline(ss, token, delimiter)) {
|
while (std::getline(ss, token, delimiter)) {
|
||||||
@@ -12,3 +12,13 @@ std::vector<std::string> splitLogFile(const std::string& input, char delimiter =
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string userManager::getScanCommandFromUser(const std::string &user)
|
||||||
|
{
|
||||||
|
if (user.find("__groupfolder") != std::string::npos)
|
||||||
|
{
|
||||||
|
return std::string(SCAN_CMD_GRP) + splitString(user, '/').back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(SCAN_CMD_USR) + user;
|
||||||
|
}
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "locations.h"
|
#include "definitions.h"
|
||||||
|
|
||||||
std::vector<std::string> splitLogFile(const std::string& input, char delimiter);
|
std::vector<std::string> splitString(const std::string& input, char delimiter);
|
||||||
|
|
||||||
class userManager
|
class userManager
|
||||||
{
|
{
|
||||||
@@ -19,9 +19,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static std::string getScanCommandFromUser(const std::string&);
|
||||||
|
|
||||||
void addUserFromLogLine(std::string &line)
|
void addUserFromLogLine(std::string &line)
|
||||||
{
|
{
|
||||||
addUser(splitLogFile(line, '|').at(USER_LOG_LOCATION));
|
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUser(std::string &user)
|
void addUser(std::string &user)
|
||||||
|
|||||||
Reference in New Issue
Block a user