5 Commits

Author SHA1 Message Date
f1b94cbfd8 Minor fixes
Some checks failed
CI / build (push) Successful in 10s
CI / release (push) Has been cancelled
2025-06-07 15:29:50 +02:00
1b44dd10db Update readme
All checks were successful
CI / build (push) Successful in 11s
CI / release (push) Has been skipped
2025-06-07 15:05:05 +02:00
1fef08bc55 Check necessary configs 2025-06-07 15:04:56 +02:00
4dc9ea3acb Import groupfolders from configfile 2025-06-07 14:41:31 +02:00
3db83f14fe Add users from configfile 2025-06-07 14:33:00 +02:00
5 changed files with 118 additions and 14 deletions

View File

@@ -1,3 +1,57 @@
# nextcloud-samba-sync
# Nextcloud-Samba Sync
A Nextcloud-Samba File scanner system
## Pre installation
- Install `samba` and `vfs-modules`
```
sudo apt update
sudo apt install samba samba-vfs-modules
```
- Create shares. The example is in `configs` folder
## Installation
1. Download a `ncsambawatcher.zip` file from a release above 2.0
2. Extract somewhere on your server (I recommend your user folder)
3. Make sure the samba configuration file is correct (See `configs/smb.24.04.conf`)
4. Configurate the `ncsambawatcher.config` file
<table>
<thead>
<tr>
<td>Name</td>
<td>Required</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<td><code>NEXTCLOUD_CONTAINER_NAME</code></td>
<td>Yes</td>
<td>The nextcloud's docker container name</td>
</tr>
<tr>
<td><code>NEXTCLOUD_USERS</code></td>
<td>No</td>
<td>Usernames separated with spaces</td>
</tr>
<tr>
<td><code>NEXTCLOUD_GROUPFOLDER_IDS</code></td>
<td>No</td>
<td>Groupfolder ids separated with spaces (only the number)</td>
</tr>
</tbody>
</table>
Example 1:
```
NEXTCLOUD_CONTAINER_NAME=nextcloud
```
Example 2: (See `configs/ncsambawatcher.config.default`)
5. Run the `init.sh` script
6. You're done :)
## Notes
- You don't need to add users and groupfolders to the configfile because the program add automaticly from the logfile
- For a user (not groupfolder): The username and the samba share name **MUST BE THE SAME**

View File

@@ -1 +1,3 @@
NEXTCLOUD_CONTAINER_NAME=nextcloud
NEXTCLOUD_USERS=username1 username2 username3
NEXTCLOUD_GROUPFOLDER_IDS=1 2 3 4

View File

@@ -43,6 +43,12 @@ public:
configs.insert(std::make_pair(splited.at(0), splited.at(1)));
}
if (configs.count("NEXTCLOUD_CONTAINER_NAME") == 0)
{
std::cerr << "The container's name not added" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Config file loaded successfuly" << std::endl;
}

View File

@@ -5,6 +5,7 @@
#include <thread>
#include <vector>
#include <set>
#include <unordered_set>
#include <array>
#include <string>
#include <mutex>
@@ -68,7 +69,7 @@ void scannerThreadFunc()
cv.wait(lock, []
{ return manager.isAnybodyFlagged(); });
std::set<std::string> scanUsers = manager.getFlaggedUsers();
std::unordered_set<std::string> scanUsers = manager.getFlaggedUsers();
manager.unflagAllUsers();
lock.unlock();
@@ -85,6 +86,7 @@ void scannerThreadFunc()
else if (child == 0) // child
{
std::string cmd = userManager::getScanCommandFromUser(user, cfm);
std::cout << "Run command: " << cmd << std::endl;
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
std::cerr << "Scan failed" << std::endl;
_exit(EXIT_FAILURE);
@@ -106,6 +108,9 @@ void scannerThreadFunc()
int main()
{
manager.tryAddUsersFromConfig(cfm);
manager.tryAddGroupIDsFromConfig(cfm);
std::thread readingThread(readingThreadFunc);
std::thread scannerThread(scannerThreadFunc);

View File

@@ -4,9 +4,10 @@
#include <string>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <sstream>
#include <mutex>
#include <stdexcept>
#include "definitions.h"
#include "configfilemanager.h"
@@ -25,28 +26,30 @@ public:
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
}
void addUser(std::string &user)
void addUser(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 0)
{
users[user] = false;
std::cout << "User added the list: " << user << std::endl;
}
}
void removeUser(std::string &user)
void removeUser(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
users.erase(user);
std::cout << "User removed the list: " << user << std::endl;
}
bool isContains(std::string &user)
bool isContains(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
return users.count(user) == 1;
}
void setUserFlagged(std::string &user)
void setUserFlagged(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
@@ -55,7 +58,7 @@ public:
}
}
void setUserUnflagged(std::string &user)
void setUserUnflagged(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
@@ -73,9 +76,9 @@ public:
}
}
std::set<std::string> getUsers()
std::unordered_set<std::string> getUsers()
{
std::set<std::string> ret;
std::unordered_set<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
@@ -87,9 +90,9 @@ public:
return ret;
}
std::set<std::string> getFlaggedUsers()
std::unordered_set<std::string> getFlaggedUsers()
{
std::set<std::string> ret;
std::unordered_set<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
@@ -116,6 +119,40 @@ public:
return false;
}
void tryAddUsersFromConfig(configfilemanager &cfm)
{
try
{
std::vector<std::string> alluser = splitString(cfm.at("NEXTCLOUD_USERS"), ' ');
for (const std::string& user : alluser)
{
addUser(user);
}
}
catch (const std::exception &e)
{
std::cerr << "No user added from configuration file" << std::endl;
}
}
void tryAddGroupIDsFromConfig(configfilemanager &cfm)
{
try
{
std::vector<std::string> allids = splitString(cfm.at("NEXTCLOUD_GROUPFOLDER_IDS"), ' ');
for (const std::string& id : allids)
{
addUser("__groupfolders/" + id);
}
}
catch (const std::exception &e)
{
std::cerr << "No groupfolder added from configuration file" << std::endl;
}
}
};
#endif // _USERMAN_H