Compare commits
3 Commits
e95d9bb552
...
31ec926793
| Author | SHA1 | Date | |
|---|---|---|---|
| 31ec926793 | |||
| ed068875c3 | |||
| a1b8d589be |
@@ -16,7 +16,6 @@ jobs:
|
||||
needs: build
|
||||
container:
|
||||
image: node:20
|
||||
steps:
|
||||
steps:
|
||||
- name: Install build tools
|
||||
run: apt update && apt install -y zip
|
||||
|
||||
48
src/configfilemanager.h
Normal file
48
src/configfilemanager.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _CONFIGFILEMANAGER_H
|
||||
#define _CONFIGFILEMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "definitions.h"
|
||||
|
||||
class configfilemanager{
|
||||
private:
|
||||
std::map<std::string, std::string> configs;
|
||||
|
||||
public:
|
||||
configfilemanager(std::string filepath = "./ncsambawatcher.config")
|
||||
{
|
||||
std::ifstream is(filepath);
|
||||
std::string tmp;
|
||||
while(std::getline(is, tmp))
|
||||
{
|
||||
if (tmp.at(0) == '#') // ignore comments
|
||||
continue;
|
||||
|
||||
std::vector<std::string> splited = splitString(tmp, '=');
|
||||
if (splited.size() != 2)
|
||||
{
|
||||
std::cerr << "Invalid line: " << tmp << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
configs.insert(std::make_pair(splited.at(0), splited.at(1)));
|
||||
}
|
||||
}
|
||||
|
||||
std::string at(const std::string &config)
|
||||
{
|
||||
return configs.at(config);
|
||||
}
|
||||
|
||||
std::string at(const char* config)
|
||||
{
|
||||
return at(std::string(config));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // _CONFIGFILEMANAGER_H
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
#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 "
|
||||
#define SCAN_CMD_USR "docker exec --user www-data %1% /var/www/html/occ files:scan --path="
|
||||
#define SCAN_CMD_GRP "docker exec --user www-data %1% /var/www/html/occ groupfolder:scan "
|
||||
|
||||
std::vector<std::string> splitString(const std::string& input, char delimiter);
|
||||
|
||||
#endif // _LOCATIONS_H
|
||||
18
src/main.cpp
18
src/main.cpp
@@ -10,11 +10,27 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include "definitions.h"
|
||||
#include "usermanager.h"
|
||||
#include "configfilemanager.h"
|
||||
|
||||
userManager manager;
|
||||
std::condition_variable cv;
|
||||
std::mutex mtx;
|
||||
configfilemanager cfm;
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, char delimiter = '|')
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
|
||||
while (std::getline(ss, token, delimiter)) {
|
||||
ret.push_back(token);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void readingThreadFunc()
|
||||
{
|
||||
@@ -68,7 +84,7 @@ void scannerThreadFunc()
|
||||
}
|
||||
else if (child == 0) // child
|
||||
{
|
||||
std::string cmd = userManager::getScanCommandFromUser(user);
|
||||
std::string cmd = userManager::getScanCommandFromUser(user, cfm);
|
||||
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
|
||||
std::cerr << "Scan failed" << std::endl;
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
#include "usermanager.h"
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, char delimiter = '|')
|
||||
std::string userManager::getScanCommandFromUser(const std::string &user, configfilemanager &cfm)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
std::string contname = cfm.at("NEXTCLOUD_CONTAINER_NAME");
|
||||
std::string baseCommand;
|
||||
std::string userCommand;
|
||||
|
||||
while (std::getline(ss, token, delimiter)) {
|
||||
ret.push_back(token);
|
||||
}
|
||||
|
||||
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();
|
||||
baseCommand = SCAN_CMD_GRP;
|
||||
userCommand = splitString(user, '/').back();
|
||||
}
|
||||
else
|
||||
{
|
||||
baseCommand = SCAN_CMD_USR;
|
||||
userCommand = user;
|
||||
}
|
||||
|
||||
return std::string(SCAN_CMD_USR) + user;
|
||||
size_t pos = 0;
|
||||
while ((pos = baseCommand.find("%1%", pos)) != std::string::npos) {
|
||||
baseCommand.replace(pos, contname.length(), contname);
|
||||
pos += contname.length(); // Move past the replacement
|
||||
}
|
||||
|
||||
return baseCommand + userCommand;
|
||||
}
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
#include "definitions.h"
|
||||
|
||||
std::vector<std::string> splitString(const std::string& input, char delimiter);
|
||||
#include "configfilemanager.h"
|
||||
|
||||
class userManager
|
||||
{
|
||||
@@ -19,7 +18,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
static std::string getScanCommandFromUser(const std::string&);
|
||||
static std::string getScanCommandFromUser(const std::string&, configfilemanager& cfm);
|
||||
|
||||
void addUserFromLogLine(std::string &line)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user